-
Notifications
You must be signed in to change notification settings - Fork 626
Add option to show symbols in symbol tree without root groups #3172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I wanted this feature for a long time and it turned out to be very easy to implement with the new way of getting symbol root names. This feature is also good for debugging ctags parsers because when sorted by line number, one can easily see at what line the parser stopped or started producing wrong output. The names "Categorized" and "Uncategorized" are the best I could come up with but I'm sure there is some better name for these so suggestions are welcome. |
I wonder why the single "Symbols" root row is needed? It seems superfluous and adds a level of indentation. The document tab with "Documents only" option avoids this and I think it's preferable. |
Neat. Categorised and Uncategorised seems fine to me, but (as I just showed :-) it needs to be translatable so British vs US spelling can be selected. Or "Category View" and "Single View". |
It's not needed but it greatly simplifies the implementation - the code constructing the tree is basically the same as before (only 1 extra line of code), there's just a single top-level category instead of several. So yeah, I agree it's unnecessary but the tree construction code is really complicated already and I don't want to make it worse by adding many more |
Yeah, it's translatable. I guess default is US, right? Haven't found any "colours" and "founts" in Geany strings ;-).
Or maybe "Flat View" instead of "Single View" (though it's not completely flat as tags with scopes are nested in their parents). But from these I probably prefer the "Categorized" names. |
Knowing the (semi-related) code for the documents list pretty good by now (courtesy of #1812) I don't think it's that bad. But if you truly don't have the desire to look into this now maybe that can be left to a future PR if it's itchy enough for that guy. |
That code is for babies really ;-). The symbol tree code spans from line 260 to line 1260 in symbols.c. It doesn't re-create the tree when something changes like the documents list - it really updates the tree by first removing invalid entries and then adding new entries, otherwise the tree would scroll all the time when you add or remove something that generates a tag. Multiple hash tables are involved in constructing it to detect the changes. If there's one piece of code to fear in Geany, it's the symbol tree code (followed by scope autocompletion). I already did some things in the past with the symbol tree to optimize it and developed quite a bit of respect to it - it works, it's very fragile because even small changes tend to break it, and better not to touch it much. In any case, anyone brave enough is encouraged to improve it :-). |
The code looks mostly good. My only concern is with the UI. In my view a checkbox |
Yeah, can do, either is fine with me. |
OK, I made the proposed change and I also like this single checkbox better. I was just thinking about the name a bit more and found |
I like it |
@elextr I just added a commit mentioning this feature in the documentation. Is it sufficient this way? |
@techee, docs are fine for current UI Just a comment, wanna bet somebody interprets "by type" as by int float string etc ;-) Technically it should be "by kind" but then beginners won't know what that means, so might as well leave it. |
Yeah, I was thinking the same - better not to leak ctags terminology to end users. Also, technically, it's not even kinds - several different kinds can be grouped into the same root in the tree by our mappings in |
I think type is good, but category might work too. |
While the current way of grouping symbols under various categories like "Functions", "Structures", "Macros" etc. may be useful in some situations, it doesn't allow true sorting by name or sorting by line number because this sorting is only valid within the group and not globally which makes it sometimes hard to find some symbol. This patch adds the option to switch between two views of the symbol tree by using a new checkbox called "Group by Type" to the context menu: - checked - the original view used by Geany - unchecked - view with a single root element "Symbols" in which all symbols are rooted and all of them either sorted by line number or alphabetically The core of the implementation is rather simple - there's always the "Symbols" root present at position 0 in tv_iters and when categorized view is selected, this root is used for all the tags. (We still need to keep the category roots in this situation to copy the icons for the tags from them but they are always empty and hidden). The rest is some UI stuff for creating entries in the context menu, I also added a config preference so this settings is remembered across Geany re-launches. I made this option global for all open files because I would find it annoying to apply this setting manually for every open file. So the code also checks whether the view type changed for the given file when switching tabs and re-creates the tree with the new setting.
I just squashed the patches and reworded the original commit message with the new "Group by Type" checkbox. Unless there are any objections, I'd merge this PR in about a week. |
While the current way of grouping symbols under various categories
like "Functions", "Structures", "Macros" etc. may be useful in some
situations, it doesn't allow true sorting by name or sorting by line
number because this sorting is only valid within the group and not
globally which makes it sometimes hard to find some symbol.
This patch adds the option to switch between two views of the symbol tree
using the context menu:
all symbols are rooted and all of them either sorted by line number
or alphabetically
The core of the implementation is rather simple - there's always the
"Symbols" root present at position 0 in tv_iters and when categorized
view is selected, this root is used for all the tags. (We still need
to keep the category roots in this situation to copy the icons for
the tags from them but they are always empty and hidden).
The rest is some UI stuff for creating entries in the context menu, I also
added a config preference so this settings is remembered across Geany
re-launches. I made this option global for all open files because
I would find it annoying to apply this setting manually for every open
file. So the code also checks whether the view type changed for the
given file when switching tabs and re-creates the tree with the new
setting.
Fixes #1082. (Together with the new Latex parser reporting scope.)