ternjs / tern_for_sublime

Sublime Text package adding Tern support
MIT License
803 stars 54 forks source link

Gives error when started typing #41

Closed pstjvn closed 10 years ago

pstjvn commented 10 years ago

I have used the instructions on the readme. npm install passed without errors.

When I try to type in a js file the following pop-up appears:

error: <urlopen error timed out>

No further indications are provided, then again when I start typing this happens again and again.

The following config is used (via .tern-project in the main folder of the project):

{
  "loadEagerly": [
    "/home/peterj/Documents/Projects/closure/library/closure/goog/*/*.js",
    "/home/peterj/Documents/Projects/closure/library/closure/goog/base.js"
  ],
  "dontLoad": [
    "/home/peterj/Documents/Projects/closure/library/closure/goog/*/*_test.js"
  ]
}

No further configuration is used.

De-facto this prevent me from using it at all.

System is Linux with working npm and node.

marijnh commented 10 years ago

Approximately how many LOC will the /*/*.js match? If it's a huge amount, say more than 50k, that might be the problem.

pstjvn commented 10 years ago

419943 LOC to be exact and this is only the base library, I have custom elements for touch devices (~10k) and custom media players for devices (~20k LOC) and this is before the project is even started...

Why is this a problem? I intended to use tern as intellisense for sublime. Alternatively I would have to write plugin that can understand closure library mechanism to require files, then load those and analyze them, but this is basically what all other tools are doing when compiling, those run on Java and it is kind of heavy on the system... I was hoping this could be the 'quick and dirty' way to actually helpful intellisense...

Any way to increase the capacity so it can handle this use case?

marijnh commented 10 years ago

Why is this a problem?

Because Tern builds up a data structure that maps the way types travel between all variables and properties in the system, and this data structure is going to be huge for 400k of code.

The node and requirejs plugins have a relatively workable solution to this problem—they will give each dependency a budget, and only load files for it (in a breadth-first way) until the budget is exhausted. That way, the chances of figuring out the types of the library is decent, but the analyzer won't go down a rabbit hole, pulling in the whole dependency tree. It is probably possible to write a similar plugin for closure, but I have zero experience with closure, so I can't say much about that.

pstjvn commented 10 years ago

Thank you.

One last question to clarify if it is feasible to even start looking into this: with requirejs-like type of plugin is it possible to direct the tern module to keep in memory only the relevant bits (i.e. each file has its own includes and upon switching from file to file in sublime force tern to load only the file and the ones included in it, thus dumping structures from other files and freeing memory). Closure works very similar to requirejs: at the top of the file you 'require' namespaces which can very easily be resolved to filenames from a dependency json structure, in the same json structure are listed all dependencies for that namespace so basically it is very easy to build a list of all dependencies for a given namespace from a single file, i.e. no need to read the file content to know which file requires what, it suffice to load the dependency file only and lookup the namespace(s) there.

What do you think?

marijnh commented 10 years ago

is it possible to direct the tern module to keep in memory only the relevant bits

No. Tern keeps a model for a whole project in memory, and keeps using that as you switch between files (loading in new files as needed). Still, I doubt you'll ever be working on more than a dozen kloc at a time (unless your files are gigantic).

pstjvn commented 10 years ago

The problem is indeed that: previous projects in unminimized format tend to be over 4MB and encompass more than 400 files. In closure your project is one namespace that pulls up everything inside one big program and has a 'main' function that starts it all, so if you open to edit the file with the 'main' function you end up requiring the whole program with every file ever needed. Google does that so they can run application wide optimizations and diagnostics....

I see it would not be possible to do what I intended, but thanks for your help.