Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter type not assigned for parse in TypeScript. #86

Closed
Symbolk opened this issue May 28, 2021 · 11 comments
Closed

Parameter type not assigned for parse in TypeScript. #86

Symbolk opened this issue May 28, 2021 · 11 comments

Comments

@Symbolk
Copy link

Symbolk commented May 28, 2021

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?

@ahlinc
Copy link
Contributor

ahlinc commented May 28, 2021

I suppose because you need to return "" the empty string in case of the end of the input.

@Symbolk
Copy link
Author

Symbolk commented May 29, 2021

I suppose because you need to return "" the empty string in case of the end of the input.

Yeah, you are right!
Now I can compile and run it, but got another error:

'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`)..

I have tried node 14.16.1 and 14.0.0, they are corresponding to version 83 (https://nodejs.org/en/download/releases/), but it seems that there is NO version corresponding to version 87, so I am confused.

@ahlinc
Copy link
Contributor

ahlinc commented May 29, 2021

Looks like an issue with your environment and somehow customly compiled nodejs version. Could you provide more info:

  • About your operation system / distro.
  • Do you have a system node installation by some package manager?
  • Where do you get other versions of node executables.
  • A full command how you call your script with Node when you got the error.

@Symbolk
Copy link
Author

Symbolk commented May 29, 2021

Looks like an issue with your environment and somehow customly compiled nodejs version. Could you provide more info:

  • About your operation system / distro.
  • Do you have a system node installation by some package manager?
  • Where do you get other versions of node executables.
  • A full command how you call your script with Node when you got the error.
  1. System: macOS 10.15.6
  2. Yes, I manage multiple node versions with NVM, the system version is 14.16.0
  3. I install the versions with nvm install VERSION
  4. I am developing a VSCode extension in typescript, and I'd like to integrate node-tree-sitter into it. When debugging the extension with F5 in VSCode, it reports this error.

2F15A4A7-0A52-45B3-99A5-B5B77C598BC5

@gpetrov
Copy link
Contributor

gpetrov commented May 29, 2021

You have to compile tree-sitter for the electron version of vs code, not your local node

@ahlinc
Copy link
Contributor

ahlinc commented May 29, 2021

@Symbolk
Copy link
Author

Symbolk commented May 30, 2021

@gpetrov @ahlinc Thanks for the hint! I am trying to rebuild it, but the following error is reported:

⠹ Building module: tree-sitter, Completed: 0gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CC(target) Release/obj.target/tree_sitter/vendor/tree-sitter/lib/src/lib.o
⠏ Building module: tree-sitter, Completed: 0  LIBTOOL-STATIC Release/tree_sitter.a
⠹ Building module: tree-sitter, Completed: 0  CXX(target) Release/obj.target/tree_sitter_runtime_binding/src/binding.o
⠦ Building module: tree-sitter, Completed: 0In file included from ../src/binding.cc:1:
In file included from /Users/symbolk/.electron-gyp/12.0.4/include/node/node.h:67:
In file included from /Users/symbolk/.electron-gyp/12.0.4/include/node/v8.h:30:
/Users/symbolk/.electron-gyp/12.0.4/include/node/v8-internal.h:452: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
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/type_traits:697:50: note: 'remove_cv' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
                                                 ^
⠋ Building module: tree-sitter, Completed: 01 error generated.
make: *** [Release/obj.target/tree_sitter_runtime_binding/src/binding.o] Error 1
✖ Rebuild Failed

An unhandled error occurred inside electron-rebuild
node-gyp failed to rebuild '/Users/symbolk/coding/vscode/somanyconflicts/node_modules/tree-sitter'.
Error: `make` failed with exit code: 2



Error: node-gyp failed to rebuild '/Users/symbolk/coding/vscode/somanyconflicts/node_modules/tree-sitter'.
Error: `make` failed with exit code: 2


    at ModuleRebuilder.rebuildNodeGypModule (/Users/symbolk/coding/vscode/somanyconflicts/node_modules/electron-rebuild/lib/src/module-rebuilder.js:193:19)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Rebuilder.rebuildModuleAt (/Users/symbolk/coding/vscode/somanyconflicts/node_modules/electron-rebuild/lib/src/rebuild.js:190:9)
    at async Rebuilder.rebuild (/Users/symbolk/coding/vscode/somanyconflicts/node_modules/electron-rebuild/lib/src/rebuild.js:152:17)
    at async /Users/symbolk/coding/vscode/somanyconflicts/node_modules/electron-rebuild/lib/src/cli.js:146:9

VSCode information:
image

Node version: 14.16.0

@gpetrov
Copy link
Contributor

gpetrov commented May 30, 2021

This is a common problem when rebuilding node 14+ modules on new macOS.

They need c++14 compiler.

So just edit binding.gyp and change:

'xcode_settings': {
        'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
      },

To

'xcode_settings': {
        'CLANG_CXX_LANGUAGE_STANDARD': 'c++14',
      },

@gpetrov
Copy link
Contributor

gpetrov commented May 30, 2021

Seems there is also a PR for this:

#83

@Symbolk
Copy link
Author

Symbolk commented May 30, 2021

Seems there is also a PR for this:

#83

Right, I also found several similar issues in other projects.

Now the problem is, since the pr is not merged yet but I am blocked by it, is there any way to rebuild a version and depend it on myself? I guess there should be a way but sorry I am new to node and ts.

@Symbolk
Copy link
Author

Symbolk commented May 30, 2021

I managed to solve this by manually editing node_modules/tree-sitter/binding.gyp and run ./node_modules/.bin/electron-rebuild to rebuild it to get the correct node_modules/tree-sitter/build/tree_sitter_runtime_binding.node.

Cheers!

@Symbolk Symbolk closed this as completed May 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants