Skip to content

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

Merged
merged 1 commit into from
Sep 21, 2022

Conversation

techee
Copy link
Member

@techee techee commented Apr 17, 2022

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:

  • Categorized - the original view used by Geany
  • Uncategorized - view with a single root element "Symbols" in which
    all symbols are rooted and all of them either sorted by line number
    or alphabetically

Screen Shot 2022-04-17 at 16 17 38

Screen Shot 2022-04-17 at 16 18 33

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.)

@techee
Copy link
Member Author

techee commented Apr 17, 2022

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.

@techee techee removed the filetype label Apr 17, 2022
@kugel-
Copy link
Member

kugel- commented Apr 17, 2022

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.

@elextr
Copy link
Member

elextr commented Apr 17, 2022

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".

@techee
Copy link
Member Author

techee commented Apr 18, 2022

I wonder why the single "Symbols" root row is needed? It seems superfluous and adds a level of indentation.

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 if (categorized) do_stuff; else do_stuff2;

@techee
Copy link
Member Author

techee commented Apr 18, 2022

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.

Yeah, it's translatable. I guess default is US, right? Haven't found any "colours" and "founts" in Geany strings ;-).

Or "Category View" and "Single View".

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.

@kugel-
Copy link
Member

kugel- commented Apr 18, 2022

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 if (categorized) do_stuff; else do_stuff2;

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.

@techee
Copy link
Member Author

techee commented Apr 18, 2022

Knowing the (semi-related) code for the documents list pretty good by now (courtesy of #1812) I don't think it's that bad

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 :-).

@kugel-
Copy link
Member

kugel- commented Jul 11, 2022

The code looks mostly good. My only concern is with the UI. In my view a checkbox [ ] Show categories (or maybe categories -> groups) is preferable and saves a line in the menu. What do you think?

@techee
Copy link
Member Author

techee commented Aug 27, 2022

Yeah, can do, either is fine with me.

@techee
Copy link
Member Author

techee commented Aug 28, 2022

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 [ ] Group by Type more fitting so I used it. What do you think?

@kugel-
Copy link
Member

kugel- commented Aug 28, 2022

I like it

@techee
Copy link
Member Author

techee commented Aug 28, 2022

@elextr I just added a commit mentioning this feature in the documentation. Is it sufficient this way?

@elextr
Copy link
Member

elextr commented Aug 29, 2022

@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.

@techee
Copy link
Member Author

techee commented Aug 29, 2022

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 tm_parser.c.

@kugel-
Copy link
Member

kugel- commented Aug 29, 2022

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.
@techee
Copy link
Member Author

techee commented Sep 13, 2022

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.

@techee techee merged commit 0bc92b0 into geany:master Sep 21, 2022
@b4n b4n added this to the 1.39/2.0 milestone Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Symbols list with symbols grouped by scope
4 participants