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

Adding cohost completion handler #11048

Open
wants to merge 41 commits into
base: main
Choose a base branch
from

Conversation

alexgav
Copy link
Contributor

@alexgav alexgav commented Oct 20, 2024

Summary of the changes

  • Moving most of the completion code to the common (Workspaces) layer
  • Adding cohost handler for completion

I tried making each commit small and serving a single purpose, so looking commit-by-commit could be helpful, though returned data in each individual commit is not going to be correct, especially in the first few commits. A lot of merging, filtering and ordering was added in the last few commits to ensure correct final completion list is returned.

One unfortunate thing here is conversion between VS and Roslyn LSP types that we have to do until we move to Roslyn LSP types everywhere in our code. Completion code uses LSP types throughout most of the common code much more so than other requests, and while we need common code for non-cohost LSP endpoint, most of it has to use VS LSP types for now.

Fixes: #10697

Switch passed in and returned types from Roslyn to VS Platform LSP types since that's what all of the common completion code in the Workspaces layer uses. We will need to convert returned Roslyn completion items to VS platform LSP completion items.
…e workspaces layer (to be used in cohosting later)
…g HTML completion item labels to RazorCompletionListProvider
… layer and use it in cohost completion request
Also simplifying parameters passed to the response re-writers to only what's needed.
…hooked up and we are getting VSInternalCompletionContext in CompletionParams
…ng them

They all already checked (or should've checked) for language and were operating on either C# or HTML, never on both. HTML re-writer will get called from the client and can be much simpler. In cohosting it doesn't make sense to have them all in one list since C# will get called in OOP and HTML on the client (in VS).
Renamed some fields and variables dealing with "add snippets" options and added comments. We currently have two options that mean "add snippets" - one for the delegated completion, and one for Razor completion. The values of those don't correlate. The Razor one is always true in LSP and Cohost, always false for legacy editor. The delegation one actually depends on the position.
Also adding a snippet completion provider test and markup transition test
…ces test projects

The tests were left behind (some in this PR, some in prior PRs) when the code was moved to Workspaces layer. This commit addresses most of them other than in Delegation subworkspace
We had inconsistent handling of null completion item labels between our response re-writers. Some handled null labels, others would through. Since label shouldn't be null (non-nullable), I adjusted the tests not to use null labels.

Also the tests previously passed because they created DelegatedCompletionListProvider with only a selected DelegatedResponseRewriter. Now the DelegatedCompletionHelper will apply all response re-writers for the correct language (either C# or HTML), which is what the product actually does, so I feel that's fine. It exposed these test failures due to inconsistent null label handling
Switching AllTriggerCharacters to string[] since we only use it for registration/capability data, which needs string[]. and we never do look ups via Contains. Also removing rendundant property and calculations in CompletionListProvider
@alexgav alexgav requested review from a team as code owners October 20, 2024 06:53
Copy link
Contributor

@davidwengier davidwengier left a comment

Choose a reason for hiding this comment

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

Love the thoroughness of the tests! Nice work

@@ -10,12 +10,12 @@

<ItemGroup>
<None Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
<Compile Include="..\OSSkipConditionFactAttribute.cs" LinkBase="Shared" />
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems related to the build failure. I'm guessing it was removed because of the new project reference? Perhaps instead of referencing a test project from another, whatever is needed from it could be move to the common project?

TriggerKind = RoslynCompletionTriggerKind.TriggerCharacter
},
expectedItemLabels: ["char", "DateTime", "Exception"],
expectedItemCount: 996);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is validating the count valuable? Seems pretty fragile.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I mentioned in one of the comments, Roslyn doesn't seem to always return all items initially (possibly related to our async code generation or something like that?). Waiting for expected number of items ensures we are waiting for everything to be ready (not sure if there is a better event to wait for?). I agree it may end up being fragile. If it is, we could switch from checking for exact match to checking that returned count is greater than the baseline number. I'd like to leave it as is for now and see if it causes issues, in which case we can modify the check.

TriggerCharacter = "@",
TriggerKind = RoslynCompletionTriggerKind.TriggerCharacter
},
expectedItemLabels: ["using", "using directive ...", "page", "page directive ..."],
Copy link
Contributor

@davidwengier davidwengier Oct 20, 2024

Choose a reason for hiding this comment

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

Should this include a couple of C# completion items too, just to prevent regressions?

Copy link
Contributor

Choose a reason for hiding this comment

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

A shower thought: Slightly at odds perhaps with other comments in this file, but I think given that we own the directive completions, it would not be a bad thing if this test included all of the results we expect our directive completion to produce. Would be good for preventing regression, and identifying FUSE issues in future when we switch over to it formally.

public async Task CSharpClassesAtTransition()
{
await VerifyCompletionListAsync(
input: $"""
Copy link
Contributor

Choose a reason for hiding this comment

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

All of the raw strings in this file are interpolated, none of the raw strings in this file contain any interpolation 😁

Context = completionContext
};

// Roslyn doesn't always return all items right away, so using retry logic
Copy link
Contributor

Choose a reason for hiding this comment

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

This is very surprising. Is this copied from the existing tests, or is this something you are seeing in these tests specifically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did see it in these tests specifically. E.g. at the "@" I initially got something like 556 items, but later 1000 items (max items returned by Roslyn). Adding re-try made tests run reliably. I am not sure why.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like that could be an issue with our test code, but not sure. Were the items we were expecting not present when it return 556? Seems like a fair number of completion items

@davidwengier davidwengier removed the request for review from a team October 20, 2024 11:23
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.

Port Completion endpoints to cohosting
2 participants