-
Notifications
You must be signed in to change notification settings - Fork 196
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 option for element completion commit characters #9379
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
58a5491
Add new option to control the behaviour
davidwengier a0a2f8f
fixup
davidwengier d7444d3
Wire up new option to completion options
davidwengier d6cdda9
Stop using space as a commit character for tag helpers
davidwengier 2d872a3
String space from commit characters from delegated servers
davidwengier 5506fdc
Cleanup
davidwengier 1c5c46e
Just options monitor directly since it's already here
davidwengier 6f5b2af
Tag helper completion provider tests
davidwengier e8c2f6c
Tests for HtmlCommitCharacterResponseRewriter
davidwengier 9daddbd
Remove unused parameter
davidwengier 2df13ff
Remove unused parameter
davidwengier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
...NetCore.Razor.LanguageServer/Completion/Delegation/HtmlCommitCharacterResponseRewriter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Razor.LanguageServer.Protocol; | ||
using Microsoft.VisualStudio.LanguageServer.Protocol; | ||
|
||
namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion.Delegation; | ||
|
||
internal class HtmlCommitCharacterResponseRewriter(RazorLSPOptionsMonitor razorLSPOptionsMonitor) : DelegatedCompletionResponseRewriter | ||
{ | ||
private readonly RazorLSPOptionsMonitor _razorLSPOptionsMonitor = razorLSPOptionsMonitor; | ||
|
||
public override int Order => ExecutionBehaviorOrder.ChangesCompletionItems; | ||
|
||
public override Task<VSInternalCompletionList> RewriteAsync(VSInternalCompletionList completionList, int hostDocumentIndex, DocumentContext hostDocumentContext, DelegatedCompletionParams delegatedParameters, CancellationToken cancellationToken) | ||
{ | ||
if (delegatedParameters.ProjectedKind != RazorLanguageKind.Html) | ||
{ | ||
return Task.FromResult(completionList); | ||
} | ||
|
||
if (_razorLSPOptionsMonitor.CurrentValue.CommitElementsWithSpace) | ||
{ | ||
return Task.FromResult(completionList); | ||
} | ||
|
||
string[]? itemCommitChars = null; | ||
if (completionList.CommitCharacters is { } commitCharacters) | ||
{ | ||
if (commitCharacters.TryGetFirst(out var commitChars)) | ||
{ | ||
itemCommitChars = commitChars.Where(s => s != " ").ToArray(); | ||
|
||
// If the default commit characters didn't include " " already, then we set our list to null to avoid over-specifying commit characters | ||
if (itemCommitChars.Length == commitChars.Length) | ||
{ | ||
itemCommitChars = null; | ||
} | ||
} | ||
else if (commitCharacters.TryGetSecond(out var vsCommitChars)) | ||
{ | ||
itemCommitChars = vsCommitChars.Where(s => s.Character != " ").Select(s => s.Character).ToArray(); | ||
|
||
// If the default commit characters didn't include " " already, then we set our list to null to avoid over-specifying commit characters | ||
if (itemCommitChars.Length == vsCommitChars.Length) | ||
{ | ||
itemCommitChars = null; | ||
} | ||
} | ||
} | ||
|
||
foreach (var item in completionList.Items) | ||
{ | ||
if (item.Kind == CompletionItemKind.Element) | ||
{ | ||
if (item.CommitCharacters is null) | ||
{ | ||
if (itemCommitChars is not null) | ||
{ | ||
// This item wants to use the default commit characters, so change it to our updated version of them, without the space | ||
item.CommitCharacters = itemCommitChars; | ||
} | ||
} | ||
else | ||
{ | ||
// This item has its own commit characters, so just remove spaces | ||
item.CommitCharacters = item.CommitCharacters?.Where(s => s != " ").ToArray(); | ||
} | ||
} | ||
} | ||
|
||
return Task.FromResult(completionList); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/Razor/src/Microsoft.VisualStudio.RazorExtension/xlf/VSPackage.cs.xlf
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If 'itemCommitChars' is null can we just early return and do nothing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because each item could specify its own commit characters, so we still have to go through them all and update that. If
itemCommitChars
is null it just means the server didn't specify a default set.