Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "parse-tree",
"displayName": "Parse tree",
"description": "Access document syntax using tree-sitter",
"version": "0.39.0",
"version": "0.40.0",
"publisher": "pokey",
"repository": {
"type": "git",
Expand Down Expand Up @@ -36,6 +36,7 @@
"onLanguage:go",
"onLanguage:haskell",
"onLanguage:html",
"onLanguage:java-properties",
"onLanguage:java",
"onLanguage:javascript",
"onLanguage:javascriptreact",
Expand Down Expand Up @@ -88,7 +89,7 @@
"publish": "vsce publish patch"
},
"devDependencies": {
"@cursorless/tree-sitter-wasms": "0.4.0",
"@cursorless/tree-sitter-wasms": "0.5.0",
"@types/mocha": "^2.2.42",
"@types/node": "^8.10.25",
"@types/vscode": "~1.58.0",
Expand Down
19 changes: 13 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ interface Language {
}

// Be sure to declare the language in package.json and include a minimalist grammar.
const languages: {
[id: string]: Language;
} = {
const languages: Record<string, Language | undefined> = {
// eslint-disable-next-line @typescript-eslint/naming-convention
"java-properties": { module: "tree-sitter-properties" },
agda: { module: "tree-sitter-agda" },
c: { module: "tree-sitter-c" },
clojure: { module: "tree-sitter-clojure" },
cpp: { module: "tree-sitter-cpp" },
csharp: { module: "tree-sitter-c_sharp" },
css: { module: "tree-sitter-css" },
dart: { module: "tree-sitter-dart" },
elm: { module: "tree-sitter-elm" },
elixir: { module: "tree-sitter-elixir" },
elm: { module: "tree-sitter-elm" },
gdscript: { module: "tree-sitter-gdscript" },
gleam: { module: "tree-sitter-gleam" },
go: { module: "tree-sitter-go" },
Expand Down Expand Up @@ -68,7 +68,7 @@ const initParser = treeSitter.Parser.init(); // TODO this isn't a field, suppres
export async function activate(context: vscode.ExtensionContext) {
console.debug("Activating tree-sitter...");
// Parse of all visible documents
const trees: { [uri: string]: treeSitter.Tree } = {};
const trees: Record<string, treeSitter.Tree | undefined> = {};

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

const language = languages[document.languageId];
if (language?.parser == null) {
throw new Error(`No parser for language ${document.languageId}`);
}
const t = language.parser?.parse(document.getText());
if (t == null) {
throw Error(`Failed to parse ${document.uri}`);
Expand Down Expand Up @@ -184,6 +187,9 @@ export async function activate(context: vscode.ExtensionContext) {
return;
}
const old = trees[edit.document.uri.toString()];
if (old == null) {
throw new Error(`No existing tree for ${edit.document.uri}`);
}
for (const e of edit.contentChanges) {
const startIndex = e.rangeOffset;
const oldEndIndex = e.rangeOffset + e.rangeLength;
Expand Down Expand Up @@ -243,13 +249,14 @@ export async function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.workspace.onDidOpenTextDocument(openIfVisible)
);

// Don't wait for the initial color, it takes too long to inspect the themes and causes VSCode extension host to hang
colorAllOpen();

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

if (typeof ret === "undefined") {
if (ret == null) {
const document = vscode.workspace.textDocuments.find(
(textDocument) => textDocument.uri.toString() === uri.toString()
);
Expand Down