Merge pull request #1488 from snoweuph/feat/jq
Some checks are pending
Set up binary cache / cachix (default) (push) Waiting to run
Set up binary cache / cachix (maximal) (push) Waiting to run
Set up binary cache / cachix (nix) (push) Waiting to run
Treewide Checks / Validate flake (push) Waiting to run
Treewide Checks / Check formatting (push) Waiting to run
Treewide Checks / Check source tree for typos (push) Waiting to run
Treewide Checks / Validate documentation builds (push) Waiting to run
Treewide Checks / Validate documentation builds-1 (push) Waiting to run
Treewide Checks / Validate documentation builds-2 (push) Waiting to run
Treewide Checks / Validate documentation builds-3 (push) Waiting to run
Treewide Checks / Validate hyperlinks in documentation sources (push) Waiting to run
Treewide Checks / Validate Editorconfig conformance (push) Waiting to run
Build and deploy documentation / Check latest commit (push) Waiting to run
Build and deploy documentation / publish (push) Blocked by required conditions

languages/jq: init
This commit is contained in:
Snoweuph 2026-03-28 09:51:55 +01:00 committed by GitHub
commit ac5cf327c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 118 additions and 0 deletions

View file

@ -109,6 +109,7 @@ isMaximal: {
twig.enable = false;
gettext.enable = false;
fluent.enable = false;
jq.enable = false;
# Nim LSP is broken on Darwin and therefore
# should be disabled by default. Users may still enable

View file

@ -283,6 +283,8 @@
- Added `languages.tex`. Currently only highlighting, formatting and lsp. No
previewing yet.
- Added `languages.jq`. Supports highlighting, formatting and lsp.
- Didn't Add
[`syntax-gaslighting`](https://github.com/NotAShelf/syntax-gaslighting.nvim),
you're crazy.

View file

@ -63,6 +63,7 @@ in {
./gettext.nix
./fluent.nix
./openscad.nix
./jq.nix
# This is now a hard deprecation.
(mkRenamedOptionModule ["vim" "languages" "enableLSP"] ["vim" "lsp" "enable"])

View file

@ -0,0 +1,114 @@
{
config,
lib,
pkgs,
...
}: let
inherit (builtins) attrNames;
inherit (lib.options) literalExpression mkEnableOption mkOption;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.meta) getExe;
inherit (lib.types) enum listOf;
inherit (lib.nvim.attrsets) mapListToAttrs;
inherit (lib.nvim.types) mkGrammarOption;
cfg = config.vim.languages.jq;
defaultServers = ["jq-lsp"];
servers = {
jq-lsp = {
enable = true;
cmd = [(getExe pkgs.jq-lsp)];
filetypes = ["jq"];
root_markers = [".git"];
};
};
defaultFormat = ["jqfmt"];
formats = {
jqfmt = {
command = getExe pkgs.jqfmt;
args = [
"-ob"
"-ar"
"-op=pipe"
];
};
};
in {
options.vim.languages.jq = {
enable = mkEnableOption "JQ support";
treesitter = {
enable =
mkEnableOption "JQ treesitter"
// {
default = config.vim.languages.enableTreesitter;
defaultText = literalExpression "config.vim.languages.enableTreesitter";
};
package = mkGrammarOption pkgs "jq";
};
lsp = {
enable =
mkEnableOption "JQ LSP support"
// {
default = config.vim.lsp.enable;
defaultText = literalExpression "config.vim.lsp.enable";
};
servers = mkOption {
type = listOf (enum (attrNames servers));
default = defaultServers;
description = "JQ LSP server to use";
};
};
format = {
enable =
mkEnableOption "JQ formatting"
// {
default = config.vim.languages.enableFormat;
defaultText = literalExpression "config.vim.languages.enableFormat";
};
type = mkOption {
description = "JQ formatter to use";
type = listOf (enum (attrNames formats));
default = defaultFormat;
};
};
};
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.treesitter.enable {
vim.treesitter = {
enable = true;
grammars = [cfg.treesitter.package];
};
})
(mkIf cfg.lsp.enable {
vim.lsp.servers =
mapListToAttrs (n: {
name = n;
value = servers.${n};
})
cfg.lsp.servers;
})
(mkIf cfg.format.enable {
vim.formatter.conform-nvim = {
enable = true;
setupOpts = {
formatters_by_ft.jq = cfg.format.type;
formatters =
mapListToAttrs (name: {
inherit name;
value = formats.${name};
})
cfg.format.type;
};
};
})
]);
}