I have created a tree-sitter parser that is parsing some legacy SAP language we use in order to make a package compatible for ATOM. I will be very literate in my actions taken, as I am not very confident where I messed up.
According to the tree-sitter documentation many guides I read - I've done the following:
Added D:\path-to-project\node_modules.bin to PATH
npm install -g node-gyp (I have installed the dependencies - MSVC 2017 and Python 2.7)
Created a new directory and cd to it:
npm init (followed the dialog)
npm install
npm install --save-dev nan
npm install --save-dev tree-sitter-cli
Now we can create our tree-sitter grammar.js file and generate the tree-sitter parser so I did:
Created the grammar.js and wrote down the necessary grammar Opened CMD, cd to project folder and:
tree-sitter generate
node-gyp configure
node-gyp build
tree-sitter test (To check if the parser is working correctly, which it does)
Accordingly now I can integrate the parser inside an ATOM package. So I published the tree-sitter parser that I created to npm via - 'npm publish' then:
I created a package from ATOMs Generate package function, created a "grammar" directory in the package and a .cson file with the following values:
name: 'Human readable name'
scopeName: 'A unique, stable identifier for the language.'
type: 'tree-sitter' (indicates that we are using tree-sitter grammar not TextMate one)
parser: 'Here we must the npm package name that we published to NPM'
fileTypes: ['array of file extensions that the package will run on for example 'cpp'']
Here is where it gets interesting. After 'npm install my-npm-package-name' inside my ATOM package directory I get an error inside ATOM:
The module '\\?\D:\Users\myUser\github\my-ATOM-package-name\node_modules\my-tree-sitter-npm-package
\build\Release\my-tree-sitter-npm-package_binding.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 73. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
in D:\Users\myUser\.atom\packages\my-ATOM-package-name\grammars\the-cson-file-mentioned.cson
From the web investigation I did, this is due that ATOM uses different NodeJs version from what I am using (NodeJs v 12.4.0). This is where I am stuck at, after many tries to recompile with 'electron-rebuild' I have given up with no success and decided that I need more experienced helper.
I am developing and installing on Windows. NodeJS is installed with nvm and I am developing with v12.4.0.
I managed to resolve the issue. Apparently or not so apparently you should:
If it still complains that you are running different version you should:
Before publishing to npm: delete binding.gyp, package-lock.json files and the Electron binary folder