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

Support adding and removing projects from solution without restart #1825

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 40 additions & 2 deletions src/OmniSharp.MSBuild/ProjectSystem.cs
Expand Up @@ -126,9 +126,47 @@ public void Initalize(IConfiguration configuration)

_manager.QueueProjectUpdate(projectFilePath, allowAutoRestore: true, projectIdInfo);
}

if(!string.IsNullOrEmpty(_solutionFileOrRootPath))
{
_fileSystemWatcher.Watch(_solutionFileOrRootPath, OnSolutionFileUpdate);
}
}

private void OnSolutionFileUpdate(string filePath, FileChangeType changeType)
{
if(changeType == FileChangeType.Change)
{
var afterChange = GetProjectPathsAndIdsFromSolution(filePath);
var current = _manager.GetAllProjects().Select(x => x.ProjectIdInfo);

var projectsToAdd = afterChange
.Select(x => x.info.Id)
.Except(current.Select(x => x.Id))
.Select(projectId => afterChange.Single(af => af.info.Id == projectId));

var projectsToRemove = current
.Select(x => x.Id)
.Except(afterChange.Select(x => x.info.Id))
.Select(projectId => current.Single(af => af.Id == projectId));

foreach(var (path, info) in projectsToAdd)
{
_logger.LogInformation($"Project {path} added to solution, adding project to queue.");
_manager.QueueProjectUpdate(path, true, info);
}

// foreach(var projectToRemove in projectsToRemove)
// {
// _manager.QueueProjectUpdate(path, true, info);
// }
}
else if(changeType == FileChangeType.Delete)
{
}
}

private IEnumerable<(string, ProjectIdInfo)> GetInitialProjectPathsAndIds()
private IEnumerable<(string path, ProjectIdInfo info)> GetInitialProjectPathsAndIds()
{
// If a solution was provided, use it.
if (!string.IsNullOrEmpty(_environment.SolutionFilePath))
Expand Down Expand Up @@ -156,7 +194,7 @@ private IEnumerable<(string, ProjectIdInfo)> GetInitialProjectPathsAndIds()
});
}

private IEnumerable<(string, ProjectIdInfo)> GetProjectPathsAndIdsFromSolution(string solutionFilePath)
private IEnumerable<(string path, ProjectIdInfo info)> GetProjectPathsAndIdsFromSolution(string solutionFilePath)
{
_logger.LogInformation($"Detecting projects in '{solutionFilePath}'.");

Expand Down