From 474f961b2a31c0fe8281188150c08cc2849bf4df Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Tue, 9 Mar 2021 23:55:11 -0500 Subject: Native LSP, more Lua, less CoC --- lua/lsp/bash-ls.lua | 3 +++ lua/lsp/css-ls.lua | 3 +++ lua/lsp/docker-ls.lua | 3 +++ lua/lsp/graphql-ls.lua | 3 +++ lua/lsp/html-ls.lua | 11 +++++++++ lua/lsp/javascript-ls.lua | 3 +++ lua/lsp/json-ls.lua | 11 +++++++++ lua/lsp/lsp-config.lua | 61 +++++++++++++++++++++++++++++++++++++++++++++++ lua/lsp/lsp-kind.lua | 27 +++++++++++++++++++++ lua/lsp/lua-ls.lua | 42 ++++++++++++++++++++++++++++++++ lua/lsp/python-ls.lua | 3 +++ lua/lsp/vim-ls.lua | 3 +++ lua/lsp/yaml-ls.lua | 3 +++ 13 files changed, 176 insertions(+) create mode 100644 lua/lsp/bash-ls.lua create mode 100644 lua/lsp/css-ls.lua create mode 100644 lua/lsp/docker-ls.lua create mode 100644 lua/lsp/graphql-ls.lua create mode 100644 lua/lsp/html-ls.lua create mode 100644 lua/lsp/javascript-ls.lua create mode 100644 lua/lsp/json-ls.lua create mode 100644 lua/lsp/lsp-config.lua create mode 100644 lua/lsp/lsp-kind.lua create mode 100644 lua/lsp/lua-ls.lua create mode 100644 lua/lsp/python-ls.lua create mode 100644 lua/lsp/vim-ls.lua create mode 100644 lua/lsp/yaml-ls.lua (limited to 'lua/lsp') diff --git a/lua/lsp/bash-ls.lua b/lua/lsp/bash-ls.lua new file mode 100644 index 00000000..ae3e7d70 --- /dev/null +++ b/lua/lsp/bash-ls.lua @@ -0,0 +1,3 @@ +-- npm i -g bash-language-server +require'lspconfig'.bashls.setup{} + diff --git a/lua/lsp/css-ls.lua b/lua/lsp/css-ls.lua new file mode 100644 index 00000000..337fd585 --- /dev/null +++ b/lua/lsp/css-ls.lua @@ -0,0 +1,3 @@ +-- npm install -g vscode-css-languageserver-bin +require'lspconfig'.cssls.setup{} + diff --git a/lua/lsp/docker-ls.lua b/lua/lsp/docker-ls.lua new file mode 100644 index 00000000..32b8b946 --- /dev/null +++ b/lua/lsp/docker-ls.lua @@ -0,0 +1,3 @@ +-- npm install -g dockerfile-language-server-nodejs +require'lspconfig'.dockerls.setup{} + diff --git a/lua/lsp/graphql-ls.lua b/lua/lsp/graphql-ls.lua new file mode 100644 index 00000000..6369446d --- /dev/null +++ b/lua/lsp/graphql-ls.lua @@ -0,0 +1,3 @@ +-- npm install -g graphql-language-service-cli +require'lspconfig'.graphql.setup{} + diff --git a/lua/lsp/html-ls.lua b/lua/lsp/html-ls.lua new file mode 100644 index 00000000..b27650a6 --- /dev/null +++ b/lua/lsp/html-ls.lua @@ -0,0 +1,11 @@ +-- npm install -g vscode-html-languageserver-bin +--Enable (broadcasting) snippet capability for completion +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities.textDocument.completion.completionItem.snippetSupport = true + +require'lspconfig'.html.setup { + capabilities = capabilities, +} + + +require'lspconfig'.html.setup{} diff --git a/lua/lsp/javascript-ls.lua b/lua/lsp/javascript-ls.lua new file mode 100644 index 00000000..62ca0675 --- /dev/null +++ b/lua/lsp/javascript-ls.lua @@ -0,0 +1,3 @@ +-- npm install -g typescript typescript-language-server +require'lspconfig'.tsserver.setup{} + diff --git a/lua/lsp/json-ls.lua b/lua/lsp/json-ls.lua new file mode 100644 index 00000000..474f1803 --- /dev/null +++ b/lua/lsp/json-ls.lua @@ -0,0 +1,11 @@ +-- npm install -g vscode-json-languageserver +require'lspconfig'.jsonls.setup { + commands = { + Format = { + function() + vim.lsp.buf.range_formatting({},{0,0},{vim.fn.line("$"),0}) + end + } + } +} + diff --git a/lua/lsp/lsp-config.lua b/lua/lsp/lsp-config.lua new file mode 100644 index 00000000..74b82865 --- /dev/null +++ b/lua/lsp/lsp-config.lua @@ -0,0 +1,61 @@ +-- local nvim_lsp = require('lspconfig') +-- local on_attach = function(client, bufnr) +-- 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 + +-- buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + +-- -- Mappings. +-- local opts = { noremap=true, silent=true } +-- buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) +-- -- buf_set_keymap('n', 'gd', ':lua vim.lsp.buf.definition()') +-- buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) +-- buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) +-- buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) +-- buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) +-- buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) +-- buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) +-- buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) +-- buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) +-- buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) +-- -- buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) +-- buf_set_keymap('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) +-- buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) +-- buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) +-- buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) + +-- -- *vim.lsp.buf.code_action() + +-- -- Set some keybinds conditional on server capabilities +-- if client.resolved_capabilities.document_formatting then +-- buf_set_keymap("n", "f", "lua vim.lsp.buf.formatting()", opts) +-- elseif client.resolved_capabilities.document_range_formatting then +-- buf_set_keymap("n", "f", "lua vim.lsp.buf.range_formatting()", opts) +-- end +-- -- Set autocommands conditional on server_capabilities +-- -- if client.resolved_capabilities.document_highlight then +-- -- vim.api.nvim_exec([[ +-- -- hi LspReferenceRead cterm=bold ctermbg=red guibg=Pink +-- -- hi LspReferenceText cterm=bold ctermbg=red guibg=Pink +-- -- hi LspReferenceWrite cterm=bold ctermbg=red guibg=Pink +-- -- augroup lsp_document_highlight +-- -- autocmd! * +-- -- autocmd CursorHold lua vim.lsp.buf.document_highlight() +-- -- autocmd CursorMoved lua vim.lsp.buf.clear_references() +-- -- augroup END +-- -- ]], false) +-- -- end +-- end + +-- -- Use a loop to conveniently both setup defined servers +-- -- and map buffer local keybindings when the language server attaches +-- local servers = { "pyright", "rust_analyzer", "tsserver" } +-- for _, lsp in ipairs(servers) do +-- nvim_lsp[lsp].setup { on_attach = on_attach } +-- end + + +vim.fn.sign_define("LspDiagnosticsSignError", {text = "", numhl = "LspDiagnosticsDefaultError"}) +vim.fn.sign_define("LspDiagnosticsSignWarning", {text = "", numhl = "LspDiagnosticsDefaultWarning"}) +vim.fn.sign_define("LspDiagnosticsSignInformation", {text = "", numhl = "LspDiagnosticsDefaultInformation"}) +vim.fn.sign_define("LspDiagnosticsSignHint", {text = "", numhl = "LspDiagnosticsDefaultHint"}) diff --git a/lua/lsp/lsp-kind.lua b/lua/lsp/lsp-kind.lua new file mode 100644 index 00000000..7ac3fefa --- /dev/null +++ b/lua/lsp/lsp-kind.lua @@ -0,0 +1,27 @@ +-- commented options are defaults +require('lspkind').init({ + with_text = false, + symbol_map = { + Text = '  ', + Method = '  ', + Function = '  ', + Constructor = '  ', + Variable = '[]', + Class = '  ', + Interface = ' 蘒', + Module = '  ', + Property = '  ', + Unit = ' 塞 ', + Value = '  ', + Enum = ' 練', + Keyword = '  ', + Snippet = '  ', + Color = '', + File = '', + Folder = ' ﱮ ', + EnumMember = '  ', + Constant = '  ', + Struct = '  ' + }, +}) + diff --git a/lua/lsp/lua-ls.lua b/lua/lsp/lua-ls.lua new file mode 100644 index 00000000..95e72216 --- /dev/null +++ b/lua/lsp/lua-ls.lua @@ -0,0 +1,42 @@ +-- https://github.com/sumneko/lua-language-server/wiki/Build-and-Run-(Standalone) +-- TODO fix for different systems and put variable for user + +-- local system_name +-- if vim.fn.has("mac") == 1 then +-- system_name = "macOS" +-- elseif vim.fn.has("unix") == 1 then +-- system_name = "Linux" +-- elseif vim.fn.has('win32') == 1 then +-- system_name = "Windows" +-- else +-- print("Unsupported system for sumneko") +-- end + +-- set the path to the sumneko installation; if you previously installed via the now deprecated :LspInstall, use +local sumneko_root_path = "/Users/chris/.config/nvim/lua-language-server" +local sumneko_binary = "/Users/chris/.config/nvim/lua-language-server/bin/macOS/lua-language-server" + +require'lspconfig'.sumneko_lua.setup { + cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"}; + 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 = vim.split(package.path, ';'), + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = {'vim'}, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = { + [vim.fn.expand('$VIMRUNTIME/lua')] = true, + [vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true, + }, + }, + }, + }, +} diff --git a/lua/lsp/python-ls.lua b/lua/lsp/python-ls.lua new file mode 100644 index 00000000..0be71acb --- /dev/null +++ b/lua/lsp/python-ls.lua @@ -0,0 +1,3 @@ +-- npm i -g pyright +require'lspconfig'.pyright.setup{} + diff --git a/lua/lsp/vim-ls.lua b/lua/lsp/vim-ls.lua new file mode 100644 index 00000000..ac1e6e19 --- /dev/null +++ b/lua/lsp/vim-ls.lua @@ -0,0 +1,3 @@ +-- npm install -g vim-language-server +require'lspconfig'.vimls.setup{} + diff --git a/lua/lsp/yaml-ls.lua b/lua/lsp/yaml-ls.lua new file mode 100644 index 00000000..6b2de91e --- /dev/null +++ b/lua/lsp/yaml-ls.lua @@ -0,0 +1,3 @@ +-- npm install -g yaml-language-server +require'lspconfig'.yamlls.setup{} + -- cgit v1.2.3