diff --git a/.config/nvim/lsp/gopls.lua b/.config/nvim/lsp/gopls.lua index e69de29..58528ce 100644 --- a/.config/nvim/lsp/gopls.lua +++ b/.config/nvim/lsp/gopls.lua @@ -0,0 +1,8 @@ +return { + cmd = { 'gopls' }, + filetypes = { 'go' }, + root_markers = { + 'go.mod', + 'go.sum', + }, +} diff --git a/.config/nvim/lsp/lua-language-server.lua b/.config/nvim/lsp/luals.lua similarity index 100% rename from .config/nvim/lsp/lua-language-server.lua rename to .config/nvim/lsp/luals.lua diff --git a/.config/nvim/lsp/pyright.lua b/.config/nvim/lsp/pyright.lua index ad93565..3a2e9ec 100644 --- a/.config/nvim/lsp/pyright.lua +++ b/.config/nvim/lsp/pyright.lua @@ -1,5 +1,20 @@ +local function set_python_path(path) + local clients = vim.lsp.get_clients { + bufnr = vim.api.nvim_get_current_buf(), + name = 'pyright', + } + for _, client in ipairs(clients) do + if client.settings then + client.settings.python = vim.tbl_deep_extend('force', client.settings.python, { pythonPath = path }) + else + client.config.settings = vim.tbl_deep_extend('force', client.config.settings, { python = { pythonPath = path } }) + end + client.notify('workspace/didChangeConfiguration', { settings = nil }) + end +end + return { - cmd = { 'pyright' }, + cmd = { 'pyright-langserver', '--stdio' }, filetypes = { 'python' }, root_markers = { 'pyproject.toml', @@ -14,7 +29,23 @@ return { analysis = { autoSearchPaths = true, useLibraryCodeForTypes = true, + diagnosticMode = 'openFilesOnly', }, }, }, + on_attach = function(client, bufnr) + vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightOrganizeImports', function() + client:exec_cmd { + command = 'pyright.organizeimports', + arguments = { vim.uri_from_bufnr(bufnr) }, + } + end, { + desc = 'Organize Imports', + }) + vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightSetPythonPath', set_python_path, { + desc = 'Reconfigure pyright with the provided python path', + nargs = 1, + complete = 'file', + }) + end, } diff --git a/.config/nvim/lsp/ruff.lua b/.config/nvim/lsp/ruff.lua new file mode 100644 index 0000000..1df0b76 --- /dev/null +++ b/.config/nvim/lsp/ruff.lua @@ -0,0 +1,33 @@ +---@brief +--- +--- https://github.com/astral-sh/ruff +--- +--- A Language Server Protocol implementation for Ruff, an extremely fast Python linter and code formatter, written in Rust. It can be installed via `pip`. +--- +--- ```sh +--- pip install ruff +--- ``` +--- +--- **Available in Ruff `v0.4.5` in beta and stabilized in Ruff `v0.5.3`.** +--- +--- This is the new built-in language server written in Rust. It supports the same feature set as `ruff-lsp`, but with superior performance and no installation required. Note that the `ruff-lsp` server will continue to be maintained until further notice. +--- +--- Server settings can be provided via: +--- +--- ```lua +--- vim.lsp.config('ruff', { +--- init_options = { +--- settings = { +--- -- Server settings should go here +--- } +--- } +--- }) +--- ``` +--- +--- Refer to the [documentation](https://docs.astral.sh/ruff/editors/) for more details. +return { + cmd = { 'ruff', 'server' }, + filetypes = { 'python' }, + root_markers = { 'pyproject.toml', 'ruff.toml', '.ruff.toml', '.git' }, + settings = {}, +} diff --git a/.config/nvim/lsp/rust-analyzer.lua b/.config/nvim/lsp/rust-analyzer.lua index e69de29..a564707 100644 --- a/.config/nvim/lsp/rust-analyzer.lua +++ b/.config/nvim/lsp/rust-analyzer.lua @@ -0,0 +1 @@ +return {} diff --git a/.config/nvim/lsp/tsls.lua b/.config/nvim/lsp/tsls.lua index e69de29..a564707 100644 --- a/.config/nvim/lsp/tsls.lua +++ b/.config/nvim/lsp/tsls.lua @@ -0,0 +1 @@ +return {} diff --git a/.config/nvim/lsp/yaml-language-server.lua b/.config/nvim/lsp/yaml-language-server.lua deleted file mode 100644 index e69de29..0000000 diff --git a/.config/nvim/lsp/yamlls.lua b/.config/nvim/lsp/yamlls.lua new file mode 100644 index 0000000..a564707 --- /dev/null +++ b/.config/nvim/lsp/yamlls.lua @@ -0,0 +1 @@ +return {} diff --git a/.config/nvim/lua/plugins/linter.lua b/.config/nvim/lua/plugins/linter.lua deleted file mode 100644 index 0c86a52..0000000 --- a/.config/nvim/lua/plugins/linter.lua +++ /dev/null @@ -1,83 +0,0 @@ -return { - 'mfussenegger/nvim-lint', - event = { 'BufReadPre', 'BufNewFile' }, - dependencies = { - { 'williamboman/mason.nvim', config = true }, - }, - config = function() - local lint = require 'lint' - -- Define a custom biome linter - local mason_registry = require 'mason-registry' - local biome_path = mason_registry.get_package('biome'):get_install_path() .. '/node_modules/@biomejs/biome/bin/biome' - lint.linters.biome = { - name = 'biome', - cmd = biome_path, -- Command to run the linter - args = { 'lint' }, -- Arguments for the command - stdin = false, -- Send content via stdin - append_fname = true, -- Automatically add the current file name to the command arguments - stream = 'both', -- Result stream - ignore_exitcode = true, -- Treat exit code != 1 as an error - parser = function(output) - local diagnostics = {} - - -- The diagnostic details we need are spread in the first 3 lines of - -- each error report. These variables are declared out of the FOR - -- loop because we need to carry their values to parse multiple lines. - local fetch_message = false - local lnum, col, code, message - - -- When a lnum:col:code line is detected fetch_message is set to true. - -- While fetch_message is true we will search for the error message. - -- When a error message is detected, we will create the diagnostic and - -- set fetch_message to false to restart the process and get the next - -- diagnostic. - for _, line in ipairs(vim.fn.split(output, '\n')) do - if fetch_message then - _, _, message = string.find(line, '%s×(.+)') - - if message then - message = (message):gsub('^%s+×%s*', '') - - table.insert(diagnostics, { - source = 'biomejs', - lnum = tonumber(lnum) - 1, - col = tonumber(col), - message = message, - code = code, - }) - - fetch_message = false - end - else - _, _, lnum, col, code = string.find(line, '[^:]+:(%d+):(%d+)%s([%a%/]+)') - - if lnum then - fetch_message = true - end - end - end - - return diagnostics - end, -- Custom parser for output - } - -- Set up linters by filetype - lint.linters_by_ft = { - vue = { 'biome' }, -- Lint Vue files using the overridden biome command - javascript = { 'biome' }, - json = { 'biome' }, - typescript = { 'biome' }, - javascriptreact = { 'biome' }, - typescriptreact = { 'biome' }, - python = { 'ruff', 'mypy' }, - -- Add more filetypes as needed - } - - local lint_augroup = vim.api.nvim_create_augroup('lint', { clear = true }) - vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost', 'InsertLeave' }, { - group = lint_augroup, - callback = function() - lint.try_lint() - end, - }) - end, -} diff --git a/.config/nvim/lua/plugins/lsp.lua b/.config/nvim/lua/plugins/lsp.lua index 357e322..a564707 100644 --- a/.config/nvim/lua/plugins/lsp.lua +++ b/.config/nvim/lua/plugins/lsp.lua @@ -1,216 +1 @@ -return { - - 'neovim/nvim-lspconfig', - dependencies = { - - { 'williamboman/mason.nvim', config = true }, - 'williamboman/mason-lspconfig.nvim', - 'WhoIsSethDaniel/mason-tool-installer.nvim', - - { 'j-hui/fidget.nvim', opts = {} }, - - 'hrsh7th/cmp-nvim-lsp', - }, - config = function() - vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }), - callback = function(event) - local map = function(keys, func, desc, mode) - mode = mode or 'n' - vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) - end - - map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') - map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') - map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') - map('D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') - map('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') - map('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') - map('rn', vim.lsp.buf.rename, '[R]e[n]ame') - map('ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' }) - map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') - - local client = vim.lsp.get_client_by_id(event.data.client_id) - if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then - local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false }) - vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { - buffer = event.buf, - group = highlight_augroup, - callback = vim.lsp.buf.document_highlight, - }) - - vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { - buffer = event.buf, - group = highlight_augroup, - callback = vim.lsp.buf.clear_references, - }) - - vim.api.nvim_create_autocmd('LspDetach', { - group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }), - callback = function(event2) - vim.lsp.buf.clear_references() - vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event2.buf } - end, - }) - end - - if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then - map('th', function() - vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) - end, '[T]oggle Inlay [H]ints') - end - end, - }) - - local capabilities = vim.lsp.protocol.make_client_capabilities() - capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities()) - local mason_registry = require 'mason-registry' - local vue_language_server_path = mason_registry.get_package('vue-language-server'):get_install_path() .. '/node_modules/@vue/language-server' - local servers = { - rust_analyzer = { - filetypes = { 'rust' }, - capabilities = capabilities, - }, - vtsls = { - filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact' }, - settings = { - vtsls = { - -- autoUseWorkspaceTsdk = true, - tsserver = { - globalPlugins = { - { - name = '@vue/typescript-plugin', - location = vue_language_server_path, - languages = { 'vue' }, - configNamespace = 'typescript', - enableForWorkspaceTypeScriptVersions = true, - }, - }, - }, - }, - }, - capabilities = capabilities, - }, - html = { - filetypes = { 'html' }, - capabilities = capabilities, - opts = { - settings = { - html = { - format = { - templating = true, - wrapLineLength = 120, - wrapAttributes = 'auto', - }, - hover = { - documentation = true, - references = true, - }, - }, - }, - }, - }, - biome = { - capabilities = capabilities, - }, - svelte = { - capabilities = capabilities, - }, - phpactor = { - filetypes = { 'php' }, - capabilities = capabilities, - }, - vuels = { - filetypes = { 'vue' }, - capabilities = capabilities, - init_options = { - config = { - css = {}, - emmet = {}, - html = { - suggest = {}, - }, - javascript = { - format = {}, - }, - stylusSupremacy = {}, - typescript = { - format = {}, - }, - vetur = { - completion = { - autoImport = true, - tagCasing = 'kebab', - useScaffoldSnippets = true, - }, - format = { - defaultFormatter = { - js = 'biome', - ts = 'biome', - }, - defaultFormatterOptions = {}, - scriptInitialIndent = false, - styleInitialIndent = false, - }, - useWorkspaceDependencies = false, - validation = { - script = true, - style = true, - template = true, - templateProps = true, - interpolation = true, - }, - experimental = { - templateInterpolationService = true, - }, - }, - }, - }, - }, - pyright = { - settings = { - pyright = { - disableOrganizeImports = true, -- Using Ruff - }, - python = { - analysis = { - ignore = { '*' }, -- Using Ruff - typeCheckingMode = 'off', -- Using mypy - }, - }, - }, - }, - gopls = { - capabilities = capabilities, - }, - lua_ls = { - settings = { - Lua = { - completion = { - callSnippet = 'Replace', - }, - }, - }, - }, - } - - require('mason').setup() - - local ensure_installed = vim.tbl_keys(servers or {}) - vim.list_extend(ensure_installed, { - 'stylua', - }) - require('mason-tool-installer').setup { ensure_installed = ensure_installed } - - require('mason-lspconfig').setup { - handlers = { - function(server_name) - local server = servers[server_name] or {} - - server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) - require('lspconfig')[server_name].setup(server) - end, - }, - } - end, -} +return {}