oleg-shilo / codemap.vscode

Code map (syntax tree) of the active document
MIT License
84 stars 28 forks source link

Feature proposal - Document Symbol #31

Closed AlencarGabriel closed 4 years ago

AlencarGabriel commented 4 years ago

Hello Oleg, working here I had an interesting idea.

I'd like to know if you accept my proposal for implementation in the extension.

CodeMap replaces VsCode's Outline very well, especially for extensions that don't implement Language Server.

My proposal would be to take advantage of this extension to also implement the Find Symbol feature (Ctrl + R), since users already define the syntax of their languages. So there would be no need to change anything today, just add the functionality.

What do you think?

oleg-shilo commented 4 years ago

I think it's an excellent idea. And it is actually quite easy to implement as (you are right) the MAP is already there :)

I am finishing the work for cs-script extension hopefully next week so will jump on this one right after that.

There are some challenges: how to handle multiple matches. But nothing that cannot be solved.

AlencarGabriel commented 4 years ago

@oleg-shilo , analyzing Vscode's Document Symbol API, I realized that if you implement the symbols using her register, the symbols will also be displayed in the Outline view.

Were you thinking of using the standard symbol API, or creating a custom Find Symbol?

oleg-shilo commented 4 years ago

I am actually aiming for CodeMap mapping based navigation. vscode.FindSymbol is already available and does not need any infrastructure provided by any extension(s).

And it is also acting as a navigation UX across the workspace whereas CodeMap is all about opened document.

Also vscode.FindSymbol restricts the user to the languages supported by the VSCode syntax providers, and there are not that many who does it in full.

CodeMap from the other hand offers simplified code DOM pasring ifrastructure that can be fitted with any custom algorithm provided for users. Thus even more exotic languages are supported (e.g. Erlang, Lua). Thus I think sticking to CodeMap parsers offers more opportunities for the user.

AlencarGabriel commented 4 years ago

I fully agree with you that CodeMap offers more opportunity for the user. This is the reason why I am using and recommending its extension, as I work with a language that does not yet provide a Language Server (https://gabrielalencar.dev/2019/12/01/Outline-Advpl-VsCode/).

Perhaps my last interaction was not clear (possibly due to the translation, I'm Brazilian).

My question was for the vscode.DocumentSymbol class (https://microsoft.github.io/language-server-protocol/specification#textDocument_documentSymbol). I already started an implementation of it in the past and I remember that in addition to the FindSymbol it also adds the symbols in the Outline View (which I think would hinder).

When I opened this issue, the intention was to use the native FindSymbol (ctrl + R) of VsCode, but today I think that this might not be the best option, but a customized "FindSymbol".

oleg-shilo commented 4 years ago

OK, makes sense. I will try to find some time next week for it. Txs

oleg-shilo commented 4 years ago

Done in v1.12.0

image

AlencarGabriel commented 4 years ago

Wow, I really liked the implementation. Met expectations very well! 👏

I just have a suggestion for improvement: show the icons like Code Map View:

CodeMap

oleg-shilo commented 4 years ago

Can you elaborate? What icons do you mean? All tree view items already have icons: image

AlencarGabriel commented 4 years ago

I mean showing the icons in the "Quick Pick (Alt + P)" as it is displayed in the tree view.

oleg-shilo commented 4 years ago

Ah, no, cannot be done.

The feature is implemented with vscode.window.showQuickPick(...), which offers an absolute zero support for styling or any other customization (except selection model).

AlencarGabriel commented 4 years ago

Nor using the $(<icon-name>) syntax?

https://github.com/microsoft/vscode-codicons https://github.com/microsoft/vscode-icons

oleg-shilo commented 4 years ago

Excellent. Didn't know about this trick. It works. Thank you. Not sure if custom icons can be used this way too but will try.

oleg-shilo commented 4 years ago

Done.

image

Unfortunately this trick does not work with custom icons but since VSCode has all required icons embedded that was not a show stopper anyway.

AlencarGabriel commented 4 years ago

Wonderful 👏 . I suggested it this way exactly because the icons of the extension are the same as native to VsCode.

oleg-shilo commented 4 years ago

Yep. Exactly. Interestingly enough this trick $(icon_name) is not universal. Thus it does not in TreeView node text.

AlencarGabriel commented 4 years ago

hummm, good to know that. I really only used it so far on the StatusBar.

I like the community because of these exchanges of experiences.

Really the documentation says that only in a few points it is possible to contribute to this trick: https://code.visualstudio.com/api/references/icons-in-labels#icons-in-labels

oleg-shilo commented 4 years ago

Yep.

in hovers, in the StatusBarItem text and QuickPickItem label API

And in this case it is QuickPickItem. As well as in your case of StatusBarItem. The only one extra case left - "on hover" :o)

AlencarGabriel commented 4 years ago

thanks for the improvement! I tested it and it worked correctly :clap:.