From 63c6c81f6e19036bd0bd0ed9d88de1a3e2e6a214 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 7 Jun 2025 09:38:37 +0200 Subject: [PATCH] nvim: Fix ltex disabled autostart Fixes #1ef7570. We implement our own autostart-aware lsp register function. Any lsp which has the option {autostart=false} set at their config root will be not automatically enabled and can instead be enabled on demand. --- README.md | 2 +- nvim/.config/nvim/lua/plugins/lsp.lua | 40 ++++++++++++++++++--------- sh/README.md | 17 ++++++------ 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 588629c..a9c852a 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ After all files are linked and you open a new shell session, the `dotlink` alias [^1]: This alias only works when the dotfiles are cloned into `~/.dotfiles`, mirroring my setup. This is due to a hard-coded cd into this directory. - If your dotfiles lie in another directory and you want to use the dotlink alias, simply change the corresponding line in `bootstrap/.config/sh/alias.d/dotlink.sh` + If your dotfiles lie in another directory, and you want to use the dotlink alias, simply change the corresponding line in `bootstrap/.config/sh/alias.d/dotlink.sh` Both automatic installation paths are presumably somewhat brittle. In any case, I would suggest to manually look through the files for things you want instead of copying and activating everything. Dotfiles are too personal to be standardized like that. diff --git a/nvim/.config/nvim/lua/plugins/lsp.lua b/nvim/.config/nvim/lua/plugins/lsp.lua index b2478f7..9f31a30 100644 --- a/nvim/.config/nvim/lua/plugins/lsp.lua +++ b/nvim/.config/nvim/lua/plugins/lsp.lua @@ -56,9 +56,14 @@ local lsp = { vim.fn.sign_define("DiagnosticSignInfo", { text = "", texthl = "DiagnosticSignInfo" }) vim.fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" }) - local function register(server_name, config) + local function register(server_name, config, enabled) if vim.fn.has("nvim-0.11") == 1 then vim.lsp.config(server_name, config) + if enabled == false or vim.lsp.config[server_name]["autostart"] == false then + vim.lsp.enable(server_name, false) + else + vim.lsp.enable(server_name, true) + end else require("lspconfig")[server_name].setup(config) end @@ -186,19 +191,28 @@ local lsp = { vim.api.nvim_create_autocmd("User", { pattern = "SpellEnable", callback = function() - register("ltex", { - on_attach = function(_, _) - if require("core.util").is_available("ltex_extra") then - require("ltex_extra").setup() - end - end, - settings = { - ltex = { - language = vim.o.spelllang, - }, - }, + local mapped = {} + local lang_map = { + en_us = "en-US", + en_gb = "en-GB", + de_de = "de-DE", + } + for _, v in ipairs(vim.opt.spelllang:get()) do + table.insert(mapped, lang_map[v]) + end + vim.lsp.config("ltex", { + settings = { ltex = { language = mapped } }, }) - vim.cmd("LspStart ltex") + -- single-shot setup: Enable for this buffer + -- but instantly disable again globally + vim.lsp.enable("ltex") + vim.lsp.enable("ltex", false) + end, + }) + vim.api.nvim_create_autocmd("User", { + pattern = "SpellDisable", + callback = function() + vim.lsp.enable("ltex", false) end, }) end, diff --git a/sh/README.md b/sh/README.md index 364a6bd..9d6695c 100644 --- a/sh/README.md +++ b/sh/README.md @@ -3,18 +3,17 @@ The bare minimum terminal configuration for a working system. Contains: -* an XDG compliant home directory setup -* several basic environment variables -* simple aliases -* an optional fzf default setup -* X autostart +- an XDG compliant home directory setup +- several basic environment variables +- simple aliases +- an optional fzf default setup +- X autostart -While other modules are largely optional, +While other modules are largely optional, this module is the only one strictly necessary for the system to really work at all. Additionally contains two scripts on which some other modules build: -* a simple script to detect if applications exist +- a simple script to detect if applications exist (and optionally warn the user if they don't) -* and a script to check if internet connectivity exists - +- and a script to check if internet connectivity exists