Merge pull request #1080 from poseidon-rises/languages/json

languages/json: init
This commit is contained in:
raf 2025-08-13 23:15:05 +03:00 committed by GitHub
commit f578f82b4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 107 additions and 1 deletions

View file

@ -56,6 +56,7 @@ isMaximal: {
clang.enable = isMaximal; clang.enable = isMaximal;
css.enable = isMaximal; css.enable = isMaximal;
html.enable = isMaximal; html.enable = isMaximal;
json.enable = isMaximal;
sql.enable = isMaximal; sql.enable = isMaximal;
java.enable = isMaximal; java.enable = isMaximal;
kotlin.enable = isMaximal; kotlin.enable = isMaximal;

View file

@ -478,7 +478,11 @@
[just-lsp]: https://github.com/terror/just-lsp [just-lsp]: https://github.com/terror/just-lsp
[roslyn-ls]: https://github.com/dotnet/vscode-csharp [roslyn-ls]: https://github.com/dotnet/vscode-csharp
[jsonls]: https://github.com/microsoft/vscode/tree/1.101.2/extensions/json-language-features/server
[jsonfmt]: https://github.com/caarlos0/jsonfmt
- Add just support under `vim.languages.just` using [just-lsp]. - Add just support under `vim.languages.just` using [just-lsp].
- Add [roslyn-ls] to the `vim.languages.csharp` module. - Add [roslyn-ls] to the `vim.languages.csharp` module.
- Added json support under `vim.languages.json` using [jsonls] and [jsonfmt].

View file

@ -21,6 +21,7 @@ in {
./html.nix ./html.nix
./haskell.nix ./haskell.nix
./java.nix ./java.nix
./json.nix
./lua.nix ./lua.nix
./markdown.nix ./markdown.nix
./nim.nix ./nim.nix

View file

@ -0,0 +1,100 @@
{
config,
pkgs,
lib,
...
}: let
inherit (builtins) attrNames;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.meta) getExe;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.types) enum package;
inherit (lib.nvim.types) mkGrammarOption singleOrListOf;
inherit (lib.nvim.attrsets) mapListToAttrs;
cfg = config.vim.languages.json;
defaultServers = ["jsonls"];
servers = {
jsonls = {
cmd = [(getExe pkgs.vscode-json-languageserver) "--stdio"];
filetypes = ["json" "jsonc"];
init_options = {provideFormatter = true;};
root_markers = [".git"];
};
};
defaultFormat = "jsonfmt";
formats = {
jsonfmt = {
package = pkgs.writeShellApplication {
name = "jsonfmt";
runtimeInputs = [pkgs.jsonfmt];
text = "jsonfmt -w -";
};
};
};
in {
options.vim.languages.json = {
enable = mkEnableOption "JSON langauge support";
treesitter = {
enable = mkEnableOption "JSON treesitter" // {default = config.vim.languages.enableTreesitter;};
package = mkGrammarOption pkgs "json";
};
lsp = {
enable = mkEnableOption "JSON LSP support" // {default = config.vim.lsp.enable;};
servers = mkOption {
type = singleOrListOf (enum (attrNames servers));
default = defaultServers;
description = "JSON LSP server to use";
};
};
format = {
enable = mkEnableOption "JSON formatting" // {default = config.vim.languages.enableFormat;};
type = mkOption {
description = "JSON formatter to use";
type = enum (attrNames formats);
default = defaultFormat;
};
package = mkOption {
description = "JSON 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.servers =
mapListToAttrs (name: {
inherit name;
value = servers.${name};
})
cfg.lsp.servers;
})
(mkIf cfg.format.enable {
vim.formatter.conform-nvim = {
enable = true;
setupOpts.formatters_by_ft.json = [cfg.format.type];
setupOpts.formatters.${cfg.format.type} = {
command = getExe cfg.format.package;
};
};
})
]);
}