Closed mlb- closed 11 years ago
tags files are a compromise form of code navigation that is not really suitable for languages like JS: (a) they're created offline, (b) they are very imprecise (which tags are relevant at a given code point).
estr includes a tags file generator for JS, combined with an extended tags file format (added variable scope information) and a scoped tags Vim plugin that uses the scope information. Adding tern's type information would help to put more information into the tags file format (again, using the extended form), but then one would again need a plugin (instead of the built-in tags navigation) to make full use of that information.
Using tern's server directly from a Vim plugin, such as tern's own, will make better use of tern's more precise information, and will support online use (update jump tables as you edit the code). You can see the jump-to-definition feature in tern's online demo, it is just not enabled yet in tern's Vim plugin.
Something alltogether different is tagbar's code outline functionality - this is currently based on tags files, to be (mostly) language independent. Again, such feature could be supported directly based on tern queries (what modules/classes/functions are in each file).
@clausreinke I think I see what you're saying. Do you think it would be more appropriate for me to close this issue and open one for tagbar to support estr or tern?
Another alternative is for me to attempt to solve this on my own (which would result in PRs for both this and the tagbar project). However, both projects are lacking in documentation for contributors.
you can create the JSON file for each seperate project to parse as tagbar
@mlb- I use jsctags to generate tag files for JS to outline methods in a class and it works fine. This works with every tag plugin like tagbar or taglist-plus. For lazy updating of tag files you can use taginator.
I think this would be a worthwhile addition, though I'm not going to work on it myself (no time, no experience with ctags). People used to ctags will be happy to be able to generate accurate ctags. jsctags and jsctagsmm were inspirations for Tern. My impression (though not quantitatively verified) is that Tern's inference is currently superior to jsctags'.
@mlb - I haven't decided yet what to do about the estr/tern split in general - have been waiting for a type annotated AST to use for refactorings ( @marijnh : would tern work over esprima as well, or is it tied to acorn?), but from what I've seen for my TypeScript Vim plugin, I expect tags for JS to be legacy technology once we have a working jump-to-def in Vim. I'd rather focus on other aspects of JS support in Vim.
@samdraz - are there docs for tagbar JSON format? I thought it was tags file based.
@hoshi - the doctorjs network graph is a mess (the main repo's core functionality has been broken mozilla/doctorjs#5 for many years, patches to make it run on windows weren't accepted, the project is looking for a maintainer, so there are various forks with an old/unbroken inference engine and new node support, just to get something working on some platforms, but with dimvar gone, no one touches the inference code).
@clausreinke oh :( I installed it on my linux machines some time ago and it just worked fine, so I didn't know it is broken.
Is it possible to include the line number
in the /bin/condense
output?
With that it could be possible to parse that into sort of ctags.
EDIT: Although it misses the scope
property mozilla/doctorjs#5, here it is a comparison between tern/condense and jsctags: https://gist.github.com/ramitos/46962b581b907cd62421
Yes, this is planned (see #27), I just haven't gotten around to it yet.
Please note there are vim plugins that update tags in the background and handle auto completion pretty well, perhaps tern can integrate with them in some sort? Using ctags
files could be the easiest option IMO.
Still, seeing how there exists a vim plugin that is optimized for the live updating of context information through a Tern server, I'm not sure whether taking the roundabout way through ctags files (and losing a lot of information in the process) is a very useful thing.
Vim has native ctags support. If there was just some simple tool to convert tern's output to ctags format, it could be really simple to do what we ask for.
On 27 במאי 2013, at 15:49, Marijn Haverbeke notifications@github.com wrote:
Still, seeing how there exists a vim plugin that is optimized for the live updating of context information through a Tern server, I'm not sure whether taking the roundabout way through ctags files (and losing a lot of information in the process) is a very useful thing.
— Reply to this email directly or view it on GitHub.
Tern only knows about methods when I open the file containing the definition. This way I can't jump from one file to another with the "find definition" feature. Is that right or didn't I find the right way to do this?
At the moment I need ctags for this use case. On every file change or git jump command I regenerate the tags for the entire project so I can jump between files. Omni completion are then comes from tern.
In your .tern-project
file, set loadEagerly
to the files you want to be loaded automatically. See http://ternjs.net/doc/manual.html#configuration
Is it possible to to set a folder for loadEagerly instead of specifying each and every file?
Sadly, I'm not always writing code, but having to delve into others' contributions for maintenance/bugfixes. I can appreciate that tern provides an intelligent, IDE-like jump-to-definition, but that is insufficient when attempting to navigate/explore a codebase. Jumping about from definition to definition might work in the small, but it's often helpful to have an abstract, higher-view of things.
tl;dr: It's much more convenient knowing which classes/objects have what methods/variables at a glance vs. having to jump about.
Tern's condense
cli now outputs the span of each tag. So it's possible now to parse that into ctags.
I've compiled all test cases of tern with the condense
output and the jsctags (with namespaces) output: http://cl.ly/Picv
Edit: I started playing with the idea, but I'm not sure I will be able to have a finished parser (ramitos/jsctags)
@ramitos Looking at the ctags code in doctorjs, I noticed you were also involved in that. Probably you know more about ctags than I ever will, so my current plan is to wait and see what you come up with.
@marijnh I wasn't really involved, just did a PR with some fixes the way they were using require
(that worked in node < 0.4)
I have working prototype that, although not finished, is close enough to jsctags output. It's not perfect, but close enough. Now with span in all properties, I will be able to finish it :)
@bjarneheden
Is it possible to to set a folder for loadEagerly instead of specifying each and every file?
I had a FIXME in the code to allow glob patterns there. Patch 6e44bf0673cf10818ea5c26d5f74a72c2297370a finally implements this (you can say lib/*.js
, for example, or even lib/**/*.js
)
I would happily use some people to try if this fits their needs, to find bugs and/or edge cases: https://github.com/ramitos/jsctags
cc/ @majutsushi
Very nice! I've added a 'related software' section to the manual and linked to this. Closing this bug for now -- further discussion can go on on the jsctags bug tracker.
It would be lovely if ctags output would be available. This would definitely make vim users happier, especially those using tagbar.