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

Reloadsolution #101

Closed
wants to merge 6 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Microsoft.AspNet.Mvc;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc;
using OmniSharp.AspNet5;
using OmniSharp.Models;
using OmniSharp.MSBuild;
using OmniSharp.MSBuild.ProjectFile;
using OmniSharp.Services;

namespace OmniSharp
{
Expand All @@ -11,12 +12,14 @@ public class ProjectSystemController
private readonly AspNet5Context _aspnet5Context;
private readonly OmnisharpWorkspace _workspace;
private readonly MSBuildContext _msbuildContext;
private readonly IEnumerable<IProjectSystem> _projectSystems;

public ProjectSystemController(AspNet5Context aspnet5Context, MSBuildContext msbuildContext, OmnisharpWorkspace workspace)
public ProjectSystemController(AspNet5Context aspnet5Context, MSBuildContext msbuildContext, OmnisharpWorkspace workspace, IEnumerable<IProjectSystem> projectSystems)
{
_aspnet5Context = aspnet5Context;
_msbuildContext = msbuildContext;
_workspace = workspace;
_projectSystems = projectSystems;
}

[HttpPost("/projects")]
Expand Down Expand Up @@ -56,5 +59,15 @@ public ProjectInformationResponse CurrentProject(Request request)
AspNet5Project = aspNet5ProjectItem
};
}

[HttpPost("/reloadsolution")]
public bool ReloadSolution()
{
foreach (var projectSystem in _projectSystems)
{
projectSystem.Reload();
}
return true;
}
}
}
29 changes: 24 additions & 5 deletions src/OmniSharp/AspNet5/AspNet5ProjectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public AspNet5ProjectSystem(OmnisharpWorkspace workspace,
lifetime.ApplicationStopping.Register(OnShutdown);
}

public void Initalize()
public void Initialize()
{
_context.RuntimePath = GetRuntimePath();

Expand Down Expand Up @@ -345,7 +345,7 @@ public void Initalize()
_context.Connection.Start();

// Initialize the ASP.NET 5 projects
Initialize();
Initialization();
});

wh.Wait();
Expand Down Expand Up @@ -416,7 +416,7 @@ private void TriggerDependeees(string path)
}
}

private void Initialize()
private void Initialization()
{
foreach (var project in _context.Projects.Values)
{
Expand Down Expand Up @@ -508,7 +508,7 @@ private string GetRuntimePath()
{
var versionOrAlias = GetRuntimeVersionOrAlias() ?? _options.AspNet5.Alias ?? "default";
var seachedLocations = new List<string>();

foreach (var location in GetRuntimeLocations())
{
var paths = GetRuntimePathsFromVersionOrAlias(versionOrAlias, location);
Expand All @@ -525,7 +525,7 @@ private string GetRuntimePath()
_logger.WriteInformation(string.Format("Using KRE '{0}'.", path));
return path;
}

seachedLocations.Add(path);
}
}
Expand Down Expand Up @@ -638,5 +638,24 @@ public static string ResolveRootDirectory(string projectPath)
return projectPath;
}

public void Reload()
{
// clear projects collection
foreach (var projectId in _workspace.CurrentSolution.ProjectIds)
{
_workspace.RemoveProject(projectId);
}
// clear context
_context.Projects.Clear();
_context.ProjectContextMapping.Clear();

// get every projects
if (!ScanForProjects())
{
_logger.WriteInformation("No ASP.NET 5 projects found");
}

Initialization();
}
}
}
17 changes: 16 additions & 1 deletion src/OmniSharp/MSBuild/MSBuildProjectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public MSBuildProjectSystem(OmnisharpWorkspace workspace,
_context = context;
}

public void Initalize()
public void Initialize()
{
var solutionFilePath = _env.SolutionFilePath;

Expand Down Expand Up @@ -276,5 +276,20 @@ private void UpdateProject(ProjectFileInfo projectFileInfo)
_workspace.RemoveMetadataReference(project.Id, reference);
}
}

public void Reload()
{
// clear projects collection
foreach (var projectId in _workspace.CurrentSolution.ProjectIds)
{
_workspace.RemoveProject(projectId);
}

// clear context
_context.Projects.Clear();
_context.ProjectGuidToWorkspaceMapping.Clear();

Initialize();
}
}
}
3 changes: 2 additions & 1 deletion src/OmniSharp/Services/IProjectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public interface IProjectSystem
{
void Initalize();
void Initialize();
void Reload();
}
}
2 changes: 1 addition & 1 deletion src/OmniSharp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void Configure(IApplicationBuilder app,

foreach (var projectSystem in projectSystems)
{
projectSystem.Initalize();
projectSystem.Initialize();
}

// Mark the workspace as initialized
Expand Down
7 changes: 5 additions & 2 deletions tests/OmniSharp.Tests/CurrentProjectFacts.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Microsoft.CodeAnalysis;
using System.Collections.Generic;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using OmniSharp.AspNet5;
using OmniSharp.Models;
using OmniSharp.Services;
using Xunit;

namespace OmniSharp.Tests
Expand All @@ -10,6 +12,7 @@ public class CurrentProjectFacts
{
private readonly AspNet5Context _context;
private readonly OmnisharpWorkspace _workspace;
private readonly IEnumerable<IProjectSystem> _projectSystems;

public CurrentProjectFacts()
{
Expand Down Expand Up @@ -37,7 +40,7 @@ public void CanGetAspNet5Project()

private AspNet5Project GetProjectContainingSourceFile(string name)
{
var controller = new ProjectSystemController(_context, null, _workspace);
var controller = new ProjectSystemController(_context, null, _workspace, _projectSystems);

var request = new Request
{
Expand Down