Skip to content

languages/fish: init #807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/rl-0.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@
- Disable mini.indentscope for applicable filetypes.
- Fix fzf-lua having a hard dependency on fzf.
- Enable inlay hints support - `config.vim.lsp.inlayHints`.
- Add Fish language support under `vim.languages.fish`.

[tebuevd](https://github.com/tebuevd):

Expand Down
1 change: 1 addition & 0 deletions modules/plugins/languages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ in {
./clang.nix
./css.nix
./elixir.nix
./fish.nix
./fsharp.nix
./gleam.nix
./go.nix
Expand Down
95 changes: 95 additions & 0 deletions modules/plugins/languages/fish.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
config,
pkgs,
lib,
...
}: let
inherit (builtins) attrNames;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.meta) getExe;
inherit (lib.lists) isList;
inherit (lib.types) bool either enum listOf package str;
inherit (lib.nvim.lua) expToLua toLuaObject;
inherit (lib.nvim.types) mkGrammarOption;

cfg = config.vim.languages.fish;

defaultFormat = "fish_indent";

formats = {
fish_indent = {
cmd = "${pkgs.fish}/bin/fish_indent";
};
};
in {
options.vim.languages.fish = {
enable = mkEnableOption "Fish language support";

format = {
enable = mkOption {
type = bool;
default = config.vim.languages.enableFormat;
description = "Enable Fish formatting";
};

type = mkOption {
type = enum (attrNames formats);
default = defaultFormat;
description = "Fish formatter to use";
};

cmd = mkOption {
type = str;
default = formats.${cfg.format.type}.cmd;
description = "Path to fish formatter executable";
};
};

lsp = {
enable = mkEnableOption "Fish LSP support via fish-lsp" // {default = config.vim.languages.enableLSP;};

package = mkOption {
description = "fish-lsp package, or the command to run as a list of strings";
type = either package (listOf str);
default = pkgs.fish-lsp;
};
};

treesitter = {
enable = mkEnableOption "Fish Treesitter support" // {default = config.vim.languages.enableTreesitter;};
package = mkGrammarOption pkgs "fish";
};
};

config = mkMerge [
(mkIf cfg.format.enable {
vim.formatter.conform-nvim = {
enable = true;
setupOpts.formatters_by_ft.fish = [cfg.format.type];
setupOpts.formatters.${cfg.format.type} = {command = cfg.format.cmd;};
};
})

(mkIf (cfg.enable && cfg.lsp.enable) {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.fish-lsp = let
cmd =
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else toLuaObject ["${getExe cfg.lsp.package}" "start"];
in ''
lspconfig.fish_lsp.setup {
capabilities = capabilities;
on_attach = default_on_attach;
cmd = ${cmd};
}
'';
})

(mkIf cfg.treesitter.enable {
vim.treesitter.enable = true;
vim.treesitter.grammars = [cfg.treesitter.package];
})
];
}