-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1507 from savpek/feature/background-analysis
Background analysis support
- Loading branch information
Showing
24 changed files
with
584 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/OmniSharp.Abstractions/Models/Events/ProjectAnalyzeStatusMessage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace OmniSharp.Models.Events | ||
{ | ||
public class ProjectDiagnosticStatusMessage | ||
{ | ||
public ProjectDiagnosticStatus Status { get; set; } | ||
public string ProjectFilePath { get; set; } | ||
public string Type = "background"; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/OmniSharp.Abstractions/Models/Events/ProjectDiagnosticStatus.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace OmniSharp.Models.Events | ||
{ | ||
public enum ProjectDiagnosticStatus | ||
{ | ||
Started = 0, | ||
Ready = 1 | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/OmniSharp.Abstractions/Models/v1/ReAnalyze/ReanalyzeRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using OmniSharp.Mef; | ||
using OmniSharp.Models; | ||
|
||
namespace OmniSharp.Abstractions.Models.V1.ReAnalyze | ||
{ | ||
[OmniSharpEndpoint(OmniSharpEndpoints.ReAnalyze, typeof(ReAnalyzeRequest), typeof(ReanalyzeResponse))] | ||
public class ReAnalyzeRequest: SimpleFileRequest | ||
{ | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/OmniSharp.Abstractions/Models/v1/ReAnalyze/ReanalyzeResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using OmniSharp.Models; | ||
|
||
namespace OmniSharp.Abstractions.Models.V1.ReAnalyze | ||
{ | ||
public class ReanalyzeResponse : IAggregateResponse | ||
{ | ||
public IAggregateResponse Merge(IAggregateResponse response) { return response; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/OmniSharp.Roslyn.CSharp/Services/Diagnostics/ReAnalyzeService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Collections.Immutable; | ||
using System.Composition; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.Extensions.Logging; | ||
using OmniSharp.Abstractions.Models.V1.ReAnalyze; | ||
using OmniSharp.Mef; | ||
using OmniSharp.Roslyn.CSharp.Workers.Diagnostics; | ||
|
||
namespace OmniSharp.Roslyn.CSharp.Services.Diagnostics | ||
{ | ||
[OmniSharpHandler(OmniSharpEndpoints.ReAnalyze, LanguageNames.CSharp)] | ||
public class ReAnalyzeService : IRequestHandler<ReAnalyzeRequest, ReanalyzeResponse> | ||
{ | ||
private readonly ICsDiagnosticWorker _diagWorker; | ||
private readonly OmniSharpWorkspace _workspace; | ||
private readonly ILogger<ReAnalyzeService> _logger; | ||
|
||
[ImportingConstructor] | ||
public ReAnalyzeService(ICsDiagnosticWorker diagWorker, OmniSharpWorkspace workspace, ILoggerFactory loggerFactory) | ||
{ | ||
_diagWorker = diagWorker; | ||
_workspace = workspace; | ||
_logger = loggerFactory.CreateLogger<ReAnalyzeService>(); | ||
} | ||
|
||
public Task<ReanalyzeResponse> Handle(ReAnalyzeRequest request) | ||
{ | ||
|
||
if(!string.IsNullOrEmpty(request.FileName)) | ||
{ | ||
var currentSolution = _workspace.CurrentSolution; | ||
|
||
var projectIds = WhenRequestIsProjectFileItselfGetFilesFromIt(request.FileName, currentSolution) | ||
?? GetProjectIdsFromDocumentFilePaths(request.FileName, currentSolution); | ||
|
||
_logger.LogInformation($"Queue analysis for project(s) {string.Join(", ", projectIds)}"); | ||
|
||
_diagWorker.QueueDocumentsForDiagnostics(projectIds); | ||
} | ||
else | ||
{ | ||
_logger.LogInformation($"Queue analysis for all projects."); | ||
_diagWorker.QueueDocumentsForDiagnostics(); | ||
} | ||
|
||
return Task.FromResult(new ReanalyzeResponse()); | ||
} | ||
|
||
private ImmutableArray<ProjectId>? WhenRequestIsProjectFileItselfGetFilesFromIt(string FileName, Solution currentSolution) | ||
{ | ||
var projects = currentSolution.Projects.Where(x => CompareProjectPath(FileName, x)).Select(x => x.Id).ToImmutableArray(); | ||
|
||
if(!projects.Any()) | ||
return null; | ||
|
||
return projects; | ||
} | ||
|
||
private static bool CompareProjectPath(string FileName, Project x) | ||
{ | ||
return String.Compare( | ||
x.FilePath, | ||
FileName, | ||
StringComparison.InvariantCultureIgnoreCase) == 0; | ||
} | ||
|
||
private static ImmutableArray<ProjectId> GetProjectIdsFromDocumentFilePaths(string FileName, Solution currentSolution) | ||
{ | ||
return currentSolution | ||
.GetDocumentIdsWithFilePath(FileName) | ||
.Select(docId => currentSolution.GetDocument(docId).Project.Id) | ||
.Distinct() | ||
.ToImmutableArray(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/OmniSharp.Roslyn.CSharp/Workers/Diagnostics/AnalyzerWorkType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace OmniSharp.Roslyn.CSharp.Workers.Diagnostics | ||
{ | ||
public enum AnalyzerWorkType | ||
{ | ||
Background, Foreground | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.