Skip to content

Commit

Permalink
Rewrite to fix breaking change introduced by neovim/nvim-lspconfig#3232
Browse files Browse the repository at this point in the history
  • Loading branch information
mettavi committed Sep 5, 2024
1 parent 6414063 commit 8fbd696
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 86 deletions.
86 changes: 0 additions & 86 deletions nvim/.config/nvim/lua/mettavi/plugins/lsp/lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ return {
{ "folke/neodev.nvim", opts = {} },
},
config = function()
-- import lspconfig plugin
local lspconfig = require("lspconfig")

-- import mason_lspconfig plugin
local mason_lspconfig = require("mason-lspconfig")

-- import cmp-nvim-lsp plugin
local cmp_nvim_lsp = require("cmp_nvim_lsp")

local keymap = vim.keymap -- for conciseness

vim.api.nvim_create_autocmd("LspAttach", {
Expand Down Expand Up @@ -67,89 +58,12 @@ return {
end,
})

-- used to enable autocompletion (assign to every lsp server config)
local capabilities = cmp_nvim_lsp.default_capabilities()

-- Change the Diagnostic symbols in the sign column (gutter)
-- (not in youtube nvim video)
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 = "" })
end

mason_lspconfig.setup_handlers({
-- default handler for installed servers
function(server_name)
lspconfig[server_name].setup({
capabilities = capabilities,
})
end,
["svelte"] = function()
-- configure svelte server
lspconfig["svelte"].setup({
capabilities = capabilities,
on_attach = function(client, bufnr)
vim.api.nvim_create_autocmd("BufWritePost", {
pattern = { "*.js", "*.ts" },
callback = function(ctx)
-- Here use ctx.match instead of ctx.file
client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.match })
end,
})
end,
})
end,
["bashls"] = function()
-- configure bash language server
lspconfig["bashls"].setup({
capabilities = capabilities,
filetypes = { "sh", "bash" },
})
end,
["graphql"] = function()
-- configure graphql language server
lspconfig["graphql"].setup({
capabilities = capabilities,
filetypes = { "graphql", "gql", "svelte", "typescriptreact", "javascriptreact" },
})
end,
["emmet_ls"] = function()
-- configure emmet language server
lspconfig["emmet_ls"].setup({
capabilities = capabilities,
filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" },
})
end,
["lua_ls"] = function()
-- configure lua server (with special settings)
lspconfig["lua_ls"].setup({
capabilities = capabilities,
settings = {
Lua = {
-- make the language server recognize "vim" global
diagnostics = {
globals = { "vim" },
},
completion = {
callSnippet = "Replace",
},
},
},
})
end,

-- configure typescript server with plugin
["tsserver"] = function()
lspconfig["tsserver"].setup({
capabilities = capabilities,
-- settings = {
-- implicitProjectConfiguration = {
-- checkJs = true,
-- },
-- },
})
end,
})
end,
}
90 changes: 90 additions & 0 deletions nvim/.config/nvim/lua/mettavi/plugins/lsp/mason.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ return {
"jay-babu/mason-nvim-dap.nvim",
},
config = function()
-- import lspconfig plugin
require("lspconfig")

-- import cmp-nvim-lsp plugin
local cmp_nvim_lsp = require("cmp_nvim_lsp")

-- import lspconfig plugin
local lspconfig = require("lspconfig")

-- used to enable autocompletion (assign to every lsp server config)
local capabilities = cmp_nvim_lsp.default_capabilities()

-- import mason
local mason = require("mason")

Expand Down Expand Up @@ -72,5 +84,83 @@ return {
})

mason_nvim_dap.setup()

mason_lspconfig.setup_handlers({
-- default handler for installed servers
function(server_name)
-- https://github.com/neovim/nvim-lspconfig/pull/3232
if server_name == "tsserver" then
server_name = "ts_ls"
end
lspconfig[server_name].setup({
capabilities = capabilities,
})
end,
["svelte"] = function()
-- configure svelte server
lspconfig["svelte"].setup({
capabilities = capabilities,
on_attach = function(client, bufnr)
vim.api.nvim_create_autocmd("BufWritePost", {
pattern = { "*.js", "*.ts" },
callback = function(ctx)
-- Here use ctx.match instead of ctx.file
client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.match })
end,
})
end,
})
end,
["bashls"] = function()
-- configure bash language server
lspconfig["bashls"].setup({
capabilities = capabilities,
filetypes = { "sh", "bash" },
})
end,
["graphql"] = function()
-- configure graphql language server
lspconfig["graphql"].setup({
capabilities = capabilities,
filetypes = { "graphql", "gql", "svelte", "typescriptreact", "javascriptreact" },
})
end,
["emmet_ls"] = function()
-- configure emmet language server
lspconfig["emmet_ls"].setup({
capabilities = capabilities,
filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" },
})
end,
["lua_ls"] = function()
-- configure lua server (with special settings)
lspconfig["lua_ls"].setup({
capabilities = capabilities,
settings = {
Lua = {
-- make the language server recognize "vim" global
diagnostics = {
globals = { "vim" },
},
completion = {
callSnippet = "Replace",
},
},
},
})
end,

-- configure typescript server with plugin
-- ["tsserver"] = function()
-- lspconfig["tsserver"].setup({
-- capabilities = capabilities,
-- -- settings = {
-- -- implicitProjectConfiguration = {
-- -- checkJs = true,
-- -- },
-- -- },
-- })
-- end,
})
end,
}

0 comments on commit 8fbd696

Please sign in to comment.