mike-lischke / antlr4-c3

A grammar agnostic code completion engine for ANTLR4 based parsers
MIT License
397 stars 62 forks source link

Unable to use Antlr4-c3 with angular #34

Closed goyaltushar92 closed 4 years ago

goyaltushar92 commented 4 years ago

In 1 of my projects our team was previously using antlr4-c3 with angular 6 but, after version update it doesn't seems to work. it says ERROR in ./node_modules/antlr4ts/misc/InterpreterDataReader.js Module not found: Error: Can't resolve 'fs'. i don't think it is problem with antlr4ts, as in our POC project we were able to use antlr4ts without any issue. Please also suggest, if we can have a work arround, or we need to use older version of library.

mike-lischke commented 4 years ago

That's a pretty odd problem. "fs" is a standard Node.js module, how can it fail to load?

goyaltushar92 commented 4 years ago

fs is not available for browsers... it is file system specific library as file system is not available on browser, so, this library too isn't available. I readed some where InterpreterDataReader.js is used for tests. is it realy needed to be loaded...

mike-lischke commented 4 years ago

Now I understand. Well, this is a tricky situation. The interpreter data reader is used to load interpreter data (which is not used by the c3 engine, but is part of the ANTLR4 Java runtime (and C++ and TS...)). However, TS and JS runtimes are a bit special, as you can use them in a browser environment and that's the tricky part: how to avoid importing the data read in such a case?

However, that is not a problem of antlr4-c3 but of antlr4ts. Can you open a new issue there?

goyaltushar92 commented 4 years ago

I checked your code, I found 1 possible issue, in CodeCompletionCore.ts we have import { IntervalSet } from 'antlr4ts/misc'; i also checked antr4ts repo 'antlr4ts/misc' loads InterpreterDataReader too. so, replacing import { IntervalSet } from 'antlr4ts/misc'; with import { IntervalSet } from 'antlr4ts/misc/IntervalSet'; should work.

goyaltushar92 commented 4 years ago

i have created a pull request for the same

mike-lischke commented 4 years ago

Interesting solution. Does it resolve the fs issue now?

goyaltushar92 commented 4 years ago

Yes, that fixed my issue... I think you can push a release