summaryrefslogtreecommitdiffstats
path: root/.config/nvim/plugin/50-lsp.lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/plugin/50-lsp.lua')
-rw-r--r--.config/nvim/plugin/50-lsp.lua90
1 files changed, 90 insertions, 0 deletions
diff --git a/.config/nvim/plugin/50-lsp.lua b/.config/nvim/plugin/50-lsp.lua
new file mode 100644
index 0000000..de86ecd
--- /dev/null
+++ b/.config/nvim/plugin/50-lsp.lua
@@ -0,0 +1,90 @@
+--
+-- LSP client configurations
+--
+
+local function inspect_lsp()
+ local client = vim.lsp.get_clients()[1]
+ if client == nil then
+ vim.notify("No LSP client loaded")
+ return
+ end
+ vim.notify(vim.inspect(client.server_capabilities), vim.log.levels.INFO)
+end
+
+vim.pack.add({ "https://github.com/neovim/nvim-lspconfig" })
+
+vim.api.nvim_create_user_command("LspInspect", inspect_lsp, { desc = "Inpsect LSP client" })
+
+-- Enable LSP server capabilities if available when attaching, see `:help lsp-attach`
+vim.api.nvim_create_autocmd("LspAttach", {
+ desc = "Enable LSP capabilities",
+ group = vim.g.dotfiles.augroup,
+ callback = function(ev)
+ local client = assert(vim.lsp.get_client_by_id(ev.data.client_id))
+ if client:supports_method("textDocument/completion") then
+ vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true })
+ else
+ vim.notify("Client " .. client.name .. " does not support completion", vim.log.levels.WARN)
+ end
+ if client:supports_method("textDocument/inlayHint") then
+ vim.lsp.inlay_hint.enable(true, { bufnr = 0 })
+ else
+ vim.notify("Client " .. client.name .. " does not support inlay hints", vim.log.levels.WARN)
+ end
+ end,
+})
+
+vim.api.nvim_create_user_command("LspHintToggle", function()
+ vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = 0 }), { bufnr = 0 })
+end, { desc = "Toggle LSP inlay hints" })
+
+------------------------------------------------------------------------------------------------------------------------
+-- Lua
+------------------------------------------------------------------------------------------------------------------------
+
+vim.lsp.config("lua_ls", {
+ on_init = function(client)
+ -- Use `.luarc.json` or `.luarc.jsonc` if available, then exit
+ -- See `:help vim.lsp.ClientConfig` for `workspace_folders`
+ if client.workspace_folders then
+ local path = client.workspace_folders[1].name
+ if
+ path ~= vim.fn.stdpath("config")
+ and (vim.uv.fs_stat(path .. "/.luarc.json") or vim.uv.fs_stat(path .. "/.luarc.jsonc"))
+ then
+ return
+ end
+ end
+ -- See Lua language server configuration settings at https://luals.github.io/wiki/settings
+ client.config.settings.Lua = vim.tbl_deep_extend("force", client.config.settings.Lua, {
+ runtime = {
+ version = "Lua 5.1",
+ path = { "?.lua", "?/init.lua" }, -- See `:h lua-module-load`
+ },
+ workspace = {
+ checkThirdParty = false,
+ library = vim.api.nvim_get_runtime_file("", true), -- Load all folders in 'runtimepath'
+ },
+ })
+ end,
+})
+vim.lsp.enable("lua_ls")
+
+------------------------------------------------------------------------------------------------------------------------
+-- Bash
+------------------------------------------------------------------------------------------------------------------------
+
+vim.lsp.enable("bashls")
+
+------------------------------------------------------------------------------------------------------------------------
+-- Markdown
+------------------------------------------------------------------------------------------------------------------------
+
+vim.lsp.config("marksman", { filetypes = { "markdown" } })
+vim.lsp.enable("marksman")
+
+------------------------------------------------------------------------------------------------------------------------
+-- Vimscript
+------------------------------------------------------------------------------------------------------------------------
+
+vim.lsp.enable("vimls")