From 316cd28587d10b0eca86898d81f0a83b5acff181 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Thu, 4 Jul 2024 12:41:35 +0200 Subject: [PATCH] =?UTF-8?q?lsp=20pls=20w=C3=B6rk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/custom/plugins/configs/lsp.lua | 31 ++++ lua/custom/plugins/configs/lspsettings.lua | 202 +++++++++++++++++++++ lua/custom/plugins/lsp.lua | 8 + lua/custom/plugins/ui.lua | 7 +- 4 files changed, 243 insertions(+), 5 deletions(-) create mode 100644 lua/custom/plugins/configs/lsp.lua create mode 100644 lua/custom/plugins/configs/lspsettings.lua create mode 100644 lua/custom/plugins/lsp.lua diff --git a/lua/custom/plugins/configs/lsp.lua b/lua/custom/plugins/configs/lsp.lua new file mode 100644 index 0000000..8efd086 --- /dev/null +++ b/lua/custom/plugins/configs/lsp.lua @@ -0,0 +1,31 @@ +local lspconfig = require "lspconfig" +local lspsettings = require "custom.plugins.configs.lspsettings" + +-- these are using the defaults +local servers = { + "html", + "cssls", + "tsserver", + "clangd", + "bashls", + "cmake", + "yamlls", + "texlab", + "csharp_ls", +} + +for _, lsp in ipairs(servers) do + lspconfig[lsp].setup() +end + +local server_with_settings = { + -- "textlsp", + "ltex", + "rust_analyzer", + "basedpyright", +} + +for _, lsp in ipairs(server_with_settings) do + lspconfig[lsp].setup(lspsettings[lsp]) +end + diff --git a/lua/custom/plugins/configs/lspsettings.lua b/lua/custom/plugins/configs/lspsettings.lua new file mode 100644 index 0000000..67f82ff --- /dev/null +++ b/lua/custom/plugins/configs/lspsettings.lua @@ -0,0 +1,202 @@ +local M = {} + +M.basedpyright = { + root_dir = vim.loop.cwd, + flags = { debounce_text_changes = 300 }, + single_file_support = true, + settings = { + python = { + analysis = { + autoSearchPaths = true, + diagnosticMode = "openFilesOnly", + useLibraryCodeForTypes = true, + typeCheckingMode = "basic", + }, + }, + }, +} +M.rust_analyzer = { + settings = { + ["rust-analyzer"] = { + check = { + command = "clippy", + }, + imports = { + granularity = { + group = "module", + }, + prefix = "self", + }, + cargo = { + buildScripts = { + enable = true, + }, + }, + procMacro = { + enable = true, + }, + }, + }, +} + +M.ltex = { + use_spellfile = false, + settings = { + ltex = { + checkFrequency = "save", -- shut up while i'm just editing, see + -- specific language (such as en-GB or de-DE is recommended, but I + -- want multilingual) + language = "auto", + enabled = { + "bibtex", + "tex", + "latex", + "gitcommit", + "markdown", + "org", + "restructuredtext", + "rsweave", + "quarto", + "rmd", + "context", + -- "html", + -- "xhtml", + }, + additionalRules = { + enablePickyRules = true, + -- thats cool, but often adds diagnostics in + -- places where a german might confuse words that are similar + -- between english and german REGARDLESS of context. I seem to use the + -- english words only in the proper contexts, so leaving this on + -- just adds annoying hints like 'Hinweis: "list/NN.*" (English) bedeutet "Liste", + -- "Verzeichnis" (German). Meinten Sie vielleicht 'cunning', 'trick'?' + -- everytime I use the word "list". I liked that this makes the hints be + -- in german regardless of the language I'm working in through... + --motherTongue = "de", + }, + -- load token and additional languagetool items later + }, + }, +} + +M.textlsp = { + filetypes = { + "bibtex", + "tex", + "latex", + "gitcommit", + "markdown", + "org", + "restructuredtext", + "rsweave", + "quarto", + "rmd", + "context", + "html", + "xhtml", + }, + settings = { + textLSP = { + analysers = { + languagetool = { + enabled = true, + check_text = { + on_open = true, + on_save = true, + on_change = false, + }, + }, + gramformer = { + -- gramformer dependency needs to be installed manually + enabled = true, + gpu = false, + check_text = { + on_open = false, + on_save = true, + on_change = false, + }, + }, + hf_checker = { + enabled = false, + gpu = false, + quantize = 32, + model = "pszemraj/flan-t5-large-grammar-synthesis", + min_length = 40, + check_text = { + on_open = false, + on_save = true, + on_change = false, + }, + }, + hf_instruction_checker = { + enabled = true, + gpu = false, + quantize = 32, + model = "grammarly/coedit-large", + min_length = 40, + check_text = { + on_open = false, + on_save = true, + on_change = false, + }, + }, + hf_completion = { + enabled = true, + gpu = false, + quantize = 32, + model = "bert-base-multilingual-cased", + topk = 5, + }, + -- openai = { + -- enabled = false, + -- api_key = "", + -- check_text = { + -- on_open = false, + -- on_save = false, + -- on_change = false, + -- }, + -- model = "gpt-3.5-turbo", + -- max_token = 16, + -- }, + -- grammarbot = { + -- enabled = false, + -- api_key = "", + -- -- longer texts are split, this parameter sets the maximum number of splits per analysis + -- input_max_requests = 1, + -- check_text = { + -- on_open = false, + -- on_save = false, + -- on_change = false, + -- }, + -- }, + }, + documents = { + -- org = { + -- org_todo_keywords = { + -- "TODO", + -- "IN_PROGRESS", + -- "DONE", + -- }, + -- }, + txt = { + parse = true, + }, + }, + }, + }, +} + +-- load secrets +-- the secret module should just return a string with the token +local available, token = require("custom.utils").try_require "custom.secret.languagetool_token" +if available then + M.ltex.languageToolOrg = { + apiKey = token, + username = "accounts@cscherr.de", + languageToolHttpServerUrl = "https://api.languagetoolplus.com/v2/", + } + M.ltex.languageToolHttpServerUrl = "https://api.languagetoolplus.com/v2/" +end + +return M + diff --git a/lua/custom/plugins/lsp.lua b/lua/custom/plugins/lsp.lua new file mode 100644 index 0000000..8583502 --- /dev/null +++ b/lua/custom/plugins/lsp.lua @@ -0,0 +1,8 @@ +return { + { + 'neovim/nvim-lspconfig', + config = function() + require "custom.plugins.configs.lsp" + end, + }, +} diff --git a/lua/custom/plugins/ui.lua b/lua/custom/plugins/ui.lua index 1bd9b1e..08003bf 100644 --- a/lua/custom/plugins/ui.lua +++ b/lua/custom/plugins/ui.lua @@ -11,7 +11,6 @@ return { { 'tf', ' NvimTreeToggle ', desc = '[T]oggle [F]ile explorer' }, }, }, - { 'ggandor/leap.nvim', lazy = false, @@ -33,7 +32,6 @@ return { }, { 'kdheepak/lazygit.nvim', - lazy = false, keys = { 'gg' }, cmd = 'LazyGit', -- optional for floating window border decoration @@ -48,12 +46,11 @@ return { mode = { 'n', 'v' }, [';'] = { name = '+telescope' }, [';f'] = { name = '+find' }, - [';d'] = { name = '+lsp/todo' }, ['g'] = { name = '+goto' }, [']'] = { name = '+next' }, ['['] = { name = '+prev' }, - ['x'] = { name = '+diagnostics/quickfix' }, - ['d'] = { name = '+debug' }, + ['d'] = { name = '+lsp/debug' }, + ['r'] = { name = '+diagnostics/quickfix' }, ['c'] = { name = '+code' }, ['g'] = { name = '+git' }, ['t'] = { name = '+toggle/tools' },