mirror of
https://github.com/aminnairi/dotfiles.git
synced 2026-09-14 16:52:12 +02:00
many changes to hopefully get the vim global to work with lua_ls
This commit is contained in:
@@ -3,18 +3,20 @@ return {
|
|||||||
event = "VeryLazy",
|
event = "VeryLazy",
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"williamboman/mason-lspconfig.nvim",
|
"williamboman/mason-lspconfig.nvim",
|
||||||
|
"hrsh7th/nvim-cmp",
|
||||||
},
|
},
|
||||||
init = function()
|
config = function()
|
||||||
|
local lspconfig = require("lspconfig")
|
||||||
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||||
local whichKey = require("which-key")
|
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"
|
|
||||||
|
|
||||||
|
local on_attach = function(_, buffer)
|
||||||
whichKey.register({
|
whichKey.register({
|
||||||
["<leader>l"] = {
|
["<leader>l"] = {
|
||||||
name = "LSP",
|
name = "LSP",
|
||||||
@@ -46,63 +48,63 @@ return {
|
|||||||
vim.lsp.buf.declaration()
|
vim.lsp.buf.declaration()
|
||||||
end,
|
end,
|
||||||
"Go to symbol declaration",
|
"Go to symbol declaration",
|
||||||
buffer = ev.buf,
|
buffer = buffer,
|
||||||
},
|
},
|
||||||
d = {
|
d = {
|
||||||
function()
|
function()
|
||||||
vim.lsp.buf.definition()
|
vim.lsp.buf.definition()
|
||||||
end,
|
end,
|
||||||
"Go to symbol definition",
|
"Go to symbol definition",
|
||||||
buffer = ev.buf,
|
buffer = buffer,
|
||||||
},
|
},
|
||||||
h = {
|
h = {
|
||||||
function()
|
function()
|
||||||
vim.lsp.buf.hover()
|
vim.lsp.buf.hover()
|
||||||
end,
|
end,
|
||||||
"Hover symbol documentation",
|
"Hover symbol documentation",
|
||||||
buffer = ev.buf,
|
buffer = buffer,
|
||||||
},
|
},
|
||||||
i = {
|
i = {
|
||||||
function()
|
function()
|
||||||
vim.lsp.buf.implementation()
|
vim.lsp.buf.implementation()
|
||||||
end,
|
end,
|
||||||
"Go to symbol implementation",
|
"Go to symbol implementation",
|
||||||
buffer = ev.buf,
|
buffer = buffer,
|
||||||
},
|
},
|
||||||
s = {
|
s = {
|
||||||
function()
|
function()
|
||||||
vim.lsp.buf.signature_help()
|
vim.lsp.buf.signature_help()
|
||||||
end,
|
end,
|
||||||
"Go to symbol signature",
|
"Go to symbol signature",
|
||||||
buffer = ev.buf,
|
buffer = buffer,
|
||||||
},
|
},
|
||||||
t = {
|
t = {
|
||||||
function()
|
function()
|
||||||
vim.lsp.buf.type_definition()
|
vim.lsp.buf.type_definition()
|
||||||
end,
|
end,
|
||||||
"Go to symbol type definition",
|
"Go to symbol type definition",
|
||||||
buffer = ev.buf,
|
buffer = buffer,
|
||||||
},
|
},
|
||||||
r = {
|
r = {
|
||||||
function()
|
function()
|
||||||
vim.lsp.buf.rename()
|
vim.lsp.buf.rename()
|
||||||
end,
|
end,
|
||||||
"Rename symbol",
|
"Rename symbol",
|
||||||
buffer = ev.buf,
|
buffer = buffer,
|
||||||
},
|
},
|
||||||
c = {
|
c = {
|
||||||
function()
|
function()
|
||||||
vim.lsp.buf.code_action()
|
vim.lsp.buf.code_action()
|
||||||
end,
|
end,
|
||||||
"LSP code action",
|
"LSP code action",
|
||||||
buffer = ev.buf,
|
buffer = buffer,
|
||||||
},
|
},
|
||||||
R = {
|
R = {
|
||||||
function()
|
function()
|
||||||
vim.lsp.buf.references()
|
vim.lsp.buf.references()
|
||||||
end,
|
end,
|
||||||
"Go to symbol deferences",
|
"Go to symbol deferences",
|
||||||
buffer = ev.buf,
|
buffer = buffer,
|
||||||
},
|
},
|
||||||
f = {
|
f = {
|
||||||
function()
|
function()
|
||||||
@@ -111,49 +113,49 @@ return {
|
|||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
"Format file",
|
"Format file",
|
||||||
buffer = ev.buf,
|
buffer = buffer,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
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
|
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.lua_ls.setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
settings = {
|
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 = {
|
Lua = {
|
||||||
runtime = {
|
runtime = {
|
||||||
-- Tell the language server which version of Lua you"re using (most likely LuaJIT in the case of Neovim)
|
-- Tell the language server which version of Lua you're using
|
||||||
version = "LuaJIT",
|
-- (most likely LuaJIT in the case of Neovim)
|
||||||
|
version = 'LuaJIT'
|
||||||
},
|
},
|
||||||
diagnostics = {
|
diagnostics = {
|
||||||
-- Get the language server to recognize the `vim` global
|
globals = {
|
||||||
globals = { "vim" },
|
"vim"
|
||||||
|
},
|
||||||
},
|
},
|
||||||
workspace = {
|
|
||||||
-- Make the server aware of Neovim runtime files
|
-- Make the server aware of Neovim runtime files
|
||||||
library = vim.api.nvim_get_runtime_file("", true),
|
workspace = {
|
||||||
},
|
checkThirdParty = false,
|
||||||
-- Do not send telemetry data containing a randomized but unique identifier
|
library = {
|
||||||
telemetry = {
|
vim.env.VIMRUNTIME
|
||||||
enable = false,
|
-- "${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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
client.notify("workspace/didChangeConfiguration", { settings = client.config.settings })
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
lspconfig.tsserver.setup({
|
lspconfig.tsserver.setup({
|
||||||
|
|||||||
Reference in New Issue
Block a user