languages/fsharp: init

This commit is contained in:
Marlon Rosenberg 2025-03-24 22:25:01 +01:00
parent df1b3f7968
commit 9f8b7edbf6
4 changed files with 114 additions and 0 deletions
docs
manual/configuring
release-notes
modules/plugins/languages

View file

@ -19,6 +19,7 @@ formatting to diagnostics. The following languages have sections under the
- Go: [vim.languages.go.enable](#opt-vim.languages.go.enable) - Go: [vim.languages.go.enable](#opt-vim.languages.go.enable)
- Lua: [vim.languages.lua.enable](#opt-vim.languages.lua.enable) - Lua: [vim.languages.lua.enable](#opt-vim.languages.lua.enable)
- PHP: [vim.languages.php.enable](#opt-vim.languages.php.enable) - PHP: [vim.languages.php.enable](#opt-vim.languages.php.enable)
- F#: [vim.languages.fsharp.enable](#opt-vim.languages.fsharp.enable)
Adding support for more languages, and improving support for existing ones are Adding support for more languages, and improving support for existing ones are
great places where you can contribute with a PR. great places where you can contribute with a PR.

View file

@ -276,3 +276,7 @@
[rice-cracker-dev](https://github.com/rice-cracker-dev): [rice-cracker-dev](https://github.com/rice-cracker-dev):
- `eslint_d` now checks for configuration files to load. - `eslint_d` now checks for configuration files to load.
[Sc3l3t0n](https://github.com/Sc3l3t0n)
- Add F# support under `vim.languages.fsharp`.

View file

@ -10,6 +10,7 @@ in {
./clang.nix ./clang.nix
./css.nix ./css.nix
./elixir.nix ./elixir.nix
./fsharp.nix
./gleam.nix ./gleam.nix
./go.nix ./go.nix
./hcl.nix ./hcl.nix

View file

@ -0,0 +1,108 @@
{
lib,
pkgs,
config,
...
}: let
inherit (builtins) attrNames;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) either listOf package str enum;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.lists) isList;
inherit (lib.nvim.types) mkGrammarOption;
inherit (lib.nvim.lua) expToLua;
defaultServer = "fsautocomplete";
servers = {
fsautocomplete = {
package = pkgs.fsautocomplete;
internalFormatter = false;
lspConfig = ''
lspconfig.fsautocomplete.setup {
capabilities = capabilities;
on_attach = default_on_attach;
cmd = ${
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else "{'${cfg.lsp.package}/bin/fsautocomplete'}"
},
}
'';
};
};
defaultFormat = "fantomas";
formats = {
fantomas = {
package = pkgs.fantomas;
nullConfig = ''
table.insert(
ls_sources,
null_ls.builtins.formatting.fantomas.with({
command = "${cfg.format.package}/bin/fantomas",
})
)
'';
};
};
cfg = config.vim.languages.fsharp;
in {
options = {
vim.languages.fsharp = {
enable = mkEnableOption "F# language support";
treesitter = {
enable = mkEnableOption "F# treesitter" // {default = config.vim.languages.enableTreesitter;};
package = mkGrammarOption pkgs "fsharp";
};
lsp = {
enable = mkEnableOption "F# LSP support" // {default = config.vim.languages.enableLSP;};
server = mkOption {
description = "F# LSP server to use";
type = enum (attrNames servers);
default = defaultServer;
};
package = mkOption {
description = "F# LSP server package, or the command to run as a list of strings";
type = either package (listOf str);
default = servers.${cfg.lsp.server}.package;
};
};
format = {
enable = mkEnableOption "F# formatting" // {default = config.vim.languages.enableFormat;};
type = mkOption {
description = "F# formatter to use";
type = enum (attrNames formats);
default = defaultFormat;
};
package = mkOption {
description = "F# formatter package";
type = package;
default = formats.${cfg.format.type}.package;
};
};
};
};
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.treesitter.enable {
vim.treesitter.enable = true;
vim.treesitter.grammars = [cfg.treesitter.package];
})
(mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.fsharp-lsp = servers.${cfg.lsp.server}.lspConfig;
})
(mkIf cfg.format.enable {
vim.lsp.null-ls.enable = true;
vim.lsp.null-ls.sources.fsharp-format = formats.${cfg.format.type}.nullConfig;
})
]);
}