atom / symbols-view

Jump to symbols in Atom
MIT License
165 stars 115 forks source link

No Symbols Found using ES2015 const and => for functions #174

Closed dannyfritz closed 6 years ago

dannyfritz commented 8 years ago

I get No Symbols Found on this file.

atom_2016-04-28_07-53-24

dperetti commented 8 years ago

Also doesn't work (and should!) without the const, like :

_onChange = () => {
    ...
}
iolsen commented 7 years ago

So the reason for this behavior is the regular expressions we're feeding to ctags.

As a quick way to get this working slightly better, If you have a .ctags file in your home directory with additional expressions defined, Atom's call to ctags will pick them up. At least on Mac. I grabbed these and added them to my ~/.ctags file:

--regex-JavaScript=/[ \t.]([A-Z][A-Z0-9._$]+)[ \t]*[=:][ \t]*([0-9"'\[\{]|null)/\1/n,constant/

--regex-JavaScript=/\.([A-Za-z0-9._$]+)[ \t]*=[ \t]*\{/\1/o,object/
--regex-JavaScript=/['"]*([A-Za-z0-9_$]+)['"]*[ \t]*:[ \t]*\{/\1/o,object/
--regex-JavaScript=/([A-Za-z0-9._$]+)\[["']([A-Za-z0-9_$]+)["']\][ \t]*=[ \t]*\{/\1\.\2/o,object/

--regex-JavaScript=/([A-Za-z0-9._$]+)[ \t]*=[ \t]*\(function\(\)/\1/c,class/
--regex-JavaScript=/['"]*([A-Za-z0-9_$]+)['"]*:[ \t]*\(function\(\)/\1/c,class/
--regex-JavaScript=/class[ \t]+([A-Za-z0-9._$]+)[ \t]*/\1/c,class/
--regex-JavaScript=/([A-Za-z$][A-Za-z0-9_$()]+)[ \t]*=[ \t]*[Rr]eact.createClass[ \t]*\(/\1/c,class/
--regex-JavaScript=/([A-Z][A-Za-z0-9_$]+)[ \t]*=[ \t]*[A-Za-z0-9_$]*[ \t]*[{(]/\1/c,class/
--regex-JavaScript=/([A-Z][A-Za-z0-9_$]+)[ \t]*:[ \t]*[A-Za-z0-9_$]*[ \t]*[{(]/\1/c,class/

--regex-JavaScript=/([A-Za-z$][A-Za-z0-9_$]+)[ \t]*=[ \t]*function[ \t]*\(/\1/f,function/

--regex-JavaScript=/(function)*[ \t]*([A-Za-z$_][A-Za-z0-9_$]+)[ \t]*\([^)]*\)[ \t]*\{/\2/f,function/
--regex-JavaScript=/['"]*([A-Za-z$][A-Za-z0-9_$]+)['"]*:[ \t]*function[ \t]*\(/\1/m,method/
--regex-JavaScript=/([A-Za-z0-9_$]+)\[["']([A-Za-z0-9_$]+)["']\][ \t]*=[ \t]*function[ \t]*\(/\2/m,method/

This yields better behavior for some JS. It still doesn't handle your sample file correctly, but you'll get some symbols.

Parsing modern JS with regular expressions is hard. 😣

paulodiovani commented 6 years ago

This seems to be a duplicate of #160