diff --git a/lua/frame/setup.lua b/lua/frame/setup.lua index 5e707e6..46964ab 100644 --- a/lua/frame/setup.lua +++ b/lua/frame/setup.lua @@ -6,6 +6,7 @@ local tree_cb = require 'nvim-tree.config'.nvim_tree_callback -- following optio -- a add file/dir require 'nvim-tree'.setup { open_on_setup = true; + open_on_setup_file = false, git = { enable = true, ignore = true, @@ -21,6 +22,7 @@ require 'nvim-tree'.setup { args = {}, }, view = { + width = 24, mappings = { custom_only = true, list = { @@ -68,7 +70,7 @@ vim.cmd([[colorscheme gruvbox]]) vim.opt.termguicolors = true require("bufferline").setup { options = { - sort_by = 'insert_after_current', + sort_by = 'id', numbers = 'ordinal', -- 左侧让出 nvim-tree 的位置 diagnostics = "nvim_lsp"; diff --git a/lua/lsp/base.lua b/lua/lsp/base.lua index c7ebcf2..97aeadd 100644 --- a/lua/lsp/base.lua +++ b/lua/lsp/base.lua @@ -1,27 +1,2 @@ -local runtime_path = vim.split(package.path, ';') -table.insert(runtime_path, "lua/?.lua") -table.insert(runtime_path, "lua/?/init.lua") return { - settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = 'LuaJIT', - -- Setup your lua path - path = runtime_path, - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = {'vim'}, - }, - workspace = { - -- Make the server aware of Neovim runtime files - library = vim.api.nvim_get_runtime_file("", true), - }, - -- Do not send telemetry data containing a randomized but unique identifier - telemetry = { - enable = false - }, - }, - }, } diff --git a/lua/lsp/eslint.lua b/lua/lsp/eslint.lua new file mode 100644 index 0000000..e5fc460 --- /dev/null +++ b/lua/lsp/eslint.lua @@ -0,0 +1,13 @@ +local eslint_config = require("lspconfig.server_configurations.eslint") + +return { + on_attach = function(client, bufnr) + -- neovim's LSP client does not currently support dynamic capabilities registration, so we need to set + -- the resolved capabilities of the eslint server ourselves! + client.resolved_capabilities.document_formatting = true + end, + settings = { + format = { enable = true }, + }, + cmd = { "yarn", "exec", unpack(eslint_config.default_config.cmd) } +} diff --git a/lua/lsp/lua.lua b/lua/lsp/lua.lua index e69de29..4ea38c0 100644 --- a/lua/lsp/lua.lua +++ b/lua/lsp/lua.lua @@ -0,0 +1,27 @@ +local runtime_path = vim.split(package.path, ';') +table.insert(runtime_path, "lua/?.lua") +table.insert(runtime_path, "lua/?/init.lua") +return { + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + -- Setup your lua path + path = runtime_path, + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { 'vim' }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false + }, + }, + }, +} diff --git a/lua/lsp/setup.lua b/lua/lsp/setup.lua index c7f5c1b..956b866 100644 --- a/lua/lsp/setup.lua +++ b/lua/lsp/setup.lua @@ -6,33 +6,10 @@ local lsp_installer = require "nvim-lsp-installer" -- Mappings. -- See `:help vim.diagnostic.*` for documentation on any of the below functions local keyOpts = { noremap = true, silent = true } -vim.api.nvim_set_keymap('n', 'e', 'lua vim.diagnostic.open_float()', keyOpts) -vim.api.nvim_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', keyOpts) -vim.api.nvim_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', keyOpts) -vim.api.nvim_set_keymap('n', 'q', 'lua vim.diagnostic.setloclist()', keyOpts) - --- Use an on_attach function to only map the following keys --- after the language server attaches to the current buffer -local on_attach = function(client, bufnr) - -- Enable completion triggered by - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') - - -- Mappings. - -- See `:help vim.lsp.*` for documentation on any of the below functions - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', keyOpts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', '', 'lua vim.lsp.buf.definition()', keyOpts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', keyOpts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()', keyOpts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', '', 'lua vim.lsp.buf.signature_help()', keyOpts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', keyOpts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', keyOpts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', keyOpts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'D', 'lua vim.lsp.buf.type_definition()', keyOpts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()', keyOpts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()', keyOpts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', keyOpts) - vim.api.nvim_buf_set_keymap(bufnr, 'n', 'f', 'lua vim.lsp.buf.formatting()', keyOpts) -end +-- vim.api.nvim_buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') +vim.api.nvim_set_keymap('n', '', 'lua vim.lsp.buf.definition()', keyOpts) +vim.api.nvim_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', keyOpts) +vim.api.nvim_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', keyOpts) @@ -40,9 +17,17 @@ end -- https://github.com/williamboman/nvim-lsp-installer#available-lsps -- { key: 语言 value: 配置文件 } local servers = { - sumneko_lua = require "lsp.base", -- /lua/lsp/lua.lua + sumneko_lua = require "lsp.lua", -- /lua/lsp/lua.lua gopls = require "lsp.base", - volar = require "lsp.base" + volar = require "lsp.base", + basels = require "lsp.base", + cssls = require "lsp.base", + eslint = require "lsp.eslint", + tsserver = require "lsp.base", + prosemd_lsp = require "lsp.base", + pyright = require "lsp.base", + rust_analyzer = require "lsp.base", + tailwindcss = require "lsp.base", } -- 自动安装 LanguageServers @@ -58,7 +43,6 @@ end lsp_installer.on_server_ready(function(server) local opts = servers[server.name] - opts.on_attach = on_attach opts.capabilities = capabilities opts.flags = { debounce_text_changes = 150, @@ -74,45 +58,45 @@ require('nvim-ts-autotag').setup() -- nvim-cmp setup local cmp = require 'cmp' -cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = '' } })) +cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = '' } })) cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }, - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { 'i', 's' }), - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { 'i', 's' }), - }), - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'buffer' }, - { name = 'path' } - }, + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { 'i', 's' }), + }), + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'buffer' }, + { name = 'path' } + }, } diff --git a/lua/plugins.lua b/lua/plugins.lua index 5f77b1b..575252e 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -12,6 +12,7 @@ return require('packer').startup(function() use { 'neovim/nvim-lspconfig', 'williamboman/nvim-lsp-installer' } use 'windwp/nvim-autopairs' + use 'windwp/nvim-ts-autotag' use 'hrsh7th/nvim-cmp' diff --git a/maps.vim b/maps.vim index b1483a0..ef5bc02 100644 --- a/maps.vim +++ b/maps.vim @@ -37,8 +37,8 @@ nnoremap H ^ " nmap q :wqa -nmap q :wq! -nmap Q :wqa! +nmap q :BufferLineCycleNext:BufferLineCloseLeft +nmap Q :qa! " 重新加载设置 map R :source ~/.config/nvim/init.vim diff --git a/vimrc.vim b/vimrc.vim index d33e885..b8034eb 100644 --- a/vimrc.vim +++ b/vimrc.vim @@ -22,7 +22,7 @@ au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g " 始终显示左侧符号栏 如git error信息等 -set signcolumn=yes:2 +set signcolumn=yes:1 " 在文件外修改时自动加载 set autoread