pistoletpierre / language-systemverilog

Atom SystemVerilog language support
MIT License
5 stars 2 forks source link

use tree-sitter-verilog #4

Closed drom closed 4 years ago

drom commented 5 years ago

Hi, I have developed SystemVerilog 2017 parser: https://github.com/tree-sitter/tree-sitter-verilog Based on GitHub's Tree-Sitter parser generator infrastructure: http://tree-sitter.github.io/tree-sitter I also have SystemVerilog language plugin here: https://github.com/drom/language-verilog I would love to merge these features into your plugin.

pistoletpierre commented 5 years ago

What would the effective change be for these features you're talking about?

drom commented 5 years ago

I did not quite get your question. If you are asking:

  1. How tree-sitter based syntax highlighter different from the regexp based plugin you have now?

Tree-sitter is the full parser, so it sees the correct structure of the source file instead of RegExp guess about the structure. More about tree-sitter can be found here: http://tree-sitter.github.io/tree-sitter/ In fact most of Atom language highlighters already use tree-sitter https://github.com/drom/awesome-tree-sitter

  1. What code need to be added to the plugin to enable tree-sitter?

You can see in my repo here: https://github.com/drom/language-verilog I can prepare PR if you are interested.

pistoletpierre commented 5 years ago

Tree-sitter is the full parser, so it sees the correct structure of the source file instead of RegExp guess about the structure.

I can prepare PR if you are interested.

Sounds great; please do!

pistoletpierre commented 5 years ago

Failed to load a language-systemverilog package grammar

Cannot find module './build/Release/tree_sitter_verilog_binding' in /Users/my_username/.atom/packages/language-systemverilog/grammars/tree-sitter-systemverilog.cson

I'm not sure what to make of that. I made your changes, updated the dependencies, and now I'm seeing that error

drom commented 5 years ago

Have you run apm rebuild ?

pistoletpierre commented 5 years ago

Yep, that's post-rebuild. Pre-rebuild I was getting a dependency problem from tree-sitter-verilog

drom commented 5 years ago

Yep, I have not tested it under Windows :(

pistoletpierre commented 5 years ago

Me either; I'm on MacOS

drom commented 5 years ago

do you have g++ installed somewhere?

pistoletpierre commented 5 years ago

Yep

drom commented 5 years ago

could you try installing tree-sitter-verilog by itself? Like npm i tree-sitter-verilog

pistoletpierre commented 5 years ago

The module '/[...]/language-systemverilog/node_modules/tree-sitter-verilog/build/Release/tree_sitter_verilog_binding.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 72. This version of Node.js requires NODE_MODULE_VERSION 64. Please try re-compiling or re-installing the module (for instance, using npm rebuild or npm install). in /Users/my_username/.atom/packages/language-systemverilog/grammars/tree-sitter-systemverilog.cson

It's a different error at least, so we're probably moving in the right direction

drom commented 5 years ago

node --version ?

pistoletpierre commented 5 years ago

v12.6.0

drom commented 5 years ago

atom --version ?

pistoletpierre commented 5 years ago

Atom : 1.39.1 Electron: 3.1.10 Chrome : 66.0.3359.181 Node : 10.2.0

drom commented 5 years ago

you need node v10. nvm i 10 https://github.com/nvm-sh/nvm

pistoletpierre commented 5 years ago
image

😂😂

pistoletpierre commented 5 years ago

I thought "Ah nice everything's working now" but then the window didn't respond and eventually showed that ^

drom commented 5 years ago

apm rebuild

pistoletpierre commented 5 years ago

Same problem I'm afraid

pistoletpierre commented 5 years ago

nvm i 10 gave me v10.16.0. I then tried nvm i 10.2.0 to match Atom's npm version exactly and got the following:

> npm i tree-sitter-verilog

> tree-sitter-verilog@0.16.0 install /[...]/language-systemverilog/node_modules/tree-sitter-verilog
> node bin/install.js

build
In file included from ../src/binding.cc:2:
/Users/peter/.node-gyp/10.2.0/include/node/node.h:53:10: fatal error: 'core.h' file not found

#include "core.h"  // NOLINT(build/include_order)
         ^~~~~~~~

1 error generated.

make: *** [Release/obj.target/tree_sitter_verilog_binding/src/binding.o] Error 1

gyp

ERR! build error

gyp
ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/[...]/.nvm/versions/node/v10.2.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp
 ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR!
stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)

gyp ERR!
 System Darwin 18.7.0

gyp ERR! command "/[...]/.nvm/versions/node/v10.2.0/bin/node" "/[...]/.nvm/versions/node/v10.2.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"

gyp ERR! cwd /[...]/language-systemverilog/node_modules/tree-sitter-verilog
gyp ERR!
node -v v10.2.0
gyp ERR! node-gyp -v v3.6.2
gyp
 ERR! not ok

done
+ tree-sitter-verilog@0.16.0
updated 1 package in 15.903s
drom commented 5 years ago

You need newer Node 10. nvm i 10

