Skip to content

Conversation

@dibarbet
Copy link
Member

Looks like
image

Along the way I cleaned up a bunch of the testing methods and fixed a couple bugs I discovered during cleanup.

@dibarbet dibarbet added Area-IDE LSP issues related to the roslyn language server protocol implementation labels Jun 15, 2022
@dibarbet dibarbet requested a review from a team as a code owner June 15, 2022 18:47
static LSP.Diagnostic[]? GetApplicableDiagnostics(LSP.CodeActionContext context, IUnifiedSuggestedAction action)
{
if (action is UnifiedCodeFixSuggestedAction codeFixAction)
if (action is UnifiedCodeFixSuggestedAction codeFixAction && context.Diagnostics != null)
Copy link
Member Author

Choose a reason for hiding this comment

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

real bug - if the client didn't pass us diagnostics with the code action request we would throw. found during test cleanup

{
public abstract partial class AbstractLanguageServerProtocolTests
{
internal record struct InitializationOptions()
Copy link
Member Author

Choose a reason for hiding this comment

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

struct to cleanup all the test method overloads


protected virtual TestComposition Composition => s_composition;

private protected virtual TestAnalyzerReferenceByLanguage TestAnalyzerReferences
Copy link
Member Author

Choose a reason for hiding this comment

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

moved diagnostics initialization into the base so that individual tests don't have to do something special to get diagnostics working.

/// </summary>
protected Task<TestLspServer> CreateTestLspServerAsync(string[] markups, LSP.ClientCapabilities? clientCapabilities = null)
=> CreateTestLspServerAsync(markups, Array.Empty<string>(), LanguageNames.CSharp, clientCapabilities);
private protected Task<TestLspServer> CreateTestLspServerAsync(string markup, InitializationOptions? initializationOptions = null)
Copy link
Member Author

Choose a reason for hiding this comment

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

overload cleanup using initialization options

return new ProjectOrDocumentId(additionalDocument.Id);
}

return null;
Copy link
Member

Choose a reason for hiding this comment

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

does this indicate a bug?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope! It is a valid scenario when a document is removed / deleted for example.

var workspaceConfigurationService = exportProvider.GetExportedValue<TestWorkspaceConfigurationService>();
workspaceConfigurationService.Options = new WorkspaceConfigurationOptions(EnableOpeningSourceGeneratedFiles: true);

if (lspOptions.OptionUpdater != null)
Copy link
Member Author

Choose a reason for hiding this comment

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

bug fix - previously the solution crawler was created before we set the LSP options. So even when pull diagnostics was on in the tests we also turned on solution crawler

=> new WorkspaceDiagnosticReport(new[]
{
new WorkspaceDocumentDiagnosticReport(new WorkspaceUnchangedDocumentDiagnosticReport(identifier.Uri, resultId, version: null))
});
Copy link
Member

Choose a reason for hiding this comment

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

what's the expected future for the PullDiags vs ExperimentalPullDiags apis?

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 future is experimental pull diagnostics. And the VS one will be deprecated. The experimental APIs were just added to the official spec recently

var documentDiagnostics = await diagnosticAnalyzerService.GetDiagnosticsForSpanAsync(Document, range: null, cancellationToken: cancellationToken).ConfigureAwait(false);
// We call GetDiagnosticsForIdsAsync as we want to ensure we get the full set of diagnostics for this document
// including those reported as a compilation end diagnostic. These are not included in document pull (uses GetDiagnosticsForSpan) due to cost.
// However we can include them as a part of workspace pull when FSA is on.
Copy link
Member

Choose a reason for hiding this comment

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

this make sense... but where is the FSA check done?

Copy link
Member Author

Choose a reason for hiding this comment

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

/// Creates the appropriate LSP type to report a new set of diagnostics and resultId.
/// </summary>
protected abstract TReport CreateReport(TextDocumentIdentifier identifier, LSP.Diagnostic[]? diagnostics, string? resultId);
protected abstract TReport CreateReport(TextDocumentIdentifier identifier, LSP.Diagnostic[] diagnostics, string resultId);
Copy link
Member Author

Choose a reason for hiding this comment

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

result of bug fixing - for VSCode diagnostics we were previously creating unchanged reports for removed documents. This splits it out so we know exactly which is being called and can create appropriate types

+ '|' + string.Format(FeaturesResources.Introduce_constant_for_0, "1"));

var topLevelAction = Assert.Single(results.Where(action => action.Title == FeaturesResources.Introduce_constant));
var expectedChildActionTitle = FeaturesResources.Introduce_constant + '|' + string.Format(FeaturesResources.Introduce_constant_for_0, "1");
Copy link
Member Author

Choose a reason for hiding this comment

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

test fallout of always having diagnostics be enabled in LSP tests

@dibarbet dibarbet mentioned this pull request Jun 16, 2022
20 tasks
@dibarbet dibarbet merged commit e4d1ce6 into dotnet:main Jun 16, 2022
@dibarbet dibarbet deleted the additional_file_diagnostics branch June 16, 2022 17:00
@ghost ghost added this to the Next milestone Jun 16, 2022
chsienki added a commit to chsienki/roslyn that referenced this pull request Jun 20, 2022
@RikkiGibson RikkiGibson modified the milestones: Next, 17.3 P3 Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE LSP issues related to the roslyn language server protocol implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants