summaryrefslogtreecommitdiff
path: root/lua/lsp
diff options
context:
space:
mode:
Diffstat (limited to 'lua/lsp')
-rw-r--r--lua/lsp/angular-ls.lua6
-rw-r--r--lua/lsp/emmet-ls.lua23
-rw-r--r--lua/lsp/init.lua227
-rw-r--r--lua/lsp/null-ls.lua83
-rw-r--r--lua/lsp/svelte-ls.lua5
-rw-r--r--lua/lsp/tailwindcss-ls.lua13
-rw-r--r--lua/lsp/ts-fmt-lint.lua49
-rw-r--r--lua/lsp/tsserver-ls.lua67
8 files changed, 232 insertions, 241 deletions
diff --git a/lua/lsp/angular-ls.lua b/lua/lsp/angular-ls.lua
deleted file mode 100644
index 818faf38..00000000
--- a/lua/lsp/angular-ls.lua
+++ /dev/null
@@ -1,6 +0,0 @@
--- TODO: find correct root filetype
--- :LspInstall angular
-require("lspconfig").angularls.setup {
- cmd = { DATA_PATH .. "/lspinstall/angular/node_modules/@angular/language-server/bin/ngserver", "--stdio" },
- on_attach = require("lsp").common_on_attach,
-}
diff --git a/lua/lsp/emmet-ls.lua b/lua/lsp/emmet-ls.lua
deleted file mode 100644
index e38747ac..00000000
--- a/lua/lsp/emmet-ls.lua
+++ /dev/null
@@ -1,23 +0,0 @@
--- if not package.loaded['lspconfig'] then
--- return
--- end
-
-local nvim_lsp = require "lspconfig"
-local configs = require "lspconfig/configs"
-local capabilities = vim.lsp.protocol.make_client_capabilities()
-capabilities.textDocument.completion.completionItem.snippetSupport = true
-
-configs.emmet_ls = {
- default_config = {
- cmd = { "emmet-ls", "--stdio" },
- filetypes = { "html", "css", "javascript", "typescript", "vue" },
- root_dir = function()
- return vim.loop.cwd()
- end,
- settings = {},
- },
-}
-
-nvim_lsp.emmet_ls.setup {
- -- on_attach = on_attach;
-}
diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua
index 01f82737..5a0d6c1e 100644
--- a/lua/lsp/init.lua
+++ b/lua/lsp/init.lua
@@ -1,4 +1,5 @@
--- TODO: figure out why this don't work
+local lsp_config = {}
+
vim.fn.sign_define(
"LspDiagnosticsSignError",
{ texthl = "LspDiagnosticsSignError", text = "", numhl = "LspDiagnosticsSignError" }
@@ -16,37 +17,68 @@ vim.fn.sign_define(
{ texthl = "LspDiagnosticsSignInformation", text = "", numhl = "LspDiagnosticsSignInformation" }
)
-vim.cmd "nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>"
-vim.cmd "nnoremap <silent> gD <cmd>lua vim.lsp.buf.declaration()<CR>"
-vim.cmd "nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>"
-vim.cmd "nnoremap <silent> gi <cmd>lua vim.lsp.buf.implementation()<CR>"
-vim.cmd "nnoremap <silent> gp <cmd>lua require'lsp'.PeekDefinition()<CR>"
-vim.cmd "nnoremap <silent> K :lua vim.lsp.buf.hover()<CR>"
--- vim.cmd('nnoremap <silent> <C-k> <cmd>lua vim.lsp.buf.signature_help()<CR>')
-vim.cmd "nnoremap <silent> <C-p> :lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = O.lsp.popup_border}})<CR>"
-vim.cmd "nnoremap <silent> <C-n> :lua vim.lsp.diagnostic.goto_next({popup_opts = {border = O.lsp.popup_border}})<CR>"
--- scroll down hover doc or scroll in definition preview
--- scroll up hover doc
-vim.cmd 'command! -nargs=0 LspVirtualTextToggle lua require("lsp/virtual_text").toggle()'
+-- local opts = { border = "single" }
+-- TODO revisit this
+-- local border = {
+-- { "🭽", "FloatBorder" },
+-- { "▔", "FloatBorder" },
+-- { "🭾", "FloatBorder" },
+-- { "▕", "FloatBorder" },
+-- { "🭿", "FloatBorder" },
+-- { "▁", "FloatBorder" },
+-- { "🭼", "FloatBorder" },
+-- { "▏", "FloatBorder" },
+-- }
+
+-- My font didn't like this :/
+-- vim.api.nvim_set_keymap(
+-- "n",
+-- "gl",
+-- '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics({ show_header = false, border = { { "🭽", "FloatBorder" }, { "▔", "FloatBorder" }, { "🭾", "FloatBorder" }, { "▕", "FloatBorder" }, { "🭿", "FloatBorder" }, { "▁", "FloatBorder" }, { "🭼", "FloatBorder" }, { "▏", "FloatBorder" }, } })<CR>',
+-- { noremap = true, silent = true }
+-- )
+
+function lsp_config.setup_default_bindings()
+ if lvim.lsp.default_keybinds then
+ vim.cmd "nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>"
+ vim.cmd "nnoremap <silent> gD <cmd>lua vim.lsp.buf.declaration()<CR>"
+ vim.cmd "nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>"
+ vim.cmd "nnoremap <silent> gi <cmd>lua vim.lsp.buf.implementation()<CR>"
+ vim.api.nvim_set_keymap(
+ "n",
+ "gl",
+ '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics({ show_header = false, border = "single" })<CR>',
+ { noremap = true, silent = true }
+ )
+
+ vim.cmd "nnoremap <silent> gp <cmd>lua require'lsp'.PeekDefinition()<CR>"
+ vim.cmd "nnoremap <silent> K :lua vim.lsp.buf.hover()<CR>"
+ vim.cmd "nnoremap <silent> <C-p> :lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})<CR>"
+ vim.cmd "nnoremap <silent> <C-n> :lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})<CR>"
+ -- vim.cmd "nnoremap <silent> <tab> <cmd>lua vim.lsp.buf.signature_help()<CR>"
+ -- scroll down hover doc or scroll in definition preview
+ -- scroll up hover doc
+ vim.cmd 'command! -nargs=0 LspVirtualTextToggle lua require("lsp/virtual_text").toggle()'
+ end
+end
-- Set Default Prefix.
-- Note: You can set a prefix per lsp server in the lv-globals.lua file
-vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
- virtual_text = {
- prefix = "",
- spacing = 0,
- },
- signs = true,
- underline = true,
-})
+function lsp_config.setup_handlers()
+ vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
+ virtual_text = lvim.lsp.diagnostics.virtual_text,
+ signs = lvim.lsp.diagnostics.signs,
+ underline = lvim.lsp.document_highlight,
+ })
-vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
- border = O.lsp.popup_border,
-})
+ vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
+ border = lvim.lsp.popup_border,
+ })
-vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
- border = O.lsp.popup_border,
-})
+ vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
+ border = lvim.lsp.popup_border,
+ })
+end
-- symbols for autocomplete
vim.lsp.protocol.CompletionItemKind = {
@@ -84,7 +116,10 @@ autocmd BufWritePre *.lua lua vim.lsp.buf.formatting_sync(nil, 100) ]]
-- Java
-- autocmd FileType java nnoremap ca <Cmd>lua require('jdtls').code_action()<CR>
-local function documentHighlight(client, bufnr)
+local function lsp_highlight_document(client)
+ if lvim.lsp.document_highlight == false then
+ return -- we don't need further
+ end
-- Set autocommands conditional on server_capabilities
if client.resolved_capabilities.document_highlight then
vim.api.nvim_exec(
@@ -102,7 +137,6 @@ local function documentHighlight(client, bufnr)
)
end
end
-local lsp_config = {}
-- Taken from https://www.reddit.com/r/neovim/comments/gyb077/nvimlsp_peek_defination_javascript_ttserver/
function lsp_config.preview_location(location, context, before_context)
@@ -126,7 +160,7 @@ function lsp_config.preview_location(location, context, before_context)
false
)
local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype")
- return vim.lsp.util.open_floating_preview(contents, filetype, { border = O.lsp.popup_border })
+ return vim.lsp.util.open_floating_preview(contents, filetype, { border = lvim.lsp.popup_border })
end
function lsp_config.preview_location_callback(_, method, result)
@@ -169,65 +203,102 @@ function lsp_config.PeekImplementation()
end
end
-if O.lsp.document_highlight then
- function lsp_config.common_on_attach(client, bufnr)
- documentHighlight(client, bufnr)
+function lsp_config.common_on_attach(client, bufnr)
+ if lvim.lsp.on_attach_callback then
+ lvim.lsp.on_attach_callback(client, bufnr)
end
+ lsp_highlight_document(client)
end
-function lsp_config.tsserver_on_attach(client, bufnr)
- -- lsp_config.common_on_attach(client, bufnr)
+local function no_formatter_on_attach(client, bufnr)
+ if lvim.lsp.on_attach_callback then
+ lvim.lsp.on_attach_callback(client, bufnr)
+ end
+ lsp_highlight_document(client)
client.resolved_capabilities.document_formatting = false
+end
- local ts_utils = require "nvim-lsp-ts-utils"
-
- -- defaults
- ts_utils.setup {
- debug = false,
- disable_commands = false,
- enable_import_on_completion = false,
- import_all_timeout = 5000, -- ms
-
- -- eslint
- eslint_enable_code_actions = true,
- eslint_enable_disable_comments = true,
- eslint_bin = O.lang.tsserver.linter,
- eslint_config_fallback = nil,
- eslint_enable_diagnostics = true,
-
- -- formatting
- enable_formatting = O.lang.tsserver.autoformat,
- formatter = O.lang.tsserver.formatter.exe,
- formatter_config_fallback = nil,
-
- -- parentheses completion
- complete_parens = false,
- signature_help_in_parens = false,
-
- -- update imports on file move
- update_imports_on_move = false,
- require_confirmation_on_move = false,
- watch_dir = nil,
+function lsp_config.common_capabilities()
+ local capabilities = vim.lsp.protocol.make_client_capabilities()
+ capabilities.textDocument.completion.completionItem.snippetSupport = true
+ capabilities.textDocument.completion.completionItem.resolveSupport = {
+ properties = {
+ "documentation",
+ "detail",
+ "additionalTextEdits",
+ },
}
-
- -- required to fix code action ranges
- ts_utils.setup_client(client)
-
- -- TODO: keymap these?
- -- vim.api.nvim_buf_set_keymap(bufnr, "n", "gs", ":TSLspOrganize<CR>", {silent = true})
- -- vim.api.nvim_buf_set_keymap(bufnr, "n", "qq", ":TSLspFixCurrent<CR>", {silent = true})
- -- vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", ":TSLspRenameFile<CR>", {silent = true})
- -- vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", ":TSLspImportAll<CR>", {silent = true})
+ return capabilities
end
-require("lv-utils").define_augroups {
+require("core.autocmds").define_augroups {
_general_lsp = {
{ "FileType", "lspinfo", "nnoremap <silent> <buffer> q :q<CR>" },
},
}
--- Use a loop to conveniently both setup defined servers
--- and map buffer local keybindings when the language server attaches
--- local servers = {"pyright", "tsserver"}
--- for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup {on_attach = on_attach} end
+local function is_table(t)
+ return type(t) == "table"
+end
+
+local function is_string(t)
+ return type(t) == "string"
+end
+
+local function has_value(tab, val)
+ for _, value in ipairs(tab) do
+ if value == val then
+ return true
+ end
+ end
+
+ return false
+end
+
+function lsp_config.setup(lang)
+ local lang_server = lvim.lang[lang].lsp
+ local provider = lang_server.provider
+ if require("utils").check_lsp_client_active(provider) then
+ return
+ end
+
+ local overrides = lvim.lsp.override
+
+ if is_table(overrides) then
+ if has_value(overrides, lang) then
+ return
+ end
+ end
+
+ if is_string(overrides) then
+ if overrides == lang then
+ return
+ end
+ end
+ local sources = require("lsp.null-ls").setup(lang)
+
+ for _, source in pairs(sources) do
+ local method = source.method
+ local format_method = "NULL_LS_FORMATTING"
+
+ if is_table(method) then
+ if has_value(method, format_method) then
+ lang_server.setup.on_attach = no_formatter_on_attach
+ end
+ end
+
+ if is_string(method) then
+ if method == format_method then
+ lang_server.setup.on_attach = no_formatter_on_attach
+ end
+ end
+ end
+
+ if provider == "" or provider == nil then
+ return
+ end
+
+ require("lspconfig")[provider].setup(lang_server.setup)
+end
+
return lsp_config
diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua
new file mode 100644
index 00000000..48924be5
--- /dev/null
+++ b/lua/lsp/null-ls.lua
@@ -0,0 +1,83 @@
+local M = {}
+
+local null_ls = require "null-ls"
+local sources = {}
+
+local local_executables = { "prettier", "prettierd", "prettier_d_slim", "eslint_d", "eslint" }
+
+local function is_table(t)
+ return type(t) == "table"
+end
+
+local function is_string(t)
+ return type(t) == "string"
+end
+
+local function has_value(tab, val)
+ for _, value in ipairs(tab) do
+ if value == val then
+ return true
+ end
+ end
+
+ return false
+end
+
+local find_local_exe = function(exe)
+ vim.cmd "let root_dir = FindRootDirectory()"
+ local root_dir = vim.api.nvim_get_var "root_dir"
+ local local_exe = root_dir .. "/node_modules/.bin/" .. exe
+ return local_exe
+end
+
+local function setup_ls(exe, type)
+ if has_value(local_executables, exe) then
+ local smart_executable = null_ls.builtins[type][exe]
+ local local_executable = find_local_exe(exe)
+ if vim.fn.executable(local_executable) == 1 then
+ smart_executable._opts.command = local_executable
+ table.insert(sources, smart_executable)
+ else
+ if vim.fn.executable(exe) == 1 then
+ table.insert(sources, smart_executable)
+ end
+ end
+ else
+ if vim.fn.executable(exe) == 1 then
+ table.insert(sources, null_ls.builtins[type][exe])
+ end
+ end
+ null_ls.register { sources = sources }
+end
+
+-- TODO: for linters and formatters with spaces and '-' replace with '_'
+local function setup(filetype, type)
+ local executables = nil
+ if type == "diagnostics" then
+ executables = lvim.lang[filetype].linters
+ end
+ if type == "formatting" then
+ executables = lvim.lang[filetype].formatter.exe
+ end
+
+ if is_table(executables) then
+ for _, exe in pairs(executables) do
+ if exe ~= "" then
+ setup_ls(exe, type)
+ end
+ end
+ end
+ if is_string(executables) and executables ~= "" then
+ setup_ls(executables, type)
+ end
+end
+
+-- TODO: return the formatter if one was registered, then turn off the builtin formatter
+function M.setup(filetype)
+ setup(filetype, "formatting")
+ setup(filetype, "diagnostics")
+ lvim.sources = sources
+ return sources
+end
+
+return M
diff --git a/lua/lsp/svelte-ls.lua b/lua/lsp/svelte-ls.lua
deleted file mode 100644
index e5ddb3b3..00000000
--- a/lua/lsp/svelte-ls.lua
+++ /dev/null
@@ -1,5 +0,0 @@
--- TODO: what is a svelte filetype
-require("lspconfig").svelte.setup {
- cmd = { DATA_PATH .. "/lspinstall/svelte/node_modules/.bin/svelteserver", "--stdio" },
- on_attach = require("lsp").common_on_attach,
-}
diff --git a/lua/lsp/tailwindcss-ls.lua b/lua/lsp/tailwindcss-ls.lua
deleted file mode 100644
index 38c1e7cc..00000000
--- a/lua/lsp/tailwindcss-ls.lua
+++ /dev/null
@@ -1,13 +0,0 @@
--- TODO: what is a tailwindcss filetype
-local lspconfig = require "lspconfig"
-
-lspconfig.tailwindcss.setup {
- cmd = {
- "node",
- DATA_PATH .. "/lspinstall/tailwindcss/tailwindcss-intellisense/extension/dist/server/tailwindServer.js",
- "--stdio",
- },
- filetypes = O.lang.tailwindcss.filetypes,
- root_dir = require("lspconfig/util").root_pattern("tailwind.config.js", "postcss.config.ts", ".postcssrc"),
- on_attach = require("lsp").common_on_attach,
-}
diff --git a/lua/lsp/ts-fmt-lint.lua b/lua/lsp/ts-fmt-lint.lua
deleted file mode 100644
index a73b817e..00000000
--- a/lua/lsp/ts-fmt-lint.lua
+++ /dev/null
@@ -1,49 +0,0 @@
--- Example configuations here: https://github.com/mattn/efm-langserver
--- You can look for project scope Prettier and Eslint with e.g. vim.fn.glob("node_modules/.bin/prettier") etc. If it is not found revert to global Prettier where needed.
-local M = {}
-
-M.setup = function()
- local tsserver_args = {}
-
- if O.lang.tsserver.linter == "eslint" or O.lang.tsserver.linter == "eslint_d" then
- local eslint = {
- lintCommand = O.lang.tsserver.linter .. " -f unix --stdin --stdin-filename {INPUT}",
- lintStdin = true,
- lintFormats = { "%f:%l:%c: %m" },
- lintIgnoreExitCode = true,
- formatCommand = O.lang.tsserver.linter .. " --fix-to-stdout --stdin --stdin-filename=${INPUT}",
- formatStdin = true,
- }
- table.insert(tsserver_args, eslint)
- end
-
- require("lspconfig").efm.setup {
- -- init_options = {initializationOptions},
- cmd = { DATA_PATH .. "/lspinstall/efm/efm-langserver" },
- init_options = { documentFormatting = true, codeAction = false },
- root_dir = require("lspconfig").util.root_pattern(".git/", "package.json"),
- filetypes = {
- "vue",
- "javascript",
- "javascriptreact",
- "typescript",
- "typescriptreact",
- "javascript.jsx",
- "typescript.tsx",
- },
- settings = {
- rootMarkers = { ".git/", "package.json" },
- languages = {
- vue = tsserver_args,
- javascript = tsserver_args,
- javascriptreact = tsserver_args,
- ["javascript.jsx"] = tsserver_args,
- typescript = tsserver_args,
- ["typescript.tsx"] = tsserver_args,
- typescriptreact = tsserver_args,
- },
- },
- }
-end
-
-return M
diff --git a/lua/lsp/tsserver-ls.lua b/lua/lsp/tsserver-ls.lua
deleted file mode 100644
index 8ed801e8..00000000
--- a/lua/lsp/tsserver-ls.lua
+++ /dev/null
@@ -1,67 +0,0 @@
-vim.cmd "let proj = FindRootDirectory()"
-local root_dir = vim.api.nvim_get_var "proj"
-
--- use the global prettier if you didn't find the local one
-local prettier_instance = root_dir .. "/node_modules/.bin/prettier"
-if vim.fn.executable(prettier_instance) ~= 1 then
- prettier_instance = O.lang.tsserver.formatter.exe
-end
-
-O.formatters.filetype["javascriptreact"] = {
- function()
- return {
- exe = prettier_instance,
- -- TODO: allow user to override this
- args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote" },
- stdin = true,
- }
- end,
-}
-O.formatters.filetype["javascript"] = O.formatters.filetype["javascriptreact"]
-
-require("formatter.config").set_defaults {
- logging = false,
- filetype = O.formatters.filetype,
-}
-
-if require("lv-utils").check_lsp_client_active "tsserver" then
- return
-end
-
--- npm install -g typescript typescript-language-server
--- require'snippets'.use_suggested_mappings()
--- local capabilities = vim.lsp.protocol.make_client_capabilities()
--- capabilities.textDocument.completion.completionItem.snippetSupport = true;
--- local on_attach_common = function(client)
--- print("LSP Initialized")
--- require'completion'.on_attach(client)
--- require'illuminate'.on_attach(client)
--- end
-require("lspconfig").tsserver.setup {
- cmd = {
- DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server",
- "--stdio",
- },
- filetypes = {
- "javascript",
- "javascriptreact",
- "javascript.jsx",
- "typescript",
- "typescriptreact",
- "typescript.tsx",
- },
- on_attach = require("lsp").tsserver_on_attach,
- -- This makes sure tsserver is not used for formatting (I prefer prettier)
- -- on_attach = require'lsp'.common_on_attach,
- root_dir = require("lspconfig/util").root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git"),
- settings = { documentFormatting = false },
- handlers = {
- ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
- virtual_text = O.lang.tsserver.diagnostics.virtual_text,
- signs = O.lang.tsserver.diagnostics.signs,
- underline = O.lang.tsserver.diagnostics.underline,
- update_in_insert = true,
- }),
- },
-}
-require("lsp.ts-fmt-lint").setup()