diff --git a/nvim/after/lsp/arduino_language_server.lua b/nvim/after/lsp/arduino_language_server.lua deleted file mode 100644 index 321d14d..0000000 --- a/nvim/after/lsp/arduino_language_server.lua +++ /dev/null @@ -1,9 +0,0 @@ -return { - cmd = { - "arduino-language-server", - "-clangd", "/usr/lib/llvm/21/bin/clangd", - "-cli", "/usr/bin/arduino-cli", - "-cli-config", "~/.arduino15/arduino-cli.yaml", - "-fqbn", "esp32:esp32:adafruit_qtpy_esp32s3_nopsram" - } -} diff --git a/nvim/after/lsp/bashls.lua b/nvim/after/lsp/bashls.lua index c554369..04af992 100644 --- a/nvim/after/lsp/bashls.lua +++ b/nvim/after/lsp/bashls.lua @@ -1,3 +1,10 @@ return { - filetypes = { 'zsh', 'bash', 'sh' } + cmd = { 'bash-language-server', 'start' }, + settings = { + bashIde = { + globPattern = vim.env.GLOB_PATTERN or '*@(.sh|.inc|.bash|.command)', + }, + }, + filetypes = { 'zsh', 'bash', 'sh' }, + root_markers = { '.git' }, } diff --git a/nvim/after/lsp/clangd.lua b/nvim/after/lsp/clangd.lua new file mode 100644 index 0000000..596d811 --- /dev/null +++ b/nvim/after/lsp/clangd.lua @@ -0,0 +1,91 @@ +-- https://clangd.llvm.org/extensions.html#switch-between-sourceheader +local function switch_source_header(bufnr, client) + local method_name = 'textDocument/switchSourceHeader' + ---@diagnostic disable-next-line:param-type-mismatch + if not client or not client:supports_method(method_name) then + return vim.notify(('method %s is not supported by any servers active on the current buffer'):format(method_name)) + end + local params = vim.lsp.util.make_text_document_params(bufnr) + ---@diagnostic disable-next-line:param-type-mismatch + client:request(method_name, params, function(err, result) + if err then + error(tostring(err)) + end + if not result then + vim.notify('corresponding file cannot be determined') + return + end + vim.cmd.edit(vim.uri_to_fname(result)) + end, bufnr) +end + +local function symbol_info(bufnr, client) + local method_name = 'textDocument/symbolInfo' + ---@diagnostic disable-next-line:param-type-mismatch + if not client or not client:supports_method(method_name) then + return vim.notify('Clangd client not found', vim.log.levels.ERROR) + end + local win = vim.api.nvim_get_current_win() + local params = vim.lsp.util.make_position_params(win, client.offset_encoding) + ---@diagnostic disable-next-line:param-type-mismatch + client:request(method_name, params, function(err, res) + if err or #res == 0 then + -- Clangd always returns an error, there is no reason to parse it + return + end + local container = string.format('container: %s', res[1].containerName) ---@type string + local name = string.format('name: %s', res[1].name) ---@type string + vim.lsp.util.open_floating_preview({ name, container }, '', { + height = 2, + width = math.max(string.len(name), string.len(container)), + focusable = false, + focus = false, + title = 'Symbol Info', + }) + end, bufnr) +end + +---@class ClangdInitializeResult: lsp.InitializeResult +---@field offsetEncoding? string + +---@type vim.lsp.Config +return { + cmd = { 'clangd' }, + filetypes = { 'c', 'c.doxygen', 'cpp', 'cpp.doxygen', 'objc', 'objcpp', 'cuda' }, + root_markers = { + '.clangd', + '.clang-tidy', + '.clang-format', + 'compile_commands.json', + 'compile_flags.txt', + 'configure.ac', -- AutoTools + '.git', + }, + get_language_id = function(_, ftype) + local t = { objc = 'objective-c', objcpp = 'objective-cpp', cuda = 'cuda-cpp' } + return t[ftype] or ftype + end, + capabilities = { + textDocument = { + completion = { + editsNearCursor = true, + }, + }, + offsetEncoding = { 'utf-8', 'utf-16' }, + }, + ---@param init_result ClangdInitializeResult + on_init = function(client, init_result) + if init_result.offsetEncoding then + client.offset_encoding = init_result.offsetEncoding + end + end, + on_attach = function(client, bufnr) + vim.api.nvim_buf_create_user_command(bufnr, 'LspClangdSwitchSourceHeader', function() + switch_source_header(bufnr, client) + end, { desc = 'Switch between source/header' }) + + vim.api.nvim_buf_create_user_command(bufnr, 'LspClangdShowSymbolInfo', function() + symbol_info(bufnr, client) + end, { desc = 'Show symbol info' }) + end, +} diff --git a/nvim/after/lsp/gdscript.lua b/nvim/after/lsp/gdscript.lua index ccef542..2ddeef7 100644 --- a/nvim/after/lsp/gdscript.lua +++ b/nvim/after/lsp/gdscript.lua @@ -1,7 +1,7 @@ return { + cmd = vim.lsp.rpc.connect('127.0.0.1', 6005), filetypes = { 'gd', 'gdscript', 'gdscript3' }, root_markers = { 'project.godot', '.git' }, - cmd = vim.lsp.rpc.connect('127.0.0.1', 6005) } diff --git a/nvim/after/lsp/jinja-lsp.lua b/nvim/after/lsp/jinja-lsp.lua deleted file mode 100644 index ddb6bb1..0000000 --- a/nvim/after/lsp/jinja-lsp.lua +++ /dev/null @@ -1,3 +0,0 @@ -return { - template_extension = { 'html', 'jinja', 'j2', 'tera' } -} diff --git a/nvim/after/lsp/jinja_lsp.lua b/nvim/after/lsp/jinja_lsp.lua new file mode 100644 index 0000000..90dcd96 --- /dev/null +++ b/nvim/after/lsp/jinja_lsp.lua @@ -0,0 +1,15 @@ +vim.filetype.add { + extension = { + -- tera = 'jinja', + jinja = 'jinja', + jinja2 = 'jinja', + j2 = 'jinja', + } +} + +return { + name = 'jinja_lsp', + cmd = { 'jinja-lsp' }, + filetypes = { 'jinja', 'tera', 'html' }, + -- template_extension = { 'html', 'jinja', 'j2', 'tera' }, +} diff --git a/nvim/after/lsp/pylsp.lua b/nvim/after/lsp/pylsp.lua index 335d2f1..78a0e90 100644 --- a/nvim/after/lsp/pylsp.lua +++ b/nvim/after/lsp/pylsp.lua @@ -1,4 +1,14 @@ return { + cmd = { 'pylsp' }, + filetypes = { 'python' }, + root_markers = { + 'pyproject.toml', + 'setup.py', + 'setup.cfg', + 'requirements.txt', + 'Pipfile', + '.git', + }, settings = { pylsp = { plugins = { diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua index 8484d25..448f847 100644 --- a/nvim/lua/plugins.lua +++ b/nvim/lua/plugins.lua @@ -28,5 +28,4 @@ vim.schedule(function() -- Experimental -- require('plugins.note_taking') -- In house note taking plugin (TODO: rename once the plugin name is solidified) - -- require('plugins.nvim-lint') -- Linter loader end) diff --git a/nvim/lua/plugins/language_support.lua b/nvim/lua/plugins/language_support.lua index c577c33..42b68f2 100644 --- a/nvim/lua/plugins/language_support.lua +++ b/nvim/lua/plugins/language_support.lua @@ -9,7 +9,6 @@ end -- Start treesitter parsing on the current buffer vim.api.nvim_create_autocmd("FileType", { callback = function(ev) - -- Use pcall to prevent blocking errors pcall(vim.treesitter.start, ev.buf) end }) @@ -53,12 +52,11 @@ vim.api.nvim_create_autocmd('LspAttach', { -- end, -- }) - -- Keyboard Mappings local bufnr = args.buf - local bufopts = { noremap = true, silent = true, buffer = bufnr } - vim.keymap.set('n', '', function() vim.diagnostic.jump({count=-1, float=true}) end, bufopts) - vim.keymap.set('n', '', function() vim.diagnostic.jump({count=1, float=true}) end, bufopts) + + vim.keymap.set('n', '', function() vim.diagnostic.jump({ count = -1, float = true }) end, bufopts) + vim.keymap.set('n', '', function() vim.diagnostic.jump({ count = 1, float = true }) end, bufopts) vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, bufopts) vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) @@ -74,6 +72,14 @@ vim.api.nvim_create_autocmd('LspAttach', { }) -- Enable LSP engines --- vim.lsp.enable('clangd') -vim.lsp.enable('gdscript') -vim.lsp.enable('r_language_server') +local enabled_lsps = { + 'clangd', + 'gdscript', + 'jinja_lsp', + 'pylsp', + 'r_language_server', +} + +for _, lsp in pairs(enabled_lsps) do + vim.lsp.enable(lsp) +end diff --git a/wezterm/wezterm.lua b/wezterm/wezterm.lua index 605559e..a60937d 100644 --- a/wezterm/wezterm.lua +++ b/wezterm/wezterm.lua @@ -24,36 +24,6 @@ config.automatically_reload_config = true -- Linux specific fixes if wezterm.target_triple == 'x86_64-unknown-linux-gnu' then - -- Fixing the cursor theme - -- local xcursor_size = nil - -- local xcursor_theme = nil - -- - -- local theme_success, stdout, _ = wezterm.run_child_process({ - -- "gsettings", - -- "get", - -- "org.gnome.desktop.interface", - -- "cursor-theme" - -- }) - -- - -- if theme_success then - -- xcursor_theme = stdout:gsub("'(.+)'\n", "%1") - -- end - -- - -- local cursor_success, _, _ = wezterm.run_child_process({ - -- "gsettings", - -- "get", - -- "org.gnome.desktop.interface", - -- "cursor-size" - -- }) - -- - -- if cursor_success then - -- xcursor_size = tonumber(stdout) - -- end - -- - -- config.xcursor_theme = xcursor_theme - -- config.xcursor_size = xcursor_size - -- end cursor theme - config.disable_default_key_bindings = true end