11import type { Position , TextDocument } from "@cursorless/common" ;
2- import { showError , type TreeSitter } from "@cursorless/common" ;
2+ import { type TreeSitter } from "@cursorless/common" ;
33import type * as treeSitter from "web-tree-sitter" ;
44import { ide } from "../../singletons/ide.singleton" ;
55import { getNodeRange } from "../../util/nodeSelectors" ;
@@ -11,9 +11,8 @@ import type {
1111import { checkCaptureStartEnd } from "./checkCaptureStartEnd" ;
1212import { isContainedInErrorNode } from "./isContainedInErrorNode" ;
1313import { normalizeCaptureName } from "./normalizeCaptureName" ;
14- import { parsePredicates } from "./parsePredicates " ;
14+ import { parsePredicatesWithErrorHandling } from "./parsePredicatesWithErrorHandling " ;
1515import { positionToPoint } from "./positionToPoint" ;
16- import { predicateToString } from "./predicateToString" ;
1716import {
1817 getStartOfEndOfRange ,
1918 rewriteStartOfEndOf ,
@@ -46,31 +45,7 @@ export class TreeSitterQuery {
4645 treeSitter : TreeSitter ,
4746 query : treeSitter . Query ,
4847 ) {
49- const { errors, predicates } = parsePredicates ( query . predicates ) ;
50-
51- if ( errors . length > 0 ) {
52- for ( const error of errors ) {
53- const context = [
54- `language ${ languageId } ` ,
55- `pattern ${ error . patternIdx } ` ,
56- `predicate \`${ predicateToString (
57- query . predicates [ error . patternIdx ] [ error . predicateIdx ] ,
58- ) } \``,
59- ] . join ( ", " ) ;
60-
61- void showError (
62- ide ( ) . messages ,
63- "TreeSitterQuery.parsePredicates" ,
64- `Error parsing predicate for ${ context } : ${ error . error } ` ,
65- ) ;
66- }
67-
68- // We show errors to the user, but we don't want to crash the extension
69- // unless we're in test mode
70- if ( ide ( ) . runMode === "test" ) {
71- throw new Error ( "Invalid predicates" ) ;
72- }
73- }
48+ const predicates = parsePredicatesWithErrorHandling ( languageId , query ) ;
7449
7550 return new TreeSitterQuery ( treeSitter , query , predicates ) ;
7651 }
0 commit comments