microsoft / language-server-protocol

Defines a common protocol for language servers.
https://microsoft.github.io/language-server-protocol/
Creative Commons Attribution 4.0 International
11.25k stars 799 forks source link

Semantic regions #1192

Open floitsch opened 3 years ago

floitsch commented 3 years ago

Languages often have sections/regions that have different meaning. It would be great if the LSP server could inform the client about this regions, so they could handle them differently. Specifically, it is often a good idea to change the background of these regions to convey the information in a fast and easy way.

For example, in C++, the following regions have some meaning for the programmer:

rcjsuen commented 3 years ago

@floitsch How would clients render this information to the user? Do you have some example screenshots and/or mock-up designs?

rwols commented 3 years ago

Isn't this what textDocument/documentSymbols is for?

floitsch commented 3 years ago

I'm not good with graphics, but here is (more or less) what I would imagine. When I was using Microsoft Visual Studio a long time ago, I had this enabled for comments (as in my mockup), and it made reading the code much nicer.

Wrt documentSymbols: there is often an overlap. However, I would not have document-symbols for every semantic region.

A concrete example: a Doxygen comment would be a region, but would not be worthy of a document-symbol entry.

Similarly, you wouldn't use document-symbol entries for public and private in C++.

Finally, languages sometimes have embedded sections, like regular expressions. Take a Free-spacing regular expression that allows new lines and comments. You would want to mark the regular expression as reg-exp region, but still highlight the comments in it as "comment".

In some way I see regions as the semantic tokens for background.

image

rcjsuen commented 3 years ago

I'm not good with graphics, but here is (more or less) what I would imagine.

@floitsch Sorry, I haven't used Visual Studio before. Could you attach an original picture so it is easier to compare what you are adding in your mockup versus what the default editor looks like in Visual Studio?

floitsch commented 3 years ago

So the modified screen shot was from visual studio code (just the editor view). The difference is the background color for the comments and the private section.

current_c++