diff options
Diffstat (limited to 'lua/lvim/lsp')
| -rw-r--r-- | lua/lvim/lsp/config.lua | 17 | ||||
| -rw-r--r-- | lua/lvim/lsp/handlers.lua | 127 | ||||
| -rw-r--r-- | lua/lvim/lsp/init.lua | 51 | ||||
| -rw-r--r-- | lua/lvim/lsp/manager.lua | 1 | ||||
| -rw-r--r-- | lua/lvim/lsp/null-ls/code_actions.lua | 11 | ||||
| -rw-r--r-- | lua/lvim/lsp/null-ls/formatters.lua | 20 | ||||
| -rw-r--r-- | lua/lvim/lsp/null-ls/init.lua | 8 | ||||
| -rw-r--r-- | lua/lvim/lsp/null-ls/linters.lua | 20 | ||||
| -rw-r--r-- | lua/lvim/lsp/peek.lua | 12 | ||||
| -rw-r--r-- | lua/lvim/lsp/providers/sumneko_lua.lua | 21 | ||||
| -rw-r--r-- | lua/lvim/lsp/utils.lua | 10 | 
11 files changed, 77 insertions, 221 deletions
| diff --git a/lua/lvim/lsp/config.lua b/lua/lvim/lsp/config.lua index 5cfe5b1f..8c7a0dd9 100644 --- a/lua/lvim/lsp/config.lua +++ b/lua/lvim/lsp/config.lua @@ -32,7 +32,11 @@ return {    },    document_highlight = true,    code_lens_refresh = true, -  popup_border = "single", +  float = { +    focusable = false, +    style = "minimal", +    border = "rounded", +  },    on_attach_callback = nil,    on_init_callback = nil,    automatic_servers_installation = true, @@ -61,13 +65,14 @@ return {      "angularls",      "ansiblels",      "ccls", -    "cssmodules_ls",      "csharp_ls", +    "cssmodules_ls",      "denols",      "ember",      "emmet_ls",      "eslint",      "eslintls", +    "grammarly",      "graphql",      "jedi_language_server",      "ltex", @@ -75,15 +80,17 @@ return {      "pylsp",      "quick_lint_js",      "rome", -    "sorbet", -    "sqlls", -    "sqls",      "solang", +    "solidity_ls", +    "sorbet",      "sourcekit",      "spectral", +    "sqlls", +    "sqls",      "stylelint_lsp",      "tailwindcss",      "tflint",      "volar", +    "zk",    },  } diff --git a/lua/lvim/lsp/handlers.lua b/lua/lvim/lsp/handlers.lua index 45f73e91..5da0b21e 100644 --- a/lua/lvim/lsp/handlers.lua +++ b/lua/lvim/lsp/handlers.lua @@ -11,130 +11,15 @@ function M.setup()      severity_sort = lvim.lsp.diagnostics.severity_sort,      float = lvim.lsp.diagnostics.float,    } -  if vim.fn.has "nvim-0.6" == 1 then -    vim.diagnostic.config(config) -  else -    vim.lsp.handlers["textDocument/publishDiagnostics"] = function(_, _, params, client_id, _) -      local uri = params.uri -      local bufnr = vim.uri_to_bufnr(uri) -      if not bufnr then -        return -      end - -      local diagnostics = params.diagnostics -      vim.lsp.diagnostic.save(diagnostics, bufnr, client_id) -      if not vim.api.nvim_buf_is_loaded(bufnr) then -        return -      end -      vim.lsp.diagnostic.display(diagnostics, bufnr, client_id, config) -    end - -    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 = lvim.lsp.popup_border, -    }) -  end +  vim.diagnostic.config(config) +  vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, lvim.lsp.float) +  vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, lvim.lsp.float)  end  function M.show_line_diagnostics() -  if vim.fn.has "nvim-0.6" == 1 then -    return vim.diagnostic.open_float(0, { scope = "line" }) -  end - -  local function split_by_chunk(text, chunkSize) -    local s = {} -    for i = 1, #text, chunkSize do -      s[#s + 1] = text:sub(i, i + chunkSize - 1) -    end -    return s -  end -  local diagnostics = vim.lsp.diagnostic.get_line_diagnostics() -  local severity_highlight = { -    "LspDiagnosticsFloatingError", -    "LspDiagnosticsFloatingWarning", -    "LspDiagnosticsFloatingInformation", -    "LspDiagnosticsFloatingHint", -  } -  local ok, vim_diag = pcall(require, "vim.diagnostic") -  if ok then -    local buf_id = vim.api.nvim_win_get_buf(0) -    local win_id = vim.api.nvim_get_current_win() -    local cursor_position = vim.api.nvim_win_get_cursor(win_id) -    severity_highlight = { -      "DiagnosticFloatingError", -      "DiagnosticFloatingWarn", -      "DiagnosticFloatingInfo", -      "DiagnosticFloatingHint", -    } -    diagnostics = vim_diag.get(buf_id, { lnum = cursor_position[1] - 1 }) -  end -  local lines = {} -  local max_width = vim.fn.winwidth(0) - 5 -  local height = #diagnostics -  local width = 0 -  local opts = {} -  local close_events = { "CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre" } -  if height == 0 then -    return -  end -  local bufnr = vim.api.nvim_create_buf(false, true) -  local diag_message -  table.sort(diagnostics, function(a, b) -    return a.severity < b.severity -  end) - -  local hash = {} -  local diagnostics_no_dupes = {} -  for _, v in ipairs(diagnostics) do -    if not hash[v["message"]] then -      diagnostics_no_dupes[#diagnostics_no_dupes + 1] = v -- you could print here instead of saving to result table if you wanted -      hash[v["message"]] = true -    end -  end -  -- print(vim.inspect(diagnostics_no_dupes)) - -  for i, diagnostic in ipairs(diagnostics_no_dupes) do -    local source = diagnostic.source -    diag_message = diagnostic.message:gsub("[\n\r]", " ") -    if source then -      if string.find(source, "/") then -        source = string.sub(diagnostic.source, string.find(diagnostic.source, "([%w-_]+)$")) -      end -      diag_message = string.format("%d. %s: %s", i, source, diag_message) -    else -      diag_message = string.format("%d. %s", i, diag_message) -    end -    if diagnostic.code then -      diag_message = string.format("%s [%s]", diag_message, diagnostic.code) -    end -    local msgs = split_by_chunk(diag_message, max_width) -    for _, diag in ipairs(msgs) do -      table.insert(lines, { message = diag, severity = diagnostic.severity }) -      width = math.max(diag:len(), width) -    end -  end -  height = #lines -  opts = vim.lsp.util.make_floating_popup_options(width, height, opts) -  opts["style"] = "minimal" -  opts["border"] = "rounded" -  opts["focusable"] = true - -  vim.api.nvim_buf_set_option(bufnr, "bufhidden", "wipe") -  local winnr = vim.api.nvim_open_win(bufnr, false, opts) -  vim.api.nvim_win_set_option(winnr, "winblend", 0) -  vim.api.nvim_buf_set_var(bufnr, "lsp_floating_window", winnr) -  for i, diag in ipairs(lines) do -    vim.api.nvim_buf_set_lines(bufnr, i - 1, i - 1, 0, { diag.message }) -    vim.api.nvim_buf_add_highlight(bufnr, -1, severity_highlight[diag.severity], i - 1, 0, diag.message:len()) -  end - -  vim.api.nvim_command( -    "autocmd QuitPre <buffer> ++nested ++once lua pcall(vim.api.nvim_win_close, " .. winnr .. ", true)" -  ) -  vim.lsp.util.close_preview_autocmd(close_events, winnr) +  local config = lvim.lsp.diagnostics.float +  config.scope = "line" +  return vim.diagnostic.open_float(0, config)  end  return M diff --git a/lua/lvim/lsp/init.lua b/lua/lvim/lsp/init.lua index 68a64d6c..0be13484 100644 --- a/lua/lvim/lsp/init.lua +++ b/lua/lvim/lsp/init.lua @@ -1,24 +1,13 @@  local M = {}  local Log = require "lvim.core.log"  local utils = require "lvim.utils" +local autocmds = require "lvim.core.autocmds"  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( -      [[ -      augroup lsp_document_highlight -        autocmd! * <buffer> -        autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight() -        autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references() -      augroup END -    ]], -      false -    ) -  end +  autocmds.enable_lsp_document_highlight(client.id)  end  local function lsp_code_lens_refresh(client) @@ -27,16 +16,7 @@ local function lsp_code_lens_refresh(client)    end    if client.resolved_capabilities.code_lens then -    vim.api.nvim_exec( -      [[ -      augroup lsp_code_lens_refresh -        autocmd! * <buffer> -        autocmd InsertLeave <buffer> lua vim.lsp.codelens.refresh() -        autocmd InsertLeave <buffer> lua vim.lsp.codelens.display() -      augroup END -    ]], -      false -    ) +    autocmds.enable_code_lens_refresh()    end  end @@ -101,6 +81,15 @@ local function select_default_formater(client)    end  end +function M.common_on_exit(_, _) +  if lvim.lsp.document_highlight then +    autocmds.disable_lsp_document_highlight() +  end +  if lvim.lsp.code_lens_refresh then +    autocmds.disable_code_lens_refresh() +  end +end +  function M.common_on_init(client, bufnr)    if lvim.lsp.on_init_callback then      lvim.lsp.on_init_callback(client, bufnr) @@ -132,17 +121,11 @@ function M.get_common_opts()    return {      on_attach = M.common_on_attach,      on_init = M.common_on_init, +    on_exit = M.common_on_exit,      capabilities = M.common_capabilities(),    }  end -local LSP_DEPRECATED_SIGN_MAP = { -  ["DiagnosticSignError"] = "LspDiagnosticsSignError", -  ["DiagnosticSignWarn"] = "LspDiagnosticsSignWarning", -  ["DiagnosticSignHint"] = "LspDiagnosticsSignHint", -  ["DiagnosticSignInfo"] = "LspDiagnosticsSignInformation", -} -  function M.setup()    Log:debug "Setting up LSP support" @@ -151,13 +134,7 @@ function M.setup()      return    end -  local is_neovim_5 = vim.fn.has "nvim-0.6" ~= 1 -    for _, sign in ipairs(lvim.lsp.diagnostics.signs.values) do -    local lsp_sign_name = LSP_DEPRECATED_SIGN_MAP[sign.name] -    if is_neovim_5 and lsp_sign_name then -      vim.fn.sign_define(lsp_sign_name, { texthl = lsp_sign_name, text = sign.text, numhl = lsp_sign_name }) -    end      vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name })    end @@ -171,7 +148,7 @@ function M.setup()    require("lvim.lsp.null-ls").setup() -  require("lvim.core.autocmds").configure_format_on_save() +  autocmds.configure_format_on_save()  end  return M diff --git a/lua/lvim/lsp/manager.lua b/lua/lvim/lsp/manager.lua index c95b9f69..6c748020 100644 --- a/lua/lvim/lsp/manager.lua +++ b/lua/lvim/lsp/manager.lua @@ -24,6 +24,7 @@ local function resolve_config(name, user_config)    local config = {      on_attach = require("lvim.lsp").common_on_attach,      on_init = require("lvim.lsp").common_on_init, +    on_exit = require("lvim.lsp").common_on_exit,      capabilities = require("lvim.lsp").common_capabilities(),    } diff --git a/lua/lvim/lsp/null-ls/code_actions.lua b/lua/lvim/lsp/null-ls/code_actions.lua index ff59fabf..bf6492b5 100644 --- a/lua/lvim/lsp/null-ls/code_actions.lua +++ b/lua/lvim/lsp/null-ls/code_actions.lua @@ -14,20 +14,11 @@ local is_registered = function(name)    return require("null-ls.sources").is_registered(query)  end -function M.list_registered_providers(filetype) +function M.list_registered(filetype)    local registered_providers = services.list_registered_providers_names(filetype)    return registered_providers[METHOD] or {}  end -function M.list_available(filetype) -  local availables = require("null-ls.sources").get_available(filetype, METHOD) -  local actors = vim.tbl_map(function(src) -    return src.name -  end, availables) -  table.sort(actors) -  return actors -end -  function M.list_configured(actions_configs)    local actors, errors = {}, {} diff --git a/lua/lvim/lsp/null-ls/formatters.lua b/lua/lvim/lsp/null-ls/formatters.lua index b2e191c5..0613f16f 100644 --- a/lua/lvim/lsp/null-ls/formatters.lua +++ b/lua/lvim/lsp/null-ls/formatters.lua @@ -12,26 +12,18 @@ local is_registered = function(name)    return require("null-ls.sources").is_registered(query)  end -function M.list_registered_providers(filetype) +function M.list_registered(filetype)    local null_ls_methods = require "null-ls.methods"    local formatter_method = null_ls_methods.internal["FORMATTING"]    local registered_providers = services.list_registered_providers_names(filetype)    return registered_providers[formatter_method] or {}  end -function M.list_available(filetype) -  local formatters = {} -  local tbl = require "lvim.utils.table" -  for _, provider in pairs(null_ls.builtins.formatting) do -    if tbl.contains(provider.filetypes or {}, function(ft) -      return ft == "*" or ft == filetype -    end) then -      table.insert(formatters, provider.name) -    end -  end - -  table.sort(formatters) -  return formatters +function M.list_supported(filetype) +  local s = require "null-ls.sources" +  local supported_formatters = s.get_supported(filetype, "formatting") +  table.sort(supported_formatters) +  return supported_formatters  end  function M.list_configured(formatter_configs) diff --git a/lua/lvim/lsp/null-ls/init.lua b/lua/lvim/lsp/null-ls/init.lua index f5e820e8..68e20c98 100644 --- a/lua/lvim/lsp/null-ls/init.lua +++ b/lua/lvim/lsp/null-ls/init.lua @@ -9,14 +9,8 @@ function M:setup()      return    end -  null_ls.config(lvim.lsp.null_ls.config)    local default_opts = require("lvim.lsp").get_common_opts() - -  if vim.tbl_isempty(lvim.lsp.null_ls.setup or {}) then -    lvim.lsp.null_ls.setup = default_opts -  end - -  require("lspconfig")["null-ls"].setup(lvim.lsp.null_ls.setup) +  null_ls.setup(vim.tbl_deep_extend("force", default_opts, lvim.lsp.null_ls.setup))  end  return M diff --git a/lua/lvim/lsp/null-ls/linters.lua b/lua/lvim/lsp/null-ls/linters.lua index 6a793d26..67e530a9 100644 --- a/lua/lvim/lsp/null-ls/linters.lua +++ b/lua/lvim/lsp/null-ls/linters.lua @@ -12,26 +12,18 @@ local is_registered = function(name)    return require("null-ls.sources").is_registered(query)  end -function M.list_registered_providers(filetype) +function M.list_registered(filetype)    local null_ls_methods = require "null-ls.methods"    local linter_method = null_ls_methods.internal["DIAGNOSTICS"]    local registered_providers = services.list_registered_providers_names(filetype)    return registered_providers[linter_method] or {}  end -function M.list_available(filetype) -  local linters = {} -  local tbl = require "lvim.utils.table" -  for _, provider in pairs(null_ls.builtins.diagnostics) do -    if tbl.contains(provider.filetypes or {}, function(ft) -      return ft == "*" or ft == filetype -    end) then -      table.insert(linters, provider.name) -    end -  end - -  table.sort(linters) -  return linters +function M.list_supported(filetype) +  local s = require "null-ls.sources" +  local supported_linters = s.get_supported(filetype, "diagnostics") +  table.sort(supported_linters) +  return supported_linters  end  function M.list_configured(linter_configs) diff --git a/lua/lvim/lsp/peek.lua b/lua/lvim/lsp/peek.lua index 08345aff..f006f934 100644 --- a/lua/lvim/lsp/peek.lua +++ b/lua/lvim/lsp/peek.lua @@ -47,9 +47,8 @@ local function create_floating_file(location, opts)    -- Set some autocmds to close the window    vim.api.nvim_command( -    "autocmd QuitPre <buffer> ++nested ++once lua pcall(vim.api.nvim_win_close, " .. winnr .. ", true)" +    string.format("autocmd %s <buffer> ++once lua pcall(vim.api.nvim_win_close, %d, true)", unpack(close_events), winnr)    ) -  vim.lsp.util.close_preview_autocmd(close_events, winnr)    return bufnr, winnr  end @@ -73,10 +72,6 @@ local function preview_location_callback(result)    end  end -local function preview_location_callback_old_signature(_, _, result) -  return preview_location_callback(result) -end -  local function preview_location_callback_new_signature(_, result)    return preview_location_callback(result)  end @@ -136,10 +131,7 @@ function M.Peek(what)    else      -- Make a new request and then create the new window in the callback      local params = vim.lsp.util.make_position_params() -    local preview_callback = preview_location_callback_old_signature -    if vim.fn.has "nvim-0.5.1" > 0 then -      preview_callback = preview_location_callback_new_signature -    end +    local preview_callback = preview_location_callback_new_signature      local success, _ = pcall(vim.lsp.buf_request, 0, "textDocument/" .. what, params, preview_callback)      if not success then        print( diff --git a/lua/lvim/lsp/providers/sumneko_lua.lua b/lua/lvim/lsp/providers/sumneko_lua.lua index 6585c8c7..7c0030c1 100644 --- a/lua/lvim/lsp/providers/sumneko_lua.lua +++ b/lua/lvim/lsp/providers/sumneko_lua.lua @@ -7,8 +7,6 @@ local opts = {        workspace = {          library = {            [require("lvim.utils").join_paths(get_runtime_dir(), "lvim", "lua")] = true, -          [vim.fn.expand "$VIMRUNTIME/lua"] = true, -          [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true,          },          maxPreload = 100000,          preloadFileSize = 10000, @@ -16,4 +14,21 @@ local opts = {      },    },  } -return opts + +local lua_dev_loaded, lua_dev = pcall(require, "lua-dev") +if not lua_dev_loaded then +  return opts +end + +local dev_opts = { +  library = { +    vimruntime = true, -- runtime path +    types = true, -- full signature, docs and completion of vim.api, vim.treesitter, vim.lsp and others +    -- plugins = true, -- installed opt or start plugins in packpath +    -- you can also specify the list of plugins to make available as a workspace library +    plugins = { "plenary.nvim" }, +  }, +  lspconfig = opts, +} + +return lua_dev.setup(dev_opts) diff --git a/lua/lvim/lsp/utils.lua b/lua/lvim/lsp/utils.lua index 6d1ed09c..47b1c8ba 100644 --- a/lua/lvim/lsp/utils.lua +++ b/lua/lvim/lsp/utils.lua @@ -76,4 +76,14 @@ function M.get_all_supported_filetypes()    return vim.tbl_keys(lsp_installer_filetypes or {})  end +function M.conditional_document_highlight(id) +  local client_ok, method_supported = pcall(function() +    return vim.lsp.get_client_by_id(id).resolved_capabilities.document_highlight +  end) +  if not client_ok or not method_supported then +    return +  end +  vim.lsp.buf.document_highlight() +end +  return M | 
