From bb51b61c7901e1b84f8e90b86694dda187a774c9 Mon Sep 17 00:00:00 2001 From: gameloader Date: Thu, 24 Nov 2022 19:01:27 +0800 Subject: [PATCH] change to pylsp add vue change to jaq to run code --- .gitignore | 3 +- init.lua | 4 +- lua/autocmd.lua | 4 +- lua/keybindings.lua | 9 +++- lua/lsp/config/pylsp.lua | 44 +++++++++++++++++++ lua/lsp/config/vue.lua | 44 ++++++++++++++++++- lua/lsp/init.lua | 7 ++-- lua/lsp/null-ls.lua | 2 + lua/plugin-config/JABS.lua | 1 - lua/plugin-config/coderunner.lua | 9 ---- lua/plugin-config/jaq.lua | 72 ++++++++++++++++++++++++++++++++ lua/plugins.lua | 6 ++- snippets/package.json | 6 +++ 13 files changed, 188 insertions(+), 23 deletions(-) create mode 100644 lua/lsp/config/pylsp.lua delete mode 100644 lua/plugin-config/JABS.lua delete mode 100644 lua/plugin-config/coderunner.lua create mode 100644 lua/plugin-config/jaq.lua diff --git a/.gitignore b/.gitignore index 6a57896..f8fd5a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ plugin .DS_Store -snippets/go.json \ No newline at end of file +snippets/go.json +snippets/python.json \ No newline at end of file diff --git a/init.lua b/init.lua index dd9e664..693c29b 100644 --- a/init.lua +++ b/init.lua @@ -23,12 +23,10 @@ require("plugin-config/dashboard") require("plugin-config/neoscroll") require("plugin-config/hop") require("plugin-config/live_command") --- require("plugin-config/JABS") +require("plugin-config/jaq") require("plugin-config/toggleterm") require("plugin-config/indent-blankline") -require("plugin-config/coderunner") require("plugin-config/lazygit") --- require("plugin-config/neogit") require("autocmd") require("lsp") diff --git a/lua/autocmd.lua b/lua/autocmd.lua index 8a3fb5b..7b7e511 100644 --- a/lua/autocmd.lua +++ b/lua/autocmd.lua @@ -18,8 +18,8 @@ end local autoCommands = { -- other autocommands open_folds = { - { "BufEnter", "*", "normal zx" }, - { "BufEnter", "*", "normal zR" }, + { "BufAdd", "*", "normal zx" }, + { "BufEnter,BufModifiedSet", "*", "normal zR" }, }, } diff --git a/lua/keybindings.lua b/lua/keybindings.lua index fa7b386..3cb2297 100644 --- a/lua/keybindings.lua +++ b/lua/keybindings.lua @@ -31,7 +31,7 @@ end -- code related -- 代码相关 -map("n", ",", ":RunCode", opt) +map("n", ",", ":Jaq", opt) -- markdown related -- markdown 相关 @@ -115,6 +115,8 @@ wk.register({ b = { ":Telescope buffers", "Open buffers" }, n = { ":ls", "Buffer numbers" }, c = { ":noh", "Cancel highlight" }, + C = { ":call setqflist([], 'r')", "Clear quickfix" }, + q = { ":copen", "Open quickfix" }, s = { ":Telescope current_buffer_fuzzy_find", "Searching in buffer" }, }, }) @@ -207,6 +209,11 @@ function SetKeybinds() ["d"] = { ":HeaderDecrease", "All header decrease" }, ["i"] = { ":HeaderIncrease", "All header increase" }, }, opts) + elseif fileTy == "python" then + wk.register({ + ["r"] = { ":MagmaEvaluateOperator", "Jupyter evaluate" }, + ["c"] = { ":MagmaEvaluateCell", "Jupyter evaluate cell" }, + }, opts) -- elseif fileTy == "sh" then -- wk.register({ -- ["W"] = { ":w", "test write" }, diff --git a/lua/lsp/config/pylsp.lua b/lua/lsp/config/pylsp.lua new file mode 100644 index 0000000..9df9c36 --- /dev/null +++ b/lua/lsp/config/pylsp.lua @@ -0,0 +1,44 @@ +return { + on_setup = function(server) + server.setup({ + settings = { + pylsp = { + plugins = { + pycodestyle = { + ignore = { "E501" }, + }, + }, + }, + }, + flags = { + debounce_text_changes = 150, + }, + on_attach = function(client, bufnr) + -- 禁用格式化功能,交给专门插件插件处理 + client.server_capabilities.document_formatting = false + client.server_capabilities.document_range_formatting = false + + vim.api.nvim_create_autocmd("CursorHold", { + buffer = bufnr, + callback = function() + local opts = { + focusable = false, + close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, + border = "rounded", + source = "always", + prefix = " ", + scope = "cursor", + } + vim.diagnostic.open_float(nil, opts) + end, + }) + local function buf_set_keymap(...) + vim.api.nvim_buf_set_keymap(bufnr, ...) + end + -- local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + -- 绑定快捷键 + require("keybindings").maplsp(buf_set_keymap) + end, + }) + end, +} diff --git a/lua/lsp/config/vue.lua b/lua/lsp/config/vue.lua index 723c978..8a851b7 100644 --- a/lua/lsp/config/vue.lua +++ b/lua/lsp/config/vue.lua @@ -1 +1,43 @@ -return require("lsp.config.basic_config") +return { + on_setup = function(server) + server.setup({ + filetypes = { + "typescript", + "javascript", + "javascriptreact", + "typescriptreact", + "vue", + "json", + }, + flags = { + debounce_text_changes = 150, + }, + on_attach = function(client, bufnr) + -- 禁用格式化功能,交给专门插件插件处理 + client.server_capabilities.document_formatting = false + client.server_capabilities.document_range_formatting = false + + vim.api.nvim_create_autocmd("CursorHold", { + buffer = bufnr, + callback = function() + local opts = { + focusable = false, + close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, + border = "rounded", + source = "always", + prefix = " ", + scope = "cursor", + } + vim.diagnostic.open_float(nil, opts) + end, + }) + local function buf_set_keymap(...) + vim.api.nvim_buf_set_keymap(bufnr, ...) + end + -- local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + -- 绑定快捷键 + require("keybindings").maplsp(buf_set_keymap) + end, + }) + end, +} diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 6482be7..98250ea 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -10,14 +10,15 @@ local servers = { gopls = require("lsp.config.gopls"), eslint = require("lsp.config.eslint"), -- bashls = require("lsp.config.bash"), - pyright = require("lsp.config.pyright"), + -- pyright = require("lsp.config.pyright"), + pylsp = require("lsp.config.pylsp"), + volar = require("lsp.config.vue"), -- jedi_language_server = require("lsp.config.jedi"), - vuels = require("lsp.config.vue"), -- html = require("lsp.config.html"), -- cssls = require("lsp.config.css"), -- emmet_ls = require("lsp.config.emmet"), -- jsonls = require("lsp.config.json"), - tsserver = require("lsp.config.ts"), + -- tsserver = require("lsp.config.ts"), -- rust_analyzer = require("lsp.config.rust"), -- yamlls = require("lsp.config.yamlls"), -- remark_ls = require("lsp.config.markdown"), diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index 451f24b..d4d48d7 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -16,6 +16,8 @@ require("null-ls").setup({ require("null-ls").builtins.formatting.clang_format, require("null-ls").builtins.formatting.gofmt, require("null-ls").builtins.formatting.black, + require("null-ls").builtins.formatting.eslint_d, + require("null-ls").builtins.formatting.jq, }, -- you can reuse a shared lspconfig on_attach callback here on_attach = function(client, bufnr) diff --git a/lua/plugin-config/JABS.lua b/lua/plugin-config/JABS.lua deleted file mode 100644 index bb9cde3..0000000 --- a/lua/plugin-config/JABS.lua +++ /dev/null @@ -1 +0,0 @@ -require("jabs").setup({}) diff --git a/lua/plugin-config/coderunner.lua b/lua/plugin-config/coderunner.lua deleted file mode 100644 index ba61ff3..0000000 --- a/lua/plugin-config/coderunner.lua +++ /dev/null @@ -1,9 +0,0 @@ -require("code_runner").setup({ - focus = false, - filetype = { - c = "cd $dir && gcc $fileName -o $fileNameWithoutExt -g && $dir/$fileNameWithoutExt", - cpp = "cd $dir && g++ $fileName -o $fileNameWithoutExt -g -w -std=c++11 && $dir/$fileNameWithoutExt", - go = "cd $dir && go run $fileName", - python = "cd $dir && python3 $fileName", - }, -}) diff --git a/lua/plugin-config/jaq.lua b/lua/plugin-config/jaq.lua new file mode 100644 index 0000000..4ea954b --- /dev/null +++ b/lua/plugin-config/jaq.lua @@ -0,0 +1,72 @@ +require("jaq-nvim").setup({ + cmds = { + -- Uses vim commands + internal = { + lua = "luafile %", + vim = "source %", + }, + + -- Uses shell commands + external = { + markdown = "glow %", + python = "python %", + go = "go run %", + sh = "sh %", + c = "cd $dir && gcc $file -o $fileBase -g && $dir/$fileBase", + cpp = "cd $dir && g++ $file -o $fileBase -g -w -std=c++11 && $dir/$fileBase", + }, + }, + + behavior = { + -- Default type + default = "terminal", + + -- Start in insert mode + startinsert = false, + + -- Use `wincmd p` on startup + wincmd = false, + + -- Auto-save files + autosave = false, + }, + + ui = { + float = { + -- See ':h nvim_open_win' + border = "none", + + -- See ':h winhl' + winhl = "Normal", + borderhl = "FloatBorder", + + -- See ':h winblend' + winblend = 0, + + -- Num from `0-1` for measurements + height = 0.8, + width = 0.8, + x = 0.5, + y = 0.5, + }, + + terminal = { + -- Window position + position = "bot", + + -- Window size + size = 10, + + -- Disable line numbers + line_no = false, + }, + + quickfix = { + -- Window position + position = "bot", + + -- Window size + size = 10, + }, + }, +}) diff --git a/lua/plugins.lua b/lua/plugins.lua index 79d9cf1..f16ab3e 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -153,8 +153,7 @@ return require("packer").startup(function() -- coderunner -- 代码运行 - use({ "CRAG666/code_runner.nvim", requires = "nvim-lua/plenary.nvim" }) - + use({ "is0n/jaq-nvim" }) -- cmake support -- cmake 支持 use("Civitasv/cmake-tools.nvim") @@ -194,6 +193,9 @@ return require("packer").startup(function() -- copilot 增强 use("github/copilot.vim") + ------------------- repl ---------------------- + use({ "hkupty/iron.nvim" }) + ------------------- dap ----------------------- -- dap for neovim -- dap ui和适配器 diff --git a/snippets/package.json b/snippets/package.json index d62a287..f73c9d2 100644 --- a/snippets/package.json +++ b/snippets/package.json @@ -13,6 +13,12 @@ "markdown" ], "path":"./markdown.json" + }, + { + "language":[ + "python" + ], + "path":"./python.json" } ] }