aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRiley Bruins <ribru17@hotmail.com>2024-04-08 22:20:26 -0700
committerGitHub <noreply@github.com>2024-04-09 14:20:26 +0900
commite9321bb914b3a5a88b7dff5392f0f5f8d83bee67 (patch)
tree0a646738b6f2a23b256fe8174dbe35a84b7296bd
parentfix(c_sharp): highlight `raw_string_literal` (diff)
downloadnvim-treesitter-e9321bb914b3a5a88b7dff5392f0f5f8d83bee67.tar
nvim-treesitter-e9321bb914b3a5a88b7dff5392f0f5f8d83bee67.tar.gz
nvim-treesitter-e9321bb914b3a5a88b7dff5392f0f5f8d83bee67.tar.bz2
nvim-treesitter-e9321bb914b3a5a88b7dff5392f0f5f8d83bee67.tar.lz
nvim-treesitter-e9321bb914b3a5a88b7dff5392f0f5f8d83bee67.tar.xz
nvim-treesitter-e9321bb914b3a5a88b7dff5392f0f5f8d83bee67.tar.zst
nvim-treesitter-e9321bb914b3a5a88b7dff5392f0f5f8d83bee67.zip
feat(nix): misc cleanups + comment injection (#6418)
* fix(nix): highlight strings within interpolations * feat(nix): move `derivation` to function.builtin * fix(nix): removes all `priority` workarounds * feat(nix): arbitrary injections using `#` comments
-rw-r--r--queries/nix/highlights.scm44
-rw-r--r--queries/nix/injections.scm12
-rw-r--r--tests/query/highlights/nix/test.nix5
3 files changed, 37 insertions, 24 deletions
diff --git a/queries/nix/highlights.scm b/queries/nix/highlights.scm
index 33cdaf409..0a0d9ac6f 100644
--- a/queries/nix/highlights.scm
+++ b/queries/nix/highlights.scm
@@ -8,17 +8,6 @@
"with"
] @keyword
-(variable_expression
- name: (identifier) @keyword
- (#eq? @keyword "derivation")
- (#set! "priority" 101))
-
-; exceptions
-(variable_expression
- name: (identifier) @keyword.exception
- (#any-of? @keyword.exception "abort" "throw")
- (#set! "priority" 101))
-
; if/then/else
[
"if"
@@ -33,11 +22,13 @@
(comment) @comment @spell
; strings
-([
- (string_expression)
- (indented_string_expression)
-]
- (#set! "priority" 99)) @string
+(string_fragment) @string
+
+(string_expression
+ "\"" @string)
+
+(indented_string_expression
+ "''" @string)
; paths and URLs
[
@@ -111,16 +102,16 @@
(variable_expression
name: (identifier) @function.builtin
(#any-of? @function.builtin
- ; nix eval --impure --expr 'with builtins; filter (x: !(elem x [ "abort" "derivation" "import" "throw" ]) && isFunction builtins.${x}) (attrNames builtins)'
+ ; nix eval --impure --expr 'with builtins; filter (x: !(elem x [ "abort" "import" "throw" ]) && isFunction builtins.${x}) (attrNames builtins)'
"add" "addErrorContext" "all" "any" "appendContext" "attrNames" "attrValues" "baseNameOf"
"bitAnd" "bitOr" "bitXor" "break" "catAttrs" "ceil" "compareVersions" "concatLists" "concatMap"
- "concatStringsSep" "deepSeq" "derivationStrict" "dirOf" "div" "elem" "elemAt" "fetchGit"
- "fetchMercurial" "fetchTarball" "fetchTree" "fetchurl" "filter" "filterSource" "findFile"
- "floor" "foldl'" "fromJSON" "fromTOML" "functionArgs" "genList" "genericClosure" "getAttr"
- "getContext" "getEnv" "getFlake" "groupBy" "hasAttr" "hasContext" "hashFile" "hashString" "head"
- "intersectAttrs" "isAttrs" "isBool" "isFloat" "isFunction" "isInt" "isList" "isNull" "isPath"
- "isString" "length" "lessThan" "listToAttrs" "map" "mapAttrs" "match" "mul" "parseDrvName"
- "partition" "path" "pathExists" "placeholder" "readDir" "readFile" "removeAttrs"
+ "concatStringsSep" "deepSeq" "derivation" "derivationStrict" "dirOf" "div" "elem" "elemAt"
+ "fetchGit" "fetchMercurial" "fetchTarball" "fetchTree" "fetchurl" "filter" "filterSource"
+ "findFile" "floor" "foldl'" "fromJSON" "fromTOML" "functionArgs" "genList" "genericClosure"
+ "getAttr" "getContext" "getEnv" "getFlake" "groupBy" "hasAttr" "hasContext" "hashFile"
+ "hashString" "head" "intersectAttrs" "isAttrs" "isBool" "isFloat" "isFunction" "isInt" "isList"
+ "isNull" "isPath" "isString" "length" "lessThan" "listToAttrs" "map" "mapAttrs" "match" "mul"
+ "parseDrvName" "partition" "path" "pathExists" "placeholder" "readDir" "readFile" "removeAttrs"
"replaceStrings" "scopedImport" "seq" "sort" "split" "splitVersion" "storePath" "stringLength"
"sub" "substring" "tail" "toFile" "toJSON" "toPath" "toString" "toXML" "trace" "traceVerbose"
"tryEval" "typeOf" "unsafeDiscardOutputDependency" "unsafeDiscardStringContext"
@@ -209,3 +200,8 @@
(float_expression))
(float_expression)
] @number.float
+
+; exceptions
+(variable_expression
+ name: (identifier) @keyword.exception
+ (#any-of? @keyword.exception "abort" "throw"))
diff --git a/queries/nix/injections.scm b/queries/nix/injections.scm
index 8feff0f8a..d5e8483f4 100644
--- a/queries/nix/injections.scm
+++ b/queries/nix/injections.scm
@@ -12,6 +12,18 @@
(#gsub! @injection.language "/%*%s*([%w%p]+)%s*%*/" "%1")
(#set! injection.combined))
+; #-style Comments
+((comment) @injection.language
+ . ; this is to make sure only adjacent comments are accounted for the injections
+ [
+ (string_expression
+ (string_fragment) @injection.content)
+ (indented_string_expression
+ (string_fragment) @injection.content)
+ ]
+ (#gsub! @injection.language "#%s*([%w%p]+)%s*" "%1")
+ (#set! injection.combined))
+
(apply_expression
function: (_) @_func
argument: [
diff --git a/tests/query/highlights/nix/test.nix b/tests/query/highlights/nix/test.nix
index 8ab067a2e..296a5a934 100644
--- a/tests/query/highlights/nix/test.nix
+++ b/tests/query/highlights/nix/test.nix
@@ -13,4 +13,9 @@
# ^ @variable.member
# ^ @function.call
# ^ @string.special.path
+ hi = if true then 9 else throw "an error ${here + "string"}";
+ # ^ @keyword.exception
+ # ^ @string
+ # ^ @variable
+ # ^ @string
}