summaryrefslogtreecommitdiffstats
path: root/lua/user/lsp
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2022-10-20 13:47:23 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2022-10-20 13:47:23 +0200
commitccde4a982e6fa26086d662aeea2b7285cc6ab4f7 (patch)
tree82ca0a18f574143964ed769dd2d9ba1009b5a573 /lua/user/lsp
parent88e7c8bdb0b002be8ddad75633153c4d03a30632 (diff)
downloadvim-ccde4a982e6fa26086d662aeea2b7285cc6ab4f7.zip
vim-ccde4a982e6fa26086d662aeea2b7285cc6ab4f7.tar.gz
switch from nvim-lsp-installer to mason
Diffstat (limited to 'lua/user/lsp')
-rw-r--r--lua/user/lsp/handlers.lua55
-rw-r--r--lua/user/lsp/init.lua17
-rw-r--r--lua/user/lsp/lsp-installer.lua29
-rw-r--r--lua/user/lsp/mason.lua63
-rw-r--r--lua/user/lsp/null-ls.lua4
-rw-r--r--lua/user/lsp/settings/jsonls.lua200
6 files changed, 94 insertions, 274 deletions
diff --git a/lua/user/lsp/handlers.lua b/lua/user/lsp/handlers.lua
index 0758841..853beb3 100644
--- a/lua/user/lsp/handlers.lua
+++ b/lua/user/lsp/handlers.lua
@@ -1,21 +1,21 @@
local M = {}
--- TODO: backfill this to template
-M.setup = function()
- local signs = {
- { name = "DiagnosticSignError", text = "" },
- { name = "DiagnosticSignWarn", text = "" },
- { name = "DiagnosticSignHint", text = "" },
- { name = "DiagnosticSignInfo", text = "" },
- }
+local cmp_nvim_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
+if not cmp_nvim_ok then
+ print "cpm_nvim_lsp init failed"
+ return
+end
- for _, sign in ipairs(signs) do
- vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" })
+M.setup = function()
+ local signs = { Error = "", Warn = "", Hint = "", Info = "" }
+ for type, icon in pairs(signs) do
+ local hl = "DiagnosticSign" .. type
+ vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
end
local config = {
-- disable virtual text
- virtual_text = true,
+ virtual_text = false,
-- show signs
signs = {
active = signs,
@@ -44,7 +44,7 @@ M.setup = function()
})
end
-local function lsp_highlight_document(client)
+local function lsp_highlight(client)
-- Set autocommands conditional on server_capabilities
if client.server_capabilities.document_highlight then
vim.api.nvim_exec(
@@ -60,20 +60,22 @@ local function lsp_highlight_document(client)
end
end
+local keymap = vim.keymap.set
+
local function lsp_keymaps(bufnr)
- local opts = { noremap = true, silent = true }
+ local opts = { buffer = bufnr, noremap = true, silent = true }
-- SEE : https://neovim.io/doc/user/lsp.html
- vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
- vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
- vim.api.nvim_buf_set_keymap(bufnr, "n", "ga", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
- vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
+ keymap("n", "gd", vim.lsp.buf.definition, opts)
+ keymap("n", "gr", vim.lsp.buf.references, opts)
+ keymap("n", "gi", vim.lsp.buf.implementation, opts)
+ keymap("n", "ga", vim.lsp.buf.declaration, opts)
- vim.api.nvim_buf_set_keymap(bufnr, "n", "gb", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
- vim.api.nvim_buf_set_keymap(bufnr, "n", "gé", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
- vim.api.nvim_buf_set_keymap(bufnr, "n", "gk", '<cmd>lua vim.diagnostic.open_float({ border = "rounded" })<CR>', opts)
- vim.api.nvim_buf_set_keymap(bufnr, "n", "g.", '<cmd>lua vim.diagnostic.goto_next({ border = "rounded" })<CR>', opts)
- vim.api.nvim_buf_set_keymap(bufnr, "n", "gx", '<cmd>lua vim.diagnostic.goto_prev({ border = "rounded" })<CR>', opts)
- vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>q", "<cmd>lua vim.diagnostic.setloclist()<CR>", opts)
+ keymap("n", "gb", vim.lsp.buf.hover, opts)
+ keymap("n", "gé", vim.lsp.buf.signature_help, opts)
+ keymap("n", "gk", vim.diagnostic.open_float, opts)
+ keymap("n", "g.", vim.diagnostic.goto_next, opts)
+ keymap("n", "gx", vim.diagnostic.goto_prev, opts)
+ keymap("n", "<leader>q", vim.diagnostic.setloclist, opts)
vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting()' ]] -- FIXME what ?
end
@@ -82,16 +84,11 @@ M.on_attach = function(client, bufnr)
client.server_capabilities.document_formatting = false
end
lsp_keymaps(bufnr)
- lsp_highlight_document(client)
+ lsp_highlight(client)
end
local capabilities = vim.lsp.protocol.make_client_capabilities()
-local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
-if not status_ok then
- return
-end
-
M.capabilities = cmp_nvim_lsp.default_capabilities(capabilities)
return M
diff --git a/lua/user/lsp/init.lua b/lua/user/lsp/init.lua
index 9dff1be..50c423a 100644
--- a/lua/user/lsp/init.lua
+++ b/lua/user/lsp/init.lua
@@ -1,14 +1,3 @@
-local status_ok, lspconfig = pcall(require, "lspconfig")
-if not status_ok then
- print "lspconfig init failed"
- return
-end
-
-require "user.lsp.lsp-installer"
-require("user.lsp.handlers").setup()
-require "user.lsp.null-ls"
-
-lspconfig.gdscript.setup{
- on_attach = require("user.lsp.handlers").on_attach,
- capabilities = require("user.lsp.handlers").capabilities,
-}
+require 'user.lsp.mason'
+require('user.lsp.handlers').setup()
+require 'user.lsp.null-ls'
diff --git a/lua/user/lsp/lsp-installer.lua b/lua/user/lsp/lsp-installer.lua
deleted file mode 100644
index 6427378..0000000
--- a/lua/user/lsp/lsp-installer.lua
+++ /dev/null
@@ -1,29 +0,0 @@
-local status_ok, lsp_installer = pcall(require, "nvim-lsp-installer")
-if not status_ok then
- print "nvim-lsp-installer init failed"
- return
-end
-
--- Register a handler that will be called for all installed servers.
--- Alternatively, you may also register handlers on specific server instances instead (see example below).
--- SEE : https://github.com/williamboman/nvim-lsp-installer#setup
-lsp_installer.on_server_ready(function(server)
- local opts = {
- on_attach = require("user.lsp.handlers").on_attach,
- capabilities = require("user.lsp.handlers").capabilities,
- }
-
- -- if server.name == "jsonls" then
- -- local jsonls_opts = require("user.lsp.settings.jsonls")
- -- opts = vim.tbl_deep_extend("force", jsonls_opts, opts)
- -- end
-
- -- if server.name == "sumneko_lua" then
- -- local sumneko_opts = require("user.lsp.settings.sumneko_lua")
- -- opts = vim.tbl_deep_extend("force", sumneko_opts, opts)
- -- end
-
- -- This setup() function is exactly the same as lspconfig's setup function.
- -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
- server:setup(opts)
-end)
diff --git a/lua/user/lsp/mason.lua b/lua/user/lsp/mason.lua
new file mode 100644
index 0000000..b841d72
--- /dev/null
+++ b/lua/user/lsp/mason.lua
@@ -0,0 +1,63 @@
+local mason_ok, mason = pcall(require, "mason")
+if not mason_ok then
+ print "mason init failed"
+ return
+end
+
+local mason_lspconfig_ok, mason_lspconfig = pcall(require, "mason-lspconfig")
+if not mason_lspconfig_ok then
+ print "mason-lspconfig init failed"
+ return
+end
+
+local lspconfig_ok, lspconfig = pcall(require, "lspconfig")
+if not lspconfig_ok then
+ print "lspconfig init failed"
+ return
+end
+
+require('lspconfig.ui.windows').default_options.border = 'rounded'
+
+local servers = {
+ "clangd",
+ "jdtls",
+ "jsonls",
+ "ltex",
+ "rust_analyzer",
+ "solargraph",
+ "sumneko_lua",
+}
+
+mason.setup({
+ ui = {
+ border = "single",
+ icons = {
+ package_installed = "✓",
+ package_pending = "➜",
+ package_uninstalled = "✗"
+ }
+ }
+})
+
+mason_lspconfig.setup({
+ ensure_installed = servers,
+})
+
+mason_lspconfig.setup_handlers({
+ function(server_name)
+ local opts = {
+ on_attach = require("user.lsp.handlers").on_attach,
+ capabilities = require("user.lsp.handlers").capabilities,
+ falgs = {
+ debounce_text_changes = 5000,
+ },
+ }
+
+ local require_ok, server = pcall(require, "user.lsp.settings." .. server_name)
+ if require_ok then
+ opts = vim.tbl_deep_extend("force", server, opts)
+ end
+
+ lspconfig[server_name].setup(opts)
+ end,
+})
diff --git a/lua/user/lsp/null-ls.lua b/lua/user/lsp/null-ls.lua
index 1dc7ace..389e68f 100644
--- a/lua/user/lsp/null-ls.lua
+++ b/lua/user/lsp/null-ls.lua
@@ -1,5 +1,5 @@
-local null_ls_status_ok, null_ls = pcall(require, "null-ls")
-if not null_ls_status_ok then
+local null_ls_ok, null_ls = pcall(require, "null-ls")
+if not null_ls_ok then
print "null-ls init failed"
return
end
diff --git a/lua/user/lsp/settings/jsonls.lua b/lua/user/lsp/settings/jsonls.lua
deleted file mode 100644
index da58c44..0000000
--- a/lua/user/lsp/settings/jsonls.lua
+++ /dev/null
@@ -1,200 +0,0 @@
-local default_schemas = nil
-local status_ok, jsonls_settings = pcall(require, "nlspsettings.jsonls")
-if not status_ok then
- print "nlspsettings.jsonls init failed"
- return
-else
- default_schemas = jsonls_settings.get_default_schemas()
-end
-
-local schemas = {
- {
- description = "TypeScript compiler configuration file",
- fileMatch = {
- "tsconfig.json",
- "tsconfig.*.json",
- },
- url = "https://json.schemastore.org/tsconfig.json",
- },
- {
- description = "Lerna config",
- fileMatch = { "lerna.json" },
- url = "https://json.schemastore.org/lerna.json",
- },
- {
- description = "Babel configuration",
- fileMatch = {
- ".babelrc.json",
- ".babelrc",
- "babel.config.json",
- },
- url = "https://json.schemastore.org/babelrc.json",
- },
- {
- description = "ESLint config",
- fileMatch = {
- ".eslintrc.json",
- ".eslintrc",
- },
- url = "https://json.schemastore.org/eslintrc.json",
- },
- {
- description = "Bucklescript config",
- fileMatch = { "bsconfig.json" },
- url = "https://raw.githubusercontent.com/rescript-lang/rescript-compiler/8.2.0/docs/docson/build-schema.json",
- },
- {
- description = "Prettier config",
- fileMatch = {
- ".prettierrc",
- ".prettierrc.json",
- "prettier.config.json",
- },
- url = "https://json.schemastore.org/prettierrc",
- },
- {
- description = "Vercel Now config",
- fileMatch = { "now.json" },
- url = "https://json.schemastore.org/now",
- },
- {
- description = "Stylelint config",
- fileMatch = {
- ".stylelintrc",
- ".stylelintrc.json",
- "stylelint.config.json",
- },
- url = "https://json.schemastore.org/stylelintrc",
- },
- {
- description = "A JSON schema for the ASP.NET LaunchSettings.json files",
- fileMatch = { "launchsettings.json" },
- url = "https://json.schemastore.org/launchsettings.json",
- },
- {
- description = "Schema for CMake Presets",
- fileMatch = {
- "CMakePresets.json",
- "CMakeUserPresets.json",
- },
- url = "https://raw.githubusercontent.com/Kitware/CMake/master/Help/manual/presets/schema.json",
- },
- {
- description = "Configuration file as an alternative for configuring your repository in the settings page.",
- fileMatch = {
- ".codeclimate.json",
- },
- url = "https://json.schemastore.org/codeclimate.json",
- },
- {
- description = "LLVM compilation database",
- fileMatch = {
- "compile_commands.json",
- },
- url = "https://json.schemastore.org/compile-commands.json",
- },
- {
- description = "Config file for Command Task Runner",
- fileMatch = {
- "commands.json",
- },
- url = "https://json.schemastore.org/commands.json",
- },
- {
- description = "AWS CloudFormation provides a common language for you to describe and provision all the infrastructure resources in your cloud environment.",
- fileMatch = {
- "*.cf.json",
- "cloudformation.json",
- },
- url = "https://raw.githubusercontent.com/awslabs/goformation/v5.2.9/schema/cloudformation.schema.json",
- },
- {
- description = "The AWS Serverless Application Model (AWS SAM, previously known as Project Flourish) extends AWS CloudFormation to provide a simplified way of defining the Amazon API Gateway APIs, AWS Lambda functions, and Amazon DynamoDB tables needed by your serverless application.",
- fileMatch = {
- "serverless.template",
- "*.sam.json",
- "sam.json",
- },
- url = "https://raw.githubusercontent.com/awslabs/goformation/v5.2.9/schema/sam.schema.json",
- },
- {
- description = "Json schema for properties json file for a GitHub Workflow template",
- fileMatch = {
- ".github/workflow-templates/**.properties.json",
- },
- url = "https://json.schemastore.org/github-workflow-template-properties.json",
- },
- {
- description = "golangci-lint configuration file",
- fileMatch = {
- ".golangci.toml",
- ".golangci.json",
- },
- url = "https://json.schemastore.org/golangci-lint.json",
- },
- {
- description = "JSON schema for the JSON Feed format",
- fileMatch = {
- "feed.json",
- },
- url = "https://json.schemastore.org/feed.json",
- versions = {
- ["1"] = "https://json.schemastore.org/feed-1.json",
- ["1.1"] = "https://json.schemastore.org/feed.json",
- },
- },
- {
- description = "Packer template JSON configuration",
- fileMatch = {
- "packer.json",
- },
- url = "https://json.schemastore.org/packer.json",
- },
- {
- description = "NPM configuration file",
- fileMatch = {
- "package.json",
- },
- url = "https://json.schemastore.org/package.json",
- },
- {
- description = "JSON schema for Visual Studio component configuration files",
- fileMatch = {
- "*.vsconfig",
- },
- url = "https://json.schemastore.org/vsconfig.json",
- },
- {
- description = "Resume json",
- fileMatch = { "resume.json" },
- url = "https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json",
- },
-}
-
-local function extend(tab1, tab2)
- for _, value in ipairs(tab2) do
- table.insert(tab1, value)
- end
- return tab1
-end
-
-local extended_schemas = extend(schemas, default_schemas)
-
-local opts = {
- settings = {
- json = {
- schemas = extended_schemas,
- },
- },
- setup = {
- commands = {
- Format = {
- function()
- vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 })
- end,
- },
- },
- },
-}
-
-return opts