Skip to content

Commit 7ded70a

Browse files
authored
Improve parse tree errors (#207)
1 parent a73ff87 commit 7ded70a

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

src/extension.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,7 @@ export async function activate(context: vscode.ExtensionContext) {
2525
throw new Error("Depends on pokey.parse-tree extension");
2626
}
2727

28-
const { getNodeAtLocation: getNodeAtLocationImpl } =
29-
await parseTreeExtension.activate();
30-
31-
const getNodeAtLocation = (location: vscode.Location) => {
32-
try {
33-
return getNodeAtLocationImpl(location);
34-
} catch (error) {
35-
const document = vscode.window.activeTextEditor?.document;
36-
if (document?.uri === location.uri) {
37-
throw Error(`Language '${document.languageId}' is not implemented yet`);
38-
}
39-
throw error;
40-
}
41-
};
28+
const { getNodeAtLocation } = await parseTreeExtension.activate();
4229

4330
var isActive = vscode.workspace
4431
.getConfiguration("cursorless")

src/languages/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,23 @@ export function getNodeMatcher(
3131
includeSiblings: boolean
3232
): NodeMatcher {
3333
const matchers = languageMatchers[languageId];
34+
3435
if (matchers == null) {
35-
throw Error(`Language '${languageId}' is not implemented yet`);
36+
throw Error(
37+
`Language '${languageId}' is not implemented yet; See https://github.com/pokey/cursorless-vscode/blob/master/docs/adding-a-new-language.md`
38+
);
3639
}
40+
3741
const matcher = matchers[scopeType];
42+
3843
if (matcher == null) {
3944
return notSupported;
4045
}
46+
4147
if (includeSiblings) {
4248
return matcherIncludeSiblings(matcher);
4349
}
50+
4451
return matcher;
4552
}
4653

src/processTargets.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,16 +263,16 @@ function transformSelection(
263263
return [{ selection, context: {} }];
264264

265265
case "containingScope":
266-
let node: SyntaxNode | null = context.getNodeAtLocation(
267-
new Location(selection.editor.document.uri, selection.selection)
268-
);
269-
270266
const nodeMatcher = getNodeMatcher(
271267
selection.editor.document.languageId,
272268
modifier.scopeType,
273269
modifier.includeSiblings ?? false
274270
);
275271

272+
let node: SyntaxNode | null = context.getNodeAtLocation(
273+
new Location(selection.editor.document.uri, selection.selection)
274+
);
275+
276276
while (node != null) {
277277
const matches = nodeMatcher(selection, node);
278278
if (matches != null) {

0 commit comments

Comments
 (0)