diff --git a/CHANGELOG.md b/CHANGELOG.md index 303fec2c88..8759b1b02e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.cs b/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.cs index ccb3079484..a35fd33c01 100644 --- a/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.cs +++ b/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.cs @@ -90,12 +90,11 @@ 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); @@ -103,7 +102,7 @@ internal static ProjectFileInfo CreateNoBuild(string filePath, ProjectLoader loa return new ProjectFileInfo(projectIdInfo, filePath, data, sessionId: Guid.NewGuid(), dotNetInfo); } - public static (ProjectFileInfo, ImmutableArray, ProjectLoadedEventArgs) Load(string filePath, ProjectIdInfo projectIdInfo, ProjectLoader loader, Guid sessionId, IDotNetCliService dotNetCli) + public static (ProjectFileInfo, ImmutableArray, ProjectLoadedEventArgs) Load(string filePath, ProjectIdInfo projectIdInfo, ProjectLoader loader, Guid sessionId, DotNetInfo dotNetInfo) { if (!File.Exists(filePath)) { @@ -116,8 +115,6 @@ public static (ProjectFileInfo, ImmutableArray, 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, diff --git a/src/OmniSharp.MSBuild/ProjectManager.cs b/src/OmniSharp.MSBuild/ProjectManager.cs index 9339e1a533..2f15f5b6ff 100644 --- a/src/OmniSharp.MSBuild/ProjectManager.cs +++ b/src/OmniSharp.MSBuild/ProjectManager.cs @@ -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(); @@ -81,7 +81,7 @@ public ProjectManager( OmniSharpWorkspace workspace, IAnalyzerAssemblyLoader analyzerAssemblyLoader, ImmutableArray eventSinks, - IDotNetCliService dotNetCliService) + DotNetInfo dotNetInfo) { _logger = loggerFactory.CreateLogger(); _options = options ?? new MSBuildOptions(); @@ -95,7 +95,7 @@ public ProjectManager( _projectLoader = projectLoader; _workspace = workspace; _eventSinks = eventSinks; - _dotNetCli = dotNetCliService; + _dotNetInfo = dotNetInfo; _queue = new BufferBlock(); _processLoopCancellation = new CancellationTokenSource(); _processLoopTask = Task.Run(() => ProcessLoopAsync(_processLoopCancellation.Token)); @@ -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)); @@ -649,7 +649,7 @@ private void UpdateProjectReferences(Project project, ImmutableArray 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); diff --git a/src/OmniSharp.MSBuild/ProjectSystem.cs b/src/OmniSharp.MSBuild/ProjectSystem.cs index f686850c63..0e52d59253 100644 --- a/src/OmniSharp.MSBuild/ProjectSystem.cs +++ b/src/OmniSharp.MSBuild/ProjectSystem.cs @@ -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) @@ -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. diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectFileInfoTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectFileInfoTests.cs index 34561f1ffb..e5c406f17b 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectFileInfoTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectFileInfoTests.cs @@ -28,7 +28,6 @@ private ProjectFileInfo CreateProjectFileInfo(OmniSharpTestHost host, ITestProje { var msbuildLocator = host.GetExport(); var sdksPathResolver = host.GetExport(); - var dotNetCli = host.GetExport(); var loader = new ProjectLoader( options: new MSBuildOptions(), @@ -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; }