Skip to content

Commit 1dbebdd

Browse files
Don't expose HtmlTriggerCharacters set
Rather than directly exposing a set, this change adds instance methods to test for valid HTML triggers.
1 parent cb31a56 commit 1dbebdd

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/CompletionTriggerAndCommitCharacters.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ internal class CompletionTriggerAndCommitCharacters(LanguageServerFeatureOptions
2525
private static readonly FrozenSet<string> s_razorTriggerCharacters = new[] { RazorDelegationTriggerCharacter, "<", ":", " " }.ToFrozenSet();
2626
private static readonly FrozenSet<string> s_razorDelegationTriggerCharacters = new[] { RazorDelegationTriggerCharacter }.ToFrozenSet();
2727
private static readonly FrozenSet<string> s_csharpTriggerCharacters = new[] { " ", "(", "=", "#", ".", "<", "[", "{", "\"", "/", ":", "~" }.ToFrozenSet();
28-
public FrozenSet<string> HtmlTriggerCharacters =>
28+
29+
private FrozenSet<string> HtmlTriggerCharacters =>
2930
_languageServerFeatureOptions.UseVsCodeCompletionTriggerCharacters ? s_vsCodeHtmlTriggerCharacters : s_vsHtmlTriggerCharacters;
3031

3132
private FrozenSet<string> AllDelegationTriggerCharacters => _allDelegationTriggerCharacters
@@ -52,6 +53,9 @@ public bool IsValidCSharpTrigger(CompletionContext completionContext)
5253
public bool IsValidDelegationTrigger(CompletionContext completionContext)
5354
=> IsValidTrigger(AllDelegationTriggerCharacters, completionContext);
5455

56+
public bool IsValidHtmlTrigger(CompletionContext completionContext)
57+
=> IsValidTrigger(HtmlTriggerCharacters, completionContext);
58+
5559
public bool IsValidRazorTrigger(CompletionContext completionContext)
5660
=> IsValidTrigger(s_razorTriggerCharacters, completionContext);
5761

@@ -61,6 +65,9 @@ public bool IsCSharpTriggerCharacter(string ch)
6165
public bool IsDelegationTriggerCharacter(string ch)
6266
=> AllDelegationTriggerCharacters.Contains(ch);
6367

68+
public bool IsHtmlTriggerCharacter(string ch)
69+
=> HtmlTriggerCharacters.Contains(ch);
70+
6471
public bool IsRazorTriggerCharacter(string ch)
6572
=> s_razorTriggerCharacters.Contains(ch);
6673

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/Delegation/DelegatedCompletionHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ internal static class DelegatedCompletionHelper
6969
// For HTML we don't want to delegate to HTML language server is completion is due to a trigger characters that is not
7070
// HTML trigger character. Doing so causes bad side effects in VSCode HTML client as we will end up with non-matching
7171
// completion entries
72-
return triggerAndCommitCharacters.HtmlTriggerCharacters.Contains(triggerCharacter) ? context : null;
72+
return triggerAndCommitCharacters.IsHtmlTriggerCharacter(triggerCharacter) ? context : null;
7373
}
7474

7575
// Trigger character not associated with the current language. Transform the context into an invoked context.

src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/LanguageClient/Cohost/CohostDocumentCompletionEndpoint.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,15 @@ public ImmutableArray<Registration> GetRegistrations(VSInternalClientCapabilitie
137137
CommitElementsWithSpace: clientSettings.AdvancedSettings.CommitElementsWithSpace);
138138
using var _ = HashSetPool<string>.GetPooledObject(out var existingHtmlCompletions);
139139

140-
if (CompletionTriggerAndCommitCharacters.IsValidTrigger(_triggerAndCommitCharacters.HtmlTriggerCharacters, completionContext))
140+
if (_triggerAndCommitCharacters.IsValidHtmlTrigger(completionContext))
141141
{
142142
// We can just blindly call HTML LSP because if we are in C#, generated HTML seen by HTML LSP may return
143143
// results we don't want to show. So we want to call HTML LSP only if we know we are in HTML content.
144144
if (documentPositionInfo.LanguageKind == RazorLanguageKind.Html)
145145
{
146-
htmlCompletionList = await GetHtmlCompletionListAsync(request, razorDocument, razorCompletionOptions, cancellationToken)
147-
.ConfigureAwait(false);
146+
htmlCompletionList = await GetHtmlCompletionListAsync(
147+
request, razorDocument, razorCompletionOptions, cancellationToken).ConfigureAwait(false);
148+
148149
if (htmlCompletionList is not null)
149150
{
150151
existingHtmlCompletions.UnionWith(htmlCompletionList.Items.Select(i => i.Label));

0 commit comments

Comments
 (0)