drom commented 5 years ago

nvm i 10.16.0 ?

pistoletpierre commented 5 years ago

Yep that's what I did the first time; that's when Atom crashed. Then I noticed the version mismatch and thought maybe going to 10.2.0 would solve it. Guess not

drom commented 5 years ago

How did you installed my branch of the plugin? apm -d link ?

drom commented 5 years ago

do you run atom -d ?

pistoletpierre commented 5 years ago

apm link. Didn't use the -d flag though

drom commented 5 years ago

Try dev mode: apm link -d then atom -d

pistoletpierre commented 5 years ago

-d isn't accepted as a valid flag on MacOS's apm. atom -d does work, however

drom commented 5 years ago

apm link -d

pistoletpierre commented 5 years ago

apm link -d then atom -d: it's crashing even sooner now; before it would open the GUI and it looked like I could just start typing. Now it opens a blank window and hangs for a while before showing that "crashed" dialog

drom commented 5 years ago

apm rebuild ?

pistoletpierre commented 5 years ago

Same problem I'm afraid

drom commented 5 years ago

ll ~/.atom/dev/packages/

pistoletpierre commented 5 years ago

lrwxr-xr-x 1 my_username staff 48 Jul 27 13:08 language-systemverilog -> /Users/my_username/scratch/language-systemverilog/

drom commented 5 years ago
cd ~/.atom/dev/packages/language-systemverilog/
rm -rf node_modules/ package-lock.json
apm rebuild
atom -d
pistoletpierre commented 5 years ago
Failed to load a language-systemverilog package grammar

Cannot find module 'tree-sitter-verilog' in /Users/my_username/.atom/dev/packages/language-systemverilog/grammars/tree-sitter-systemverilog.cson
drom commented 5 years ago
cd ~/.atom/dev/packages/language-systemverilog/
git pull
rm -rf node_modules/ package-lock.json
nvm i 10
npm i
apm link -d
apm rebuild
atom -d
pistoletpierre commented 5 years ago

It runs through everything without problems but then when the GUI opens it hangs with a blank screen for a while before showing the "crashed" dialog

drom commented 5 years ago

https://flight-manual.atom.io/hacking-atom/sections/debugging/

pistoletpierre commented 5 years ago

I like the idea of having an exact grammar parser rather than some regex matching but for now I'm going to leave it alone in favor of some higher-priority items on my TODO list.

drom commented 5 years ago

Sure. Will try later.

drom commented 5 years ago

@pistoletpierre I have installed it on MacOS ; Atom v1.40.1 without a problem. Could you give it a try again?

pistoletpierre commented 5 years ago

Same problem I'm afraid. apm link -d && apm install && atom -d: I get the output pasted below. If I try the nvm+npm stuff it crashes the editor and shows a dialog like the screencap I put in this response: https://github.com/pistoletpierre/language-systemverilog/issues/4#issuecomment-515698005.

Atom: 1.40.1 x64 Electron: 3.1.10 OS: Mac OS X 10.14.6 Thrown From: language-systemverilog package 0.12.2

Stack Trace

Failed to load a language-systemverilog package grammar

At Cannot find module './build/Release/tree_sitter_verilog_binding' in ~/.atom/dev/packages/language-systemverilog/grammars/tree-sitter-systemverilog.cson

Error: Cannot find module './build/Release/tree_sitter_verilog_binding'
    at Module._resolveFilename (internal/modules/cjs/loader.js:602:15)
    at Module._resolveFilename (/Applications/Atom.app/Contents/Resources/electron.asar/common/reset-search-paths.js:35:12)
    at Function.Module._resolveFilename (/app.asar/src/module-cache.js:336:28)
    at Function.Module._load (internal/modules/cjs/loader.js:528:25)
    at Module.require (internal/modules/cjs/loader.js:658:17)
    at require (/app.asar/src/native-compile-cache.js:68:27)
    at Object.<anonymous> (~/Dropbox/Code/language_systemverilog_treesitter/language-systemverilog/node_modules/tree-sitter-verilog/index.js:2:20)
    at Object.<anonymous> (~/Dropbox/Code/language_systemverilog_treesitter/language-systemverilog/node_modules/tree-sitter-verilog/index.js:15:3)
    at Module._compile (/app.asar/src/native-compile-cache.js:121:30)
    at /app.asar/src/compile-cache.js:255:23)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:559:12)
    at Function.Module._load (internal/modules/cjs/loader.js:551:3)
    at Module.require (internal/modules/cjs/loader.js:658:17)
    at require (/app.asar/src/native-compile-cache.js:68:27)
    at /app.asar/src/tree-sitter-grammar.js:61:27)
    at GrammarRegistry.createGrammar (/app.asar/src/grammar-registry.js:604:14)
    at CSON.readFile (/app.asar/src/grammar-registry.js:583:29)
    at /app.asar/node_modules/season/lib/cson.js:219:59
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:440:3)
  at /packages/language-systemverilog/grammars/tree-sitter-systemverilog.cson:1:1