add activities
This commit is contained in:
@@ -53,10 +53,12 @@ public static class RoslynAnalysis
|
|||||||
public static async Task Analyse(SharpIdeSolutionModel solutionModel)
|
public static async Task Analyse(SharpIdeSolutionModel solutionModel)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"RoslynAnalysis: Loading solution");
|
Console.WriteLine($"RoslynAnalysis: Loading solution");
|
||||||
|
using var _ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.{nameof(Analyse)}");
|
||||||
_sharpIdeSolutionModel = solutionModel;
|
_sharpIdeSolutionModel = solutionModel;
|
||||||
var timer = Stopwatch.StartNew();
|
var timer = Stopwatch.StartNew();
|
||||||
if (_workspace is null)
|
if (_workspace is null)
|
||||||
{
|
{
|
||||||
|
using var __ = SharpIdeOtel.Source.StartActivity("CreateWorkspace");
|
||||||
var configuration = new ContainerConfiguration()
|
var configuration = new ContainerConfiguration()
|
||||||
.WithAssemblies(MefHostServices.DefaultAssemblies)
|
.WithAssemblies(MefHostServices.DefaultAssemblies)
|
||||||
.WithAssembly(typeof(RemoteSnapshotManager).Assembly);
|
.WithAssembly(typeof(RemoteSnapshotManager).Assembly);
|
||||||
@@ -74,17 +76,25 @@ public static class RoslynAnalysis
|
|||||||
_semanticTokensLegendService = container.GetExports<RemoteSemanticTokensLegendService>().FirstOrDefault();
|
_semanticTokensLegendService = container.GetExports<RemoteSemanticTokensLegendService>().FirstOrDefault();
|
||||||
_semanticTokensLegendService!.SetLegend(TokenTypeProvider.ConstructTokenTypes(false), TokenTypeProvider.ConstructTokenModifiers());
|
_semanticTokensLegendService!.SetLegend(TokenTypeProvider.ConstructTokenTypes(false), TokenTypeProvider.ConstructTokenModifiers());
|
||||||
}
|
}
|
||||||
var solution = await _workspace.OpenSolutionAsync(_sharpIdeSolutionModel.FilePath, new Progress());
|
using (var ___ = SharpIdeOtel.Source.StartActivity("OpenSolution"))
|
||||||
|
{
|
||||||
|
var solution = await _workspace.OpenSolutionAsync(_sharpIdeSolutionModel.FilePath, new Progress());
|
||||||
|
}
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
Console.WriteLine($"RoslynAnalysis: Solution loaded in {timer.ElapsedMilliseconds}ms");
|
Console.WriteLine($"RoslynAnalysis: Solution loaded in {timer.ElapsedMilliseconds}ms");
|
||||||
_solutionLoadedTcs.SetResult();
|
_solutionLoadedTcs.SetResult();
|
||||||
|
|
||||||
foreach (var assembly in MefHostServices.DefaultAssemblies)
|
using (var ____ = SharpIdeOtel.Source.StartActivity("LoadAnalyzersAndFixers"))
|
||||||
{
|
{
|
||||||
var fixers = CodeFixProviderLoader.LoadCodeFixProviders([assembly], LanguageNames.CSharp);
|
foreach (var assembly in MefHostServices.DefaultAssemblies)
|
||||||
_codeFixProviders.AddRange(fixers);
|
{
|
||||||
var refactoringProviders = CodeRefactoringProviderLoader.LoadCodeRefactoringProviders([assembly], LanguageNames.CSharp);
|
var fixers = CodeFixProviderLoader.LoadCodeFixProviders([assembly], LanguageNames.CSharp);
|
||||||
_codeRefactoringProviders.AddRange(refactoringProviders);
|
_codeFixProviders.AddRange(fixers);
|
||||||
|
var refactoringProviders = CodeRefactoringProviderLoader.LoadCodeRefactoringProviders([assembly], LanguageNames.CSharp);
|
||||||
|
_codeRefactoringProviders.AddRange(refactoringProviders);
|
||||||
|
}
|
||||||
|
_codeFixProviders = _codeFixProviders.DistinctBy(s => s.GetType().Name).ToHashSet();
|
||||||
|
_codeRefactoringProviders = _codeRefactoringProviders.DistinctBy(s => s.GetType().Name).ToHashSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
// // TODO: Distinct on the assemblies first
|
// // TODO: Distinct on the assemblies first
|
||||||
@@ -100,37 +110,35 @@ public static class RoslynAnalysis
|
|||||||
// _codeRefactoringProviders.AddRange(refactoringProviders);
|
// _codeRefactoringProviders.AddRange(refactoringProviders);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
_codeFixProviders = _codeFixProviders.DistinctBy(s => s.GetType().Name).ToHashSet();
|
|
||||||
_codeRefactoringProviders = _codeRefactoringProviders.DistinctBy(s => s.GetType().Name).ToHashSet();
|
|
||||||
|
|
||||||
await UpdateSolutionDiagnostics();
|
await UpdateSolutionDiagnostics();
|
||||||
foreach (var project in solution.Projects)
|
// foreach (var project in solution.Projects)
|
||||||
{
|
// {
|
||||||
// foreach (var document in project.Documents)
|
// // foreach (var document in project.Documents)
|
||||||
// {
|
// // {
|
||||||
// var semanticModel = await document.GetSemanticModelAsync();
|
// // var semanticModel = await document.GetSemanticModelAsync();
|
||||||
// Guard.Against.Null(semanticModel, nameof(semanticModel));
|
// // Guard.Against.Null(semanticModel, nameof(semanticModel));
|
||||||
// var documentDiagnostics = semanticModel.GetDiagnostics().Where(d => d.Severity is not DiagnosticSeverity.Hidden).ToList();
|
// // var documentDiagnostics = semanticModel.GetDiagnostics().Where(d => d.Severity is not DiagnosticSeverity.Hidden).ToList();
|
||||||
// foreach (var diagnostic in documentDiagnostics)
|
// // foreach (var diagnostic in documentDiagnostics)
|
||||||
// {
|
// // {
|
||||||
// var test = await GetCodeFixesAsync(document, diagnostic);
|
// // var test = await GetCodeFixesAsync(document, diagnostic);
|
||||||
// }
|
// // }
|
||||||
// // var syntaxTree = await document.GetSyntaxTreeAsync();
|
// // // var syntaxTree = await document.GetSyntaxTreeAsync();
|
||||||
// // var root = await syntaxTree!.GetRootAsync();
|
// // // var root = await syntaxTree!.GetRootAsync();
|
||||||
// // var classifiedSpans = await Classifier.GetClassifiedSpansAsync(document, root.FullSpan);
|
// // // var classifiedSpans = await Classifier.GetClassifiedSpansAsync(document, root.FullSpan);
|
||||||
// // foreach (var span in classifiedSpans)
|
// // // foreach (var span in classifiedSpans)
|
||||||
// // {
|
// // // {
|
||||||
// // var classifiedSpan = root.GetText().GetSubText(span.TextSpan);
|
// // // var classifiedSpan = root.GetText().GetSubText(span.TextSpan);
|
||||||
// // Console.WriteLine($"{span.TextSpan}: {span.ClassificationType}");
|
// // // Console.WriteLine($"{span.TextSpan}: {span.ClassificationType}");
|
||||||
// // Console.WriteLine(classifiedSpan);
|
// // // Console.WriteLine(classifiedSpan);
|
||||||
// // }
|
// // // }
|
||||||
// }
|
// // }
|
||||||
}
|
// }
|
||||||
Console.WriteLine("RoslynAnalysis: Analysis completed.");
|
Console.WriteLine("RoslynAnalysis: Analysis completed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task UpdateSolutionDiagnostics()
|
public static async Task UpdateSolutionDiagnostics()
|
||||||
{
|
{
|
||||||
|
using var _ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.{nameof(UpdateSolutionDiagnostics)}");
|
||||||
await _solutionLoadedTcs.Task;
|
await _solutionLoadedTcs.Task;
|
||||||
foreach (var project in _sharpIdeSolutionModel!.AllProjects)
|
foreach (var project in _sharpIdeSolutionModel!.AllProjects)
|
||||||
{
|
{
|
||||||
@@ -143,6 +151,7 @@ public static class RoslynAnalysis
|
|||||||
|
|
||||||
public static async Task<ImmutableArray<Diagnostic>> GetProjectDiagnostics(SharpIdeProjectModel projectModel)
|
public static async Task<ImmutableArray<Diagnostic>> GetProjectDiagnostics(SharpIdeProjectModel projectModel)
|
||||||
{
|
{
|
||||||
|
using var _ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.{nameof(GetProjectDiagnostics)}");
|
||||||
await _solutionLoadedTcs.Task;
|
await _solutionLoadedTcs.Task;
|
||||||
var cancellationToken = CancellationToken.None;
|
var cancellationToken = CancellationToken.None;
|
||||||
var project = _workspace!.CurrentSolution.Projects.Single(s => s.FilePath == projectModel.FilePath);
|
var project = _workspace!.CurrentSolution.Projects.Single(s => s.FilePath == projectModel.FilePath);
|
||||||
@@ -156,6 +165,7 @@ public static class RoslynAnalysis
|
|||||||
|
|
||||||
public static async Task<ImmutableArray<(FileLinePositionSpan fileSpan, Diagnostic diagnostic)>> GetDocumentDiagnostics(SharpIdeFile fileModel)
|
public static async Task<ImmutableArray<(FileLinePositionSpan fileSpan, Diagnostic diagnostic)>> GetDocumentDiagnostics(SharpIdeFile fileModel)
|
||||||
{
|
{
|
||||||
|
using var _ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.{nameof(GetDocumentDiagnostics)}");
|
||||||
await _solutionLoadedTcs.Task;
|
await _solutionLoadedTcs.Task;
|
||||||
var cancellationToken = CancellationToken.None;
|
var cancellationToken = CancellationToken.None;
|
||||||
var project = _workspace!.CurrentSolution.Projects.Single(s => s.FilePath == ((IChildSharpIdeNode)fileModel).GetNearestProjectNode()!.FilePath);
|
var project = _workspace!.CurrentSolution.Projects.Single(s => s.FilePath == ((IChildSharpIdeNode)fileModel).GetNearestProjectNode()!.FilePath);
|
||||||
@@ -177,6 +187,7 @@ public static class RoslynAnalysis
|
|||||||
public record SharpIdeRazorMappedClassifiedSpan(SharpIdeRazorSourceSpan SourceSpanInRazor, string CsharpClassificationType);
|
public record SharpIdeRazorMappedClassifiedSpan(SharpIdeRazorSourceSpan SourceSpanInRazor, string CsharpClassificationType);
|
||||||
public static async Task<IEnumerable<SharpIdeRazorClassifiedSpan>> GetRazorDocumentSyntaxHighlighting(SharpIdeFile fileModel)
|
public static async Task<IEnumerable<SharpIdeRazorClassifiedSpan>> GetRazorDocumentSyntaxHighlighting(SharpIdeFile fileModel)
|
||||||
{
|
{
|
||||||
|
using var _ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.{nameof(GetRazorDocumentSyntaxHighlighting)}");
|
||||||
await _solutionLoadedTcs.Task;
|
await _solutionLoadedTcs.Task;
|
||||||
var cancellationToken = CancellationToken.None;
|
var cancellationToken = CancellationToken.None;
|
||||||
var timer = Stopwatch.StartNew();
|
var timer = Stopwatch.StartNew();
|
||||||
@@ -284,6 +295,7 @@ public static class RoslynAnalysis
|
|||||||
|
|
||||||
public static async Task<IEnumerable<(FileLinePositionSpan fileSpan, ClassifiedSpan classifiedSpan)>> GetDocumentSyntaxHighlighting(SharpIdeFile fileModel)
|
public static async Task<IEnumerable<(FileLinePositionSpan fileSpan, ClassifiedSpan classifiedSpan)>> GetDocumentSyntaxHighlighting(SharpIdeFile fileModel)
|
||||||
{
|
{
|
||||||
|
using var _ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.{nameof(GetDocumentSyntaxHighlighting)}");
|
||||||
await _solutionLoadedTcs.Task;
|
await _solutionLoadedTcs.Task;
|
||||||
var cancellationToken = CancellationToken.None;
|
var cancellationToken = CancellationToken.None;
|
||||||
var project = _workspace!.CurrentSolution.Projects.Single(s => s.FilePath == ((IChildSharpIdeNode)fileModel).GetNearestProjectNode()!.FilePath);
|
var project = _workspace!.CurrentSolution.Projects.Single(s => s.FilePath == ((IChildSharpIdeNode)fileModel).GetNearestProjectNode()!.FilePath);
|
||||||
@@ -307,6 +319,7 @@ public static class RoslynAnalysis
|
|||||||
|
|
||||||
public static async Task<CompletionList> GetCodeCompletionsForDocumentAtPosition(SharpIdeFile fileModel, LinePosition linePosition)
|
public static async Task<CompletionList> GetCodeCompletionsForDocumentAtPosition(SharpIdeFile fileModel, LinePosition linePosition)
|
||||||
{
|
{
|
||||||
|
using var _ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.{nameof(GetCodeCompletionsForDocumentAtPosition)}");
|
||||||
await _solutionLoadedTcs.Task;
|
await _solutionLoadedTcs.Task;
|
||||||
var project = _workspace!.CurrentSolution.Projects.Single(s => s.FilePath == ((IChildSharpIdeNode)fileModel).GetNearestProjectNode()!.FilePath);
|
var project = _workspace!.CurrentSolution.Projects.Single(s => s.FilePath == ((IChildSharpIdeNode)fileModel).GetNearestProjectNode()!.FilePath);
|
||||||
var document = project.Documents.Single(s => s.FilePath == fileModel.Path);
|
var document = project.Documents.Single(s => s.FilePath == fileModel.Path);
|
||||||
@@ -317,6 +330,7 @@ public static class RoslynAnalysis
|
|||||||
|
|
||||||
public static async Task<ImmutableArray<CodeAction>> GetCodeFixesForDocumentAtPosition(SharpIdeFile fileModel, LinePosition linePosition)
|
public static async Task<ImmutableArray<CodeAction>> GetCodeFixesForDocumentAtPosition(SharpIdeFile fileModel, LinePosition linePosition)
|
||||||
{
|
{
|
||||||
|
using var _ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.{nameof(GetCodeFixesForDocumentAtPosition)}");
|
||||||
var cancellationToken = CancellationToken.None;
|
var cancellationToken = CancellationToken.None;
|
||||||
var project = _workspace!.CurrentSolution.Projects.Single(s => s.FilePath == ((IChildSharpIdeNode)fileModel).GetNearestProjectNode()!.FilePath);
|
var project = _workspace!.CurrentSolution.Projects.Single(s => s.FilePath == ((IChildSharpIdeNode)fileModel).GetNearestProjectNode()!.FilePath);
|
||||||
var document = project.Documents.Single(s => s.FilePath == fileModel.Path);
|
var document = project.Documents.Single(s => s.FilePath == fileModel.Path);
|
||||||
@@ -414,6 +428,7 @@ public static class RoslynAnalysis
|
|||||||
|
|
||||||
public static async Task ApplyCodeActionAsync(CodeAction codeAction)
|
public static async Task ApplyCodeActionAsync(CodeAction codeAction)
|
||||||
{
|
{
|
||||||
|
using var _ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.{nameof(ApplyCodeActionAsync)}");
|
||||||
var cancellationToken = CancellationToken.None;
|
var cancellationToken = CancellationToken.None;
|
||||||
var operations = await codeAction.GetOperationsAsync(cancellationToken);
|
var operations = await codeAction.GetOperationsAsync(cancellationToken);
|
||||||
foreach (var operation in operations)
|
foreach (var operation in operations)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ public static class ProjectEvaluation
|
|||||||
private static readonly ProjectCollection _projectCollection = ProjectCollection.GlobalProjectCollection;
|
private static readonly ProjectCollection _projectCollection = ProjectCollection.GlobalProjectCollection;
|
||||||
public static async Task<Project> GetProject(string projectFilePath)
|
public static async Task<Project> GetProject(string projectFilePath)
|
||||||
{
|
{
|
||||||
|
using var _ = SharpIdeOtel.Source.StartActivity($"{nameof(ProjectEvaluation)}.{nameof(GetProject)}");
|
||||||
Guard.Against.Null(projectFilePath, nameof(projectFilePath));
|
Guard.Against.Null(projectFilePath, nameof(projectFilePath));
|
||||||
|
|
||||||
await Task.CompletedTask.ConfigureAwait(ConfigureAwaitOptions.ForceYielding);
|
await Task.CompletedTask.ConfigureAwait(ConfigureAwaitOptions.ForceYielding);
|
||||||
|
|||||||
Reference in New Issue
Block a user