ctags
ctags copied to clipboard
Question about the expected behavior of JavaScript parser
I'm working hard to extend cork to support symbol tables.
foo.js (taken from angular.js):
function createChildScopeClass(parent) {
function ChildScope() {
this.$$watchers = this.$$nextSibling =
this.$$childHead = this.$$childTail = null;
this.$$listeners = {};
this.$$listenerCount = {};
this.$$watchersCount = 0;
this.$id = nextUid();
this.$$ChildScope = null;
}
ChildScope.prototype = parent;
return ChildScope;
}
Without using the symbol table code, ctags reports ChildScope two times:
[yamato@slave]~/var/ctags-github% u-ctags-no-symbol-table -o - /tmp/foo.js
ChildScope /tmp/foo.js /^ ChildScope.prototype = parent;$/;" c
ChildScope /tmp/foo.js /^ function ChildScope() {$/;" c function:createChildScopeClass
createChildScopeClass /tmp/foo.js /^function createChildScopeClass(parent) {$/;" f
With the symbol table code, ctags reports it only once:
[yamato@slave]~/var/ctags-github% u-ctags-with-symbol-table -o - /tmp/foo.js
ChildScope /tmp/foo.js /^ function ChildScope() {$/;" c function:createChildScopeClass
createChildScopeClass /tmp/foo.js /^function createChildScopeClass(parent) {$/;" f
How do you think about this difference?
I think the output of u-ctags-symbol-table is a bit better. However, the evaluation of the quality of tags output is very upto the design of parser especially about dynamically type language.
The symbol table is introduced in 19f653c46e0684cdef1e0c40638b4076bfd42b54. So we can implement the idea I proposed in this issue.
What needs to be done?
How do you think about this idea? Is "unifying the tags for ChildScope into one" a good idea?
Yes. I was toying with code to create tags for all fields in an object, by looking for this., and it would also only work if we filtered out duplicates.
I see. Yes, please, go ahead.
What do I need to do to build u-ctags-with-symbol-table?
The symbol table is already introduced to the JavaScript parser.
In the names of function level, symbol-table means registerEntry and anyKindsEntryInScope.
If you register a tag entry filling its scopeIndex member, you can find the tag entry in the scope specifying the scopeIndex LATER.
registerEntry() is for registering. anyKindsEntryInScope() is one of the function you can use for finding. More functions can be found in ... entry.h: foreachEntriesInScope and any*.
Both ChildScope are defined in createChildScopeClass. So register the first ChildScope after filling its scopeIndex with the cork index of createChildScopeClass.
When finding the second one, look up the table with anyEntryInScope or something. The any* may return the first one. So you can avoid tagging the second one.
If you find interesting information in the second one, you can attach the information to the first one.
Got it. Thanks!