Skip to content

Commit

Permalink
Add proper jsonc comment support (#2145)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pokey authored Dec 15, 2023
1 parent 15bfde5 commit 071258f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { htmlScopeSupport } from "./html";
import { javaScopeSupport } from "./java";
import { javascriptScopeSupport } from "./javascript";
import { jsonScopeSupport } from "./json";
import { pythonScopeSupport } from "./python";
import { LanguageScopeSupportFacetMap } from "./scopeSupportFacets.types";
import { talonScopeSupport } from "./talon";
Expand All @@ -10,18 +11,20 @@ export function getLanguageScopeSupport(
languageId: string,
): LanguageScopeSupportFacetMap {
switch (languageId) {
case "javascript":
return javascriptScopeSupport;
case "typescript":
return typescriptScopeSupport;
case "html":
return htmlScopeSupport;
case "java":
return javaScopeSupport;
case "javascript":
return javascriptScopeSupport;
case "json":
return jsonScopeSupport;
case "python":
return pythonScopeSupport;
case "html":
return htmlScopeSupport;
case "talon":
return talonScopeSupport;
case "typescript":
return typescriptScopeSupport;
}
throw Error(`Unsupported language: '${languageId}'`);
}
13 changes: 13 additions & 0 deletions packages/common/src/scopeSupportFacets/json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable @typescript-eslint/naming-convention */

import {
LanguageScopeSupportFacetMap,
ScopeSupportFacetLevel,
} from "./scopeSupportFacets.types";

const { supported } = ScopeSupportFacetLevel;

export const jsonScopeSupport: LanguageScopeSupportFacetMap = {
"comment.line": supported,
"comment.block": supported,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Hello world
*/
---

[Content] =
[Removal] =
[Domain] = 0:0-2:2
0| /*
>--
1| Hello world
-------------
2| */
--<

[Insertion delimiter] = "\n"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Hello world
---

[Content] =
[Removal] =
[Domain] = 0:0-0:14
0| // Hello world
>--------------<

[Insertion delimiter] = "\n"
6 changes: 6 additions & 0 deletions queries/json.scm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
;;! ^^^^^^^^
(string) @string

;;!! // aaa
;;! ^^^^^^
;;!! /* aaa */
;;! ^^^^^^^^^
(comment) @comment @textFragment

;;!! {"value": 0}
;;! ^^^^^^^ ^
;;! ----------
Expand Down
3 changes: 0 additions & 3 deletions queries/jsonc.scm
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
;; import json.scm

;; Currently not supported by our Tree sitter parser
;; (comment) @comment @textFragment

0 comments on commit 071258f

Please sign in to comment.