Skip to content
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

Add SemanticHighlight Endpoint #1734

Merged
merged 3 commits into from
Mar 16, 2020
Merged

Conversation

JoeRobich
Copy link
Member

@JoeRobich JoeRobich commented Mar 15, 2020

Implementation of a semantic highlight endpoint. The data that will eventually be returned is different enough from the Highlight endpoint that I thought a new one was justified. This is a simple implementation that supports classification and the static modifier.

As requested in dotnet/vscode-csharp#3565

@dnfclas
Copy link

dnfclas commented Mar 15, 2020

CLA assistant check
All CLA requirements met.

@@ -0,0 +1,6 @@
namespace OmniSharp.Models.SemanticHighlight
{
public enum SemanticHighlightModifier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't seem to be used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although the work isn't planned, we can expect that Rolsyn will introduce a classification API which provides this additional information about classified spans. I wanted the API to reflect it so that consumers could expect it being returned. I could probably process the classifications and return a static modifier...

@filipw
Copy link
Member

filipw commented Mar 15, 2020

looks good, thanks for adding this 👍
I just left some small comments

Copy link
Member

@filipw filipw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, thanks

@JoeRobich JoeRobich force-pushed the semantic-highlight branch from c379074 to 0e1feff Compare March 15, 2020 20:11
@NTaylorMullen
Copy link
Contributor

@ryanbrandenburg since you own our semantic classification you should take a look at this as well. It will also enable us to call through to Roslyn for semantic colorization as well 😄

namespace OmniSharp.Roslyn.CSharp.Services.SemanticHighlight
{
[OmniSharpHandler(OmniSharpEndpoints.V2.Highlight, LanguageNames.CSharp)]
public class SemanticHighlightService : IRequestHandler<SemanticHighlightRequest, SemanticHighlightResponse>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify, this current impl doesn't take advantage of the partial semantic classification tech that's available right?

Oh and "partial" in the sense of only updating a single lines classification if only that line changed.

I ask because for C# files this might be a huge performance hit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The highlight request has an optional range property so that only that TextSpan is classified.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought VSCode re-requested the entire document pretty frequently though to account for external file changes, project changes etc. Maybe I'm wrong though, my information is coming from design discussions during the features creation; not out of personal trial and error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, perhaps you are referring to the provideDocumentSemanticTokensEdits api

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup exactly!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking about that API for a bit, I'm not sure the Edits api is super useful. It seems mostly to benefit requesting changes from a remote LSP where bandwidth is a concern. It also requires the LSP to hold on to previous state in order to generate the Edits diff as well as fully classify the new state of the document.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure how the client interprets all of the data in a response but I imagine it'd also optimize the clients processing of the data

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I feel like that api would basically be faked by the editor assuming they have a good method of generating the diffs from two sets of SyntaxTokens. Since they already have the before state which the LSP really shouldn't be expected to hold on to.

@filipw filipw merged commit 2ce941d into OmniSharp:master Mar 16, 2020
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.

4 participants