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 support to avoid showing F1 help for TS diagnostics #64242

Merged
merged 1 commit into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.CodeAnalysis.Diagnostics;

namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript
{
internal static class VSTypeScriptWellKnownDiagnosticCustomTags
Copy link
Contributor

Choose a reason for hiding this comment

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

I never remember the rules correctly, but introducing this new class means that we (TypeScript VS) will also need to bump our Roslyn version to access this tag? @mavasani

{
public const string DoesNotSupportF1Help = WellKnownDiagnosticCustomTags.DoesNotSupportF1Help;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public override bool TryGetValue(int index, string columnName, [NotNullWhen(retu
content = (data.GetValidHelpLinkUri() != null) ? string.Format(EditorFeaturesResources.Get_help_for_0, data.Id) : null;
return content != null;
case StandardTableKeyNames.HelpKeyword:
content = data.Id;
content = data.GetHelpKeyword();
return content != null;
case StandardTableKeyNames.HelpLink:
content = data.GetValidHelpLinkUri()?.AbsoluteUri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public override bool TryGetValue(int index, string columnName, [NotNullWhen(true
content = (data.GetValidHelpLinkUri() != null) ? string.Format(EditorFeaturesResources.Get_help_for_0, data.Id) : null;
return content != null;
case StandardTableKeyNames.HelpKeyword:
content = data.Id;
content = data.GetHelpKeyword();
return content != null;
case StandardTableKeyNames.HelpLink:
content = data.GetValidHelpLinkUri()?.AbsoluteUri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics
Dim projectId = documentId.ProjectId

Dim item1 = CreateItem(workspace.CurrentSolution, projectId, documentId, DiagnosticSeverity.Error, "http://link/")
Dim provider = New TestDiagnosticService(item1)
Dim item2 = CreateItem(workspace.CurrentSolution, projectId, documentId, DiagnosticSeverity.Error, customTags:={WellKnownDiagnosticCustomTags.DoesNotSupportF1Help})
Dim provider = New TestDiagnosticService(item1, item2)

Dim tableManagerProvider = New TestTableManagerProvider()

Expand All @@ -487,12 +488,13 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics

Dim sink = DirectCast(sinkAndSubscription.Key, TestTableManagerProvider.TestTableManager.TestSink)
Dim snapshot = sink.Entries.First().GetCurrentSnapshot()
Assert.Equal(1, snapshot.Count)
Assert.Equal(2, snapshot.Count)

Dim keyword As Object = Nothing
Assert.True(snapshot.TryGetValue(0, StandardTableKeyNames.HelpKeyword, keyword))

Assert.Equal(item1.Id, keyword.ToString())

Assert.False(snapshot.TryGetValue(1, StandardTableKeyNames.HelpKeyword, keyword))
End Using
End Sub

Expand Down Expand Up @@ -762,7 +764,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics
Return CreateItem(solution, documentId.ProjectId, documentId, severity)
End Function

Private Shared Function CreateItem(solution As Solution, projectId As ProjectId, documentId As DocumentId, Optional severity As DiagnosticSeverity = DiagnosticSeverity.Error, Optional link As String = Nothing) As DiagnosticData
Private Shared Function CreateItem(solution As Solution, projectId As ProjectId, documentId As DocumentId, Optional severity As DiagnosticSeverity = DiagnosticSeverity.Error, Optional link As String = Nothing, Optional customTags As String() = Nothing) As DiagnosticData
Dim location =
If(documentId Is Nothing,
If(projectId Is Nothing, New DiagnosticDataLocation(New FileLinePositionSpan("", Nothing)), New DiagnosticDataLocation(New FileLinePositionSpan(solution.GetProject(projectId).FilePath, Nothing))),
Expand All @@ -776,7 +778,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics
defaultSeverity:=severity,
isEnabledByDefault:=True,
warningLevel:=0,
customTags:=ImmutableArray(Of String).Empty,
customTags:=If(customTags IsNot Nothing, customTags.ToImmutableArray(), ImmutableArray(Of String).Empty),
properties:=ImmutableDictionary(Of String, String).Empty,
projectId,
location:=location,
Expand Down
4 changes: 4 additions & 0 deletions src/Workspaces/Core/Portable/Diagnostics/DiagnosticData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,5 +368,9 @@ internal bool IsBuildDiagnostic()
// TODO: the value stored in HelpLink should already be valid URI (https://github.com/dotnet/roslyn/issues/59205)
internal Uri? GetValidHelpLinkUri()
=> Uri.TryCreate(HelpLink, UriKind.Absolute, out var uri) ? uri : null;

// Return the diagnostic ID as the HelpKeyword, unless the diagnostic does support F1 help for keyword.
internal string? GetHelpKeyword()
=> CustomTags.Contains(WellKnownDiagnosticCustomTags.DoesNotSupportF1Help) ? null : Id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Microsoft.CodeAnalysis.Diagnostics
{
internal static class WellKnownDiagnosticCustomTags
mavasani marked this conversation as resolved.
Show resolved Hide resolved
{
public const string DoesNotSupportF1Help = nameof(DoesNotSupportF1Help);
}
}