many changes to hopefully get the vim global to work with lua_ls

This commit is contained in:
aminnairi
2023-12-24 12:24:16 +01:00
parent 35e7ff10ce
commit 67e8f8f45f
+225 -223
View File
@@ -1,241 +1,243 @@
return { return {
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
event = "VeryLazy", event = "VeryLazy",
dependencies = { dependencies = {
"williamboman/mason-lspconfig.nvim", "williamboman/mason-lspconfig.nvim",
}, "hrsh7th/nvim-cmp",
init = function() },
local whichKey = require("which-key") config = function()
local lspconfig = require("lspconfig")
local capabilities = require("cmp_nvim_lsp").default_capabilities()
local whichKey = require("which-key")
local signs = { Error = "󰅚 ", Warn = "󰀪 ", Hint = "󰌶 ", Info = "" }
-- Use LspAttach autocommand to only map the following keys for type, icon in pairs(signs) do
-- after the language server attaches to the current buffer local hl = "DiagnosticSign" .. type
vim.api.nvim_create_autocmd("LspAttach", { vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
group = vim.api.nvim_create_augroup("UserLspConfig", {}), end
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
whichKey.register({ local on_attach = function(_, buffer)
["<leader>l"] = { whichKey.register({
name = "LSP", ["<leader>l"] = {
d = { name = "LSP",
name = "LSP Diagnostic", d = {
o = { name = "LSP Diagnostic",
function() o = {
vim.diagnostic.open_float() function()
end, vim.diagnostic.open_float()
"Open LSP diagnostic", end,
}, "Open LSP diagnostic",
p = { },
function() p = {
vim.diagnostic.goto_prev() function()
end, vim.diagnostic.goto_prev()
"Previous LSP diagnostic", end,
}, "Previous LSP diagnostic",
n = { },
function() n = {
vim.diagnostic.goto_next() function()
end, vim.diagnostic.goto_next()
"Next LSP diagnostic", end,
}, "Next LSP diagnostic",
}, },
b = { },
name = "LSP Buffer", b = {
D = { name = "LSP Buffer",
function() D = {
vim.lsp.buf.declaration() function()
end, vim.lsp.buf.declaration()
"Go to symbol declaration", end,
buffer = ev.buf, "Go to symbol declaration",
}, buffer = buffer,
d = { },
function() d = {
vim.lsp.buf.definition() function()
end, vim.lsp.buf.definition()
"Go to symbol definition", end,
buffer = ev.buf, "Go to symbol definition",
}, buffer = buffer,
h = { },
function() h = {
vim.lsp.buf.hover() function()
end, vim.lsp.buf.hover()
"Hover symbol documentation", end,
buffer = ev.buf, "Hover symbol documentation",
}, buffer = buffer,
i = { },
function() i = {
vim.lsp.buf.implementation() function()
end, vim.lsp.buf.implementation()
"Go to symbol implementation", end,
buffer = ev.buf, "Go to symbol implementation",
}, buffer = buffer,
s = { },
function() s = {
vim.lsp.buf.signature_help() function()
end, vim.lsp.buf.signature_help()
"Go to symbol signature", end,
buffer = ev.buf, "Go to symbol signature",
}, buffer = buffer,
t = { },
function() t = {
vim.lsp.buf.type_definition() function()
end, vim.lsp.buf.type_definition()
"Go to symbol type definition", end,
buffer = ev.buf, "Go to symbol type definition",
}, buffer = buffer,
r = { },
function() r = {
vim.lsp.buf.rename() function()
end, vim.lsp.buf.rename()
"Rename symbol", end,
buffer = ev.buf, "Rename symbol",
}, buffer = buffer,
c = { },
function() c = {
vim.lsp.buf.code_action() function()
end, vim.lsp.buf.code_action()
"LSP code action", end,
buffer = ev.buf, "LSP code action",
}, buffer = buffer,
R = { },
function() R = {
vim.lsp.buf.references() function()
end, vim.lsp.buf.references()
"Go to symbol deferences", end,
buffer = ev.buf, "Go to symbol deferences",
}, buffer = buffer,
f = { },
function() f = {
vim.lsp.buf.format({ function()
async = true, vim.lsp.buf.format({
}) async = true,
end, })
"Format file", end,
buffer = ev.buf, "Format file",
}, buffer = buffer,
}, },
}, },
}) },
end, })
}) end
local signs = { Error = "󰅚 ", Warn = "󰀪 ", Hint = "󰌶 ", Info = "" } lspconfig.lua_ls.setup({
capabilities = capabilities,
on_attach = on_attach,
on_init = function(client)
local path = client.workspace_folders[1].name
if not vim.loop.fs_stat(path .. '/.luarc.json') and not vim.loop.fs_stat(path .. '/.luarc.jsonc') then
client.config.settings = vim.tbl_deep_extend('force', client.config.settings, {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using
-- (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT'
},
diagnostics = {
globals = {
"vim"
},
},
-- Make the server aware of Neovim runtime files
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME
-- "${3rd}/luv/library"
-- "${3rd}/busted/library",
}
-- or pull in all of 'runtimepath'. NOTE: this is a lot slower
-- library = vim.api.nvim_get_runtime_file("", true)
}
}
})
for type, icon in pairs(signs) do client.notify("workspace/didChangeConfiguration", { settings = client.config.settings })
local hl = "DiagnosticSign" .. type end
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) return true
end end
end, })
config = function()
local lspconfig = require("lspconfig")
local capabilities = require("cmp_nvim_lsp").default_capabilities()
local on_attach = function() end
lspconfig.lua_ls.setup({ lspconfig.tsserver.setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
settings = { })
Lua = {
runtime = {
-- Tell the language server which version of Lua you"re using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
},
},
})
lspconfig.tsserver.setup({ lspconfig.volar.setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
}) filetypes = {
"vue",
},
})
lspconfig.volar.setup({ lspconfig.cssls.setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
filetypes = { filetypes = {
"vue", "css",
}, "scss",
}) "sass",
"less",
},
})
lspconfig.cssls.setup({ lspconfig.cssmodules_ls.setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
filetypes = { filetypes = {
"css", "javascript",
"scss", "javascriptreact",
"sass", "typescript",
"less", "typescriptreact",
}, },
}) })
lspconfig.cssmodules_ls.setup({ lspconfig.prismals.setup({
capabilities = capabilities, on_attach = on_attach,
on_attach = on_attach, filetypes = {
filetypes = { "prisma",
"javascript", },
"javascriptreact", capabilities = capabilities,
"typescript", })
"typescriptreact",
},
})
lspconfig.prismals.setup({ lspconfig.yamlls.setup({
on_attach = on_attach, capabilities = capabilities,
filetypes = { filetypes = {
"prisma", "yaml",
}, },
capabilities = capabilities, })
})
lspconfig.yamlls.setup({ lspconfig.marksman.setup({
capabilities = capabilities, capabilities = capabilities,
filetypes = { filetypes = {
"yaml", "markdown",
}, },
}) })
lspconfig.marksman.setup({ lspconfig.eslint.setup({
capabilities = capabilities, capabilities = capabilities,
filetypes = { on_attach = on_attach,
"markdown", })
},
})
lspconfig.eslint.setup({ lspconfig.dockerls.setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
}) })
lspconfig.dockerls.setup({ lspconfig.rust_analyzer.setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
}) })
lspconfig.rust_analyzer.setup({ lspconfig.intelephense.setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
}) })
lspconfig.intelephense.setup({ lspconfig.elmls.setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = on_attach, on_attach = on_attach,
}) })
end,
lspconfig.elmls.setup({
capabilities = capabilities,
on_attach = on_attach,
})
end,
} }