bmalehorn / vscode-fish

Fish syntax highlighting and formatting
MIT License
65 stars 7 forks source link

[Request] Symbol support #23

Closed RGFTheCoder closed 3 years ago

RGFTheCoder commented 3 years ago

I don't know how difficult this would be, but adding symbol support (for functions and maybe local variables) would be very useful.

This would directly enable two large things: Outline panel - Can help when you have many long functions in one file (especially if it doesn't make sense to separate them into separate files) Symbol renaming - Pressing F2 with the cursor over a function name or variable would let you easily rename all instances (at least locally), and could handle renaming foreign instances by introducing some sort of alias at the top of the file.

bmalehorn commented 3 years ago

Hi @RGFTheCoder, thanks for the interest in the extension. vscode-fish parses & highlights fish code with a bunch of regular expressions, which don't 100% capture how fish itself parses the file.

While in theory I could implement a full-blown parser in vscode-fish, what most language extension do is run the actual language compiler / interpreter to identify symbols. While I'd be interested in doing that, fish doesn't have a "build server" setting like higher-end languages. The closest thing would be fish_indent --dump-parse-tree, which is too basic to use for syntax highlighting or symbol support (explored in https://github.com/bmalehorn/vscode-fish/issues/13).

So overall, I'd like to have this feature too, but fish would have to add this syntax dump as a feature, and I don't think they're planning on doing that. Also it's pretty common for dynamic languages to lack this feature, both the python and ruby VSCode extensions don't have symbol support by default. Part of that reason is that the symbol support in dynamic languages would not be 100% accurate, as renaming foo in this code:

eval 'set -l foo 5'
echo $foo

would not rename inside the eval code.

Does that all make sense?

RGFTheCoder commented 3 years ago

True; I was just hoping for a very simple regex that matched /function ([a-zA-Z0-9]+)/ and any later occurances of the symbol, or maybe just /function ([a-zA-Z0-9]+)/ so it appeared in the outline, but I guess that would become very inconsistent and hard to replace/extend after a while

bmalehorn commented 3 years ago

Yeah, that would work in some cases but would have some false positives / negatives, and wouldn't work across files. I'd rather not have the symbol replace rather than have something inconsistent.