From 75d553bf64a00ce6764eca8ea77faac851cfb295 Mon Sep 17 00:00:00 2001 From: Donnerinoern <72634505+Donnerinoern@users.noreply.github.com> Date: Thu, 18 Jan 2024 17:28:46 +0100 Subject: [PATCH 1/2] languages/markdown: added marksman LSP --- docs/release-notes/rl-0.6.md | 2 ++ modules/languages/markdown/config.nix | 24 +++++++++++++++- modules/languages/markdown/markdown.nix | 37 ++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/rl-0.6.md b/docs/release-notes/rl-0.6.md index 8d74eec..f1ef364 100644 --- a/docs/release-notes/rl-0.6.md +++ b/docs/release-notes/rl-0.6.md @@ -25,3 +25,5 @@ Release notes for release 0.6 [donnerinoern](https://github.com/donnerinoern): - Added Gruvbox theme + +- Added marksman LSP for Markdown diff --git a/modules/languages/markdown/config.nix b/modules/languages/markdown/config.nix index ba49fb9..8a9e7eb 100644 --- a/modules/languages/markdown/config.nix +++ b/modules/languages/markdown/config.nix @@ -4,9 +4,25 @@ lib, ... }: let - inherit (lib) nvim mkIf mkMerge; + inherit (lib) nvim mkIf mkMerge isList; cfg = config.vim.languages.markdown; + servers = { + marksman = { + package = pkgs.marksman; + lspConfig = '' + lspconfig.marksman.setup{ + capabilities = capabilities; + on_attach = default_on_attach; + cmd = ${ + if isList cfg.lsp.package + then nvim.lua.expToLua cfg.lsp.package + else ''{"${cfg.lsp.package}/bin/marksman", "server"}'' + }, + } + ''; + }; + }; in { config = mkIf cfg.enable (mkMerge [ (mkIf cfg.treesitter.enable { @@ -26,5 +42,11 @@ in { autocmd FileType markdown noremap p :Glow ''; }) + + (mkIf cfg.lsp.enable { + vim.lsp.lspconfig.enable = true; + + vim.lsp.lspconfig.sources.markdown-lsp = servers.${cfg.lsp.server}.lspConfig; + }) ]); } diff --git a/modules/languages/markdown/markdown.nix b/modules/languages/markdown/markdown.nix index 153eae5..9ff06f8 100644 --- a/modules/languages/markdown/markdown.nix +++ b/modules/languages/markdown/markdown.nix @@ -4,9 +4,27 @@ lib, ... }: let - inherit (lib) mkEnableOption mkOption types nvim; + inherit (builtins) attrNames; + inherit (lib) mkEnableOption mkOption types nvim isList; cfg = config.vim.languages.markdown; + defaultServer = "marksman"; + servers = { + marksman = { + package = pkgs.marksman; + lspConfig = '' + lspconfig.marksman.setup{ + capabilities = capabilities; + on_attach = default_on_attach; + cmd = ${ + if isList cfg.lsp.package + then nvim.lua.expToLua cfg.lsp.package + else ''{"${cfg.lsp.package}/bin/marksman", "server"}'' + }, + } + ''; + }; + }; in { options.vim.languages.markdown = { enable = mkEnableOption "Markdown markup language support"; @@ -26,5 +44,22 @@ in { mdPackage = nvim.types.mkGrammarOption pkgs "markdown"; mdInlinePackage = nvim.types.mkGrammarOption pkgs "markdown-inline"; }; + + lsp = { + enable = mkEnableOption "Enable Markdown LSP support" // {default = config.vim.languages.enableLSP;}; + + server = mkOption { + description = "Markdown LSP server to use"; + type = with types; enum (attrNames servers); + default = defaultServer; + }; + + package = mkOption { + description = "Markdown LSP server package, or the command to run as a list of strings"; + example = ''[lib.getExe pkgs.jdt-language-server " - data " " ~/.cache/jdtls/workspace "]''; + type = with types; either package (listOf str); + default = servers.${cfg.lsp.server}.package; + }; + }; }; } From 0bfefe97797ced114cfe107c0b68f9909cfa861f Mon Sep 17 00:00:00 2001 From: Donnerinoern <72634505+Donnerinoern@users.noreply.github.com> Date: Thu, 18 Jan 2024 19:40:27 +0100 Subject: [PATCH 2/2] languages/markdown: fixed glow not working and added option for changing keybind --- docs/release-notes/rl-0.6.md | 2 ++ modules/languages/markdown/config.nix | 18 ++++++++++++------ modules/languages/markdown/markdown.nix | 15 ++++++++++----- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/docs/release-notes/rl-0.6.md b/docs/release-notes/rl-0.6.md index f1ef364..de68373 100644 --- a/docs/release-notes/rl-0.6.md +++ b/docs/release-notes/rl-0.6.md @@ -27,3 +27,5 @@ Release notes for release 0.6 - Added Gruvbox theme - Added marksman LSP for Markdown + +- Fixed Markdown-previewer Glow not working and added an option for changing the preview keybind diff --git a/modules/languages/markdown/config.nix b/modules/languages/markdown/config.nix index 8a9e7eb..7084314 100644 --- a/modules/languages/markdown/config.nix +++ b/modules/languages/markdown/config.nix @@ -4,9 +4,13 @@ lib, ... }: let - inherit (lib) nvim mkIf mkMerge isList; + inherit (lib) nvim mkIf mkMerge mkBinding isList; cfg = config.vim.languages.markdown; + self = import ./markdown.nix { + inherit lib config pkgs; + }; + mappings = self.options.vim.languages.markdown.glow.mappings; servers = { marksman = { package = pkgs.marksman; @@ -34,12 +38,14 @@ in { (mkIf cfg.glow.enable { vim.startPlugins = ["glow-nvim"]; - vim.globals = { - "glow_binary_path" = "${pkgs.glow}/bin"; - }; + vim.maps.normal = mkMerge [ + (mkBinding cfg.glow.mappings.openPreview ":Glow" mappings.openPreview.description) + ]; - vim.configRC.glow = nvim.dag.entryAnywhere '' - autocmd FileType markdown noremap p :Glow + vim.luaConfigRC.glow = nvim.dag.entryAnywhere '' + require('glow').setup({ + glow_path = "${pkgs.glow}/bin/glow" + }); ''; }) diff --git a/modules/languages/markdown/markdown.nix b/modules/languages/markdown/markdown.nix index 9ff06f8..7c07667 100644 --- a/modules/languages/markdown/markdown.nix +++ b/modules/languages/markdown/markdown.nix @@ -5,7 +5,7 @@ ... }: let inherit (builtins) attrNames; - inherit (lib) mkEnableOption mkOption types nvim isList; + inherit (lib) mkEnableOption mkMappingOption mkOption types nvim isList; cfg = config.vim.languages.markdown; defaultServer = "marksman"; @@ -29,10 +29,15 @@ in { options.vim.languages.markdown = { enable = mkEnableOption "Markdown markup language support"; - glow.enable = mkOption { - type = types.bool; - default = true; - description = "Enable markdown preview in neovim with glow"; + glow = { + enable = mkOption { + type = types.bool; + default = true; + description = "Enable markdown preview in neovim with glow"; + }; + mappings = { + openPreview = mkMappingOption "Open preview" "p"; + }; }; treesitter = {