From 69cd77630b1af497db09369118afd89504cc80f0 Mon Sep 17 00:00:00 2001 From: Soliprem <73885403+Soliprem@users.noreply.github.com> Date: Sat, 28 Sep 2024 22:21:27 +0200 Subject: [PATCH] lsp/otter: init (#385) * r: implementing lsp * r: version bump to context fixes treesitter bug * r: changing treesitter package definition to mkGrammarOption * added changelog entry * created otter file * created otter file * update * update * otter: fixing fixing input * committing flake.lock * fixed typo * configuration: disabling ccc and enabling otter * added assertion to make sure ccc and otter aren't enabled at the same time * configuration: otter set for isMaximal * otter: changelog * otter: better changelog * otter-nvim: renamed from otter to otter-nvim * otter: added setupopts --------- Co-authored-by: raf --- configuration.nix | 3 +- docs/release-notes/rl-0.7.md | 2 + flake.lock | 17 +++++++ flake.nix | 5 +++ modules/plugins/languages/ts.nix | 2 +- modules/plugins/lsp/default.nix | 1 + modules/plugins/lsp/otter/config.nix | 39 ++++++++++++++++ modules/plugins/lsp/otter/default.nix | 6 +++ modules/plugins/lsp/otter/otter.nix | 64 +++++++++++++++++++++++++++ 9 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 modules/plugins/lsp/otter/config.nix create mode 100644 modules/plugins/lsp/otter/default.nix create mode 100644 modules/plugins/lsp/otter/otter.nix diff --git a/configuration.nix b/configuration.nix index 08b0f9b6..b21b26aa 100644 --- a/configuration.nix +++ b/configuration.nix @@ -19,6 +19,7 @@ isMaximal: { lspsaga.enable = false; trouble.enable = true; lspSignature.enable = true; + otter-nvim.enable = isMaximal; lsplines.enable = isMaximal; nvim-docs-view.enable = isMaximal; }; @@ -155,7 +156,7 @@ isMaximal: { }; utility = { - ccc.enable = isMaximal; + ccc.enable = false; vim-wakatime.enable = false; icon-picker.enable = isMaximal; surround.enable = isMaximal; diff --git a/docs/release-notes/rl-0.7.md b/docs/release-notes/rl-0.7.md index d93bb2c6..55746f2b 100644 --- a/docs/release-notes/rl-0.7.md +++ b/docs/release-notes/rl-0.7.md @@ -202,3 +202,5 @@ everyone. [Soliprem](https://github.com/Soliprem) - Add LSP and Treesitter support for R under `vim.languages.R`. +- Add Otter support under `vim.lsp.otter` and an assert to prevent conflict with + ccc diff --git a/flake.lock b/flake.lock index 91fc5060..ecc02f27 100644 --- a/flake.lock +++ b/flake.lock @@ -1373,6 +1373,22 @@ "type": "github" } }, + "plugin-otter-nvim": { + "flake": false, + "locked": { + "lastModified": 1724585935, + "narHash": "sha256-euHwoK2WHLF/hrjLY2P4yGrIbYyBN38FL3q4CKNZmLY=", + "owner": "jmbuhr", + "repo": "otter.nvim", + "rev": "ca9ce67d0399380b659923381b58d174344c9ee7", + "type": "github" + }, + "original": { + "owner": "jmbuhr", + "repo": "otter.nvim", + "type": "github" + } + }, "plugin-oxocarbon": { "flake": false, "locked": { @@ -1861,6 +1877,7 @@ "plugin-obsidian-nvim": "plugin-obsidian-nvim", "plugin-onedark": "plugin-onedark", "plugin-orgmode-nvim": "plugin-orgmode-nvim", + "plugin-otter-nvim": "plugin-otter-nvim", "plugin-oxocarbon": "plugin-oxocarbon", "plugin-plenary-nvim": "plugin-plenary-nvim", "plugin-project-nvim": "plugin-project-nvim", diff --git a/flake.nix b/flake.nix index c4996fcf..4813481b 100644 --- a/flake.nix +++ b/flake.nix @@ -156,6 +156,11 @@ flake = false; }; + plugin-otter-nvim = { + url = "github:jmbuhr/otter.nvim"; + flake = false; + }; + # Language support plugin-sqls-nvim = { url = "github:nanotee/sqls.nvim"; diff --git a/modules/plugins/languages/ts.nix b/modules/plugins/languages/ts.nix index e6e718ed..5ceccecf 100644 --- a/modules/plugins/languages/ts.nix +++ b/modules/plugins/languages/ts.nix @@ -226,7 +226,7 @@ in { { assertion = cfg.lsp.enable -> cfg.lsp.server != "tsserver"; message = '' - As of a recent lspconfig update, he `tsserver` configuration has been renamed + As of a recent lspconfig update, the `tsserver` configuration has been renamed to `ts_ls` to match upstream behaviour of `lspconfig`, and the name `tsserver` is no longer considered valid by nvf. Please set `vim.languages.ts.lsp.server` to `"ts_ls"` instead of to `${cfg.lsp.server}` diff --git a/modules/plugins/lsp/default.nix b/modules/plugins/lsp/default.nix index a5d5163d..421f5fda 100644 --- a/modules/plugins/lsp/default.nix +++ b/modules/plugins/lsp/default.nix @@ -13,6 +13,7 @@ ./trouble ./lsp-signature ./lightbulb + ./otter ./lspkind ./lsplines ./nvim-docs-view diff --git a/modules/plugins/lsp/otter/config.nix b/modules/plugins/lsp/otter/config.nix new file mode 100644 index 00000000..e5df92f7 --- /dev/null +++ b/modules/plugins/lsp/otter/config.nix @@ -0,0 +1,39 @@ +{ + config, + lib, + ... +}: let + inherit (lib.modules) mkIf mkMerge; + inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.lua) toLuaObject; + inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding; + + cfg = config.vim.lsp; + + self = import ./otter.nix {inherit lib;}; + mappingDefinitions = self.options.vim.lsp.otter-nvim.mappings; + mappings = addDescriptionsToMappings cfg.otter-nvim.mappings mappingDefinitions; +in { + config = mkIf (cfg.enable && cfg.otter-nvim.enable) { + assertions = [ + { + assertion = !config.vim.utility.ccc.enable; + message = '' + ccc and otter have a breaking conflict. It's been reported upstream. Until it's fixed, disable one of them + ''; + } + ]; + vim = { + startPlugins = ["otter-nvim"]; + + maps.normal = mkMerge [ + (mkSetBinding mappings.toggle "lua require'otter'.activate()") + ]; + + pluginRC.otter-nvim = entryAnywhere '' + -- Enable otter diagnostics viewer + require("otter").setup({${toLuaObject cfg.otter-nvim.setupOpts}}) + ''; + }; + }; +} diff --git a/modules/plugins/lsp/otter/default.nix b/modules/plugins/lsp/otter/default.nix new file mode 100644 index 00000000..935f1447 --- /dev/null +++ b/modules/plugins/lsp/otter/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./otter.nix + ./config.nix + ]; +} diff --git a/modules/plugins/lsp/otter/otter.nix b/modules/plugins/lsp/otter/otter.nix new file mode 100644 index 00000000..79797aaf --- /dev/null +++ b/modules/plugins/lsp/otter/otter.nix @@ -0,0 +1,64 @@ +{lib, ...}: let + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.nvim.binds) mkMappingOption; + inherit (lib.types) bool str listOf; + inherit (lib.nvim.types) mkPluginSetupOption; +in { + options.vim.lsp = { + otter-nvim = { + enable = mkEnableOption '' + lsp features and a code completion source for code embedded in other documents [otter-nvim] + ''; + mappings = { + toggle = mkMappingOption "Activate LSP on Cursor Position [otter-nvim]" "lo"; + }; + setupOpts = mkPluginSetupOption "otter.nvim" { + lsp = { + diagnostic_update_event = mkOption { + type = listOf str; + default = ["BufWritePost"]; + description = '' + `:h events` that cause the diagnostic to update. + Set to: {"BufWritePost", "InsertLeave", "TextChanged" } + for less performant but more instant diagnostic updates + ''; + }; + }; + buffers = { + set_filetype = mkOption { + type = bool; + default = false; + description = '' + if set to true, the filetype of the otterbuffers will be set. Other wide only + the autocommand of lspconfig that attaches the language server will be + executed without stting the filetype + ''; + }; + write_to_disk = mkOption { + type = bool; + default = false; + description = '' + write .otter. files to disk on save of main buffer. + Useful for some linters that require actual files. + Otter files are deleted on quit or main buffer close + ''; + }; + }; + strip_wrapping_quote_characters = mkOption { + type = listOf str; + default = ["'" ''"'' "`"]; + description = '' + ''; + }; + handle_leading_whitespace = mkOption { + type = bool; + default = false; + description = '' + otter may not work the way you expect when entire code blocks are indented + (eg. in Org files) When true, otter handles these cases fully. + ''; + }; + }; + }; + }; +}