Skip to content

Commit 956ea6d

Browse files
Add support for java properties (#114)
* Added properties parser * Change language id * Make types stricter * Clean up
1 parent ac40071 commit 956ea6d

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "parse-tree",
33
"displayName": "Parse tree",
44
"description": "Access document syntax using tree-sitter",
5-
"version": "0.39.0",
5+
"version": "0.40.0",
66
"publisher": "pokey",
77
"repository": {
88
"type": "git",
@@ -36,6 +36,7 @@
3636
"onLanguage:go",
3737
"onLanguage:haskell",
3838
"onLanguage:html",
39+
"onLanguage:java-properties",
3940
"onLanguage:java",
4041
"onLanguage:javascript",
4142
"onLanguage:javascriptreact",
@@ -88,7 +89,7 @@
8889
"publish": "vsce publish patch"
8990
},
9091
"devDependencies": {
91-
"@cursorless/tree-sitter-wasms": "0.4.0",
92+
"@cursorless/tree-sitter-wasms": "0.5.0",
9293
"@types/mocha": "^2.2.42",
9394
"@types/node": "^8.10.25",
9495
"@types/vscode": "~1.58.0",

src/extension.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ interface Language {
1111
}
1212

1313
// Be sure to declare the language in package.json and include a minimalist grammar.
14-
const languages: {
15-
[id: string]: Language;
16-
} = {
14+
const languages: Record<string, Language | undefined> = {
15+
// eslint-disable-next-line @typescript-eslint/naming-convention
16+
"java-properties": { module: "tree-sitter-properties" },
1717
agda: { module: "tree-sitter-agda" },
1818
c: { module: "tree-sitter-c" },
1919
clojure: { module: "tree-sitter-clojure" },
2020
cpp: { module: "tree-sitter-cpp" },
2121
csharp: { module: "tree-sitter-c_sharp" },
2222
css: { module: "tree-sitter-css" },
2323
dart: { module: "tree-sitter-dart" },
24-
elm: { module: "tree-sitter-elm" },
2524
elixir: { module: "tree-sitter-elixir" },
25+
elm: { module: "tree-sitter-elm" },
2626
gdscript: { module: "tree-sitter-gdscript" },
2727
gleam: { module: "tree-sitter-gleam" },
2828
go: { module: "tree-sitter-go" },
@@ -68,7 +68,7 @@ const initParser = treeSitter.Parser.init(); // TODO this isn't a field, suppres
6868
export async function activate(context: vscode.ExtensionContext) {
6969
console.debug("Activating tree-sitter...");
7070
// Parse of all visible documents
71-
const trees: { [uri: string]: treeSitter.Tree } = {};
71+
const trees: Record<string, treeSitter.Tree | undefined> = {};
7272

7373
/**
7474
* FIXME: On newer vscode versions some Tree sitter parser throws memory errors
@@ -141,6 +141,9 @@ export async function activate(context: vscode.ExtensionContext) {
141141
}
142142

143143
const language = languages[document.languageId];
144+
if (language?.parser == null) {
145+
throw new Error(`No parser for language ${document.languageId}`);
146+
}
144147
const t = language.parser?.parse(document.getText());
145148
if (t == null) {
146149
throw Error(`Failed to parse ${document.uri}`);
@@ -184,6 +187,9 @@ export async function activate(context: vscode.ExtensionContext) {
184187
return;
185188
}
186189
const old = trees[edit.document.uri.toString()];
190+
if (old == null) {
191+
throw new Error(`No existing tree for ${edit.document.uri}`);
192+
}
187193
for (const e of edit.contentChanges) {
188194
const startIndex = e.rangeOffset;
189195
const oldEndIndex = e.rangeOffset + e.rangeLength;
@@ -243,13 +249,14 @@ export async function activate(context: vscode.ExtensionContext) {
243249
context.subscriptions.push(
244250
vscode.workspace.onDidOpenTextDocument(openIfVisible)
245251
);
252+
246253
// Don't wait for the initial color, it takes too long to inspect the themes and causes VSCode extension host to hang
247254
colorAllOpen();
248255

249256
function getTreeForUri(uri: vscode.Uri) {
250257
const ret = trees[uri.toString()];
251258

252-
if (typeof ret === "undefined") {
259+
if (ret == null) {
253260
const document = vscode.workspace.textDocuments.find(
254261
(textDocument) => textDocument.uri.toString() === uri.toString()
255262
);

0 commit comments

Comments
 (0)