Skip to content

Commit

Permalink
Merge pull request #198 from Donnerinoern/language/markdown
Browse files Browse the repository at this point in the history
Language/markdown: Added LSP and fixed Glow not working
  • Loading branch information
NotAShelf authored Jan 19, 2024
2 parents 1e8d83b + 0bfefe9 commit f2c8413
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 11 deletions.
4 changes: 4 additions & 0 deletions docs/release-notes/rl-0.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ Release notes for release 0.6
[donnerinoern](https://github.com/donnerinoern):

- Added Gruvbox theme

- Added marksman LSP for Markdown

- Fixed Markdown-previewer Glow not working and added an option for changing the preview keybind
40 changes: 34 additions & 6 deletions modules/languages/markdown/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,29 @@
lib,
...
}: let
inherit (lib) nvim mkIf mkMerge;
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;
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 {
Expand All @@ -18,13 +38,21 @@ 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<CR>" mappings.openPreview.description)
];

vim.configRC.glow = nvim.dag.entryAnywhere ''
autocmd FileType markdown noremap <leader>p :Glow<CR>
vim.luaConfigRC.glow = nvim.dag.entryAnywhere ''
require('glow').setup({
glow_path = "${pkgs.glow}/bin/glow"
});
'';
})

(mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true;

vim.lsp.lspconfig.sources.markdown-lsp = servers.${cfg.lsp.server}.lspConfig;
})
]);
}
50 changes: 45 additions & 5 deletions modules/languages/markdown/markdown.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,40 @@
lib,
...
}: let
inherit (lib) mkEnableOption mkOption types nvim;
inherit (builtins) attrNames;
inherit (lib) mkEnableOption mkMappingOption 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";

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" "<leader>p";
};
};

treesitter = {
Expand All @@ -26,5 +49,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;
};
};
};
}

0 comments on commit f2c8413

Please sign in to comment.