Skip to content

Commit 071258f

Browse files
authored
Add proper jsonc comment support (#2145)
After bumping tree-sitter-json in cursorless-dev/vscode-parse-tree@5920905, the tree-sitter-json parser now has proper support for comments Fwiw, that version also includes proper jsonl support, so it's no longer a hack ## Checklist - [ ] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [ ] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [ ] I have not broken the cheatsheet
1 parent 15bfde5 commit 071258f

File tree

6 files changed

+54
-9
lines changed

6 files changed

+54
-9
lines changed
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { htmlScopeSupport } from "./html";
22
import { javaScopeSupport } from "./java";
33
import { javascriptScopeSupport } from "./javascript";
4+
import { jsonScopeSupport } from "./json";
45
import { pythonScopeSupport } from "./python";
56
import { LanguageScopeSupportFacetMap } from "./scopeSupportFacets.types";
67
import { talonScopeSupport } from "./talon";
@@ -10,18 +11,20 @@ export function getLanguageScopeSupport(
1011
languageId: string,
1112
): LanguageScopeSupportFacetMap {
1213
switch (languageId) {
13-
case "javascript":
14-
return javascriptScopeSupport;
15-
case "typescript":
16-
return typescriptScopeSupport;
14+
case "html":
15+
return htmlScopeSupport;
1716
case "java":
1817
return javaScopeSupport;
18+
case "javascript":
19+
return javascriptScopeSupport;
20+
case "json":
21+
return jsonScopeSupport;
1922
case "python":
2023
return pythonScopeSupport;
21-
case "html":
22-
return htmlScopeSupport;
2324
case "talon":
2425
return talonScopeSupport;
26+
case "typescript":
27+
return typescriptScopeSupport;
2528
}
2629
throw Error(`Unsupported language: '${languageId}'`);
2730
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
3+
import {
4+
LanguageScopeSupportFacetMap,
5+
ScopeSupportFacetLevel,
6+
} from "./scopeSupportFacets.types";
7+
8+
const { supported } = ScopeSupportFacetLevel;
9+
10+
export const jsonScopeSupport: LanguageScopeSupportFacetMap = {
11+
"comment.line": supported,
12+
"comment.block": supported,
13+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
Hello world
3+
*/
4+
---
5+
6+
[Content] =
7+
[Removal] =
8+
[Domain] = 0:0-2:2
9+
0| /*
10+
>--
11+
1| Hello world
12+
-------------
13+
2| */
14+
--<
15+
16+
[Insertion delimiter] = "\n"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Hello world
2+
---
3+
4+
[Content] =
5+
[Removal] =
6+
[Domain] = 0:0-0:14
7+
0| // Hello world
8+
>--------------<
9+
10+
[Insertion delimiter] = "\n"

queries/json.scm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
;;! ^^^^^^^^
1515
(string) @string
1616

17+
;;!! // aaa
18+
;;! ^^^^^^
19+
;;!! /* aaa */
20+
;;! ^^^^^^^^^
21+
(comment) @comment @textFragment
22+
1723
;;!! {"value": 0}
1824
;;! ^^^^^^^ ^
1925
;;! ----------

queries/jsonc.scm

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
11
;; import json.scm
2-
3-
;; Currently not supported by our Tree sitter parser
4-
;; (comment) @comment @textFragment

0 commit comments

Comments
 (0)