From 85a216b44eb0830e8321a0d39f698bc60a990365 Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 12 Jul 2026 23:58:37 +0200 Subject: [PATCH] feat: add lsp configuration --- lua/check_dependencies/init.lua | 54 +++++++++++++++---------------- lua/config/check_dependencies.lua | 4 +-- lua/config/init.lua | 24 +++++++------- lua/config/keybinds.lua | 8 +++++ lua/config/lps_mapping.md | 24 ++++++++++++++ lua/config/lsp.lua | 14 ++++++++ 6 files changed, 88 insertions(+), 40 deletions(-) create mode 100644 lua/config/lps_mapping.md create mode 100644 lua/config/lsp.lua diff --git a/lua/check_dependencies/init.lua b/lua/check_dependencies/init.lua index da105a5..fa88605 100644 --- a/lua/check_dependencies/init.lua +++ b/lua/check_dependencies/init.lua @@ -1,44 +1,44 @@ local M = {} -cmdsList = nil +CmdsList = nil function M.checkCommand(cmd, desc) - local toRun = "" + local toRun = "" - if IS_UNIX then - toRun = "command -v " .. cmd - else - toRun = "where " .. cmd - end + if IS_UNIX then + toRun = "command -v " .. cmd + else + toRun = "where " .. cmd + end - local p = io.popen(toRun) - local output = p:read("*l") - p:close() + local p = io.popen(toRun) + local output = p:read("*l") + p:close() - if output == nil and desc ~= nil and desc ~= "" then - vim.api.nvim_echo({ { " ✗ " .. cmd .. " [" .. desc .. "] - not found!", "DiagnosticError" } }, true, {}) - elseif output == nil then - vim.api.nvim_echo({ { " ✗ " .. cmd .. " not found!", "DiagnosticError" } }, true, {}) - else - vim.api.nvim_echo({ { " ✓ " .. cmd, "DiagnosticOk" } }, true, {}) - end + if output == nil and desc ~= nil and desc ~= "" then + vim.api.nvim_echo({ { " ✗ " .. cmd .. " [" .. desc .. "] - not found!", "DiagnosticError" } }, true, {}) + elseif output == nil then + vim.api.nvim_echo({ { " ✗ " .. cmd .. " not found!", "DiagnosticError" } }, true, {}) + else + vim.api.nvim_echo({ { " ✓ " .. cmd, "DiagnosticOk" } }, true, {}) + end end function M.run() - if cmdsList == nil or next(cmdsList) == nil then - vim.api.nvim_echo({{"Dependencies list passed is null or empty, nothing to check", "DiagnosticWarn"}}, true, {}) - return - end + if CmdsList == nil or next(CmdsList) == nil then + vim.api.nvim_echo({ { "Dependencies list passed is null or empty, nothing to check", "DiagnosticWarn" } }, true, {}) + return + end - print("Check installed system commands:") - for i, cmd in ipairs(cmdsList) do - M.checkCommand(cmd.cmd, cmd.desc) - end + print("Check installed system commands:") + for _, cmd in ipairs(CmdsList) do + M.checkCommand(cmd.cmd, cmd.desc) + end end function M.setup(cmds) - IS_UNIX = package.config:sub(1, 1) ~= "\\" - cmdsList = cmds + IS_UNIX = package.config:sub(1, 1) ~= "\\" + CmdsList = cmds end return M diff --git a/lua/config/check_dependencies.lua b/lua/config/check_dependencies.lua index ea811fb..75d0526 100644 --- a/lua/config/check_dependencies.lua +++ b/lua/config/check_dependencies.lua @@ -1,4 +1,4 @@ -function run() +function Run() local dep = require("check_dependencies") dep.setup({ @@ -20,4 +20,4 @@ function run() dep.run() end -vim.api.nvim_create_user_command("DependenciesCheck", run, {}) +vim.api.nvim_create_user_command("DependenciesCheck", Run, {}) diff --git a/lua/config/init.lua b/lua/config/init.lua index 3e0aa7b..9617cfa 100644 --- a/lua/config/init.lua +++ b/lua/config/init.lua @@ -1,13 +1,15 @@ -require('config.settings') -require('config.keybinds') -require('config.pack') +require("config.settings") +require("config.keybinds") +require("config.pack") +require("config.lsp") -require('config.theme') -require('config.neogit') -require('config.oil') -require('config.autopairs') -require('config.fzf') -require('config.indent_blank_line') -require('config.conform') +require("config.theme") +require("config.neogit") +require("config.oil") +require("config.autopairs") +require("config.fzf") +require("config.indent_blank_line") +require("config.conform") + +require("config.check_dependencies") -require('config.check_dependencies') diff --git a/lua/config/keybinds.lua b/lua/config/keybinds.lua index f301338..8a15923 100644 --- a/lua/config/keybinds.lua +++ b/lua/config/keybinds.lua @@ -54,3 +54,11 @@ end, { }) bind("n", "", "FormatConform") + +-- Lsp +bind("n", "e", vim.diagnostic.open_float) +bind("n", "gl", vim.diagnostic.setloclist) +bind("n", "gf", vim.diagnostic.setqflist) +bind("n", "f", vim.lsp.buf.format) +bind("n", "K", vim.lsp.buf.hover) +bind("n", "k", vim.lsp.buf.signature_help) diff --git a/lua/config/lps_mapping.md b/lua/config/lps_mapping.md new file mode 100644 index 0000000..24911ec --- /dev/null +++ b/lua/config/lps_mapping.md @@ -0,0 +1,24 @@ +| Set | Mapping | Function | Neovim Function | Brief Description | +| --- | ------------- | ---------------------------- | --------------------------------------- | --------------------------------------------------------------------------- | +| y | `gd` | Go to Definition | `vim.lsp.buf.definition()` | Jump to the symbol's definition. | +| y | `gD` | Go to Declaration | `vim.lsp.buf.declaration()` | Jump to the symbol's declaration. | +| y | `K` | Hover Documentation | `vim.lsp.buf.hover()` | Show documentation and type information for the symbol under the cursor. | +| y | `k` | Signature Help | `vim.lsp.buf.signature_help()` | Display the current function signature and parameter information. | +| y | `grr` | Find References | `vim.lsp.buf.references()` | List all references to the symbol across the project. | +| y | `gri` | Go to Implementation | `vim.lsp.buf.implementation()` | Jump to the implementation(s) of the symbol. | +| y | `grt` | Go to Type Definition | `vim.lsp.buf.type_definition()` | Jump to the definition of the symbol's type. | +| y | `grn` | Rename Symbol | `vim.lsp.buf.rename()` | Rename the symbol and update all references. | +| y | `gra` | Code Actions | `vim.lsp.buf.code_action()` | Show available quick fixes and refactoring actions. | +| ? | `gO` | Document Symbols | `vim.lsp.buf.document_symbol()` | List all symbols (functions, classes, variables, etc.) in the current file. | +| y | `[d` | Previous Diagnostic | `vim.diagnostic.goto_prev()` | Jump to the previous diagnostic (error, warning, hint, or info). | +| y | `]d` | Next Diagnostic | `vim.diagnostic.goto_next()` | Jump to the next diagnostic. | +| y | `e` | Diagnostic Float | `vim.diagnostic.open_float()` | Show diagnostic details in a floating window. | +| y | `gl` | Diagnostics to Location List | `vim.diagnostic.setloclist()` | Populate the location list with diagnostics from the current buffer. | +| y | `f` | Format Buffer | `vim.lsp.buf.format()` | Format the current buffer using the LSP server. | +| n | `wa` | Add Workspace Folder | `vim.lsp.buf.add_workspace_folder()` | Add a folder to the current LSP workspace. | +| n | `wr` | Remove Workspace Folder | `vim.lsp.buf.remove_workspace_folder()` | Remove a folder from the current LSP workspace. | +| n | `wl` | List Workspace Folders | `vim.lsp.buf.list_workspace_folders()` | List all folders in the current LSP workspace. | +| n | `cl` | Run CodeLens | `vim.lsp.codelens.run()` | Execute the CodeLens action at the current cursor position. | +| n | `cr` | Refresh CodeLens | `vim.lsp.codelens.refresh()` | Refresh available CodeLens actions in the buffer. | +| n | `th` | Toggle Inlay Hints | `vim.lsp.inlay_hint.enable()` | Enable or disable inline type and parameter hints. | + diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua new file mode 100644 index 0000000..1be0e24 --- /dev/null +++ b/lua/config/lsp.lua @@ -0,0 +1,14 @@ +vim.lsp.config["lua_lsp"] = { + cmd = { "lua-language-server" }, + filetypes = { "lua" }, + root_markers = { { ".luarc.json", ".luarc.jsonc" }, ".git" }, + settings = { + Lua = { + runtime = { + version = "LuaJIT", + }, + }, + }, +} + +vim.lsp.enable('lua_lsp')