Merge pull request #787 from wingrunr21/add_ts_query_support

Update TS definitions to support the Query API
This commit is contained in:
Max Brunsfeld 2020-11-03 10:30:58 -08:00 committed by GitHub
commit 2d339de5d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -37,7 +37,7 @@ declare module 'web-tree-sitter' {
export type Logger = (
message: string,
params: {[param: string]: string},
params: { [param: string]: string },
type: "parse" | "lex"
) => void;
@ -48,6 +48,7 @@ declare module 'web-tree-sitter' {
) => string | null;
export interface SyntaxNode {
id: number;
tree: Tree;
type: string;
isNamed: boolean;
@ -131,8 +132,33 @@ declare module 'web-tree-sitter' {
readonly version: number;
readonly fieldCount: number;
fieldNameForId(fieldId: number): string | null
fieldIdForName(fieldName: string): number | null
fieldNameForId(fieldId: number): string | null;
fieldIdForName(fieldName: string): number | null;
query(source: string): Query;
}
interface QueryCapture {
name: string;
node: SyntaxNode;
}
interface QueryMatch {
pattern: number;
captures: QueryCapture[];
}
interface PredicateResult {
operator: string;
operands: { name: string; type: string }[];
}
class Query {
captureNames: string[];
delete(): void;
matches(node: SyntaxNode, startPosition?: Point, endPosition?: Point): QueryMatch[];
captures(node: SyntaxNode, startPosition?: Point, endPosition?: Point): QueryCapture[];
predicatesForPattern(patternIndex: number): PredicateResult[];
}
}