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

Only request dotnet info once for the solution or directory #1857

Merged
merged 4 commits into from
Jul 22, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All changes to the project will be documented in this file.
* Added LSP handler for the `workspace/symbol` request. (PR: [#1799](https://github.com/OmniSharp/omnisharp-roslyn/pull/1799))
* Use global MSBuild property when resetting target framework ([#1738](https://github.com/OmniSharp/omnisharp-roslyn/issues/1738), PR: [#1846](https://github.com/OmniSharp/omnisharp-roslyn/pull/1846))
* Do not use Visual Studio MSBuild if it doesn't have .NET SDK resolver ([#1842](https://github.com/OmniSharp/omnisharp-roslyn/issues/1842), [#1730](https://github.com/OmniSharp/omnisharp-roslyn/issues/1730), PR: [#1845](https://github.com/OmniSharp/omnisharp-roslyn/pull/1845))
* Only request dotnet info once for the solution or directory ([#1844](https://github.com/OmniSharp/omnisharp-roslyn/issues/1844), PR: [#1857](https://github.com/OmniSharp/omnisharp-roslyn/pull/1857))
* Allow client to specify symbol filter for FindSymbols Endpoint. (PR: [#1823](https://github.com/OmniSharp/omnisharp-roslyn/pull/1823))
* Exclude additive classifications from "/highlight" requests ([#1576](https://github.com/OmniSharp/omnisharp-roslyn/issues/1576), PR: [#1726](https://github.com/OmniSharp/omnisharp-roslyn/pull/1726))
* Upgraded to Mono 6.10.0.105, msbuild 16.6 and added missing targets (PR: [#1854](https://github.com/OmniSharp/omnisharp-roslyn/pull/1854))
Expand Down
7 changes: 2 additions & 5 deletions src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,19 @@ internal static ProjectFileInfo CreateEmpty(string filePath)
return new ProjectFileInfo(new ProjectIdInfo(id, isDefinedInSolution: false), filePath, data: null, sessionId: Guid.NewGuid(), DotNetInfo.Empty);
}

internal static ProjectFileInfo CreateNoBuild(string filePath, ProjectLoader loader, IDotNetCliService dotNetCli)
internal static ProjectFileInfo CreateNoBuild(string filePath, ProjectLoader loader, DotNetInfo dotNetInfo)
{
var id = ProjectId.CreateNewId(debugName: filePath);
var project = loader.EvaluateProjectFile(filePath);

var dotNetInfo = dotNetCli.GetInfo(Path.GetDirectoryName(project.FullPath));
var data = ProjectData.Create(project);
//we are not reading the solution here
var projectIdInfo = new ProjectIdInfo(id, isDefinedInSolution: false);

return new ProjectFileInfo(projectIdInfo, filePath, data, sessionId: Guid.NewGuid(), dotNetInfo);
}

public static (ProjectFileInfo, ImmutableArray<MSBuildDiagnostic>, ProjectLoadedEventArgs) Load(string filePath, ProjectIdInfo projectIdInfo, ProjectLoader loader, Guid sessionId, IDotNetCliService dotNetCli)
public static (ProjectFileInfo, ImmutableArray<MSBuildDiagnostic>, ProjectLoadedEventArgs) Load(string filePath, ProjectIdInfo projectIdInfo, ProjectLoader loader, Guid sessionId, DotNetInfo dotNetInfo)
{
if (!File.Exists(filePath))
{
Expand All @@ -116,8 +115,6 @@ public static (ProjectFileInfo, ImmutableArray<MSBuildDiagnostic>, ProjectLoaded
return (null, diagnostics, null);
}

var dotNetInfo = dotNetCli.GetInfo(Path.GetDirectoryName(projectInstance.FullPath));

var data = ProjectData.Create(projectInstance);
var projectFileInfo = new ProjectFileInfo(projectIdInfo, filePath, data, sessionId, dotNetInfo);
var eventArgs = new ProjectLoadedEventArgs(projectIdInfo.Id,
Expand Down
10 changes: 5 additions & 5 deletions src/OmniSharp.MSBuild/ProjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public ProjectToUpdate(string filePath, bool allowAutoRestore, ProjectIdInfo pro
private readonly CancellationTokenSource _processLoopCancellation;
private readonly Task _processLoopTask;
private readonly IAnalyzerAssemblyLoader _analyzerAssemblyLoader;
private readonly IDotNetCliService _dotNetCli;
private readonly DotNetInfo _dotNetInfo;
private bool _processingQueue;
private readonly Guid _sessionId = Guid.NewGuid();

Expand All @@ -81,7 +81,7 @@ public ProjectManager(
OmniSharpWorkspace workspace,
IAnalyzerAssemblyLoader analyzerAssemblyLoader,
ImmutableArray<IMSBuildEventSink> eventSinks,
IDotNetCliService dotNetCliService)
DotNetInfo dotNetInfo)
{
_logger = loggerFactory.CreateLogger<ProjectManager>();
_options = options ?? new MSBuildOptions();
Expand All @@ -95,7 +95,7 @@ public ProjectManager(
_projectLoader = projectLoader;
_workspace = workspace;
_eventSinks = eventSinks;
_dotNetCli = dotNetCliService;
_dotNetInfo = dotNetInfo;
_queue = new BufferBlock<ProjectToUpdate>();
_processLoopCancellation = new CancellationTokenSource();
_processLoopTask = Task.Run(() => ProcessLoopAsync(_processLoopCancellation.Token));
Expand Down Expand Up @@ -299,7 +299,7 @@ private void ProcessQueue(CancellationToken cancellationToken)
}

private (ProjectFileInfo, ProjectLoadedEventArgs) LoadProject(string projectFilePath, ProjectIdInfo idInfo)
=> LoadOrReloadProject(projectFilePath, () => ProjectFileInfo.Load(projectFilePath, idInfo, _projectLoader, _sessionId, _dotNetCli));
=> LoadOrReloadProject(projectFilePath, () => ProjectFileInfo.Load(projectFilePath, idInfo, _projectLoader, _sessionId, _dotNetInfo));

private (ProjectFileInfo, ProjectLoadedEventArgs) ReloadProject(ProjectFileInfo projectFileInfo)
=> LoadOrReloadProject(projectFileInfo.FilePath, () => projectFileInfo.Reload(_projectLoader));
Expand Down Expand Up @@ -649,7 +649,7 @@ private void UpdateProjectReferences(Project project, ImmutableArray<string> pro

// We've found a project reference that we didn't know about already, but it exists on disk.
// This is likely a project that is outside of OmniSharp's TargetDirectory.
referencedProject = ProjectFileInfo.CreateNoBuild(projectReferencePath, _projectLoader, _dotNetCli);
referencedProject = ProjectFileInfo.CreateNoBuild(projectReferencePath, _projectLoader, _dotNetInfo);
AddProject(referencedProject);

QueueProjectUpdate(projectReferencePath, allowAutoRestore: true, referencedProject.ProjectIdInfo);
Expand Down
12 changes: 11 additions & 1 deletion src/OmniSharp.MSBuild/ProjectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public void Initalize(IConfiguration configuration)
_packageDependencyChecker = new PackageDependencyChecker(_loggerFactory, _eventEmitter, _dotNetCli, _options);
_loader = new ProjectLoader(_options, _environment.TargetDirectory, _propertyOverrides, _loggerFactory, _sdksPathResolver);

_manager = new ProjectManager(_loggerFactory, _options, _eventEmitter, _fileSystemWatcher, _metadataFileReferenceCache, _packageDependencyChecker, _loader, _workspace, _assemblyLoader, _eventSinks, _dotNetCli);
var dotNetInfo = GetDotNetInfo();
_manager = new ProjectManager(_loggerFactory, _options, _eventEmitter, _fileSystemWatcher, _metadataFileReferenceCache, _packageDependencyChecker, _loader, _workspace, _assemblyLoader, _eventSinks, dotNetInfo);
Initialized = true;

if (_options.LoadProjectsOnDemand)
Expand All @@ -125,6 +126,15 @@ public void Initalize(IConfiguration configuration)
}
}

private DotNetInfo GetDotNetInfo()
{
var workingDirectory = string.IsNullOrEmpty(_environment.SolutionFilePath)
? _environment.TargetDirectory
: Path.GetDirectoryName(_environment.SolutionFilePath);

return _dotNetCli.GetInfo(workingDirectory);
}

private IEnumerable<(string, ProjectIdInfo)> GetInitialProjectPathsAndIds()
{
// If a solution was provided, use it.
Expand Down
3 changes: 1 addition & 2 deletions tests/OmniSharp.MSBuild.Tests/ProjectFileInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ private ProjectFileInfo CreateProjectFileInfo(OmniSharpTestHost host, ITestProje
{
var msbuildLocator = host.GetExport<IMSBuildLocator>();
var sdksPathResolver = host.GetExport<SdksPathResolver>();
var dotNetCli = host.GetExport<IDotNetCliService>();

var loader = new ProjectLoader(
options: new MSBuildOptions(),
Expand All @@ -38,7 +37,7 @@ private ProjectFileInfo CreateProjectFileInfo(OmniSharpTestHost host, ITestProje
sdksPathResolver: sdksPathResolver);

var projectIdInfo = new ProjectIdInfo(ProjectId.CreateNewId(), false);
var (projectFileInfo, _, _) = ProjectFileInfo.Load(projectFilePath, projectIdInfo, loader, sessionId: Guid.NewGuid(), dotNetCli);
var (projectFileInfo, _, _) = ProjectFileInfo.Load(projectFilePath, projectIdInfo, loader, sessionId: Guid.NewGuid(), DotNetInfo.Empty);

return projectFileInfo;
}
Expand Down