Giter Site home page Giter Site logo

tree-sitter / node-tree-sitter Goto Github PK

View Code? Open in Web Editor NEW
546.0 18.0 101.0 576 KB

Node.js bindings for tree-sitter

Home Page: https://www.npmjs.com/package/tree-sitter

License: MIT License

Python 0.75% JavaScript 61.09% C++ 38.16%
tree-sitter nodejs binding javascript

node-tree-sitter's Introduction

node tree-sitter

Incremental parsers for node

Installation

npm install tree-sitter

Usage

First, you'll need a Tree-sitter grammar for the language you want to parse. There are many existing grammars such as tree-sitter-javascript and tree-sitter-go. You can also develop a new grammar using the Tree-sitter CLI.

Once you've got your grammar, create a parser with that grammar.

const Parser = require('tree-sitter');
const JavaScript = require('tree-sitter-javascript');

const parser = new Parser();
parser.setLanguage(JavaScript);

Then you can parse some source code,

const sourceCode = 'let x = 1; console.log(x);';
const tree = parser.parse(sourceCode);

and inspect the syntax tree.

console.log(tree.rootNode.toString());

// (program
//   (lexical_declaration
//     (variable_declarator (identifier) (number)))
//   (expression_statement
//     (call_expression
//       (member_expression (identifier) (property_identifier))
//       (arguments (identifier)))))

const callExpression = tree.rootNode.child(1).firstChild;
console.log(callExpression);

// { type: 'call_expression',
//   startPosition: {row: 0, column: 16},
//   endPosition: {row: 0, column: 30},
//   startIndex: 0,
//   endIndex: 30 }

If your source code changes, you can update the syntax tree. This will take less time than the first parse.

// Replace 'let' with 'const'
const newSourceCode = 'const x = 1; console.log(x);';

tree.edit({
  startIndex: 0,
  oldEndIndex: 3,
  newEndIndex: 5,
  startPosition: {row: 0, column: 0},
  oldEndPosition: {row: 0, column: 3},
  newEndPosition: {row: 0, column: 5},
});

const newTree = parser.parse(newSourceCode, tree);

Parsing Text From a Custom Data Structure

If your text is stored in a data structure other than a single string, you can parse it by supplying a callback to parse instead of a string:

const sourceLines = [
  'let x = 1;',
  'console.log(x);'
];

const tree = parser.parse((index, position) => {
  let line = sourceLines[position.row];
  if (line) {
    return line.slice(position.column);
  }
});

node-tree-sitter's People

Contributors

aerijo avatar ahlinc avatar amaanq avatar anqurvanillapy avatar baael avatar char0n avatar georgeseif avatar gjtorikian avatar gpetrov avatar ilanashapiro avatar joaomoreno avatar joshvera avatar maxbrunsfeld avatar observeroftime avatar psteeve avatar rafeca avatar restlessronin avatar romgrk avatar rotu avatar rtllxndr avatar segevfiner avatar simonsiefke avatar tclem avatar thibaultdalban avatar verhovsky avatar wingrunr21 avatar xapphire13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-tree-sitter's Issues

console.log(node) does not match documentation

Hy

I have written my own grammer with tree-sitter, that was quite easy! However, the nodes of the JS binding do not behave as I expected and the documentation makes you believe.

The readme states, that the call expression has properties like type, etc. when logged to the console:

const callExpression = tree.rootNode.child(1).firstChild;
console.log(callExpression);

// { type: 'call_expression',
//   startPosition: {row: 0, column: 16},
//   endPosition: {row: 0, column: 30},
//   startIndex: 0,
//   endIndex: 30 }

If I execute the same example the output of the log statement is more like this:

SyntaxNode {
  '0': 36735152,
  '1': 1,
  '2': 22,
  '3': 0,
  '4': 22,
  '5': 0,
  tree:
   Tree {
     input: [Function: input],
     getText: [Function: getTextFromString] } }

This makes it difficult to inspect the AST. Especially since the node debugger seems to crash when inspecting a node Assertion failed: (!tree->cached_nodes_.count(key)), function CacheNode, file ../src/tree.cc, line 225.

Is there any documentation describing which properties I might expect from my grammer?

Thanks,
Micha

Electron 13 build failure

Anyone tried to build for Electron 13?

Trying it with prebuild -r electron -t 13.0.1 leads to errors such as
tree-sitter\src\node.cc(32,129): error C2661: 'v8::ArrayBuffer::New': no overloaded function takes 3 arguments
tree-sitter\src\node.cc(36,42): error C3536: 'js_transfer_buffer': cannot be used before it is initialized
tree-sitter\src\node.cc(36,69): error C2665: 'v8::Uint32Array::New': none of the 2 overloads could convert all the argument types

I'm aware of #83, and the problems described above happen after changing binding.gyp to following

      "cflags": [
        "-std=c++17",
      ],
      'xcode_settings': {
        'CLANG_CXX_LANGUAGE_STANDARD': 'c++17',
      },

This does not happen when building for other versions of electron or node.

Query to match all declarations (def) and identifiers (uses) in the code

I am using node-tree-sitter to query all def-uses in the code, in the following way:

