Skip to content

Commit 7bc63be

Browse files
committed
feat: implement missing upstream APIs
1 parent f8e3630 commit 7bc63be

File tree

14 files changed

+1546
-84
lines changed

14 files changed

+1546
-84
lines changed

index.js

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ const {Query, Parser, NodeMethods, Tree, TreeCursor} = binding;
1616
* Tree
1717
*/
1818

19-
const {rootNode, edit} = Tree.prototype;
19+
const {rootNode, rootNodeWithOffset, edit} = Tree.prototype;
2020

2121
Object.defineProperty(Tree.prototype, 'rootNode', {
2222
get() {
2323
return unmarshalNode(rootNode.call(this), this);
2424
}
2525
});
2626

27+
Tree.prototype.rootNodeWithOffset = function(offset_bytes, offset_extent) {
28+
return unmarshalNode(rootNodeWithOffset.call(this, offset_bytes, offset_extent.row, offset_extent.column), this);
29+
}
30+
2731
Tree.prototype.edit = function(arg) {
2832
edit.call(
2933
this,
@@ -164,6 +168,21 @@ class SyntaxNode {
164168
return unmarshalNode(NodeMethods.previousNamedSibling(this.tree), this.tree);
165169
}
166170

171+
get parseState() {
172+
marshalNode(this);
173+
return NodeMethods.parseState(this.tree);
174+
}
175+
176+
get nextParseState() {
177+
marshalNode(this);
178+
return NodeMethods.nextParseState(this.tree);
179+
}
180+
181+
get descendantCount() {
182+
marshalNode(this);
183+
return NodeMethods.descendantCount(this.tree);
184+
}
185+
167186
hasChanges() {
168187
marshalNode(this);
169188
return NodeMethods.hasChanges(this.tree);
@@ -179,6 +198,16 @@ class SyntaxNode {
179198
return NodeMethods.isMissing(this.tree);
180199
}
181200

201+
isExtra() {
202+
marshalNode(this);
203+
return NodeMethods.isExtra(this.tree);
204+
}
205+
206+
isError() {
207+
marshalNode(this);
208+
return NodeMethods.isError(this.tree);
209+
}
210+
182211
toString() {
183212
marshalNode(this);
184213
return NodeMethods.toString(this.tree);
@@ -194,6 +223,31 @@ class SyntaxNode {
194223
return unmarshalNode(NodeMethods.namedChild(this.tree, index), this.tree);
195224
}
196225

226+
childForFieldName(fieldName) {
227+
marshalNode(this);
228+
return unmarshalNode(NodeMethods.childForFieldName(this.tree, fieldName), this.tree);
229+
}
230+
231+
childForFieldId(fieldId) {
232+
marshalNode(this);
233+
return unmarshalNode(NodeMethods.childForFieldId(this.tree, fieldId), this.tree);
234+
}
235+
236+
fieldNameForChild(childIndex) {
237+
marshalNode(this);
238+
return NodeMethods.fieldNameForChild(this.tree, childIndex);
239+
}
240+
241+
childrenForFieldName(fieldName, cursor) {
242+
marshalNode(this);
243+
return unmarshalNodes(NodeMethods.childrenForFieldName(this.tree, fieldName, cursor), this.tree);
244+
}
245+
246+
childrenForFieldId(fieldId) {
247+
marshalNode(this);
248+
return unmarshalNodes(NodeMethods.childrenForFieldId(this.tree, fieldId), this.tree);
249+
}
250+
197251
firstChildForIndex(index) {
198252
marshalNode(this);
199253
return unmarshalNode(NodeMethods.firstChildForIndex(this.tree, index), this.tree);
@@ -282,7 +336,7 @@ Parser.prototype.parse = function(input, oldTree, {bufferSize, includedRanges}={
282336
input,
283337
oldTree,
284338
bufferSize,
285-
includedRanges
339+
includedRanges,
286340
);
287341
if (tree) {
288342
tree.input = treeInput

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@
1919
"prebuild-install": "^7.1.1"
2020
},
2121
"devDependencies": {
22-
"@types/node": "^20.5.9",
22+
"@types/node": "^20.6.0",
2323
"chai": "^4.3.8",
24-
"mocha": "^8.4.0",
24+
"mocha": "^10.2.0",
2525
"node-gyp": "^9.4.0",
2626
"prebuild": "^12.0.0",
27-
"tree-sitter-javascript": "https://github.com/tree-sitter/tree-sitter-javascript.git#master"
27+
"tmp": "^0.2.1",
28+
"tree-sitter-c": "https://github.com/tree-sitter/tree-sitter-c.git#master",
29+
"tree-sitter-embedded-template": "https://github.com/tree-sitter/tree-sitter-embedded-template.git#master",
30+
"tree-sitter-html": "https://github.com/tree-sitter/tree-sitter-html.git#master",
31+
"tree-sitter-javascript": "https://github.com/tree-sitter/tree-sitter-javascript.git#master",
32+
"tree-sitter-json": "https://github.com/tree-sitter/tree-sitter-json.git#master",
33+
"tree-sitter-python": "https://github.com/tree-sitter/tree-sitter-python.git#master"
2834
},
2935
"scripts": {
3036
"install": "prebuild-install || node-gyp rebuild",

0 commit comments

Comments
 (0)