Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dibarbet committed Jan 15, 2021
1 parent 8421485 commit ce45c40
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 20 deletions.
4 changes: 2 additions & 2 deletions eng/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,9 @@ function TestUsingRunTests() {
Copy-Item -Path (Join-Path $TempDir "servicehub\logs") -Destination (Join-Path $LogDir "servicehub") -Recurse

if ($lspEditor) {
Write-Host "Copying LSP logs to $LogDir"
Write-Host "Copying LSP and telemetry logs to $LogDir"
Copy-Item -Path (Join-Path $TempDir "VisualStudio\LSP") -Destination (Join-Path $LogDir "LSP") -Recurse
Copy-Item -Path (Join-Path $TempDir "VSTelemetryLog") -Destination (Join-Path $LogDir "Telemetry") -Recurse
}
}
}
Expand Down Expand Up @@ -559,7 +560,6 @@ function Setup-IntegrationTestRun() {

$env:ROSLYN_OOP64BIT = "$oop64bit"
$env:ROSLYN_LSPEDITOR = "$lspEditor"
$env:LogLevel = "Verbose"
}

function Prepare-TempDir() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Notification;
using Roslyn.Utilities;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;

namespace Microsoft.CodeAnalysis.Editor.Implementation.InlineRename
{
Expand Down Expand Up @@ -109,8 +108,7 @@ private static bool CanRename(RenameCommandArgs args)
{
return args.SubjectBuffer.TryGetWorkspace(out var workspace) &&
workspace.CanApplyChange(ApplyChangesKind.ChangeDocument) &&
args.SubjectBuffer.SupportsRename() &&
!workspace.Services.GetService<IWorkspaceContextService>().IsInLspEditorContext();
args.SubjectBuffer.SupportsRename();
}

private static void ShowErrorDialog(Workspace workspace, string message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,6 @@ public bool TryGetTelemetryId(out Guid telemetryId)
return null;
}

if (range.Snapshot.TextBuffer.IsInLspEditorContext())
{
return null;
}

if (_workspaceStatusService != null)
{
using (operationContext?.AddScope(allowCancellation: true, description: EditorFeaturesWpfResources.Gathering_Suggestions_Waiting_for_the_solution_to_fully_load))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static async Task ProduceTagsAsync(
IClassificationService classificationService,
ClassificationTypeMap typeMap)
{
// Let LSP handle semantic classification when running in the LSP editor.
if (spanToTag.SnapshotSpan.Snapshot.TextBuffer.IsInLspEditorContext())
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ protected internal override VSServerCapabilities GetCapabilities()
var serverCapabilities = new VSServerCapabilities();

// If the LSP editor feature flag is enabled advertise support for LSP features here so they are available locally and remote.
if (Workspace.Services.GetRequiredService<IExperimentationService>().IsExperimentEnabled(VisualStudioWorkspaceContextService.LspEditorFeatureFlagName))
bool shouldUseLspEditor = Workspace.Services.GetRequiredService<IExperimentationService>().IsExperimentEnabled(VisualStudioWorkspaceContextService.LspEditorFeatureFlagName);
if (shouldUseLspEditor)
{
serverCapabilities = _defaultCapabilitiesProvider.GetCapabilities();
}
Expand All @@ -65,7 +66,10 @@ protected internal override VSServerCapabilities GetCapabilities()
OpenClose = true,
};
serverCapabilities.SupportsDiagnosticRequests = this.Workspace.IsPullDiagnostics(InternalDiagnosticsOptions.NormalDiagnosticMode);
serverCapabilities.DisableGoToWorkspaceSymbols = true;

// When using the lsp editor, set this to false to allow LSP to power goto.
// Otherwise set to true to disable LSP for goto
serverCapabilities.DisableGoToWorkspaceSymbols = !shouldUseLspEditor;
serverCapabilities.WorkspaceSymbolProvider = true;

return serverCapabilities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Composition;
using Microsoft.CodeAnalysis.Editor.Implementation.NavigateTo;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Language.NavigateTo.Interfaces;
Expand All @@ -25,8 +26,15 @@ public VisualStudioNavigateToItemProviderFactory(VisualStudioWorkspace workspace
_workspace = workspace;
}

public bool TryCreateNavigateToItemProvider(IServiceProvider serviceProvider, out INavigateToItemProvider provider)
public bool TryCreateNavigateToItemProvider(IServiceProvider serviceProvider, out INavigateToItemProvider? provider)
{
// Let LSP handle goto when running under the LSP editor.
if (_workspace.Services.GetRequiredService<IWorkspaceContextService>().IsInLspEditorContext())
{
provider = null;
return false;
}

provider = new NavigateToItemProvider(_workspace, _asyncListener);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.Shared;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Shared;
using Microsoft.CodeAnalysis.Text;
Expand All @@ -31,13 +33,38 @@ public VisualStudioTextBufferSupportsFeatureService()
}

public bool SupportsCodeFixes(ITextBuffer textBuffer)
=> SupportsCodeFixesWorker(GetContainedDocumentId(textBuffer));
{
// Disable code fix entry points when running under the LSP editor.
// The LSP client will handle displaying lightbulbs.
if (textBuffer.IsInLspEditorContext())
{
return false;
}

return SupportsCodeFixesWorker(GetContainedDocumentId(textBuffer));
}

public bool SupportsRefactorings(ITextBuffer textBuffer)
=> SupportsRefactoringsWorker(GetContainedDocumentId(textBuffer));
{
// Disable code fix entry points when running under the LSP editor.
// The LSP client will handle displaying lightbulbs.
if (textBuffer.IsInLspEditorContext())
{
return false;
}

return SupportsRefactoringsWorker(GetContainedDocumentId(textBuffer));
}

public bool SupportsRename(ITextBuffer textBuffer)
{
// Disable rename entry points when running under the LSP editor.
// The LSP client will handle the rename request.
if (textBuffer.IsInLspEditorContext())
{
return false;
}

var sourceTextContainer = textBuffer.AsTextContainer();
if (Workspace.TryGetWorkspace(sourceTextContainer, out var workspace))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void GoToImplementationOpensProvisionalTabIfDocumentNotOpen()
}

// TODO: Enable this once the GoToDefinition tests are merged
[WpfFact, Trait(Traits.Feature, Traits.Features.GoToImplementation), Trait(Traits.Editor, Traits.Editors.LanguageServerProtocol)]
[WpfFact, Trait(Traits.Feature, Traits.Features.GoToImplementation)]
public void GoToImplementationFromMetadataAsSource()
{
var project = new ProjectUtils.Project(ProjectName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,39 @@ public LspGoToDefinition(VisualStudioInstanceFactory instanceFactory)
}

[WpfFact, Trait(Traits.Feature, Traits.Features.GoToDefinition), Trait(Traits.Editor, Traits.Editors.LanguageServerProtocol)]
public void GoToDefinitionLSP()
public void GoToDefinitionWithMultipleLSP()
{
Assert.True(false);
SetUpEditor(
@"partial class /*Marker*/ $$PartialClass { }
partial class PartialClass { int i = 0; }");

VisualStudio.Editor.GoToDefinition("Class1.cs");

const string programReferencesCaption = "'PartialClass' references";
VisualStudio.Editor.WaitForActiveWindow(programReferencesCaption);
var results = VisualStudio.FindReferencesWindow.GetContents(programReferencesCaption);

var activeWindowCaption = VisualStudio.Shell.GetActiveWindowCaption();
Assert.Equal(expected: programReferencesCaption, actual: activeWindowCaption);

Assert.Collection(
results,
new Action<Reference>[]
{
reference =>
{
Assert.Equal(expected: "partial class /*Marker*/ PartialClass { }", actual: reference.Code);
Assert.Equal(expected: 0, actual: reference.Line);
Assert.Equal(expected: 25, actual: reference.Column);
},
reference =>
{
Assert.Equal(expected: "partial class PartialClass { int i = 0; }", actual: reference.Code);
Assert.Equal(expected: 2, actual: reference.Line);
Assert.Equal(expected: 14, actual: reference.Column);
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public BasicGoToImplementation(VisualStudioInstanceFactory instanceFactory)
{
}

[WpfFact, Trait(Traits.Feature, Traits.Features.GoToImplementation), Trait(Traits.Editor, Traits.Editors.LanguageServerProtocol)]
[WpfFact, Trait(Traits.Feature, Traits.Features.GoToImplementation)]
public void SimpleGoToImplementation()
{
var project = new ProjectUtils.Project(ProjectName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,23 @@ public string GetActiveBufferName()
return GetDTE().ActiveDocument.Name;
}

public string GetActiveWindowName()
{
return GetDTE().ActiveWindow.Caption;
}

public void WaitForActiveView(string expectedView)
{
using var cts = new CancellationTokenSource(Helper.HangMitigatingTimeout);
Retry(_ => GetActiveBufferName(), (actual, _) => actual == expectedView, TimeSpan.FromMilliseconds(100), cts.Token);
}

public void WaitForActiveWindow(string expectedWindow)
{
using var cts = new CancellationTokenSource(Helper.HangMitigatingTimeout);
Retry(_ => GetActiveWindowName(), (actual, _) => actual == expectedWindow, TimeSpan.FromMilliseconds(100), cts.Token);
}

public void Activate()
=> GetDTE().ActiveDocument.Activate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ public void SetUseSuggestionMode(bool value)
public void WaitForActiveView(string viewName)
=> _editorInProc.WaitForActiveView(viewName);

public void WaitForActiveWindow(string windowName)
=> _editorInProc.WaitForActiveWindow(windowName);

public string[] GetErrorTags()
=> _editorInProc.GetErrorTags();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ private static Process StartNewVisualStudioProcess(string installationPath, int
var vsExeFile = Path.Combine(installationPath, @"Common7\IDE\devenv.exe");
var vsRegEditExeFile = Path.Combine(installationPath, @"Common7\IDE\VsRegEdit.exe");

var usingLspEditor = string.Equals(Environment.GetEnvironmentVariable("ROSLYN_LSPEDITOR"), "true", StringComparison.OrdinalIgnoreCase);

if (_firstLaunch)
{
if (majorVersion == 16)
Expand All @@ -332,8 +334,9 @@ private static Process StartNewVisualStudioProcess(string installationPath, int
// Disable background download UI to avoid toasts
Process.Start(CreateSilentStartInfo(vsRegEditExeFile, $"set \"{installationPath}\" {Settings.Default.VsRootSuffix} HKCU \"FeatureFlags\\Setup\\BackgroundDownload\" Value dword 0")).WaitForExit();

var lspRegistryValue = string.Equals(Environment.GetEnvironmentVariable("ROSLYN_LSPEDITOR"), "true", StringComparison.OrdinalIgnoreCase) ? "1" : "0";
var lspRegistryValue = usingLspEditor ? "1" : "0";
Process.Start(CreateSilentStartInfo(vsRegEditExeFile, $"set \"{installationPath}\" {Settings.Default.VsRootSuffix} HKCU \"FeatureFlags\\Roslyn\\LSP\\Editor\" Value dword {lspRegistryValue}")).WaitForExit();
Registry.SetValue(@"HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\Telemetry\Channels", "fileLogger", 1, RegistryValueKind.DWord);

// Remove legacy experiment setting for controlling async completion to ensure it does not interfere.
// We no longer set this value, but it could be in place from an earlier test run on the same machine.
Expand Down Expand Up @@ -372,6 +375,12 @@ private static Process StartNewVisualStudioProcess(string installationPath, int
processStartInfo.Environment.Remove("DotNetRoot");
processStartInfo.Environment.Remove("DotNetTool");

if (usingLspEditor)
{
// When running under the LSP editor set logging to verbose to ensure LSP client logs are captured.
processStartInfo.Environment.Add("LogLevel", "Verbose");
}

// The first element of the path in CI is a .dotnet used for the Roslyn build. Make sure to remove that.
if (processStartInfo.Environment.TryGetValue("BUILD_SOURCESDIRECTORY", out var sourcesDirectory))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<NuGetPackageToIncludeInVsix Include="System.Runtime.CompilerServices.Unsafe" PkgDefEntry="BindingRedirect" />
<NuGetPackageToIncludeInVsix Include="System.Text.Encoding.CodePages" PkgDefEntry="BindingRedirect" />
<NuGetPackageToIncludeInVsix Include="System.Threading.Tasks.Extensions" PkgDefEntry="BindingRedirect" />
<NuGetPackageToIncludeInVsix Include="System.IO.Pipelines" PkgDefEntry="BindingRedirect" />
</ItemGroup>
<ItemGroup>
<None Include="source.extension.vsixmanifest">
Expand All @@ -60,6 +61,7 @@
<PackageReference Include="System.Text.Encoding.CodePages" Version="$(SystemTextEncodingCodePagesVersion)" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="$(SystemThreadingTasksExtensionsVersion)" />
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
<PackageReference Include="System.IO.Pipelines" Version="$(SystemIOPipelinesVersion)" />
</ItemGroup>

<!--
Expand Down

0 comments on commit ce45c40

Please sign in to comment.