import * as TreeSitter from 'tree-sitter'
import { Identifier } from './Identifier'
const TypeScript = require('tree-sitter-typescript').typescript
const treeSitter = new TreeSitter()
treeSitter.setLanguage(TypeScript)

 private static analyzeCode(codeLines: string[]): Identifier[] {
   const sourceCode = codeLines.join('\n')
   const tree = treeSitter.parse(sourceCode)
   const query = new TreeSitter.Query(TypeScript, `(identifier) @element`)

   let identifiers: Identifier[] = []
   const matches: TreeSitter.QueryMatch[] = query.matches(tree.rootNode)
   for (let match of matches) {
     const captures: TreeSitter.QueryCapture[] = match.captures
     for (let capture of captures) {
           identifiers.push(new Identifier(capture.name,tree.getText(capture.node))
     }
   }
   return identifiers
 }

However, it returns keywords that I do not want. For example,

For code:

    private orgLines: string[] = [];

It returns:

[โ€˜publicโ€™, โ€™string', '']

After reading the query syntax (http://tree-sitter.github.io/tree-sitter/using-parsers#query-syntax) and the test code (https://github.com/tree-sitter/node-tree-sitter/blob/master/test/query_test.js), I am wondering:

  1. Is it possible to query for all the subtypes of declarations with the wildcard: (_declaration: name (identifier))?
  2. Is it correct to filter the language-specific keywords from matches: (_) name: (identifier)?

Build failure with node 17

Installing the tree-sitter using node version 17.4.0 with npm seem to fail with the following errors:

npm ERR! In file included from ../src/binding.cc:1:
npm ERR! /home/rien/.cache/node-gyp/17.4.0/include/node/node.h:843:7: warning: cast between incompatible function types from โ€˜void (*)(v8::Local<v8::Object>)โ€™ to โ€˜node::addon_register_funcโ€™ {aka โ€˜void (*)(v8::Local<v8::Object>, v8::Local<v8::Value>, void*)โ€™} [-Wcast-function-type]
npm ERR!   843 |       (node::addon_register_func) (regfunc),                          \
npm ERR!       |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm ERR! /home/rien/.cache/node-gyp/17.4.0/include/node/node.h:877:3: note: in expansion of macro โ€˜NODE_MODULE_Xโ€™
npm ERR!   877 |   NODE_MODULE_X(modname, regfunc, NULL, 0)  // NOLINT (readability/null_usage)
npm ERR!       |   ^~~~~~~~~~~~~
npm ERR! ../src/binding.cc:25:1: note: in expansion of macro โ€˜NODE_MODULEโ€™
npm ERR!    25 | NODE_MODULE(tree_sitter_runtime_binding, InitAll)
npm ERR!       | ^~~~~~~~~~~
npm ERR! ../src/conversions.cc: In function โ€˜void node_tree_sitter::InitConversions(v8::Local<v8::Object>)โ€™:
npm ERR! ../src/conversions.cc:31:118: error: no matching function for call to โ€˜v8::ArrayBuffer::New(v8::Isolate*, uint32_t*&, long unsigned int)โ€™
npm ERR!    31 |   auto js_point_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), point_transfer_buffer, 2 * sizeof(uint32_t));
npm ERR!       |                                                                                                                      ^
npm ERR! In file included from /home/rien/.cache/node-gyp/17.4.0/include/node/v8.h:25,
npm ERR!                  from /home/rien/.cache/node-gyp/17.4.0/include/node/node.h:63,
npm ERR!                  from ../../nan/nan.h:58,
npm ERR!                  from ../src/./node.h:4,
npm ERR!                  from ../src/conversions.cc:1:
npm ERR! /home/rien/.cache/node-gyp/17.4.0/include/node/v8-array-buffer.h:198:29: note: candidate: โ€˜static v8::Local<v8::ArrayBuffer> v8::ArrayBuffer::New(v8::Isolate*, size_t)โ€™
npm ERR!   198 |   static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
npm ERR!       |                             ^~~
npm ERR! /home/rien/.cache/node-gyp/17.4.0/include/node/v8-array-buffer.h:198:29: note:   candidate expects 2 arguments, 3 provided
npm ERR! /home/rien/.cache/node-gyp/17.4.0/include/node/v8-array-buffer.h:212:29: note: candidate: โ€˜static v8::Local<v8::ArrayBuffer> v8::ArrayBuffer::New(v8::Isolate*, std::shared_ptr<v8::BackingStore>)โ€™
npm ERR!   212 |   static Local<ArrayBuffer> New(Isolate* isolate,
npm ERR!       |                             ^~~
npm ERR! /home/rien/.cache/node-gyp/17.4.0/include/node/v8-array-buffer.h:212:29: note:   candidate expects 2 arguments, 3 provided
npm ERR! make: *** [tree_sitter_runtime_binding.target.mk:127: Release/obj.target/tree_sitter_runtime_binding/src/conversions.o] Error 1

This is not the case when using node 16.

Uncaught Error: A dynamic link library (DLL) initialization routine failed.

I'm currently creating a Atom package using react, and I'm trying to use tree-sitter to extract function codes. But when I use var Parser = require('tree-sitter');, i receive the error in the title. here are the full error file(I tried to use electron rebuild but still the same error):

Error: A dynamic link library (DLL) initialization routine failed.
\\?\C:\Users\qi_qi\.atom\packages\atombubble\node_modules\tree-sitter\build\Release\tree_sitter_runtime_binding.node
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:166:20)
    at Object.Module._extensions..node (module.js:671:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:166:20)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:504:12)
    at Function.Module._load (module.js:496:3)
    at Module.require (file:///C:/Users/qi_qi/AppData/Local/atom/app-1.34.0/resources/app.asar/static/index.js:47:45)
    at require (C:\Users\qi_qi\AppData\Local\atom\app-1.34.0\resources\app\static\<embedded>:11:145974)
    at Object.<anonymous> (C:\Users\qi_qi\AppData\Local\atom\app-1.34.0\resources\app.asar\node_modules\tree-sitter\index.js:3:13)
    at Object.<anonymous> (C:\Users\qi_qi\AppData\Local\atom\app-1.34.0\resources\app.asar\node_modules\tree-sitter\index.js:440:3)
    at Module.get_Module._compile (C:\Users\qi_qi\AppData\Local\atom\app-1.34.0\resources\app\static\<embedded>:11:146684)
    at Object.value [as .js] (C:\Users\qi_qi\AppData\Local\atom\app-1.34.0\resources\app\static\<embedded>:11:150231)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:504:12)
    at Function.Module._load (module.js:496:3)
    at Module.require (file:///C:/Users/qi_qi/AppData/Local/atom/app-1.34.0/resources/app.asar/static/index.js:47:45)
    at require (C:\Users\qi_qi\AppData\Local\atom\app-1.34.0\resources\app\static\<embedded>:11:145974)
    at Bubble.componentDidMount (file:///C:/Users/qi_qi/.atom/packages/atombubble/lib/components/bubble.js:112:20)
    at Mh (C:\Users\qi_qi\.atom\packages\atombubble\node_modules\react-dom\cjs\react-dom.production.min.js:228:492)
    at Jh (C:\Users\qi_qi\.atom\packages\atombubble\node_modules\react-dom\cjs\react-dom.production.min.js:220:383)
    at Kh (C:\Users\qi_qi\.atom\packages\atombubble\node_modules\react-dom\cjs\react-dom.production.min.js:219:144)
    at nh (C:\Users\qi_qi\.atom\packages\atombubble\node_modules\react-dom\cjs\react-dom.production.min.js:216:261)
    at Tf (C:\Users\qi_qi\.atom\packages\atombubble\node_modules\react-dom\cjs\react-dom.production.min.js:214:85)
    at Object.enqueueSetState (C:\Users\qi_qi\.atom\packages\atombubble\node_modules\react-dom\cjs\react-dom.production.min.js:134:228)
    at Main.G.setState (C:\Users\qi_qi\.atom\packages\atombubble\node_modules\react\cjs\react.production.min.js:13:224)
    at Main.addBubble (file:///C:/Users/qi_qi/.atom/packages/atombubble/lib/components/main.js:68:10)
    at AtomBubbleView.addBubble (file:///C:/Users/qi_qi/.atom/packages/atombubble/lib/atombubble-view.js:51:23)
    at Object.extract (file:///C:/Users/qi_qi/.atom/packages/atombubble/lib/atombubble.js:53:27)
    at HTMLElement.atombubbleExtract (file:///C:/Users/qi_qi/.atom/packages/atombubble/lib/atombubble.js:27:42)
    at CommandRegistry.handleCommandEvent (C:\Users\qi_qi\AppData\Local\atom\app-1.34.0\resources\app\static\<embedded>:11:350017)

Tree-Sitter version x Node Tree-Sitter version

Hi!

Node Tree-Sitter is a few patch versions behind Tree-Sitter.
What are the plans for them to be in the same version?

How to compile for Node?

Thank you very much!
Tree-Sitter is really an amazing project!

cannot install on Node 18

$ brew install node
$ cd /tmp
$ mkdir tree-sitter-test
$ cd tree-sitter-test
$ npm init -y
$ npm install tree-sitter
npm ERR! code 1
npm ERR! path /private/tmp/node-test/node_modules/tree-sitter
npm ERR! command failed
npm ERR! command sh -c prebuild-install || node-gyp rebuild
npm ERR! CC(target) Release/obj.target/tree_sitter/vendor/tree-sitter/lib/src/lib.o
npm ERR!   LIBTOOL-STATIC Release/tree_sitter.a
npm ERR!   CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/binding.o
npm ERR!   CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/conversions.o
npm ERR! prebuild-install WARN install No prebuilt binaries found (target=18.0.0 runtime=node arch=arm64 libc= platform=darwin)
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | darwin | arm64
npm ERR! gyp info find Python using Python version 3.9.12 found at "/opt/homebrew/opt/[email protected]/bin/python3.9"
npm ERR! gyp info spawn /opt/homebrew/opt/[email protected]/bin/python3.9
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/private/tmp/node-test/node_modules/tree-sitter/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/space/Library/Caches/node-gyp/18.0.0/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/Users/space/Library/Caches/node-gyp/18.0.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/space/Library/Caches/node-gyp/18.0.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/private/tmp/node-test/node_modules/tree-sitter',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! In file included from ../src/binding.cc:3:
npm ERR! In file included from ../src/./language.h:4:
npm ERR! ../../nan/nan.h:2544:8: warning: 'SetAccessor' is deprecated: Do signature check in accessor [-Wdeprecated-declarations]
npm ERR!   tpl->SetAccessor(
npm ERR!        ^
npm ERR! /Users/space/Library/Caches/node-gyp/18.0.0/include/node/v8-template.h:837:3: note: 'SetAccessor' has been explicitly marked deprecated here
npm ERR!   V8_DEPRECATED("Do signature check in accessor")
npm ERR!   ^
npm ERR! /Users/space/Library/Caches/node-gyp/18.0.0/include/node/v8config.h:460:35: note: expanded from macro 'V8_DEPRECATED'
npm ERR! # define V8_DEPRECATED(message) [[deprecated(message)]]
npm ERR!                                   ^
npm ERR! 1 warning generated.
npm ERR! In file included from ../src/conversions.cc:1:
npm ERR! In file included from ../src/./node.h:4:
npm ERR! ../../nan/nan.h:2544:8: warning: 'SetAccessor' is deprecated: Do signature check in accessor [-Wdeprecated-declarations]
npm ERR!   tpl->SetAccessor(
npm ERR!        ^
npm ERR! /Users/space/Library/Caches/node-gyp/18.0.0/include/node/v8-template.h:837:3: note: 'SetAccessor' has been explicitly marked deprecated here
npm ERR!   V8_DEPRECATED("Do signature check in accessor")
npm ERR!   ^
npm ERR! /Users/space/Library/Caches/node-gyp/18.0.0/include/node/v8config.h:460:35: note: expanded from macro 'V8_DEPRECATED'
npm ERR! # define V8_DEPRECATED(message) [[deprecated(message)]]
npm ERR!                                   ^
npm ERR! ../src/conversions.cc:31:35: error: no matching function for call to 'New'
npm ERR!   auto js_point_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), point_transfer_buffer, 2 * sizeof(uint32_t));
npm ERR!                                   ^~~~~~~~~~~~~~~~
npm ERR! /Users/space/Library/Caches/node-gyp/18.0.0/include/node/v8-array-buffer.h:198:29: note: candidate function not viable: requires 2 arguments, but 3 were provided
npm ERR!   static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
npm ERR!                             ^
npm ERR! /Users/space/Library/Caches/node-gyp/18.0.0/include/node/v8-array-buffer.h:212:29: note: candidate function not viable: requires 2 arguments, but 3 were provided
npm ERR!   static Local<ArrayBuffer> New(Isolate* isolate,
npm ERR!                             ^
npm ERR! 1 warning and 1 error generated.
npm ERR! make: *** [Release/obj.target/tree_sitter_runtime_binding/src/conversions.o] Error 1
npm ERR! gyp ERR! build error 
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack     at ChildProcess.onExit (/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:527:28)
npm ERR! gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:291:12)
npm ERR! gyp ERR! System Darwin 21.4.0
npm ERR! gyp ERR! command "/opt/homebrew/Cellar/node/18.0.0/bin/node" "/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /private/tmp/node-test/node_modules/tree-sitter
npm ERR! gyp ERR! node -v v18.0.0
npm ERR! gyp ERR! node-gyp -v v9.0.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/space/.npm/_logs/2022-04-28T05_30_29_464Z-debug-0.log

Fail to build on Node 14 (when trying to update `npm` package with `yarn`)

Trying to upgrade my npm CLI I got a build error on tree-sitter. I tried to update the package itself but with the same result

OS

  NAME="Linux Mint"
  ID=linuxmint
  ID_LIKE=ubuntu
  VERSION_ID="20.1"
  VERSION_CODENAME=ulyssa
  UBUNTU_CODENAME=focal

Node & NPM

โฏ node --version
v14.16.0
	    
โฏ npm --version
6.14.11

Error log

yarn global add tree-sitter &> ~/error.txt
yarn global v1.22.5
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "@vue/cli > @vue/cli-ui > [email protected]" has unmet peer dependency "graphql@^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0".
warning "@vue/cli > @vue/cli-ui > [email protected]" has unmet peer dependency "graphql@>=0.8.0".
warning "@vue/cli > @vue/cli-ui > vue-cli-plugin-apollo > apollo-server-express > @apollographql/[email protected]" has incorrect peer dependency "graphql@^0.13.1".
warning " > [email protected]" has unmet peer dependency "[email protected] - 6.x".
[4/4] Building fresh packages...
error /home/ed8/.local/share/yarn/global/node_modules/bash-language-server/node_modules/tree-sitter: Command failed.
Exit code: 1
Command: prebuild-install || node-gyp rebuild
Arguments: 
Directory: /home/ed8/.local/share/yarn/global/node_modules/bash-language-server/node_modules/tree-sitter
Output:
prebuild-install WARN install No prebuilt binaries found (target=14.16.0 runtime=node arch=x64 libc= platform=linux)
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp info find Python using Python version 3.8.5 found at "/usr/bin/python"
gyp info spawn /usr/bin/python
gyp info spawn args [
gyp info spawn args   '/usr/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/home/ed8/.local/share/yarn/global/node_modules/bash-language-server/node_modules/tree-sitter/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/home/ed8/.cache/node-gyp/14.16.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/home/ed8/.cache/node-gyp/14.16.0',
gyp info spawn args   '-Dnode_gyp_dir=/usr/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/home/ed8/.cache/node-gyp/14.16.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/home/ed8/.local/share/yarn/global/node_modules/bash-language-server/node_modules/tree-sitter',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/home/ed8/.local/share/yarn/global/node_modules/bash-language-server/node_modules/tree-sitter/build'
  CC(target) Release/obj.target/runtime/vendor/tree-sitter/src/runtime/get_changed_ranges.o
  CC(target) Release/obj.target/runtime/vendor/tree-sitter/src/runtime/language.o
  CC(target) Release/obj.target/runtime/vendor/tree-sitter/src/runtime/lexer.o
  CC(target) Release/obj.target/runtime/vendor/tree-sitter/src/runtime/node.o
  CC(target) Release/obj.target/runtime/vendor/tree-sitter/src/runtime/stack.o
  CC(target) Release/obj.target/runtime/vendor/tree-sitter/src/runtime/parser.o
  CC(target) Release/obj.target/runtime/vendor/tree-sitter/src/runtime/subtree.o
  CC(target) Release/obj.target/runtime/vendor/tree-sitter/src/runtime/tree.o
  CC(target) Release/obj.target/runtime/vendor/tree-sitter/src/runtime/tree_cursor.o
  CC(target) Release/obj.target/runtime/vendor/tree-sitter/src/runtime/utf16.o
  CC(target) Release/obj.target/runtime/vendor/tree-sitter/externals/utf8proc/utf8proc.o
  AR(target) Release/obj.target/vendor/tree-sitter/runtime.a
  COPY Release/runtime.a
  CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/binding.o
In file included from ../src/./node.h:4,
                 from ../src/binding.cc:3:
../../../../nan/nan.h: In function โ€˜void Nan::AsyncQueueWorker(Nan::AsyncWorker*)โ€™:
../../../../nan/nan.h:2232:62: warning: cast between incompatible function types from โ€˜void (*)(uv_work_t*)โ€™ {aka โ€˜void (*)(uv_work_s*)โ€™} to โ€˜uv_after_work_cbโ€™ {aka โ€˜void (*)(uv_work_s*, int)โ€™} [-Wcast-function-type]
 2232 |     , reinterpret_cast(AsyncExecuteComplete)
      |                                                              ^
In file included from ../src/binding.cc:1:
../src/binding.cc: At global scope:
/home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:758:43: warning: cast between incompatible function types from โ€˜void (*)(v8::Local)โ€™ to โ€˜node::addon_register_funcโ€™ {aka โ€˜void (*)(v8::Local, v8::Local, void*)โ€™} [-Wcast-function-type]
  758 |       (node::addon_register_func) (regfunc),                          \
      |                                           ^
/home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:792:3: note: in expansion of macro โ€˜NODE_MODULE_Xโ€™
  792 |   NODE_MODULE_X(modname, regfunc, NULL, 0)  // NOLINT (readability/null_usage)
      |   ^~~~~~~~~~~~~
../src/binding.cc:21:1: note: in expansion of macro โ€˜NODE_MODULEโ€™
   21 | NODE_MODULE(tree_sitter_runtime_binding, InitAll)
      | ^~~~~~~~~~~
  CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/conversions.o
In file included from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
../../../../nan/nan.h: In function โ€˜void Nan::AsyncQueueWorker(Nan::AsyncWorker*)โ€™:
../../../../nan/nan.h:2232:62: warning: cast between incompatible function types from โ€˜void (*)(uv_work_t*)โ€™ {aka โ€˜void (*)(uv_work_s*)โ€™} to โ€˜uv_after_work_cbโ€™ {aka โ€˜void (*)(uv_work_s*, int)โ€™} [-Wcast-function-type]
 2232 |     , reinterpret_cast(AsyncExecuteComplete)
      |                                                              ^
../src/conversions.cc: In function โ€˜void node_tree_sitter::InitConversions(v8::Local)โ€™:
../src/conversions.cc:31:118: warning: โ€˜static v8::Local v8::ArrayBuffer::New(v8::Isolate*, void*, size_t, v8::ArrayBufferCreationMode)โ€™ is deprecated: Use the version that takes a BackingStore. See http://crbug.com/v8/9908. [-Wdeprecated-declarations]
   31 |   auto js_point_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), point_transfer_buffer, 2 * sizeof(uint32_t));
      |                                                                                                                      ^
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:5176:29: note: declared here
 5176 |   static Local New(
      |                             ^~~
../src/conversions.cc:31:118: warning: โ€˜static v8::Local v8::ArrayBuffer::New(v8::Isolate*, void*, size_t, v8::ArrayBufferCreationMode)โ€™ is deprecated: Use the version that takes a BackingStore. See http://crbug.com/v8/9908. [-Wdeprecated-declarations]
   31 |   auto js_point_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), point_transfer_buffer, 2 * sizeof(uint32_t));
      |                                                                                                                      ^
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:5176:29: note: declared here
 5176 |   static Local New(
      |                             ^~~
../src/conversions.cc:32:113: error: no matching function for call to โ€˜v8::Object::Set(v8::Local, v8::Local)โ€™
   32 |   exports->Set(Nan::New("pointTransferArray").ToLocalChecked(), Uint32Array::New(js_point_transfer_buffer, 0, 2));
      |                                                                                                                 ^
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3670:37: note: candidate: โ€˜v8::Maybe v8::Object::Set(v8::Local, v8::Local, v8::Local)โ€™
 3670 |   V8_WARN_UNUSED_RESULT Maybe Set(Local context,
      |                                     ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3670:37: note:   candidate expects 3 arguments, 2 provided
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3673:37: note: candidate: โ€˜v8::Maybe v8::Object::Set(v8::Local, uint32_t, v8::Local)โ€™
 3673 |   V8_WARN_UNUSED_RESULT Maybe Set(Local context, uint32_t index,
      |                                     ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3673:37: note:   candidate expects 3 arguments, 2 provided
../src/conversions.cc: In function โ€˜v8::Local node_tree_sitter::RangeToJS(const TSRange&)โ€™:
../src/conversions.cc:42:73: error: no matching function for call to โ€˜v8::Object::Set(v8::Local, v8::Local)โ€™
   42 |   result->Set(Nan::New(start_position_key), PointToJS(range.start_point));
      |                                                                         ^
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3670:37: note: candidate: โ€˜v8::Maybe v8::Object::Set(v8::Local, v8::Local, v8::Local)โ€™
 3670 |   V8_WARN_UNUSED_RESULT Maybe Set(Local context,
      |                                     ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3670:37: note:   candidate expects 3 arguments, 2 provided
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3673:37: note: candidate: โ€˜v8::Maybe v8::Object::Set(v8::Local, uint32_t, v8::Local)โ€™
 3673 |   V8_WARN_UNUSED_RESULT Maybe Set(Local context, uint32_t index,
      |                                     ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3673:37: note:   candidate expects 3 arguments, 2 provided
../src/conversions.cc:43:73: error: no matching function for call to โ€˜v8::Object::Set(v8::Local, v8::Local)โ€™
   43 |   result->Set(Nan::New(start_index_key), ByteCountToJS(range.start_byte));
      |                                                                         ^
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3670:37: note: candidate: โ€˜v8::Maybe v8::Object::Set(v8::Local, v8::Local, v8::Local)โ€™
 3670 |   V8_WARN_UNUSED_RESULT Maybe Set(Local context,
      |                                     ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3670:37: note:   candidate expects 3 arguments, 2 provided
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3673:37: note: candidate: โ€˜v8::Maybe v8::Object::Set(v8::Local, uint32_t, v8::Local)โ€™
 3673 |   V8_WARN_UNUSED_RESULT Maybe Set(Local context, uint32_t index,
      |                                     ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3673:37: note:   candidate expects 3 arguments, 2 provided
../src/conversions.cc:44:69: error: no matching function for call to โ€˜v8::Object::Set(v8::Local, v8::Local)โ€™
   44 |   result->Set(Nan::New(end_position_key), PointToJS(range.end_point));
      |                                                                     ^
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3670:37: note: candidate: โ€˜v8::Maybe v8::Object::Set(v8::Local, v8::Local, v8::Local)โ€™
 3670 |   V8_WARN_UNUSED_RESULT Maybe Set(Local context,
      |                                     ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3670:37: note:   candidate expects 3 arguments, 2 provided
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3673:37: note: candidate: โ€˜v8::Maybe v8::Object::Set(v8::Local, uint32_t, v8::Local)โ€™
 3673 |   V8_WARN_UNUSED_RESULT Maybe Set(Local context, uint32_t index,
      |                                     ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3673:37: note:   candidate expects 3 arguments, 2 provided
../src/conversions.cc:45:69: error: no matching function for call to โ€˜v8::Object::Set(v8::Local, v8::Local)โ€™
   45 |   result->Set(Nan::New(end_index_key), ByteCountToJS(range.end_byte));
      |                                                                     ^
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3670:37: note: candidate: โ€˜v8::Maybe v8::Object::Set(v8::Local, v8::Local, v8::Local)โ€™
 3670 |   V8_WARN_UNUSED_RESULT Maybe Set(Local context,
      |                                     ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3670:37: note:   candidate expects 3 arguments, 2 provided
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3673:37: note: candidate: โ€˜v8::Maybe v8::Object::Set(v8::Local, uint32_t, v8::Local)โ€™
 3673 |   V8_WARN_UNUSED_RESULT Maybe Set(Local context, uint32_t index,
      |                                     ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3673:37: note:   candidate expects 3 arguments, 2 provided
../src/conversions.cc: In function โ€˜Nan::Maybe node_tree_sitter::RangeFromJS(const v8::Local&)โ€™:
../src/conversions.cc:60:50: error: no matching function for call to โ€˜v8::Object::Get(v8::Local)โ€™
   60 |     auto field = Type(js_range->Get(Nan::New(key))); \
      |                                                  ^
../src/conversions.cc:68:3: note: in expansion of macro โ€˜INITโ€™
   68 |   INIT(start_point, start_position_key, PointFromJS);
      |   ^~~~
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3717:43: note: candidate: โ€˜v8::MaybeLocal v8::Object::Get(v8::Local, v8::Local)โ€™
 3717 |   V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context,
      |                                           ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3717:43: note:   candidate expects 2 arguments, 1 provided
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3720:43: note: candidate: โ€˜v8::MaybeLocal v8::Object::Get(v8::Local, uint32_t)โ€™
 3720 |   V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context,
      |                                           ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3720:43: note:   candidate expects 2 arguments, 1 provided
../src/conversions.cc:60:50: error: no matching function for call to โ€˜v8::Object::Get(v8::Local)โ€™
   60 |     auto field = Type(js_range->Get(Nan::New(key))); \
      |                                                  ^
../src/conversions.cc:69:3: note: in expansion of macro โ€˜INITโ€™
   69 |   INIT(end_point, end_position_key, PointFromJS);
      |   ^~~~
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3717:43: note: candidate: โ€˜v8::MaybeLocal v8::Object::Get(v8::Local, v8::Local)โ€™
 3717 |   V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context,
      |                                           ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3717:43: note:   candidate expects 2 arguments, 1 provided
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3720:43: note: candidate: โ€˜v8::MaybeLocal v8::Object::Get(v8::Local, uint32_t)โ€™
 3720 |   V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context,
      |                                           ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3720:43: note:   candidate expects 2 arguments, 1 provided
../src/conversions.cc:60:50: error: no matching function for call to โ€˜v8::Object::Get(v8::Local)โ€™
   60 |     auto field = Type(js_range->Get(Nan::New(key))); \
      |                                                  ^
../src/conversions.cc:70:3: note: in expansion of macro โ€˜INITโ€™
   70 |   INIT(start_byte, start_index_key, ByteCountFromJS);
      |   ^~~~
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3717:43: note: candidate: โ€˜v8::MaybeLocal v8::Object::Get(v8::Local, v8::Local)โ€™
 3717 |   V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context,
      |                                           ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3717:43: note:   candidate expects 2 arguments, 1 provided
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3720:43: note: candidate: โ€˜v8::MaybeLocal v8::Object::Get(v8::Local, uint32_t)โ€™
 3720 |   V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context,
      |                                           ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3720:43: note:   candidate expects 2 arguments, 1 provided
../src/conversions.cc:60:50: error: no matching function for call to โ€˜v8::Object::Get(v8::Local)โ€™
   60 |     auto field = Type(js_range->Get(Nan::New(key))); \
      |                                                  ^
../src/conversions.cc:71:3: note: in expansion of macro โ€˜INITโ€™
   71 |   INIT(end_byte, end_index_key, ByteCountFromJS);
      |   ^~~~
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3717:43: note: candidate: โ€˜v8::MaybeLocal v8::Object::Get(v8::Local, v8::Local)โ€™
 3717 |   V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context,
      |                                           ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3717:43: note:   candidate expects 2 arguments, 1 provided
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3720:43: note: candidate: โ€˜v8::MaybeLocal v8::Object::Get(v8::Local, uint32_t)โ€™
 3720 |   V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context,
      |                                           ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3720:43: note:   candidate expects 2 arguments, 1 provided
../src/conversions.cc: In function โ€˜v8::Local node_tree_sitter::PointToJS(const TSPoint&)โ€™:
../src/conversions.cc:80:61: error: no matching function for call to โ€˜v8::Object::Set(v8::Local, Nan::imp::FactoryBase::return_t)โ€™
   80 |   result->Set(Nan::New(row_key), Nan::New(point.row));
      |                                                             ^
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3670:37: note: candidate: โ€˜v8::Maybe v8::Object::Set(v8::Local, v8::Local, v8::Local)โ€™
 3670 |   V8_WARN_UNUSED_RESULT Maybe Set(Local context,
      |                                     ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3670:37: note:   candidate expects 3 arguments, 2 provided
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3673:37: note: candidate: โ€˜v8::Maybe v8::Object::Set(v8::Local, uint32_t, v8::Local)โ€™
 3673 |   V8_WARN_UNUSED_RESULT Maybe Set(Local context, uint32_t index,
      |                                     ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3673:37: note:   candidate expects 3 arguments, 2 provided
../src/conversions.cc:81:64: error: no matching function for call to โ€˜v8::Object::Set(v8::Local, v8::Local)โ€™
   81 |   result->Set(Nan::New(column_key), ByteCountToJS(point.column));
      |                                                                ^
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3670:37: note: candidate: โ€˜v8::Maybe v8::Object::Set(v8::Local, v8::Local, v8::Local)โ€™
 3670 |   V8_WARN_UNUSED_RESULT Maybe Set(Local context,
      |                                     ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3670:37: note:   candidate expects 3 arguments, 2 provided
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3673:37: note: candidate: โ€˜v8::Maybe v8::Object::Set(v8::Local, uint32_t, v8::Local)โ€™
 3673 |   V8_WARN_UNUSED_RESULT Maybe Set(Local context, uint32_t index,
      |                                     ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3673:37: note:   candidate expects 3 arguments, 2 provided
../src/conversions.cc: In function โ€˜Nan::Maybe node_tree_sitter::PointFromJS(const v8::Local&)โ€™:
../src/conversions.cc:92:56: error: no matching function for call to โ€˜v8::Object::Get(v8::Local)โ€™
   92 |   Local js_row = js_point->Get(Nan::New(row_key));
      |                                                        ^
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3717:43: note: candidate: โ€˜v8::MaybeLocal v8::Object::Get(v8::Local, v8::Local)โ€™
 3717 |   V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context,
      |                                           ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3717:43: note:   candidate expects 2 arguments, 1 provided
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3720:43: note: candidate: โ€˜v8::MaybeLocal v8::Object::Get(v8::Local, uint32_t)โ€™
 3720 |   V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context,
      |                                           ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3720:43: note:   candidate expects 2 arguments, 1 provided
../src/conversions.cc:98:62: error: no matching function for call to โ€˜v8::Object::Get(v8::Local)โ€™
   98 |   Local js_column = js_point->Get(Nan::New(column_key));
      |                                                              ^
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3717:43: note: candidate: โ€˜v8::MaybeLocal v8::Object::Get(v8::Local, v8::Local)โ€™
 3717 |   V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context,
      |                                           ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3717:43: note:   candidate expects 2 arguments, 1 provided
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3720:43: note: candidate: โ€˜v8::MaybeLocal v8::Object::Get(v8::Local, uint32_t)โ€™
 3720 |   V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context,
      |                                           ^~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:3720:43: note:   candidate expects 2 arguments, 1 provided
../src/conversions.cc:105:41: error: no matching function for call to โ€˜v8::Value::NumberValue()โ€™
  105 |   if (std::isfinite(js_row->NumberValue())) {
      |                                         ^
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:2861:39: note: candidate: โ€˜v8::Maybe v8::Value::NumberValue(v8::Local) constโ€™
 2861 |   V8_WARN_UNUSED_RESULT Maybe NumberValue(Local context) const;
      |                                       ^~~~~~~~~~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:2861:39: note:   candidate expects 1 argument, 0 provided
../src/conversions.cc:106:52: error: no matching function for call to โ€˜v8::Value::Int32Value()โ€™
  106 |     row = static_cast(js_row->Int32Value());
      |                                                    ^
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:2869:40: note: candidate: โ€˜v8::Maybe v8::Value::Int32Value(v8::Local) constโ€™
 2869 |   V8_WARN_UNUSED_RESULT Maybe Int32Value(Local context) const;
      |                                        ^~~~~~~~~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:2869:40: note:   candidate expects 1 argument, 0 provided
../src/conversions.cc:111:44: error: no matching function for call to โ€˜v8::Value::NumberValue()โ€™
  111 |   if (std::isfinite(js_column->NumberValue())) {
      |                                            ^
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:2861:39: note: candidate: โ€˜v8::Maybe v8::Value::NumberValue(v8::Local) constโ€™
 2861 |   V8_WARN_UNUSED_RESULT Maybe NumberValue(Local context) const;
      |                                       ^~~~~~~~~~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:2861:39: note:   candidate expects 1 argument, 0 provided
../src/conversions.cc:112:58: error: no matching function for call to โ€˜v8::Value::Int32Value()โ€™
  112 |     column = static_cast(js_column->Int32Value()) * BYTES_PER_CHARACTER;
      |                                                          ^
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:2869:40: note: candidate: โ€˜v8::Maybe v8::Value::Int32Value(v8::Local) constโ€™
 2869 |   V8_WARN_UNUSED_RESULT Maybe Int32Value(Local context) const;
      |                                        ^~~~~~~~~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:2869:40: note:   candidate expects 1 argument, 0 provided
../src/conversions.cc: In function โ€˜Nan::Maybe node_tree_sitter::ByteCountFromJS(const v8::Local&)โ€™:
../src/conversions.cc:130:47: error: no matching function for call to โ€˜v8::Value::Uint32Value()โ€™
  130 |   return Nan::Just(arg->Uint32Value() * BYTES_PER_CHARACTER);
      |                                               ^
In file included from /home/ed8/.cache/node-gyp/14.16.0/include/node/node.h:67,
                 from ../../../../nan/nan.h:53,
                 from ../src/./node.h:4,
                 from ../src/conversions.cc:1:
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:2866:41: note: candidate: โ€˜v8::Maybe v8::Value::Uint32Value(v8::Local) constโ€™
 2866 |   V8_WARN_UNUSED_RESULT Maybe Uint32Value(
      |                                         ^~~~~~~~~~~
/home/ed8/.cache/node-gyp/14.16.0/include/node/v8.h:2866:41: note:   candidate expects 1 argument, 0 provided
make: *** [tree_sitter_runtime_binding.target.mk:128: Release/obj.target/tree_sitter_runtime_binding/src/conversions.o] Error 1
make: Leaving directory '/home/ed8/.local/share/yarn/global/node_modules/bash-language-server/node_modules/tree-sitter/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
gyp ERR! System Linux 5.4.0-65-generic
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/ed8/.local/share/yarn/global/node_modules/bash-language-server/node_modules/tree-sitter
gyp ERR! node -v v14.16.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
info Visit https://yarnpkg.com/en/docs/cli/global for documentation about this command.

How to include code to handle extraction?

For example, in jison, we can do the following:

MathExpression 
    = Number Operator Number {$$={left: $1, op: $2, right: $3}}
    ;

So, how can I do that or achieve similar thing in node-tree-sitter? Or do you have a better suggestion?

Node positions become invalid after an edit

Node objects are cached in JS and then don't get updated after an edit, making their positions potentially invalid.

Possible solutions:

  • No solution. Just re-find your nodes. This would be a bummer.
  • Update the node cache on every edit
  • Some explicit method to reload nodes after an edit, possibly taking the edit as a param.

Parameter type not assigned for parse in TypeScript.

I am trying to use this lib in TypeScript, with the following code:

import * as TreeSitter from 'tree-sitter';
import { Point, SyntaxNode, Tree } from 'tree-sitter';
const JavaScript = require('tree-sitter-javascript')
const treeSitter = new TreeSitter()
treeSitter.setLanguage(JavaScript)
    const sourceLines = [
      'let x = 1;',
      'console.log(x);'
    ];
    const tree = treeSitter.parse((index: any, position: Point) => {
      let line = sourceLines[position.row]
      if (line) {
        return line.slice(position.column)
      }
    })
    console.log(tree.rootNode.toString());

However, I am facing the following errors:

Argument of type '(index: any, position: Point) => string | undefined' is not assignable to parameter of type 'string | Input | InputReader'.
  Type '(index: any, position: Point) => string | undefined' is not assignable to type 'InputReader'.
    Type 'string | undefined' is not assignable to type 'string'.
      Type 'undefined' is not assignable to type 'string'.

I skimmed the issues and found this closed one relevant (#55), any ideas?

0.17.0 Regression: Some legal queries fail

After upgrading to tree-sitter 0.17.0, some of my queries started crashing my code. The queries are part of a fairly sizable grammar, so I won't post a ton of information unless it's requested. But one query that started crashing was this:

new TSQuery(MyLanguage, '(header_1 (citekey))')

Attempting to define this query causes an immediate crash with this error message:

Assertion failed: (final_step_indices.size > 0), function ts_query__analyze_patterns, file ../vendor/tree-sitter/lib/src/./query.c, line 1258.
error Command failed with signal "SIGABRT".

I've confirmed that on reverting to 0.16.x, everything works again.

I looked a bit at the source and I think the code block the error comes from is only supposed to run if the query is unmatchable. But this query is not unmatchable, so if I'm correct that's another bug.

"node_tree_sitter_runtime_binding.node is not a valid Win32 application." under windows when using node-tree-sitter in a VSCode extension

Hi, I developed a VSCode extension to help developers handle merge conflicts, which depends on node-tree-sitter.
Its name is SoManyConflicts, the source is open at https://github.com/Symbolk/somanyconflicts and the extension can be downloaded in VSCode Market.

Since node-tree-sitter is a native module and should be built on specific platform, the extension works fine for macOS (which it is original built upon) but fails to activate on Windows, with the error message:

[2021-06-15 14:20:20.236] [exthost] [error] Activating extension Symbolk.somanyconflicts failed due to an error:
[2021-06-15 14:20:20.236] [exthost] [error] Error: \\?\c:\Users\Name\.vscode\extensions\symbolk.somanyconflicts-0.0.3\node_modules\tree-sitter\build\Release\tree_sitter_runtime_binding.node is not a valid Win32 application.
\\?\c:\Users\Name\.vscode\extensions\symbolk.somanyconflicts-0.0.3\node_modules\tree-sitter\build\Release\tree_sitter_runtime_binding.node
	at process.func [as dlopen] (electron/js2c/asar_bundle.js:5:1846)
	at Object.Module._extensions..node (internal/modules/cjs/loader.js:1185:18)
	at Object.func [as .node] (electron/js2c/asar_bundle.js:5:1846)
	at Module.load (internal/modules/cjs/loader.js:982:32)
	at Module._load (internal/modules/cjs/loader.js:823:14)
	at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
	at Function.i._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:27790)
	at Function.E._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:24542)
	at Function.c._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:93:59193)
	at Module.require (internal/modules/cjs/loader.js:1006:19)
	at v (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:4:698)
	at Object.<anonymous> (c:\Users\Name\.vscode\extensions\symbolk.somanyconflicts-0.0.3\node_modules\tree-sitter\index.js:3:13)
	at Module.u._compile (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:4:1315)
	at Object.Module._extensions..js (internal/modules/cjs/loader.js:1155:10)
	at Module.load (internal/modules/cjs/loader.js:982:32)
	at Module._load (internal/modules/cjs/loader.js:823:14)
	at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
	at Function.i._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:27790)
	at Function.E._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:24542)
	at Function.c._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:93:59193)
	at Module.require (internal/modules/cjs/loader.js:1006:19)
	at v (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:4:698)
	at Object.<anonymous> (c:\Users\Name\.vscode\extensions\symbolk.somanyconflicts-0.0.3\out\SoManyConflicts.js:20:20)
	at Module.u._compile (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:4:1315)
	at Object.Module._extensions..js (internal/modules/cjs/loader.js:1155:10)
	at Module.load (internal/modules/cjs/loader.js:982:32)
	at Module._load (internal/modules/cjs/loader.js:823:14)
	at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
	at Function.i._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:27790)
	at Function.E._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:24542)
	at Function.c._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:93:59193)
	at Module.require (internal/modules/cjs/loader.js:1006:19)
	at v (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:4:698)
	at Object.<anonymous> (c:\Users\Name\.vscode\extensions\symbolk.somanyconflicts-0.0.3\out\extension.js:18:27)
	at Module.u._compile (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:4:1315)
	at Object.Module._extensions..js (internal/modules/cjs/loader.js:1155:10)
	at Module.load (internal/modules/cjs/loader.js:982:32)
	at Module._load (internal/modules/cjs/loader.js:823:14)
	at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
	at Function.i._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:27790)
	at Function.E._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:24542)
	at Function.c._load (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:93:59193)
	at Module.require (internal/modules/cjs/loader.js:1006:19)
	at require (internal/modules/cjs/helpers.js:88:18)
	at Function.t [as __$__nodeRequire] (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:5:101)
	at f._loadCommonJSModule (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:103:25948)
	at f._doActivateExtension (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:89:12599)
	at f._activateExtension (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:89:11658)
	at processTicksAndRejections (internal/process/task_queues.js:93:5)

I and trying to rebuild it under Windows but encountered lots of problems with windows-build-tools, but once it works, it means that my users have to rebuild the extension from source to install it. Therefore, I am wondering:

  1. For the tree-sitter side, it there any way to avoid rebuilding from source for installation?
  2. For the VSCode extension side, whether it is feasible to upload a vsix file targeting at different platforms for one extension? And

Query: Querying until node... "is not equal"

Is it possible to query until node "is not equal", for example?
I'm trying to query only the public fields in a C++ file.

Example: Tree-Sitter Playground

class MyClass
{
public:
	/** 1 Comment */
	int One;
    
	/** 2 Comment */
	int Two;

    int Three;
    int Four;

protected:
	/** Bool 1 Comment */
	bool bOne;
	/** Bool 2 Comment */
	bool bTwo;
    
	bool bThree;
	bool bFour;
};

Query:

(class_specifier name: (type_identifier) @className
        (field_declaration_list
          	(access_specifier) @accessSpecifier
          	(#eq? @accessSpecifier "public:")
            (
            	((comment)? @fieldComment .)?
            	(field_declaration declarator: (field_identifier) @fieldName) 
            )
        )
    )

I doesn't return "protected:" accessor but still return its variables, but if I use another query, it starts from "protected:" accessor:

(class_specifier name: (type_identifier) @className
        (field_declaration_list
          	(access_specifier) @accessSpecifier
          	(#eq? @accessSpecifier "protected:")
            (
            	((comment)? @fieldComment .)?
            	(field_declaration declarator: (field_identifier) @fieldName) 
            )
        )
    )

How could I solve this?
Thank you.

Interest in prebuilt binaries?

Hi,

Any interest in using something like prebuild to build/store prebuilt binaries for the major node/electron versions? Not sure how you're solving this problem for Atom but I'm trying to work through how to ship cross platform binaries for VSCode.

I've been messing around with how to get things to cooperate with Travis/Appveyor on this branch in my fork.

Failed to build with node 12.1.0

npm install tree-sitter failed on macOS mojave 10.14.4, with the following errors:

> [email protected] install /Users/zyang/node_modules/tree-sitter
> prebuild-install || node-gyp rebuild

  CC(target) Release/obj.target/tree_sitter/vendor/tree-sitter/lib/src/lib.o
  LIBTOOL-STATIC Release/tree_sitter.a
  CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/binding.o
  CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/conversions.o
../src/conversions.cc:105:41: error: too few arguments to function call, single
      argument 'context' was not specified
  if (std::isfinite(js_row->NumberValue())) {
                    ~~~~~~~~~~~~~~~~~~~ ^
/Users/zyang/.node-gyp/12.1.0/include/node/v8.h:2564:3: note: 'NumberValue'
      declared here
  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
  ^
/Users/zyang/.node-gyp/12.1.0/include/node/v8config.h:347:31: note: expanded
      from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/conversions.cc:106:52: error: too few arguments to function call, single
      argument 'context' was not specified
    row = static_cast<uint32_t>(js_row->Int32Value());
                                ~~~~~~~~~~~~~~~~~~ ^
/Users/zyang/.node-gyp/12.1.0/include/node/v8.h:2569:3: note: 'Int32Value'
      declared here
  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
  ^
/Users/zyang/.node-gyp/12.1.0/include/node/v8config.h:347:31: note: expanded
      from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/conversions.cc:111:44: error: too few arguments to function call, single
      argument 'context' was not specified
  if (std::isfinite(js_column->NumberValue())) {
                    ~~~~~~~~~~~~~~~~~~~~~~ ^
/Users/zyang/.node-gyp/12.1.0/include/node/v8.h:2564:3: note: 'NumberValue'
      declared here
  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
  ^
/Users/zyang/.node-gyp/12.1.0/include/node/v8config.h:347:31: note: expanded
      from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/conversions.cc:112:58: error: too few arguments to function call, single
      argument 'context' was not specified
    column = static_cast<uint32_t>(js_column->Int32Value()) * BYTES_PER_...
                                   ~~~~~~~~~~~~~~~~~~~~~ ^
/Users/zyang/.node-gyp/12.1.0/include/node/v8.h:2569:3: note: 'Int32Value'
      declared here
  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
  ^
/Users/zyang/.node-gyp/12.1.0/include/node/v8config.h:347:31: note: expanded
      from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
../src/conversions.cc:130:47: error: too few arguments to function call, single
      argument 'context' was not specified
  return Nan::Just<uint32_t>(arg->Uint32Value() * BYTES_PER_CHARACTER);
                             ~~~~~~~~~~~~~~~~ ^
/Users/zyang/.node-gyp/12.1.0/include/node/v8.h:2567:3: note: 'Uint32Value'
      declared here
  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
  ^
/Users/zyang/.node-gyp/12.1.0/include/node/v8config.h:347:31: note: expanded
      from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
13 warnings and 5 errors generated.
make: *** [Release/obj.target/tree_sitter_runtime_binding/src/conversions.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:196:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:256:12)
gyp ERR! System Darwin 18.5.0
gyp ERR! command "/usr/local/Cellar/node/12.1.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/zyang/node_modules/tree-sitter
gyp ERR! node -v v12.1.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

It seems that conversions.cc uses in-capatible v8 API?

Tree-cached query capture nodes are not updated during tree edits.

I have a query that is behaving strangely;
as I make four replacements in my code,
the query capture nodes are updated (based on a tree cache) for some changes I make,
but fail to update after the third change.

As I log my query's captured nodes in the console after each change,
you can see an edit to the name of the JSX element Lens.change -> ChargeCard
updates the captured nodes;
the following change to delete the source captured attribute
leaves the captured nodes pointing to stale indexes in the code,
making my subsequent change, deleting the code captured attribute, impossible.

Boiled down:

[ 'source', 570, 609, 'source="app/javascript/packs/charge.js"' ],
[ 'code', 610, 621, 'code="abcd"' ],

// -> change JSX opening tag name using a tree edit

[ 'source', 569, 608, 'source="app/javascript/packs/charge.js"' ],
[ 'code', 609, 620, 'code="abcd"' ],

// -> delete "source" attribute using a tree edit

[ 'source', 569, 608, ' code="abcd"\n        onClick={(e) => {\n' ],
[ 'code', 609, 620, '         e.' ],

code under analysis:

      <Lens.change source="app/javascript/packs/charge.js" code="abcd"
        onClick={(e) => {
          e.preventDefault()
          chargeCard()
        }}
      >
        Charge your card.
      </Lens.change>

code producing changes:
https://github.com/assembleapp/donors/blob/tree-sitter/hierarch/parse.js#L51-L121
https://github.com/assembleapp/donors/blob/tree-sitter/hierarch/program.js

Can you recommend any approaches? Much obliged.

Can't install on Node 16 on M1 mac: no template named 'remove_cv_t'

I installed Node with brew install node on my M1 MacBook Air.

$ cd /tmp/
$ mkdir treesitter-test
$ cd treesitter-test/
$ node --version
v16.9.1
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help init` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (treesitter-test) 
version: (1.0.0) 
description: 
entry point: (index.js) 
test command: 
git repository: 
keywords: 
author: 
license: (ISC) 
About to write to /private/tmp/treesitter-test/package.json:

{
  "name": "treesitter-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Is this OK? (yes) 
$ npm install tree-sitter
npm ERR! code 1
npm ERR! path /private/tmp/treesitter-test/node_modules/tree-sitter
npm ERR! command failed
npm ERR! command sh -c prebuild-install || node-gyp rebuild
npm ERR! CC(target) Release/obj.target/tree_sitter/vendor/tree-sitter/lib/src/lib.o
npm ERR!   LIBTOOL-STATIC Release/tree_sitter.a
npm ERR!   CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/binding.o
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | darwin | arm64
npm ERR! gyp info find Python using Python version 3.9.6 found at "/opt/homebrew/opt/[email protected]/bin/python3.9"
npm ERR! (node:22167) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
npm ERR! (Use `node --trace-deprecation ...` to show where the warning was created)
npm ERR! gyp info spawn /opt/homebrew/opt/[email protected]/bin/python3.9
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/private/tmp/treesitter-test/node_modules/tree-sitter/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/space/Library/Caches/node-gyp/16.9.1/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/Users/space/Library/Caches/node-gyp/16.9.1',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/space/Library/Caches/node-gyp/16.9.1/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/private/tmp/treesitter-test/node_modules/tree-sitter',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! In file included from ../src/binding.cc:1:
npm ERR! In file included from /Users/space/Library/Caches/node-gyp/16.9.1/include/node/node.h:63:
npm ERR! In file included from /Users/space/Library/Caches/node-gyp/16.9.1/include/node/v8.h:30:
npm ERR! /Users/space/Library/Caches/node-gyp/16.9.1/include/node/v8-internal.h:489:38: error: no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?
npm ERR!             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
npm ERR!                                 ~~~~~^~~~~~~~~~~
npm ERR!                                      remove_cv
npm ERR! /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/type_traits:776:50: note: 'remove_cv' declared here
npm ERR! template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
npm ERR!                                                  ^
npm ERR! 1 error generated.
npm ERR! make: *** [Release/obj.target/tree_sitter_runtime_binding/src/binding.o] Error 1
npm ERR! gyp ERR! build error 
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack     at ChildProcess.onExit (/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:394:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
npm ERR! gyp ERR! System Darwin 20.6.0
npm ERR! gyp ERR! command "/opt/homebrew/Cellar/node/16.9.1/bin/node" "/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /private/tmp/treesitter-test/node_modules/tree-sitter
npm ERR! gyp ERR! node -v v16.9.1
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/space/.npm/_logs/2021-09-13T22_12_52_458Z-debug.log
$ npm --version
7.21.1

If I downgrade to Node 14, it works

brew install node@14
$ node --version
v14.17.6
$ cd /tmp/
$ rm -rf treesitter-test/
$ mkdir treesitter-test/
$ cd treesitter-test/
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See npm help init for definitive documentation on these fields
and exactly what they do.

Use npm install <pkg> afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (treesitter-test)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to /private/tmp/treesitter-test/package.json:

{
"name": "treesitter-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC"
}

Is this OK? (yes)

$ npm install tree-sitter

[email protected] install /private/tmp/treesitter-test/node_modules/tree-sitter
prebuild-install || node-gyp rebuild

prebuild-install WARN install No prebuilt binaries found (target=14.17.6 runtime=node arch=arm64 libc= platform=darwin)
CC(target) Release/obj.target/tree_sitter/vendor/tree-sitter/lib/src/lib.o
LIBTOOL-STATIC Release/tree_sitter.a
CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/binding.o
CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/conversions.o
../src/conversions.cc:31:48: warning: 'New' is deprecated: Use the version that takes a BackingStore. See http://crbug.com/v8/9908. [-Wdeprecated-declarations]
auto js_point_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), point_transfer_buffer, 2 * sizeof(uint32_t));
^
/Users/space/Library/Caches/node-gyp/14.17.6/include/node/v8.h:5173:3: note: 'New' has been explicitly marked deprecated here
V8_DEPRECATE_SOON(
^
/Users/space/Library/Caches/node-gyp/14.17.6/include/node/v8config.h:402:39: note: expanded from macro 'V8_DEPRECATE_SOON'

define V8_DEPRECATE_SOON(message) [[deprecated(message)]]

                                  ^

1 warning generated.
CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/language.o
CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/logger.o
CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/node.o
../src/node.cc:32:44: warning: 'New' is deprecated: Use the version that takes a BackingStore. See http://crbug.com/v8/9908. [-Wdeprecated-declarations]
auto js_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), transfer_buffer, transfer_buffer_length * sizeof(uint32_t));
^
/Users/space/Library/Caches/node-gyp/14.17.6/include/node/v8.h:5173:3: note: 'New' has been explicitly marked deprecated here
V8_DEPRECATE_SOON(
^
/Users/space/Library/Caches/node-gyp/14.17.6/include/node/v8config.h:402:39: note: expanded from macro 'V8_DEPRECATE_SOON'

define V8_DEPRECATE_SOON(message) [[deprecated(message)]]

                                  ^

1 warning generated.
CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/parser.o
CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/query.o
CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/tree.o
CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/tree_cursor.o
CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/util.o
SOLINK_MODULE(target) Release/tree_sitter_runtime_binding.node
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

  • [email protected]
    added 61 packages from 44 contributors and audited 61 packages in 8.674s

5 packages are looking for funding
run npm fund for details

found 0 vulnerabilities

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ โ”‚
โ”‚ New major version of npm available! 6.14.15 โ†’ 7.23.0 โ”‚
โ”‚ Changelog: https://github.com/npm/cli/releases/tag/v7.23.0 โ”‚
โ”‚ Run npm install -g npm to update! โ”‚
โ”‚ โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

This seems to be a similar issue to sass/node-sass#3077

Unsure how to recurse tree with `walk`

Hi,

I'm trying to walk the entire tree and "visit" each node but I can't figure it out using a traditional DFS algortihm. Neither of the below work:

Case 1 - Infinite Loop:

const nodeWalk = (node) => {
  if (!node) return
  while (node) {
    console.log(node.nodeText)
    if (node.gotoFirstChild()) {
      nodeWalk(node)
    }
    node.gotoNextSibling()
  }
}

Case 2 - Incomplete Tree:

const nodeWalk = (node) => {
  while (node.gotoFirstChild()) {
    console.log(node.nodeText)
    
    node.gotoNextSibling()
  }
}

Field parent is wrong

Hi!

I have been using fields like described in this comment #54 (comment)

They work well for accessing childs, but not parents

As an example, I would expect node.functionNode.parent to be node, but it isn't

Here is a minimum reproducible example, just follow the instructions in the readme
https://github.com/sguillia/tree-sitter-repro/blob/master/main.ts

This is slightly related to tree-sitter/tree-sitter-javascript#127
I had some parents with type _expression that went away with some void expressions.

Is there any way to still access fields parents?

Thank you!

Emits NODE_MODULE_VERSION error

Hello. I'm trying to use node-tree-sitter v0.17.0 in my project using node v14.15.1, npm v6.14.8.
The package installs without any error, but when I run a project it crashes with the following error:

Error: The module '/home/lereena/pabcnet-server-ts/node_modules/tree-sitter/build/Release/tree_sitter_runtime_binding.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 88. This version of Node.js requires
NODE_MODULE_VERSION 80. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).

I tried to remove node_modules and reinstall all the packages, to run npm rebuild tree-sitter, to downgrade node, but it didn't help.
Is this some package issue or maybe somebody has an idea how to fix this?

Help: How to edit a single AST?

In a certain use case, I need to edit the AST to enclose a for-loop in a statment_block for tree-sitter-javascript:

Before:

// ...preceding blocks
for(let i = 0; i < 10; i++) {
  // ...for body
}
// ...succeeding blocks

After:

// ...preceding blocks
{ for(let i = 0; i < 10; i++) {
  // ...for body
} }
// ...succeeding blocks

Is it possible to edit the AST this way using tree-sitter-node? If yes. How do I do it? Currently, the only way I see is to create a new StatementBlockNode object and then attach it to the tree. In the after case, I don't care about the row and column numbers.

How to efficiently get node under cursor

Hello,

I'm trying to get a node which is responsible for a specific position in the document; and was wondering
if there is a canonical way to do it.

Currently, I'm searching (in a trivial way) for the node manually starting from root node and down:

        let offset = document.offsetAt(position)
        const tree = this.treeParser.parse(content);

        // Start from here
        let root = tree.rootNode;
        let closestNode = root;
        let nodeNotFound = true;
        while (nodeNotFound) {
            for (let child of root.children) {
                if (
                    (Math.abs(offset - child.startIndex) <= Math.abs(offset - closestNode.startIndex))
                    && (offset >= child.startIndex)
                )
                {
                    closestNode = child;
                }
            }
            if (root == closestNode)
            {
                nodeNotFound = false;
            }
            root = closestNode;
        }
        return root;

While this probably is efficient enough for most cases. Does anyone see an improvement?

Can we get a new 0.15 release?

Hey there,

I'm getting a RangeError: Incompatible language version. Expected 9. Got 10 error at the moment, and I think it's due to this not being updated to 0.15.x yet, as I build my language implementation with that.

Only getting it on linux and not on windows (which is weird i guess, but might be due to differences in building)

API parity between node and web binding

Hello, I'm using my grammar in the browser using web-tree-sitter. However when I try to write some tests I was surprised to find that the API for node is different from that of web API. For example there is no childForFieldName method on node.

Now my only option left is to load WASM file into node and test with that. Ideally web API and node API should be exactly the same. Any plan to improve on this?

query fails to match+capture with predicates against alternating and repeating s-expressions

I'm attempting to capture the value of required_prop and, where it equals "the right value", that of conditional_prop. My query does not yield the results I expect, and diverges from the output on the tree-sitter playground. I discovered different incorrect alternation behavior there in tree-sitter/tree-sitter#1584, but I suspect node-tree-sitter is having its own problem with predicates as well.

index.js
import * as TreeSitter from 'tree-sitter';
import Python from 'tree-sitter-python';

const code = `
  class One(args):
        required_prop = 'i will match, because conditional_prop may be omitted'

  class Two(args):
        required_prop = 'i will match, because conditional_prop can be anything'
        conditional_prop = 'i do not have the correct value to be captured'

  class Three(args):
        required_prop = 'i will match, as will conditional_prop'
        conditional_prop = 'the right value'

  class Four(args):
        conditional_prop = 'the right value'
        required_prop = 'i will also match along with conditional_prop'
  `;

const query = `(class_definition
  name: (identifier) @ref
  body: (block [
    (expression_statement
      (assignment
        left: (identifier) @required
        right: (string) @required_val)
      (#match? @required "required_prop")
    )
    (_)
    (expression_statement
      (assignment
        left: (identifier) @conditional
        right: (string) @conditional_val
      (#match? @conditional "conditional_prop")
      (#match? @conditional_val "the right value")
    ))
  ]+))`;

(() => {
  const parser = TreeSitter.default();

  parser.setLanguage(Python);

  const tree = parser.parse(code);

  const matches = new TreeSitter.Query(parser.getLanguage(), query).matches(tree.rootNode);

  matches.forEach(m => {
    m.captures.forEach(c => console.log(c.name, tree.getText(c.node)));

    console.log();
  });
})();
package.json
{
  "name": "tree-sitter-query-testing",
  "version": "1.0.0",
  "description": "",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "tree-sitter": "^0.20.0",
    "tree-sitter-python": "^0.19.0"
  }
}

I expect all classes to match, and all required_props to be captured. With the query as-is, the only matches are Three and Four (output is capture name and text):

> node index.js
ref Three
required required_prop
required_val 'i will match, as will conditional_prop'
conditional conditional_prop
conditional_val 'the right value'

ref Four
conditional conditional_prop
conditional_val 'the right value'
required required_prop
required_val 'i will also match along with conditional_prop'

In the playground, removing the repetition + on the prop alternation yields the expected results, but in node-tree-sitter instead nothing matches.

Removing both conditional predicates allows all @required and @required_vals to be captured, but no @conditional or @conditional_vals are found in spite of there being seven expression_statements that meet its definition in the program.

Get NODE_MODULE_VERSION error when importing and using tree-sitter-javascript

My nodeJS version is 14.17.0, using yarn v1.22.10 as the package manager. My OS is macOS Big Sur 11.2.3.

When I add tree-sitter and tree-sitter-javascript to my vscode extension development project, all appears to be well. But when I try some basic usage of tree-sitter, the error occurs:

Activating extension 'xxx' failed: The module '/path/to/project/node_modules/tree-sitter/build/Release/tree_sitter_runtime_binding.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 83. This version of Node.js requires
NODE_MODULE_VERSION 87. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`)..

All i have done is like:

import * as TreeSitter from 'tree-sitter'
const JavaScript = require('tree-sitter-javascript')
const treeSitter = new TreeSitter()
treeSitter.setLanguage(JavaScript)

parseTextBufferSync crash when passing in an existing tree

    tree = parser.parseTextBufferSync(editor.getBuffer().buffer)
    newtree = parser.parseTextBufferSync(editor.getBuffer().buffer, tree)

crashes atom (The editor has crashed). Stepping into the second parseTextBufferSync call I see the crash happening on line 318 in index.js right when the call is executed:

  const tree = parseTextBufferSync.call(this, snapshot, oldTree, includedRanges);

P.S.: sorry for the issue blasting. I'm super excited about tree-sitter and I would prefer using the atom slack, but my invite request has ben unanswered for a few weeks

Build for Electron 11 on MacOS fails

In file included from ../src/language.cc:1:
In file included from ../src/./language.h:4:
In file included from ../node_modules/nan/nan.h:56:
In file included from /Users/sergei/Library/Caches/node-gyp/11.3.0/include/node/node.h:67:
In file included from /Users/sergei/Library/Caches/node-gyp/11.3.0/include/node/v8.h:30:
/Users/sergei/Library/Caches/node-gyp/11.3.0/include/node/v8-internal.h:418:38: error: no
      template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?
            !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
                                ~~~~~^~~~~~~~~~~
                                     remove_cv
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/type_traits:665:50: note:
      'remove_cv' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
                                                 ^

According to electron/electron#26364 the code needs to be compiled in C++14 mode to fix that.

Segfault with tree-sitter-java for multi-pattern multi-predicate query

This query:
((
  (expression_statement
    (method_invocation
      arguments: (argument_list (string_literal) @first_str))
    (#match? @first_str "one fish"))
)(expression_statement
  (method_invocation
    name: (identifier) @mname
    arguments: (argument_list (string_literal) @next_str))
  (#match? @mname "append")
)*)
This Java code:
package com.dot.dot.stuff;

public class Aaa {
	private Stuff stuff;

	public Aaa() {
	}

	public StringBuilder test() {
		StringBuilder sb = new StringBuilder();
		sb.append("one fish");
		sb.append("two fish");
		sb.append("red fish");
		sb.append("blue fish");

		return sb;
	}
}

Works in the tree-sitter playground, segfaults in node-tree-sitter v0.19.0 with tree-sitter-java 0.19.1.

   3:   ~Parser.parse+0(this=0x233e1d901479 <Parser map = 0x1cb716404881>, 0x233e1d901581 <String[283]: "package com.dot.dot.stuff;\n\npublic class Aaa {\n\x09private Stuff stuff;\n\n\x09public Aaa() {\n\x09}\n\n\x09public StringBuilder test() {\n\x09\x09StringBuilder sb = new StringBuilder();\n\x09\x09sb.append("one fish");\n\x09\x09sb.append("two fish");\n\x09\x09sb.append("red fish");\n\x09\x09sb.append("blue fish");\n\n\x09\x09return sb;\n\x09}\n}\n">, 0x1d1865b01599 <undefined>, 0x1d1865b01599 <undefined>) {
   4:    ~input+0(this=0x38cb43581119 <JSGlobal Object>, 0, 0x1cb492e6d3e1 <Object map = 0x1cb716422149>) {
   4:    } -> 0x233e1d901581 <String[283]: "package com.dot.dot.stuff;\n\npublic class Aaa {\n\x09private Stuff stuff;\n\n\x09public Aaa() {\n\x09}\n\n\x09public StringBuilder test() {\n\x09\x09StringBuilder sb = new StringBuilder();\n\x09\x09sb.append("one fish");\n\x09\x09sb.append("two fish");\n\x09\x09sb.append("red fish");\n\x09\x09sb.append("blue fish");\n\n\x09\x09return sb;\n\x09}\n}\n">
   4:    ~input+0(this=0x38cb43581119 <JSGlobal Object>, 283, 0x1cb492e6d491 <Object map = 0x1cb716422149>) {
   4:    } -> 0x1d1865b017b1 <String[0]: #>
   4:    ~Parser.getLanguage+0(this=0x233e1d901479 <Parser map = 0x1cb716404881>, 0x1d1865b01599 <undefined>) {
   4:    } -> 0x33f636ba7911 <Language map = 0x1cb716421de9>
   3:   } -> 0x1cb492e6d4e9 <Tree map = 0x1cb716422269>
   3:   ~Parser.getLanguage+0(this=0x233e1d901479 <Parser map = 0x1cb716404881>, 0x1d1865b01599 <undefined>) {
   3:   } -> 0x33f636ba7911 <Language map = 0x1cb716421de9>
   3:   ~getQuery+0(this=0x1d1865b01599 <undefined>, 0x299339ddc509 <String[4]: #java>) {
   3:   } -> 0x0ecd6a4f1b01 <String[410]: #((\n        (expression_statement\n          (method_invocation\n            arguments: (argument_list (string_literal) @first_str))\n          (#match? @first_str "^.(one fish)"))\n      )(expression_statement\n
   (method_invocation\n          name: (identifier) @mname\n          arguments: (argument_list (string_literal) @next_str))\n        (#match? @mname "append")\n      )*)\n        >
   3:   ~Query._init+0(this=0x1cb492e6d781 <Query map = 0x212864fc94b9>) {
PID 23772 received SIGSEGV for address: 0x78
/path/to/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x2e9b)[0x7feee9f5ee9b]
/usr/lib/libpthread.so.0(+0x13870)[0x7feee929e870]
/path/to/node_modules/tree-sitter/build/Release/tree_sitter_runtime_binding.node(ts_query_pattern_count+0x0)[0x7feee453ac10]
/path/to/node_modules/tree-sitter/build/Release/tree_sitter_runtime_binding.node(_ZN16node_tree_sitter5Query13GetPredicatesERKN3Nan20FunctionCallbackInfoIN2v85ValueEEE+0x56)[0x7feee4529ed6]
/path/to/node_modules/tree-sitter/build/Release/tree_sitter_runtime_binding.node(+0x18b28)[0x7feee4528b28]
node(_ZN2v88internal25FunctionCallbackArguments4CallENS0_15CallHandlerInfoE+0x108)[0x5571376c67e8]
node(+0x9194e0)[0x5571376c74e0]
node(+0x91999f)[0x5571376c799f]
node(_ZN2v88internal21Builtin_HandleApiCallEiPmPNS0_7IsolateE+0x16)[0x5571376c7bf6]
node(+0x1116439)[0x557137ec4439]
zsh: segmentation fault (core dumped)  node --trace ./index.js

This behaves a lot like @cellog's discovery in #72:

further context: the lines

        call receiver: (constant) @class
        (#eq? @class "I18n")
        method: (identifier) @method
        (#eq? @method "namespace")

are responsible. If I remove either

        method: (identifier) @method
        (#eq? @method "namespace")

or

        call receiver: (constant) @class
        (#eq? @class "I18n")

OR remove both predicates (the (#eq?

then the seg fault disappears.

It succeeds with one pattern or the other, or with both patterns sans predicates.

SyntaxNode.text fails

Calling SyntaxNode.text raises the following error

TypeError: this.input.substring is not a function
    at Tree.getTextFromString [as getText] (tree-sitter/index.js:357:21)
    at SyntaxNode.get text [as text] (tree-sitter/index.js:54:22)

I assume the call in the index.js should be this.input(node.startIndex, node.endIndex)?

'closest' return nothing for `function` type

I want to get function SyntaxNode by using closest.
But, in the example below, it returns nothing.
I could get function body by the manual way.
I am also curious how closest treat unnamed node since I want to skip unnamed function node if I don't I get function keyword instead of the node which contains whole function body.

Reproduce

Open atom-editor and enable tree-sitter and place cursor at

  • foo in method: Can get method node by closest(OK).
  • bar in function: Can NOT get function node by closest(NG).
class ClassName {
  constructor() {
    'foo'
  }
}

function func() {
  'bar'
}

code to repro

  1. Paste following code on dev-console and call getClosestFunction() by placing cursor at foo and bar.
  2. Observe console.log and see closest fail but closestManual success when the cursor is at bar.
function getClosestFunction() {
  const editor = atom.workspace.getActiveTextEditor()
  const position = editor.getCursorBufferPosition()
  const node = editor.languageMode.getSyntaxNodeAtPosition(position)
  // The names of these nodes will depend on the grammar

  const types = ['function', 'method_definition']
  const functionNodeByClosest = node.closest(types)
  const functionNodeByManual = closestManual(node, types)

  console.log('# try from node', node.text, 'at', position.toString())

  console.log("= by closest");
  if (functionNodeByClosest) {
    console.log(functionNodeByClosest.text)
  }
  console.log("= by manual");
  if (functionNodeByManual) {
    console.log(functionNodeByManual.text)
  }
}

function closestManual(node, types) {
  while (node) {
    if (node.isNamed && types.some(type => type === node.type)) {
      return node
    }

    if (node.parent) {
      node = node.parent
    } else {
      break
    }
  }
}

"TypeError: illegal invocation" when imported in multiple tests

I am having a strange bug when two (or more) test files indirectly use tree-sitter, the second import throws the following error:

yarn run v1.19.1
$ jest
 PASS  src/lib/__test__/one.test.ts
 FAIL  src/lib/__test__/two.test.ts
  โ— Test suite failed to run

    TypeError: Illegal invocation

    > 1 | import { default as Parser } from "tree-sitter";
        | ^
      2 |
      3 | export class Tokenizer {
      4 |

      at Object.get [as rootNode] (node_modules/tree-sitter/index.js:20:35)
      at Object.<anonymous> (node_modules/tree-sitter/index.js:16:26)
      at Object.<anonymous> (src/lib/tokenizer.ts:1:1)

Test Suites: 1 failed, 1 passed, 2 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.059s
Ran all test suites.
error Command failed with exit code 1.

I have made a minimal reproducible example at https://github.com/rien/node-tree-sitter-bug-minimal-reproducible-example with more info.

Running each test individually (so tree-sitter is only imported once) does not exhibit this behaviour.

I am writing a CLI app using typescript and using jest as testing framework.

Any idea what could be causing this issue?

Requiring tree-sitter from multiple threads causes error

This code causes an error:

require('tree-sitter');
const {Worker} = require('worker_threads');

new Worker('require("tree-sitter")', {eval: true});
Error: Module did not self-register.
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:800:18)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at Function.Module._load (internal/modules/cjs/loader.js:555:12)
    at Module.require (internal/modules/cjs/loader.js:666:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (/Users/govett/Downloads/tree-sitter-test/node_modules/tree-sitter/index.js:3:13)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at Function.Module._load (internal/modules/cjs/loader.js:555:12)

I believe this is due to the module not being context aware, and assuming a single isolate.

I will attempt to look into fixing this issue.

node-gyp error while installing as dependency of tree-sitter-syntax

Atom 1.14.2 on Linux (Fedora 24)

When running the "Update Package Dependencies" command from the tree-sitter-syntax package I get an error message. On the same machine, npm install tree-sitter works without errors.

Relevant part of npm-debug.log:

665 silly lifecycle [email protected]~install: Args: [ '-c', 'node-gyp rebuild' ]
666 silly lifecycle [email protected]~install: Returned: code: 1  signal: null
667 info lifecycle [email protected]~install: Failed to exec install script
668 verbose unlock done using [FILE]
669 silly rollbackFailedOptional Starting
670 silly rollbackFailedOptional Finishing
671 silly runTopLevelLifecycles Starting
672 silly runTopLevelLifecycles Finishing
673 silly install printInstalled
674 verbose stack Error: [email protected] install: `node-gyp rebuild`
674 verbose stack Exit status 1
674 verbose stack     at EventEmitter.<anonymous> (/usr/share/atom/resources/app/apm/node_modules/npm/lib/utils/lifecycle.js:242:16)
674 verbose stack     at emitTwo (events.js:87:13)
674 verbose stack     at EventEmitter.emit (events.js:172:7)
674 verbose stack     at ChildProcess.<anonymous> (/usr/share/atom/resources/app/apm/node_modules/npm/lib/utils/spawn.js:40:14)
674 verbose stack     at emitTwo (events.js:87:13)
674 verbose stack     at ChildProcess.emit (events.js:172:7)
674 verbose stack     at maybeClose (internal/child_process.js:827:16)
674 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
675 verbose pkgid [email protected]
676 verbose cwd [DIRECTORY]
677 error Linux 4.9.13-101.fc24.x86_64
678 error argv "/usr/share/atom/resources/app/apm/bin/node" "/usr/share/atom/resources/app/apm/node_modules/npm/bin/npm-cli.js" "--globalconfig" "[HOME]/.atom/.apm/.apmrc" "--userconfig" "[HOME]/.atom/.apmrc" "install" "--runtime=electron" "--target=1.3.13" "--arch=x64"
679 error node v4.4.5
680 error npm  v3.10.5
681 error code ELIFECYCLE
682 error [email protected] install: `node-gyp rebuild`
682 error Exit status 1
683 error Failed at the [email protected] install script 'node-gyp rebuild'.
683 error Make sure you have the latest version of node.js and npm installed.
683 error If you do, this is most likely a problem with the tree-sitter package,
683 error not with npm itself.
683 error Tell the author that this fails on your system:
683 error     node-gyp rebuild
683 error You can get information on how to open an issue for this project with:
683 error     npm bugs tree-sitter
683 error Or if that isn't available, you can get their info via:
683 error     npm owner ls tree-sitter
683 error There is likely additional logging output above.
684 verbose exit [ 1, true ]

Support field names

Hey,

I'm currently on a project that would greatly benefit from using field names to extract information on class/method names. I saw that you were already working on adding support to tree-sitter bindings for other languages. How are your plans regarding node? If you think it's feasible I'd also love to have a look at it.

/cc @maxbrunsfeld

Add documentation for how to use Query API

Hi,

I've noticed that #62 did implement the Query API and I sort of did figure it out on my own by just backtracing the packages, the functions being exposed etc, but only because I couldn't find any documentation on how to use the Query API in JavaScript/TypeScript.

Please add the required documentation in the README about how to use this. I personally feel it should include examples of the following

  • How to create a query
  • How to capture a node with a query
    • After capturing a node, how do I get a node inside this result? Python example: if I capture a function/method it's name, parameters and body and my goal is to get the parameter data, how do I get each parameter? Should I just use parameters: (parameters (identifier) (identifier)) @function.parameters and then loop over the result and filter the child nodes via result.node.children.filter((node) => node.type === 'identifier')? Or can this capturing be handled with queries as well? I'd like to get more information about this, since I can't find anything about this.
  • How queries work

Thanks.

Possible memory leak

If I understand correctly, transfer_buffer is re-allocated to fit the max amount of nodes ever marshalled in a single pass. I think it's never released before being re-allocated, is it possible?

(line 28)

static inline void setup_transfer_buffer(uint32_t node_count) {
uint32_t new_length = node_count * FIELD_COUNT_PER_NODE;
if (new_length > transfer_buffer_length) {
transfer_buffer_length = new_length;
transfer_buffer = static_cast<uint32_t *>(malloc(transfer_buffer_length * sizeof(uint32_t)));
auto js_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), transfer_buffer, transfer_buffer_length * sizeof(uint32_t));
Nan::Set(
Nan::New(module_exports),
Nan::New("nodeTransferArray").ToLocalChecked(),
Uint32Array::New(js_transfer_buffer, 0, transfer_buffer_length)
);
}
}

parseTextBufferSync error with Atom TextBuffer

parseTextBufferSync(editor.getBuffer(), tree)

throws an error Uncaught (in promise) TypeError: buffer.getSnapshot is not a function here. editor.getBuffer() returns a TextBuffer object, but it does not have a getSnapshot() method. I've looked and found getSnapshot mentioned in the super string interface, but not in Atom's TextBuffer object. Are we talking about a different TextBuffer here?

Query: Negated Fields causing an error in Node/C++

When using the Playground the query works normally but when using Node with C++ parser the same query causes an error ( if I remove the Negated Field it works ).

Example:
https://tree-sitter.github.io/tree-sitter/playground

Code

class MyClass
{
public:
	MyClass();
	MyClass(int b){}

	void Function();
	void FunctionB(){}
}

Query
[ (declaration declarator: (function_declarator declarator: (identifier) @N)) @C (function_definition !type declarator: (function_declarator declarator: [ (identifier) @N (field_identifier) @N ] )) @C ]

!type is the keyword that is causing an error.

Can anybody help me?
Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.