diff --git a/eng/Signing.props b/eng/Signing.props
index 3980092891..4a94789f83 100644
--- a/eng/Signing.props
+++ b/eng/Signing.props
@@ -19,6 +19,7 @@
+
diff --git a/eng/Versions.props b/eng/Versions.props
index 7d79a417e1..657cd318d1 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -91,7 +91,7 @@
1.0.1-beta1.21103.2
17.0.0-previews-1-31410-258
17.0.35-gdeb9415fdc
- 4.0.0-2.21354.7
+ 4.0.0-3.21367.2
5.0.0-preview.4.20205.1
@@ -106,7 +106,7 @@
$(MicrosoftVisualStudioPackagesVersion)
$(MicrosoftVisualStudioPackagesVersion)
$(MicrosoftVisualStudioPackagesVersion)
- 17.0.2062-g973d339867
+ 17.0.3094-g82ddffa096
0.3.1074
16.10.81-pre
$(MicrosoftVisualStudioShellPackagesVersion)
@@ -132,6 +132,7 @@
3.3.2
6.0.0-preview3.21158.1
$(RoslynPackageVersion)
+ $(RoslynPackageVersion)
$(RoslynPackageVersion)
$(RoslynPackageVersion)
$(RoslynPackageVersion)
diff --git a/src/Razor/Razor.sln b/src/Razor/Razor.sln
index d32182f13a..6265d851ea 100644
--- a/src/Razor/Razor.sln
+++ b/src/Razor/Razor.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.28410.60
+# Visual Studio Version 17
+VisualStudioVersion = 17.0.31415.485
MinimumVisualStudioVersion = 16.0.0.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3C0D6505-79B3-49D0-B4C3-176F0F1836ED}"
ProjectSection(SolutionItems) = preProject
@@ -86,6 +86,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.VisualStudio.Lang
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Remote.Razor.Test", "test\Microsoft.CodeAnalysis.Remote.Razor.Test\Microsoft.CodeAnalysis.Remote.Razor.Test.csproj", "{39233703-B752-43AC-AD86-E9D3E61B4AD9}"
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Remote.Razor.CoreComponents", "src\Microsoft.CodeAnalysis.Remote.Razor.CoreComponents\Microsoft.CodeAnalysis.Remote.Razor.CoreComponents.csproj", "{17C4A6DF-3AA5-43FE-8A0E-53DF14340446}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -390,6 +392,14 @@ Global
{39233703-B752-43AC-AD86-E9D3E61B4AD9}.Release|Any CPU.Build.0 = Release|Any CPU
{39233703-B752-43AC-AD86-E9D3E61B4AD9}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU
{39233703-B752-43AC-AD86-E9D3E61B4AD9}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU
+ {17C4A6DF-3AA5-43FE-8A0E-53DF14340446}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {17C4A6DF-3AA5-43FE-8A0E-53DF14340446}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {17C4A6DF-3AA5-43FE-8A0E-53DF14340446}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU
+ {17C4A6DF-3AA5-43FE-8A0E-53DF14340446}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU
+ {17C4A6DF-3AA5-43FE-8A0E-53DF14340446}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {17C4A6DF-3AA5-43FE-8A0E-53DF14340446}.Release|Any CPU.Build.0 = Release|Any CPU
+ {17C4A6DF-3AA5-43FE-8A0E-53DF14340446}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU
+ {17C4A6DF-3AA5-43FE-8A0E-53DF14340446}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -432,6 +442,7 @@ Global
{0FC409AF-B92B-42D0-9096-1F20360D2672} = {92463391-81BE-462B-AC3C-78C6C760741F}
{1C7BBF16-3507-4A23-91B4-9EEA03409C72} = {92463391-81BE-462B-AC3C-78C6C760741F}
{39233703-B752-43AC-AD86-E9D3E61B4AD9} = {92463391-81BE-462B-AC3C-78C6C760741F}
+ {17C4A6DF-3AA5-43FE-8A0E-53DF14340446} = {3C0D6505-79B3-49D0-B4C3-176F0F1836ED}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0035341D-175A-4D05-95E6-F1C2785A1E26}
diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensBenchmark.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensBenchmark.cs
index 1ba0900c8a..225ed98945 100644
--- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensBenchmark.cs
+++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/LanguageServer/RazorSemanticTokensBenchmark.cs
@@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer
private DocumentSnapshot UpdatedDocumentSnapshot { get; set; }
- private ForegroundDispatcher ForegroundDispatcher { get; set; }
+ private ProjectSnapshotManagerDispatcher ProjectSnapshotManagerDispatcher { get; set; }
private string PagesDirectory { get; set; }
@@ -76,7 +76,8 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer
private async Task UpdateDocumentAsync(int newVersion, DocumentSnapshot documentSnapshot)
{
- await Task.Factory.StartNew(() => VersionCache.TrackDocumentVersion(documentSnapshot, newVersion), CancellationToken.None, TaskCreationOptions.None, ForegroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ await ProjectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
+ () => VersionCache.TrackDocumentVersion(documentSnapshot, newVersion), CancellationToken.None).ConfigureAwait(false);
}
[GlobalCleanup]
@@ -101,7 +102,7 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer
var languageServer = RazorLanguageServer.GetInnerLanguageServerForTesting();
RazorSemanticTokenService = languageServer.GetService(typeof(RazorSemanticTokensInfoService)) as TestRazorSemanticTokensInfoService;
VersionCache = languageServer.GetService(typeof(DocumentVersionCache)) as DocumentVersionCache;
- ForegroundDispatcher = languageServer.GetService(typeof(ForegroundDispatcher)) as ForegroundDispatcher;
+ ProjectSnapshotManagerDispatcher = languageServer.GetService(typeof(ProjectSnapshotManagerDispatcher)) as ProjectSnapshotManagerDispatcher;
}
private class TestRazorSemanticTokensInfoService : DefaultRazorSemanticTokensInfoService
@@ -109,11 +110,11 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks.LanguageServer
public TestRazorSemanticTokensInfoService(
ClientNotifierServiceBase languageServer,
RazorDocumentMappingService documentMappingService,
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
DocumentResolver documentResolver,
DocumentVersionCache documentVersionCache,
LoggerFactory loggerFactory) :
- base(languageServer, documentMappingService, foregroundDispatcher, documentResolver, documentVersionCache, loggerFactory)
+ base(languageServer, documentMappingService, projectSnapshotManagerDispatcher, documentResolver, documentVersionCache, loggerFactory)
{
}
diff --git a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs
index f1dc695b9c..ea35c5b2ef 100644
--- a/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs
+++ b/src/Razor/benchmarks/Microsoft.AspNetCore.Razor.Microbenchmarks/ProjectSystem/ProjectSnapshotManagerBenchmarkBase.cs
@@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks
Array.Empty());
return new DefaultProjectSnapshotManager(
- new TestForegroundDispatcher(),
+ new TestProjectSnapshotManagerDispatcher(),
new TestErrorReporter(),
Array.Empty(),
#pragma warning disable CA2000 // Dispose objects before losing scope
@@ -91,13 +91,11 @@ namespace Microsoft.AspNetCore.Razor.Microbenchmarks
}
}
- private class TestForegroundDispatcher : ForegroundDispatcher
+ private class TestProjectSnapshotManagerDispatcher : ProjectSnapshotManagerDispatcher
{
- public override bool IsForegroundThread => true;
+ public override bool IsDispatcherThread => true;
- public override TaskScheduler ForegroundScheduler => TaskScheduler.Default;
-
- public override TaskScheduler BackgroundScheduler => TaskScheduler.Default;
+ public override TaskScheduler DispatcherScheduler => TaskScheduler.Default;
}
private class TestErrorReporter : ErrorReporter
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/BackgroundDocumentGenerator.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/BackgroundDocumentGenerator.cs
index e36abc002a..480b5f8aaf 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/BackgroundDocumentGenerator.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/BackgroundDocumentGenerator.cs
@@ -5,7 +5,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
-using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
@@ -13,36 +12,36 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Common
{
internal class BackgroundDocumentGenerator : ProjectSnapshotChangeTrigger
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly IEnumerable _documentProcessedListeners;
private readonly Dictionary _work;
private ProjectSnapshotManagerBase _projectManager;
private Timer _timer;
public BackgroundDocumentGenerator(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
IEnumerable documentProcessedListeners)
{
- if (foregroundDispatcher == null)
+ if (projectSnapshotManagerDispatcher is null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
- if (documentProcessedListeners == null)
+ if (documentProcessedListeners is null)
{
throw new ArgumentNullException(nameof(documentProcessedListeners));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_documentProcessedListeners = documentProcessedListeners;
_work = new Dictionary(StringComparer.Ordinal);
}
// For testing only
protected BackgroundDocumentGenerator(
- ForegroundDispatcher foregroundDispatcher)
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher)
{
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_work = new Dictionary(StringComparer.Ordinal);
_documentProcessedListeners = Enumerable.Empty();
}
@@ -136,7 +135,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Common
// Internal for testing
internal void Enqueue(DocumentSnapshot document)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
lock (_work)
{
@@ -164,8 +163,6 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Common
{
try
{
- _foregroundDispatcher.AssertBackgroundThread();
-
OnStartingBackgroundWork();
KeyValuePair[] work;
@@ -192,11 +189,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Common
OnCompletingBackgroundWork();
- await Task.Factory.StartNew(
+ await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
() => NotifyDocumentsProcessed(work),
- CancellationToken.None,
- TaskCreationOptions.None,
- _foregroundDispatcher.ForegroundScheduler);
+ CancellationToken.None);
lock (_work)
{
@@ -237,7 +232,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Common
private void ProjectSnapshotManager_Changed(object sender, ProjectChangeEventArgs args)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
switch (args.Kind)
{
@@ -317,11 +312,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Common
private void ReportError(Exception ex)
{
- _ = Task.Factory.StartNew(
+ _ = _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
() => _projectManager.ReportError(ex),
- CancellationToken.None,
- TaskCreationOptions.None,
- _foregroundDispatcher.ForegroundScheduler);
+ CancellationToken.None);
}
}
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/LanguageServerConstants.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/LanguageServerConstants.cs
index ca8c78d894..1127babf21 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/LanguageServerConstants.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/LanguageServerConstants.cs
@@ -9,14 +9,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Common
public const string ProjectConfigurationFile = "project.razor.json";
- // Semantic "Legacy" endpoints refer to an old LSP spec version, needed for now until VS reacts.
- public const string LegacyRazorSemanticTokensEndpoint = "textDocument/semanticTokens";
-
- public const string LegacyRazorSemanticTokensEditEndpoint = "textDocument/semanticTokens/edits";
-
- public const string LegacyRazorSemanticTokensRangeEndpoint = "textDocument/semanticTokens/range";
-
- public const string RazorSemanticTokensLegendEndpoint = "_ms_/textDocument/semanticTokensLegend";
+ public const string RazorSemanticTokensLegendEndpoint = "_vs_/textDocument/semanticTokensLegend";
public const string RazorSemanticTokensEditEndpoint = "textDocument/semanticTokens/full/delta";
@@ -36,8 +29,6 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Common
public const string RazorCodeActionRunnerCommand = "razor/runCodeAction";
- public const string RazorCodeActionResolveEndpoint = "textDocument/codeActionResolve";
-
// RZLS Custom Message Targets
public const string RazorUpdateCSharpBufferEndpoint = "razor/updateCSharpBuffer";
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/AutoClosingTagOnAutoInsertProvider.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/AutoClosingTagOnAutoInsertProvider.cs
index 806f2a187e..ef94f794b1 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/AutoClosingTagOnAutoInsertProvider.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/AutoClosingTagOnAutoInsertProvider.cs
@@ -1,4 +1,4 @@
-// Copyright (c) .NET Foundation. All rights reserved.
+// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@@ -288,4 +288,4 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert
SelfClosing,
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/IOnAutoInsertHandler.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/IOnAutoInsertHandler.cs
index f20d1589fa..24e909928c 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/IOnAutoInsertHandler.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/IOnAutoInsertHandler.cs
@@ -5,7 +5,7 @@ using OmniSharp.Extensions.JsonRpc;
namespace Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert
{
- [Parallel, Method("textDocument/_ms_onAutoInsert")]
+ [Parallel, Method("textDocument/_vs_onAutoInsert")]
internal interface IOnAutoInsertHandler : IJsonRpcRequestHandler, IRegistrationExtension
{
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertEndpoint.cs
index 9e2379109b..60d6ba1d41 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertEndpoint.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertEndpoint.cs
@@ -16,21 +16,21 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert
{
internal class OnAutoInsertEndpoint : IOnAutoInsertHandler
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly DocumentResolver _documentResolver;
private readonly AdhocWorkspaceFactory _workspaceFactory;
private readonly IReadOnlyList _onAutoInsertProviders;
private readonly Container _onAutoInsertTriggerCharacters;
public OnAutoInsertEndpoint(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
DocumentResolver documentResolver,
IEnumerable onAutoInsertProvider,
AdhocWorkspaceFactory workspaceFactory)
{
- if (foregroundDispatcher is null)
+ if (projectSnapshotManagerDispatcher is null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (documentResolver is null)
@@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert
throw new ArgumentNullException(nameof(workspaceFactory));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_documentResolver = documentResolver;
_workspaceFactory = workspaceFactory;
_onAutoInsertProviders = onAutoInsertProvider.ToList();
@@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert
public RegistrationExtensionResult GetRegistration()
{
- const string AssociatedServerCapability = "_ms_onAutoInsertProvider";
+ const string AssociatedServerCapability = "_vs_onAutoInsertProvider";
var registrationOptions = new OnAutoInsertRegistrationOptions()
{
@@ -70,12 +70,12 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert
public async Task Handle(OnAutoInsertParams request, CancellationToken cancellationToken)
{
- var document = await Task.Factory.StartNew(() =>
+ var document = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentResolver.TryResolveDocument(request.TextDocument.Uri.GetAbsoluteOrUNCPath(), out var documentSnapshot);
return documentSnapshot;
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
+ }, cancellationToken);
if (document is null || cancellationToken.IsCancellationRequested)
{
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertParams.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertParams.cs
index 1de0fc8315..100f8775ae 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertParams.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertParams.cs
@@ -9,13 +9,16 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert
{
internal class OnAutoInsertParams : ITextDocumentIdentifierParams, IRequest, IBaseRequest
{
+ [JsonProperty("_vs_textDocument")]
public TextDocumentIdentifier TextDocument { get; set; }
+ [JsonProperty("_vs_position")]
public Position Position { get; set; }
- [JsonProperty("ch")]
+ [JsonProperty("_vs_ch")]
public string Character { get; set; }
+ [JsonProperty("_vs_options")]
public FormattingOptions Options { get; set; }
}
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertRegistrationOptions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertRegistrationOptions.cs
index 3bde512e04..866882c9e4 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertRegistrationOptions.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertRegistrationOptions.cs
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using Newtonsoft.Json;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
namespace Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert
@@ -9,6 +10,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert
{
public DocumentSelector DocumentSelector { get; set; }
+ [JsonProperty("_vs_triggerCharacters")]
public Container TriggerCharacters { get; set; }
}
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertResponse.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertResponse.cs
index ce39023b03..c61a497928 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertResponse.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/AutoInsert/OnAutoInsertResponse.cs
@@ -1,14 +1,17 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using Newtonsoft.Json;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
namespace Microsoft.AspNetCore.Razor.LanguageServer.AutoInsert
{
internal class OnAutoInsertResponse
{
+ [JsonProperty("_vs_textEditFormat")]
public InsertTextFormat TextEditFormat { get; set; }
+ [JsonProperty("_vs_textEdit")]
public TextEdit TextEdit { get; set; }
}
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/AddUsingsCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/AddUsingsCodeActionResolver.cs
index 9279ad235f..b5d9701959 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/AddUsingsCodeActionResolver.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/AddUsingsCodeActionResolver.cs
@@ -23,13 +23,25 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
{
internal class AddUsingsCodeActionResolver : RazorCodeActionResolver
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly DocumentResolver _documentResolver;
- public AddUsingsCodeActionResolver(ForegroundDispatcher foregroundDispatcher, DocumentResolver documentResolver)
+ public AddUsingsCodeActionResolver(
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
+ DocumentResolver documentResolver)
{
- _foregroundDispatcher = foregroundDispatcher ?? throw new ArgumentNullException(nameof(foregroundDispatcher));
- _documentResolver = documentResolver ?? throw new ArgumentNullException(nameof(documentResolver));
+ if (projectSnapshotManagerDispatcher is null)
+ {
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
+ }
+
+ if (documentResolver is null)
+ {
+ throw new ArgumentNullException(nameof(documentResolver));
+ }
+
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
+ _documentResolver = documentResolver;
}
public override string Action => LanguageServerConstants.CodeActions.AddUsing;
@@ -49,11 +61,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
var path = actionParams.Uri.GetAbsoluteOrUNCPath();
- var documentSnapshot = await Task.Factory.StartNew(() =>
+ var documentSnapshot = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentResolver.TryResolveDocument(path, out var documentSnapshot);
return documentSnapshot;
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ }, cancellationToken).ConfigureAwait(false);
if (documentSnapshot is null)
{
return null;
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/AddUsingsCSharpCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/AddUsingsCSharpCodeActionResolver.cs
index b0dfa8fb5b..550a721d70 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/AddUsingsCSharpCodeActionResolver.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/AddUsingsCSharpCodeActionResolver.cs
@@ -19,18 +19,18 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
///
internal class AddUsingsCSharpCodeActionResolver : CSharpCodeActionResolver
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly DocumentResolver _documentResolver;
private readonly DocumentVersionCache _documentVersionCache;
public AddUsingsCSharpCodeActionResolver(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
DocumentResolver documentResolver,
ClientNotifierServiceBase languageServer,
DocumentVersionCache documentVersionCache)
: base(languageServer)
{
- _foregroundDispatcher = foregroundDispatcher ?? throw new ArgumentNullException(nameof(foregroundDispatcher));
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher ?? throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
_documentResolver = documentResolver ?? throw new ArgumentNullException(nameof(documentResolver));
_documentVersionCache = documentVersionCache ?? throw new ArgumentNullException(nameof(documentVersionCache));
}
@@ -87,11 +87,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
return codeAction;
}
- var documentSnapshot = await Task.Factory.StartNew(() =>
+ var documentSnapshot = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentResolver.TryResolveDocument(csharpParams.RazorFileUri.GetAbsoluteOrUNCPath(), out var documentSnapshot);
return documentSnapshot;
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ }, cancellationToken).ConfigureAwait(false);
if (documentSnapshot is null)
{
return codeAction;
@@ -109,11 +109,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
return null;
}
- var documentVersion = await Task.Factory.StartNew(() =>
+ var documentVersion = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentVersionCache.TryGetDocumentVersion(documentSnapshot, out var version);
return version;
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ }, cancellationToken).ConfigureAwait(false);
var codeDocumentIdentifier = new VersionedTextDocumentIdentifier()
{
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs
index b87efb66e9..282f2046fd 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/DefaultCSharpCodeActionResolver.cs
@@ -28,22 +28,22 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
TrimFinalNewlines = true
};
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly DocumentResolver _documentResolver;
private readonly RazorFormattingService _razorFormattingService;
private readonly DocumentVersionCache _documentVersionCache;
public DefaultCSharpCodeActionResolver(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
DocumentResolver documentResolver,
ClientNotifierServiceBase languageServer,
RazorFormattingService razorFormattingService,
DocumentVersionCache documentVersionCache)
: base(languageServer)
{
- if (foregroundDispatcher is null)
+ if (projectSnapshotManagerDispatcher is null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (documentResolver is null)
@@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
throw new ArgumentNullException(nameof(documentVersionCache));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_documentResolver = documentResolver;
_razorFormattingService = razorFormattingService;
_documentVersionCache = documentVersionCache;
@@ -99,11 +99,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
cancellationToken.ThrowIfCancellationRequested();
- var documentSnapshot = await Task.Factory.StartNew(() =>
+ var documentSnapshot = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentResolver.TryResolveDocument(csharpParams.RazorFileUri.GetAbsoluteOrUNCPath(), out var documentSnapshot);
return documentSnapshot;
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ }, cancellationToken).ConfigureAwait(false);
if (documentSnapshot is null)
{
@@ -134,11 +134,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
cancellationToken.ThrowIfCancellationRequested();
- var documentVersion = await Task.Factory.StartNew(() =>
+ var documentVersion = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentVersionCache.TryGetDocumentVersion(documentSnapshot, out var version);
return version;
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ }, cancellationToken).ConfigureAwait(false);
var codeDocumentIdentifier = new VersionedTextDocumentIdentifier()
{
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/UnformattedRemappingCSharpCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/UnformattedRemappingCSharpCodeActionResolver.cs
index 7596bfb5b2..bd5807391b 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/UnformattedRemappingCSharpCodeActionResolver.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CSharp/UnformattedRemappingCSharpCodeActionResolver.cs
@@ -19,20 +19,20 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
///
internal class UnformattedRemappingCSharpCodeActionResolver : CSharpCodeActionResolver
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly DocumentResolver _documentResolver;
private readonly DocumentVersionCache _documentVersionCache;
private readonly RazorDocumentMappingService _documentMappingService;
public UnformattedRemappingCSharpCodeActionResolver(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
DocumentResolver documentResolver,
ClientNotifierServiceBase languageServer,
DocumentVersionCache documentVersionCache,
RazorDocumentMappingService documentMappingService)
: base(languageServer)
{
- _foregroundDispatcher = foregroundDispatcher ?? throw new ArgumentNullException(nameof(foregroundDispatcher));
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher ?? throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
_documentResolver = documentResolver ?? throw new ArgumentNullException(nameof(documentResolver));
_documentVersionCache = documentVersionCache ?? throw new ArgumentNullException(nameof(documentVersionCache));
_documentMappingService = documentMappingService ?? throw new ArgumentNullException(nameof(documentMappingService));
@@ -85,14 +85,14 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
return codeAction;
}
- var (documentSnapshot, documentVersion) = await Task.Factory.StartNew(() =>
+ var (documentSnapshot, documentVersion) = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentResolver.TryResolveDocument(csharpParams.RazorFileUri.ToUri().GetAbsoluteOrUNCPath(), out var documentSnapshot);
_documentVersionCache.TryGetDocumentVersion(documentSnapshot, out var version);
return (documentSnapshot, version);
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ }, cancellationToken).ConfigureAwait(false);
if (documentSnapshot is null)
{
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs
index 6174577ab3..f80f3ff3e7 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionEndpoint.cs
@@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
private readonly RazorDocumentMappingService _documentMappingService;
private readonly IEnumerable _razorCodeActionProviders;
private readonly IEnumerable _csharpCodeActionProviders;
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly DocumentResolver _documentResolver;
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions;
private readonly ClientNotifierServiceBase _languageServer;
@@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
RazorDocumentMappingService documentMappingService,
IEnumerable razorCodeActionProviders,
IEnumerable csharpCodeActionProviders,
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
DocumentResolver documentResolver,
ClientNotifierServiceBase languageServer,
LanguageServerFeatureOptions languageServerFeatureOptions)
@@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
_documentMappingService = documentMappingService ?? throw new ArgumentNullException(nameof(documentMappingService));
_razorCodeActionProviders = razorCodeActionProviders ?? throw new ArgumentNullException(nameof(razorCodeActionProviders));
_csharpCodeActionProviders = csharpCodeActionProviders ?? throw new ArgumentNullException(nameof(csharpCodeActionProviders));
- _foregroundDispatcher = foregroundDispatcher ?? throw new ArgumentNullException(nameof(foregroundDispatcher));
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher ?? throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
_documentResolver = documentResolver ?? throw new ArgumentNullException(nameof(documentResolver));
_languageServer = languageServer ?? throw new ArgumentNullException(nameof(languageServer));
_languageServerFeatureOptions = languageServerFeatureOptions ?? throw new ArgumentNullException(nameof(languageServerFeatureOptions));
@@ -65,7 +65,8 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
CodeActionKind.RefactorExtract,
CodeActionKind.QuickFix,
CodeActionKind.Refactor
- }
+ },
+ ResolveProvider = true,
};
}
@@ -73,8 +74,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
{
_capability = capability;
- var extendableClientCapabilities = _languageServer.ClientSettings?.Capabilities as PlatformAgnosticClientCapabilities;
- _supportsCodeActionResolve = extendableClientCapabilities?.SupportsCodeActionResolve ?? false;
+ _supportsCodeActionResolve = _capability.ResolveSupport != null;
}
public async Task Handle(RazorCodeActionParams request, CancellationToken cancellationToken)
@@ -121,11 +121,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
// internal for testing
internal async Task GenerateRazorCodeActionContextAsync(RazorCodeActionParams request, CancellationToken cancellationToken)
{
- var documentSnapshot = await Task.Factory.StartNew(() =>
+ var documentSnapshot = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentResolver.TryResolveDocument(request.TextDocument.Uri.GetAbsoluteOrUNCPath(), out var documentSnapshot);
return documentSnapshot;
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ }, cancellationToken).ConfigureAwait(false);
if (documentSnapshot is null)
{
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolutionEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolutionEndpoint.cs
index e490e1c735..619cdb07f1 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolutionEndpoint.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/CodeActionResolutionEndpoint.cs
@@ -16,8 +16,6 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
{
internal class CodeActionResolutionEndpoint : IRazorCodeActionResolveHandler
{
- private const string CodeActionsResolveProviderCapability = "codeActionsResolveProvider";
-
private readonly IReadOnlyDictionary _razorCodeActionResolvers;
private readonly IReadOnlyDictionary _csharpCodeActionResolvers;
private readonly ILogger _logger;
@@ -48,9 +46,6 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
_csharpCodeActionResolvers = CreateResolverMap(csharpCodeActionResolvers);
}
- // Register VS LSP code action resolution server capability
- public RegistrationExtensionResult GetRegistration() => new RegistrationExtensionResult(CodeActionsResolveProviderCapability, true);
-
public async Task Handle(CodeAction request, CancellationToken cancellationToken)
{
if (request is null)
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/IRazorCodeActionResolveHandler.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/IRazorCodeActionResolveHandler.cs
index 8e6dfcc8dd..06d3d56d5e 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/IRazorCodeActionResolveHandler.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/IRazorCodeActionResolveHandler.cs
@@ -1,16 +1,15 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-using Microsoft.AspNetCore.Razor.LanguageServer.Common;
using OmniSharp.Extensions.JsonRpc;
+using OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
{
- [Parallel, Method(LanguageServerConstants.RazorCodeActionResolveEndpoint)]
+ [Parallel, Method(TextDocumentNames.CodeActionResolve, Direction.ClientToServer)]
internal interface IRazorCodeActionResolveHandler :
- IJsonRpcRequestHandler,
- IRegistrationExtension
+ IJsonRpcRequestHandler
{
}
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/ExtendedCodeActionContext.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/ExtendedCodeActionContext.cs
index 490fa669f3..b5d9a587a5 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/ExtendedCodeActionContext.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Models/ExtendedCodeActionContext.cs
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using Newtonsoft.Json;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Serialization;
@@ -9,6 +10,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models
internal class ExtendedCodeActionContext : CodeActionContext
{
[Optional]
+ [JsonProperty("_vs_selectionRange")]
public Range SelectionRange { get; set; }
}
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CreateComponentCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CreateComponentCodeActionResolver.cs
index d117bc175f..dfb46814f1 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CreateComponentCodeActionResolver.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/CreateComponentCodeActionResolver.cs
@@ -20,14 +20,14 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
{
internal class CreateComponentCodeActionResolver : RazorCodeActionResolver
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly DocumentResolver _documentResolver;
public CreateComponentCodeActionResolver(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
DocumentResolver documentResolver)
{
- _foregroundDispatcher = foregroundDispatcher ?? throw new ArgumentNullException(nameof(foregroundDispatcher));
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher ?? throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
_documentResolver = documentResolver ?? throw new ArgumentNullException(nameof(documentResolver));
}
@@ -48,11 +48,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
var path = actionParams.Uri.GetAbsoluteOrUNCPath();
- var document = await Task.Factory.StartNew(() =>
+ var document = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentResolver.TryResolveDocument(path, out var documentSnapshot);
return documentSnapshot;
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ }, cancellationToken).ConfigureAwait(false);
if (document is null)
{
return null;
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs
index 6a5981360c..f63182693d 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToCodeBehindCodeActionResolver.cs
@@ -26,18 +26,18 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
{
internal class ExtractToCodeBehindCodeActionResolver : RazorCodeActionResolver
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly DocumentResolver _documentResolver;
private readonly FilePathNormalizer _filePathNormalizer;
private static readonly Range s_startOfDocumentRange = new Range(new Position(0, 0), new Position(0, 0));
public ExtractToCodeBehindCodeActionResolver(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
DocumentResolver documentResolver,
FilePathNormalizer filePathNormalizer)
{
- _foregroundDispatcher = foregroundDispatcher ?? throw new ArgumentNullException(nameof(foregroundDispatcher));
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher ?? throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
_documentResolver = documentResolver ?? throw new ArgumentNullException(nameof(documentResolver));
_filePathNormalizer = filePathNormalizer ?? throw new ArgumentNullException(nameof(filePathNormalizer));
}
@@ -59,11 +59,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
var path = _filePathNormalizer.Normalize(actionParams.Uri.GetAbsoluteOrUNCPath());
- var document = await Task.Factory.StartNew(() =>
+ var document = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentResolver.TryResolveDocument(path, out var documentSnapshot);
return documentSnapshot;
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ }, cancellationToken).ConfigureAwait(false);
if (document is null)
{
return null;
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/OmniSharpVSCompletionContext.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/OmniSharpVSCompletionContext.cs
index e4bbb15563..b8b032e318 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/OmniSharpVSCompletionContext.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/OmniSharpVSCompletionContext.cs
@@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
{
public static readonly PlatformExtensionConverter JsonConverter = new PlatformExtensionConverter();
- [JsonProperty("_ms_invokeKind")]
+ [JsonProperty("_vs_invokeKind")]
public OmniSharpVSCompletionInvokeKind InvokeKind { get; set; }
}
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/OptimizedVSCompletionList.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/OptimizedVSCompletionList.cs
index cfbd09fe4b..857acaea8e 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/OptimizedVSCompletionList.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/OptimizedVSCompletionList.cs
@@ -29,13 +29,13 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
if (vsCompletionList.CommitCharacters != null)
{
- writer.WritePropertyName("_vsext_commitCharacters");
+ writer.WritePropertyName("_vs_commitCharacters");
serializer.Serialize(writer, vsCompletionList.CommitCharacters);
}
if (vsCompletionList.Data != null)
{
- writer.WritePropertyName("_vsext_data");
+ writer.WritePropertyName("_vs_data");
serializer.Serialize(writer, vsCompletionList.Data);
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/PlatformAgnosticCompletionCapability.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/PlatformAgnosticCompletionCapability.cs
index a5a06fefef..b2a9202a5d 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/PlatformAgnosticCompletionCapability.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/PlatformAgnosticCompletionCapability.cs
@@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
{
public static readonly PlatformExtensionConverter JsonConverter = new PlatformExtensionConverter();
- [JsonProperty("_ms_completionList")]
+ [JsonProperty("_vs_completionList")]
public VSCompletionListCapability VSCompletionList { get; set; }
}
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionEndpoint.cs
index ed3bf4cd07..40a16bf6e0 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionEndpoint.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/RazorCompletionEndpoint.cs
@@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
{
private PlatformAgnosticCompletionCapability _capability;
private readonly ILogger _logger;
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly DocumentResolver _documentResolver;
private readonly RazorCompletionFactsService _completionFactsService;
private readonly LSPTagHelperTooltipFactory _lspTagHelperTooltipFactory;
@@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
private IReadOnlyList _supportedItemKinds;
public RazorCompletionEndpoint(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
DocumentResolver documentResolver,
RazorCompletionFactsService completionFactsService,
LSPTagHelperTooltipFactory lspTagHelperTooltipFactory,
@@ -49,9 +49,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
ClientNotifierServiceBase languageServer,
ILoggerFactory loggerFactory)
{
- if (foregroundDispatcher == null)
+ if (projectSnapshotManagerDispatcher == null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (documentResolver == null)
@@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
throw new ArgumentNullException(nameof(loggerFactory));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_documentResolver = documentResolver;
_completionFactsService = completionFactsService;
_lspTagHelperTooltipFactory = lspTagHelperTooltipFactory;
@@ -102,14 +102,12 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
public async Task Handle(CompletionParams request, CancellationToken cancellationToken)
{
- _foregroundDispatcher.AssertBackgroundThread();
-
- var document = await Task.Factory.StartNew(() =>
+ var document = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentResolver.TryResolveDocument(request.TextDocument.Uri.GetAbsoluteOrUNCPath(), out var documentSnapshot);
return documentSnapshot;
- }, CancellationToken.None, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
+ }, CancellationToken.None);
if (document is null || cancellationToken.IsCancellationRequested)
{
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/VSCompletionItem.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/VSCompletionItem.cs
index 13cfcc39d7..a0664ce683 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/VSCompletionItem.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/VSCompletionItem.cs
@@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.LanguageServer.Tooltip;
+using Newtonsoft.Json;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
@@ -11,6 +12,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
///
internal class VSCompletionItem : CompletionItem
{
+ [JsonProperty("_vs_description")]
public VSClassifiedTextElement Description { get; set; }
}
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/VSCompletionList.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/VSCompletionList.cs
index 3c0ffbd7c6..b0feac0f08 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/VSCompletionList.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/VSCompletionList.cs
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
+using Newtonsoft.Json;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
@@ -19,11 +20,13 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
///
/// Gets or sets the default used for completion items.
///
+ [JsonProperty("_vs_commitCharacters")]
public Container CommitCharacters { get; set; }
///
/// Gets or sets the default used for completion items.
///
+ [JsonProperty("_vs_data")]
public object Data { get; set; }
public static VSCompletionList Convert(CompletionList completionList, VSCompletionListCapability vsCompletionListCapability)
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/VSCompletionListCapability.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/VSCompletionListCapability.cs
index d97ff4e857..01f5a3711f 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/VSCompletionListCapability.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/VSCompletionListCapability.cs
@@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using Newtonsoft.Json;
+
namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
{
internal class VSCompletionListCapability
@@ -9,12 +11,14 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
/// Gets or sets a value indicating whether completion lists can have VSCommitCharacters. These commit characters get propagated
/// onto underlying valid completion items unless they have their own commit characters.
///
+ [JsonProperty("_vs_commitCharacters")]
public bool CommitCharacters { get; set; }
///
/// Gets or sets a value indicating whether completion lists can have Data bags. These data bags get propagated
/// onto underlying completion items unless they have their own data bags.
///
+ [JsonProperty("_vs_data")]
public bool Data { get; set; }
}
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultDocumentVersionCache.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultDocumentVersionCache.cs
index 0adc0e1c25..e07aa66a09 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultDocumentVersionCache.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultDocumentVersionCache.cs
@@ -14,18 +14,18 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
// Internal for testing
internal readonly Dictionary> DocumentLookup;
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private ProjectSnapshotManagerBase _projectSnapshotManager;
- public DefaultDocumentVersionCache(ForegroundDispatcher foregroundDispatcher)
+ public DefaultDocumentVersionCache(ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher)
{
- if (foregroundDispatcher == null)
+ if (projectSnapshotManagerDispatcher == null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
- _foregroundDispatcher = foregroundDispatcher;
DocumentLookup = new Dictionary>(FilePathComparer.Instance);
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
}
public override void TrackDocumentVersion(DocumentSnapshot documentSnapshot, int version)
@@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(documentSnapshot));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
if (!DocumentLookup.TryGetValue(documentSnapshot.FilePath, out var documentEntries))
{
@@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(documentSnapshot));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
if (!DocumentLookup.TryGetValue(documentSnapshot.FilePath, out var documentEntries))
{
@@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
private void ProjectSnapshotManager_Changed(object sender, ProjectChangeEventArgs args)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
switch (args.Kind)
{
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultGeneratedDocumentContainerStore.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultGeneratedDocumentContainerStore.cs
index 650a29af3f..2e56cdf503 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultGeneratedDocumentContainerStore.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultGeneratedDocumentContainerStore.cs
@@ -4,7 +4,6 @@
using System;
using System.Collections.Concurrent;
using System.Threading;
-using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
@@ -13,19 +12,19 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
internal class DefaultGeneratedDocumentContainerStore : GeneratedDocumentContainerStore
{
private readonly ConcurrentDictionary _store;
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly DocumentVersionCache _documentVersionCache;
private readonly GeneratedDocumentPublisher _generatedDocumentPublisher;
private ProjectSnapshotManagerBase _projectSnapshotManager;
public DefaultGeneratedDocumentContainerStore(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
DocumentVersionCache documentVersionCache,
GeneratedDocumentPublisher generatedDocumentPublisher)
{
- if (foregroundDispatcher == null)
+ if (projectSnapshotManagerDispatcher == null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (documentVersionCache == null)
@@ -38,7 +37,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(generatedDocumentPublisher));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_documentVersionCache = documentVersionCache;
_generatedDocumentPublisher = generatedDocumentPublisher;
_store = new ConcurrentDictionary(FilePathComparer.Instance);
@@ -67,7 +66,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
// Internal for testing
internal void ProjectSnapshotManager_Changed(object sender, ProjectChangeEventArgs args)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
switch (args.Kind)
{
@@ -95,7 +94,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
var latestDocument = generatedDocumentContainer.LatestDocument;
- _ = Task.Factory.StartNew(() =>
+ _ = _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
if (!_projectSnapshotManager.IsDocumentOpen(filePath))
{
@@ -111,7 +110,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
var hostDocumentVersion = nullableHostDocumentVersion.Value;
_generatedDocumentPublisher.PublishCSharp(filePath, args.NewText, hostDocumentVersion);
- }, CancellationToken.None, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
+ }, CancellationToken.None);
};
documentContainer.GeneratedHtmlChanged += (sender, args) =>
@@ -120,7 +119,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
var latestDocument = generatedDocumentContainer.LatestDocument;
- _ = Task.Factory.StartNew(() =>
+ _ = _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
if (!_projectSnapshotManager.IsDocumentOpen(filePath))
{
@@ -136,7 +135,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
var hostDocumentVersion = nullableHostDocumentVersion.Value;
_generatedDocumentPublisher.PublishHtml(filePath, args.NewText, hostDocumentVersion);
- }, CancellationToken.None, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
+ }, CancellationToken.None);
};
return documentContainer;
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultGeneratedDocumentPublisher.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultGeneratedDocumentPublisher.cs
index 4e97ba240a..5b289bd629 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultGeneratedDocumentPublisher.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultGeneratedDocumentPublisher.cs
@@ -20,17 +20,17 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
private readonly Dictionary _publishedHtmlData;
private readonly IClientLanguageServer _server;
private readonly ILogger _logger;
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private ProjectSnapshotManagerBase _projectSnapshotManager;
public DefaultGeneratedDocumentPublisher(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
IClientLanguageServer server,
ILoggerFactory loggerFactory)
{
- if (foregroundDispatcher is null)
+ if (projectSnapshotManagerDispatcher is null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (server is null)
@@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(loggerFactory));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_server = server;
_logger = loggerFactory.CreateLogger();
_publishedCSharpData = new Dictionary(FilePathComparer.Instance);
@@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(sourceText));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
if (!_publishedCSharpData.TryGetValue(filePath, out var previouslyPublishedData))
{
@@ -123,7 +123,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(sourceText));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
if (!_publishedHtmlData.TryGetValue(filePath, out var previouslyPublishedData))
{
@@ -167,7 +167,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
private void ProjectSnapshotManager_Changed(object sender, ProjectChangeEventArgs args)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
switch (args.Kind)
{
@@ -178,12 +178,12 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
if (_publishedCSharpData.ContainsKey(args.DocumentFilePath))
{
var removed = _publishedCSharpData.Remove(args.DocumentFilePath);
- Debug.Assert(removed, "Published data should be protected by the foreground thread and should never fail to remove.");
+ Debug.Assert(removed, "Published data should be protected by the project snapshot manager's thread and should never fail to remove.");
}
if (_publishedHtmlData.ContainsKey(args.DocumentFilePath))
{
var removed = _publishedHtmlData.Remove(args.DocumentFilePath);
- Debug.Assert(removed, "Published data should be protected by the foreground thread and should never fail to remove.");
+ Debug.Assert(removed, "Published data should be protected by the project snapshot manager's thread and should never fail to remove.");
}
}
break;
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultHostDocumentFactory.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultHostDocumentFactory.cs
index 40a1501d08..e6378b25c4 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultHostDocumentFactory.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultHostDocumentFactory.cs
@@ -4,7 +4,6 @@
using System;
using System.Threading;
using System.Threading.Tasks;
-using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Text;
@@ -12,24 +11,15 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
internal class DefaultHostDocumentFactory : HostDocumentFactory
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
private readonly GeneratedDocumentContainerStore _generatedDocumentContainerStore;
- public DefaultHostDocumentFactory(
- ForegroundDispatcher foregroundDispatcher,
- GeneratedDocumentContainerStore generatedDocumentContainerStore)
+ public DefaultHostDocumentFactory(GeneratedDocumentContainerStore generatedDocumentContainerStore)
{
- if (foregroundDispatcher == null)
- {
- throw new ArgumentNullException(nameof(foregroundDispatcher));
- }
-
- if (generatedDocumentContainerStore == null)
+ if (generatedDocumentContainerStore is null)
{
throw new ArgumentNullException(nameof(generatedDocumentContainerStore));
}
- _foregroundDispatcher = foregroundDispatcher;
_generatedDocumentContainerStore = generatedDocumentContainerStore;
}
@@ -38,12 +28,12 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
public override HostDocument Create(string filePath, string targetFilePath, string fileKind)
{
- if (filePath == null)
+ if (filePath is null)
{
throw new ArgumentNullException(nameof(filePath));
}
- if (targetFilePath == null)
+ if (targetFilePath is null)
{
throw new ArgumentNullException(nameof(targetFilePath));
}
@@ -64,7 +54,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
() => sharedContainer.SetOutputAndCaptureReferenceAsync(latestDocument),
CancellationToken.None,
TaskCreationOptions.None,
- _foregroundDispatcher.BackgroundScheduler);
+ TaskScheduler.Default);
}
}
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultProjectSnapshotManagerAccessor.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultProjectSnapshotManagerAccessor.cs
index a3b5e2ed00..a14bd3624b 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultProjectSnapshotManagerAccessor.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultProjectSnapshotManagerAccessor.cs
@@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
internal class DefaultProjectSnapshotManagerAccessor : ProjectSnapshotManagerAccessor, IDisposable
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly IEnumerable _changeTriggers;
private readonly FilePathNormalizer _filePathNormalizer;
private readonly IOptionsMonitor _optionsMonitor;
@@ -21,15 +21,15 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
private bool _disposed;
public DefaultProjectSnapshotManagerAccessor(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
IEnumerable changeTriggers,
FilePathNormalizer filePathNormalizer,
IOptionsMonitor optionsMonitor,
AdhocWorkspaceFactory workspaceFactory)
{
- if (foregroundDispatcher == null)
+ if (projectSnapshotManagerDispatcher == null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (changeTriggers == null)
@@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(workspaceFactory));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_changeTriggers = changeTriggers;
_filePathNormalizer = filePathNormalizer;
_optionsMonitor = optionsMonitor;
@@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
new RemoteProjectSnapshotProjectEngineFactory(_filePathNormalizer, _optionsMonitor)
});
_instance = new DefaultProjectSnapshotManager(
- _foregroundDispatcher,
+ _projectSnapshotManagerDispatcher,
new DefaultErrorReporter(),
_changeTriggers,
workspace);
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorComponentSearchEngine.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorComponentSearchEngine.cs
index b60d7c19bd..e3a28d4da2 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorComponentSearchEngine.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultRazorComponentSearchEngine.cs
@@ -15,14 +15,14 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
internal class DefaultRazorComponentSearchEngine : RazorComponentSearchEngine
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly ProjectSnapshotManager _projectSnapshotManager;
public DefaultRazorComponentSearchEngine(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
ProjectSnapshotManagerAccessor projectSnapshotManagerAccessor)
{
- _foregroundDispatcher = foregroundDispatcher ?? throw new ArgumentNullException(nameof(foregroundDispatcher));
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher ?? throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
_projectSnapshotManager = projectSnapshotManagerAccessor?.Instance ?? throw new ArgumentNullException(nameof(projectSnapshotManagerAccessor));
}
@@ -45,11 +45,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
DefaultRazorTagHelperBinderPhase.ComponentDirectiveVisitor.TrySplitNamespaceAndType(tagHelper.Name, out var @namespaceName, out var typeName);
var lookupSymbolName = RemoveGenericContent(typeName);
- var projects = await Task.Factory.StartNew(
+ var projects = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
() => _projectSnapshotManager.Projects.ToArray(),
- CancellationToken.None,
- TaskCreationOptions.None,
- _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ CancellationToken.None).ConfigureAwait(false);
foreach (var project in projects)
{
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Definition/RazorDefinitionEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Definition/RazorDefinitionEndpoint.cs
index 14f9a7f4d5..a95033a500 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Definition/RazorDefinitionEndpoint.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Definition/RazorDefinitionEndpoint.cs
@@ -21,16 +21,16 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Definition
{
internal class RazorDefinitionEndpoint : IDefinitionHandler
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly DocumentResolver _documentResolver;
private readonly RazorComponentSearchEngine _componentSearchEngine;
public RazorDefinitionEndpoint(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
DocumentResolver documentResolver,
RazorComponentSearchEngine componentSearchEngine)
{
- _foregroundDispatcher = foregroundDispatcher ?? throw new ArgumentNullException(nameof(foregroundDispatcher));
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher ?? throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
_documentResolver = documentResolver ?? throw new ArgumentNullException(nameof(documentResolver));
_componentSearchEngine = componentSearchEngine ?? throw new ArgumentNullException(nameof(componentSearchEngine));
}
@@ -50,12 +50,12 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Definition
throw new ArgumentNullException(nameof(request));
}
- var documentSnapshot = await Task.Factory.StartNew(() =>
+ var documentSnapshot = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
var path = request.TextDocument.Uri.GetAbsoluteOrUNCPath();
_documentResolver.TryResolveDocument(path, out var documentSnapshot);
return documentSnapshot;
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ }, cancellationToken).ConfigureAwait(false);
if (documentSnapshot is null)
{
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/OmniSharpVSDiagnostic.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/OmniSharpVSDiagnostic.cs
index b1f2c3791f..f16d082c44 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/OmniSharpVSDiagnostic.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/OmniSharpVSDiagnostic.cs
@@ -20,46 +20,46 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Diagnostics
///
/// Gets or sets the project and context (e.g. Win32, MacOS, etc.) in which the diagnostic was generated.
///
- [JsonProperty("_ms_projects")]
- public OmniSharpVSProjectAndContext[]? Projects { get; set; }
+ [JsonProperty("_vs_projects")]
+ public OmniSharpVSDiagnosticProjectInformation[]? Projects { get; set; }
///
/// Gets or sets an expanded description of the diagnostic.
///
- [JsonProperty("_ms_expandedMessage")]
+ [JsonProperty("_vs_expandedMessage")]
public string? ExpandedMessage { get; set; }
///
/// Gets or sets a message shown when the user hovers over an error. If null, then message
/// is used (use to prevent a tool tip from being shown).
///
- [JsonProperty("_ms_toolTip")]
+ [JsonProperty("_vs_toolTip")]
public string? ToolTip { get; set; }
///
/// Gets or sets some non-human readable identifier so that two diagnostics that are
/// equivalent (e.g.a syntax error in both a build for Win32 and MacOs) can be consolidated.
///
- [JsonProperty("_ms_identifier")]
+ [JsonProperty("_vs_identifier")]
public string? Identifier { get; set; }
///
/// Gets or sets a string describing the diagnostic types (e.g. Security, Performance, Style, ...).
///
- [JsonProperty("_ms_diagnosticType")]
+ [JsonProperty("_vs_diagnosticType")]
public string? DiagnosticType { get; set; }
///
/// Gets or sets a rank associated with this diagnostic, used for the default sort.
/// Default == 300 will be used if no rank is specified.
///
- [JsonProperty("_ms_diagnosticRank")]
+ [JsonProperty("_vs_diagnosticRank")]
public OmniSharpVSDiagnosticRank? DiagnosticRank { get; set; }
///
/// Gets or sets an ID used to associate this diagnostic with a corresponding line in the output window.
///
- [JsonProperty("_ms_outputId")]
+ [JsonProperty("_vs_outputId")]
public int? OutputId { get; set; }
}
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/OmniSharpVSProjectAndContext.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/OmniSharpVSDiagnosticProjectInformation.cs
similarity index 81%
rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/OmniSharpVSProjectAndContext.cs
rename to src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/OmniSharpVSDiagnosticProjectInformation.cs
index 5bd250b7f2..c4bca4d2c2 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/OmniSharpVSProjectAndContext.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/OmniSharpVSDiagnosticProjectInformation.cs
@@ -3,24 +3,29 @@
#nullable enable
+using Newtonsoft.Json;
+
namespace Microsoft.AspNetCore.Razor.LanguageServer.Diagnostics
{
- internal class OmniSharpVSProjectAndContext
+ internal class OmniSharpVSDiagnosticProjectInformation
{
///
/// Gets or sets a human-readable identifier for the project in which the diagnostic was generated.
///
+ [JsonProperty("_vs_projectName")]
public string? ProjectName { get; set; }
///
/// Gets or sets a human-readable identifier for the build context (e.g. Win32 or MacOS)
/// in which the diagnostic was generated.
///
+ [JsonProperty("_vs_context")]
public string? Context { get; set; }
///
/// Gets or sets the unique identifier for the project in which the diagnostic was generated.
///
+ [JsonProperty("_vs_projectIdentifier")]
public string? ProjectIdentifier { get; set; }
}
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorDiagnosticsEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorDiagnosticsEndpoint.cs
index 2ed88f838f..764fdccb08 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorDiagnosticsEndpoint.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Diagnostics/RazorDiagnosticsEndpoint.cs
@@ -30,22 +30,22 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Diagnostics
"IDE0005_gen", // Using directive is unnecessary
};
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly DocumentResolver _documentResolver;
private readonly DocumentVersionCache _documentVersionCache;
private readonly RazorDocumentMappingService _documentMappingService;
private readonly ILogger _logger;
public RazorDiagnosticsEndpoint(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
DocumentResolver documentResolver,
DocumentVersionCache documentVersionCache,
RazorDocumentMappingService documentMappingService,
ILoggerFactory loggerFactory)
{
- if (foregroundDispatcher == null)
+ if (projectSnapshotManagerDispatcher == null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (documentResolver == null)
@@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Diagnostics
throw new ArgumentNullException(nameof(loggerFactory));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_documentResolver = documentResolver;
_documentVersionCache = documentVersionCache;
_documentMappingService = documentMappingService;
@@ -88,7 +88,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Diagnostics
int? documentVersion = null;
DocumentSnapshot documentSnapshot = null;
- await Task.Factory.StartNew(() =>
+ await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentResolver.TryResolveDocument(request.RazorDocumentUri.GetAbsoluteOrUNCPath(), out documentSnapshot);
@@ -99,7 +99,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Diagnostics
{
documentVersion = null;
}
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ }, cancellationToken).ConfigureAwait(false);
if (documentSnapshot is null)
{
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ExtendableServerCapabilities.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ExtendableServerCapabilities.cs
index 5ac148d77f..b8108f9887 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ExtendableServerCapabilities.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ExtendableServerCapabilities.cs
@@ -36,6 +36,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
TextDocumentSync = inner.TextDocumentSync;
CodeLensProvider = inner.CodeLensProvider;
Workspace = inner.Workspace;
+#pragma warning disable CS0618 // Type or member is obsolete
+ SemanticTokensProvider = inner.SemanticTokensProvider;
+#pragma warning restore CS0618 // Type or member is obsolete
RazorLanguageServerCapability.AddTo(this);
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/RazorFormattingEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/RazorFormattingEndpoint.cs
index 9ed76cd90d..e0f39a97c8 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/RazorFormattingEndpoint.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/RazorFormattingEndpoint.cs
@@ -22,22 +22,22 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
{
internal class RazorFormattingEndpoint : IDocumentFormattingHandler, IDocumentRangeFormattingHandler
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly DocumentResolver _documentResolver;
private readonly RazorFormattingService _razorFormattingService;
private readonly IOptionsMonitor _optionsMonitor;
private readonly ILogger _logger;
public RazorFormattingEndpoint(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
DocumentResolver documentResolver,
RazorFormattingService razorFormattingService,
IOptionsMonitor optionsMonitor,
ILoggerFactory loggerFactory)
{
- if (foregroundDispatcher is null)
+ if (projectSnapshotManagerDispatcher is null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (documentResolver is null)
@@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
throw new ArgumentNullException(nameof(loggerFactory));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_documentResolver = documentResolver;
_razorFormattingService = razorFormattingService;
_optionsMonitor = optionsMonitor;
@@ -90,12 +90,12 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
return null;
}
- var document = await Task.Factory.StartNew(() =>
+ var document = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentResolver.TryResolveDocument(request.TextDocument.Uri.GetAbsoluteOrUNCPath(), out var documentSnapshot);
return documentSnapshot;
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
+ }, cancellationToken);
if (document is null || cancellationToken.IsCancellationRequested)
{
@@ -124,12 +124,12 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Formatting
return null;
}
- var document = await Task.Factory.StartNew(() =>
+ var document = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentResolver.TryResolveDocument(request.TextDocument.Uri.GetAbsoluteOrUNCPath(), out var documentSnapshot);
return documentSnapshot;
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
+ }, cancellationToken);
if (document is null || cancellationToken.IsCancellationRequested)
{
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hover/RazorHoverEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hover/RazorHoverEndpoint.cs
index 405474ee77..7f50eeb938 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hover/RazorHoverEndpoint.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hover/RazorHoverEndpoint.cs
@@ -21,21 +21,21 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Hover
{
private HoverCapability _capability;
private readonly ILogger _logger;
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly DocumentResolver _documentResolver;
private readonly RazorHoverInfoService _hoverInfoService;
private readonly ClientNotifierServiceBase _languageServer;
public RazorHoverEndpoint(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
DocumentResolver documentResolver,
RazorHoverInfoService hoverInfoService,
ClientNotifierServiceBase languageServer,
ILoggerFactory loggerFactory)
{
- if (foregroundDispatcher is null)
+ if (projectSnapshotManagerDispatcher is null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (documentResolver is null)
@@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Hover
throw new ArgumentNullException(nameof(loggerFactory));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_documentResolver = documentResolver;
_hoverInfoService = hoverInfoService;
_languageServer = languageServer;
@@ -72,12 +72,12 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Hover
throw new ArgumentNullException(nameof(request));
}
- var document = await Task.Factory.StartNew(() =>
+ var document = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentResolver.TryResolveDocument(request.TextDocument.Uri.GetAbsoluteOrUNCPath(), out var documentSnapshot);
return documentSnapshot;
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
+ }, cancellationToken);
if (document is null)
{
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hover/VSHover.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hover/VSHover.cs
index 9624b44c46..1be0bf5a6b 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hover/VSHover.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Hover/VSHover.cs
@@ -3,12 +3,14 @@
#nullable enable
+using Newtonsoft.Json;
using HoverModel = OmniSharp.Extensions.LanguageServer.Protocol.Models.Hover;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Hover
{
internal class VSHover : HoverModel
{
+ [JsonProperty("_vs_rawContent")]
public object? RawContent { get; set; }
}
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/MonitorProjectConfigurationFilePathEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/MonitorProjectConfigurationFilePathEndpoint.cs
index 4a72999667..5f7a9923bb 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/MonitorProjectConfigurationFilePathEndpoint.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/MonitorProjectConfigurationFilePathEndpoint.cs
@@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
internal class MonitorProjectConfigurationFilePathEndpoint : IMonitorProjectConfigurationFilePathHandler, IDisposable
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly FilePathNormalizer _filePathNormalizer;
private readonly WorkspaceDirectoryPathResolver _workspaceDirectoryPathResolver;
private readonly IEnumerable _listeners;
@@ -25,14 +25,14 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
private bool _disposed;
public MonitorProjectConfigurationFilePathEndpoint(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
FilePathNormalizer filePathNormalizer,
WorkspaceDirectoryPathResolver workspaceDirectoryPathResolver,
IEnumerable listeners)
{
- if (foregroundDispatcher is null)
+ if (projectSnapshotManagerDispatcher is null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (filePathNormalizer is null)
@@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(listeners));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_filePathNormalizer = filePathNormalizer;
_workspaceDirectoryPathResolver = workspaceDirectoryPathResolver;
_listeners = listeners;
@@ -191,6 +191,6 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
}
// Protected virtual for testing
- protected virtual IFileChangeDetector CreateFileChangeDetector() => new ProjectConfigurationFileChangeDetector(_foregroundDispatcher, _filePathNormalizer, _listeners);
+ protected virtual IFileChangeDetector CreateFileChangeDetector() => new ProjectConfigurationFileChangeDetector(_projectSnapshotManagerDispatcher, _filePathNormalizer, _listeners);
}
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/OpenDocumentGenerator.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/OpenDocumentGenerator.cs
index 0bd5e11fa7..6c4c448af8 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/OpenDocumentGenerator.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/OpenDocumentGenerator.cs
@@ -5,7 +5,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
-using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.Extensions.Internal;
@@ -14,35 +13,35 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
internal class OpenDocumentGenerator : ProjectSnapshotChangeTrigger
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly IReadOnlyList _documentProcessedListeners;
private readonly Dictionary _work;
private ProjectSnapshotManagerBase _projectManager;
private Timer _timer;
public OpenDocumentGenerator(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
IEnumerable documentProcessedListeners)
{
- if (foregroundDispatcher == null)
+ if (projectSnapshotManagerDispatcher is null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
- if (documentProcessedListeners == null)
+ if (documentProcessedListeners is null)
{
throw new ArgumentNullException(nameof(documentProcessedListeners));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_documentProcessedListeners = documentProcessedListeners.ToArray();
_work = new Dictionary(StringComparer.Ordinal);
}
// For testing only
- protected OpenDocumentGenerator(ForegroundDispatcher foregroundDispatcher)
+ protected OpenDocumentGenerator(ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher)
{
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_work = new Dictionary(StringComparer.Ordinal);
_documentProcessedListeners = Array.Empty();
}
@@ -136,7 +135,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
// Internal for testing
internal void Enqueue(DocumentSnapshot document)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
if (!_projectManager.IsDocumentOpen(document.FilePath))
{
@@ -170,8 +169,6 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
try
{
- _foregroundDispatcher.AssertBackgroundThread();
-
OnStartingBackgroundWork();
KeyValuePair[] work;
@@ -200,11 +197,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
if (_documentProcessedListeners.Count != 0)
{
- await Task.Factory.StartNew(
+ await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
() => NotifyDocumentsProcessed(work),
- CancellationToken.None,
- TaskCreationOptions.None,
- _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ CancellationToken.None).ConfigureAwait(false);
}
lock (_work)
@@ -246,7 +241,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
private void ProjectSnapshotManager_Changed(object sender, ProjectChangeEventArgs args)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
switch (args.Kind)
{
@@ -308,11 +303,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
private void ReportError(Exception ex)
{
- _ = Task.Factory.StartNew(
+ _ = _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
() => _projectManager.ReportError(ex),
- CancellationToken.None,
- TaskCreationOptions.None,
- _foregroundDispatcher.ForegroundScheduler);
+ CancellationToken.None);
}
}
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/PlatformAgnosticClientCapabilities.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/PlatformAgnosticClientCapabilities.cs
index b2f3e651e3..1c6ec168e6 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/PlatformAgnosticClientCapabilities.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/PlatformAgnosticClientCapabilities.cs
@@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.LanguageServer.Serialization;
+using Newtonsoft.Json;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
namespace Microsoft.AspNetCore.Razor.LanguageServer
@@ -13,8 +14,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
public static readonly PlatformExtensionConverter JsonConverter = new PlatformExtensionConverter();
- public bool SupportsCodeActionResolve { get; set; } = false;
-
+ [JsonProperty("_vs_supportsVisualStudioExtensions")]
public bool SupportsVisualStudioExtensions { get; set; } = false;
}
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeDetector.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeDetector.cs
index 30dec9439e..a0d959ac61 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeDetector.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationFileChangeDetector.cs
@@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
internal class ProjectConfigurationFileChangeDetector : IFileChangeDetector
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly FilePathNormalizer _filePathNormalizer;
private readonly IEnumerable _listeners;
private readonly ILogger _logger;
@@ -28,14 +28,14 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
};
public ProjectConfigurationFileChangeDetector(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
FilePathNormalizer filePathNormalizer,
IEnumerable listeners,
ILoggerFactory loggerFactory = null)
{
- if (foregroundDispatcher is null)
+ if (projectSnapshotManagerDispatcher is null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (filePathNormalizer is null)
@@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(listeners));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_filePathNormalizer = filePathNormalizer;
_listeners = listeners;
_logger = loggerFactory?.CreateLogger();
@@ -66,13 +66,13 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
workspaceDirectory = _filePathNormalizer.Normalize(workspaceDirectory);
var existingConfigurationFiles = GetExistingConfigurationFiles(workspaceDirectory);
- await Task.Factory.StartNew(() =>
+ await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
foreach (var configurationFilePath in existingConfigurationFiles)
{
FileSystemWatcher_ProjectConfigurationFileEvent(configurationFilePath, RazorFileChangeKind.Added);
}
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
+ }, cancellationToken);
// This is an entry point for testing
OnInitializationFinished();
@@ -134,9 +134,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
private void FileSystemWatcher_ProjectConfigurationFileEvent_Background(string physicalFilePath, RazorFileChangeKind kind)
{
- _ = Task.Factory.StartNew(
+ _ = _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
() => FileSystemWatcher_ProjectConfigurationFileEvent(physicalFilePath, kind),
- CancellationToken.None, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
+ CancellationToken.None);
}
private void FileSystemWatcher_ProjectConfigurationFileEvent(string physicalFilePath, RazorFileChangeKind kind)
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs
index cd6ab0a547..ffbc47d514 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectConfigurationStateSynchronizer.cs
@@ -14,20 +14,20 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
internal class ProjectConfigurationStateSynchronizer : IProjectConfigurationFileChangeListener
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly RazorProjectService _projectService;
private readonly FilePathNormalizer _filePathNormalizer;
private readonly Dictionary _configurationToProjectMap;
internal readonly Dictionary ProjectInfoMap;
public ProjectConfigurationStateSynchronizer(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
RazorProjectService projectService,
FilePathNormalizer filePathNormalizer)
{
- if (foregroundDispatcher is null)
+ if (projectSnapshotManagerDispatcher is null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (projectService is null)
@@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(filePathNormalizer));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_projectService = projectService;
_filePathNormalizer = filePathNormalizer;
_configurationToProjectMap = new Dictionary(FilePathComparer.Instance);
@@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(args));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
switch (args.Kind)
{
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectFileChangeDetector.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectFileChangeDetector.cs
index 98b947d132..3ec7a8bf5e 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectFileChangeDetector.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectFileChangeDetector.cs
@@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
private const string ProjectFileExtension = ".csproj";
private const string ProjectFileExtensionPattern = "*" + ProjectFileExtension;
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly FilePathNormalizer _filePathNormalizer;
private readonly IEnumerable _listeners;
private FileSystemWatcher _watcher;
@@ -28,13 +28,13 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
};
public ProjectFileChangeDetector(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
FilePathNormalizer filePathNormalizer,
IEnumerable listeners)
{
- if (foregroundDispatcher is null)
+ if (projectSnapshotManagerDispatcher is null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (filePathNormalizer is null)
@@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(listeners));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_filePathNormalizer = filePathNormalizer;
_listeners = listeners;
}
@@ -64,13 +64,13 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
workspaceDirectory = _filePathNormalizer.Normalize(workspaceDirectory);
var existingProjectFiles = GetExistingProjectFiles(workspaceDirectory);
- await Task.Factory.StartNew(() =>
+ await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
foreach (var projectFilePath in existingProjectFiles)
{
FileSystemWatcher_ProjectFileEvent(projectFilePath, RazorFileChangeKind.Added);
}
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
+ }, cancellationToken);
// This is an entry point for testing
OnInitializationFinished();
@@ -134,9 +134,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
private void FileSystemWatcher_ProjectFileEvent_Background(string physicalFilePath, RazorFileChangeKind kind)
{
- _ = Task.Factory.StartNew(
+ _ = _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
() => FileSystemWatcher_ProjectFileEvent(physicalFilePath, kind),
- CancellationToken.None, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
+ CancellationToken.None);
}
private void FileSystemWatcher_ProjectFileEvent(string physicalFilePath, RazorFileChangeKind kind)
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectFileSynchronizer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectFileSynchronizer.cs
index a75453adf6..9a9ea289f3 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectFileSynchronizer.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectFileSynchronizer.cs
@@ -10,16 +10,16 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
internal class ProjectFileSynchronizer : IProjectFileChangeListener
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly RazorProjectService _projectService;
public ProjectFileSynchronizer(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
RazorProjectService projectService)
{
- if (foregroundDispatcher is null)
+ if (projectSnapshotManagerDispatcher is null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (projectService is null)
@@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(projectService));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_projectService = projectService;
}
@@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(filePath));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
switch (kind)
{
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultDocumentResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultDocumentResolver.cs
index 6a9707b2ed..58f79d714c 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultDocumentResolver.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultDocumentResolver.cs
@@ -10,18 +10,18 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
{
internal class DefaultDocumentResolver : DocumentResolver
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly ProjectResolver _projectResolver;
private readonly FilePathNormalizer _filePathNormalizer;
public DefaultDocumentResolver(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
ProjectResolver projectResolver,
FilePathNormalizer filePathNormalizer)
{
- if (foregroundDispatcher == null)
+ if (projectSnapshotManagerDispatcher == null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (projectResolver == null)
@@ -34,14 +34,14 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
throw new ArgumentNullException(nameof(filePathNormalizer));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_projectResolver = projectResolver;
_filePathNormalizer = filePathNormalizer;
}
public override bool TryResolveDocument(string documentFilePath, out DocumentSnapshot document)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
var normalizedPath = _filePathNormalizer.Normalize(documentFilePath);
if (!_projectResolver.TryResolveProject(normalizedPath, out var project))
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultProjectResolver.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultProjectResolver.cs
index 9e9f77bf82..0ace3de1ff 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultProjectResolver.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultProjectResolver.cs
@@ -14,18 +14,18 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
// Internal for testing
protected internal readonly HostProject MiscellaneousHostProject;
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly FilePathNormalizer _filePathNormalizer;
private readonly ProjectSnapshotManagerAccessor _projectSnapshotManagerAccessor;
public DefaultProjectResolver(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
FilePathNormalizer filePathNormalizer,
ProjectSnapshotManagerAccessor projectSnapshotManagerAccessor)
{
- if (foregroundDispatcher == null)
+ if (projectSnapshotManagerDispatcher == null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (filePathNormalizer == null)
@@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
throw new ArgumentNullException(nameof(projectSnapshotManagerAccessor));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_filePathNormalizer = filePathNormalizer;
_projectSnapshotManagerAccessor = projectSnapshotManagerAccessor;
@@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
throw new ArgumentNullException(nameof(documentFilePath));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
var normalizedDocumentPath = _filePathNormalizer.Normalize(documentFilePath);
var projects = _projectSnapshotManagerAccessor.Instance.Projects;
@@ -91,7 +91,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
public override ProjectSnapshot GetMiscellaneousProject()
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
var miscellaneousProject = _projectSnapshotManagerAccessor.Instance.GetLoadedProject(MiscellaneousHostProject.FilePath);
if (miscellaneousProject == null)
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultRazorProjectService.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultRazorProjectService.cs
index 41c7f39586..e32028acf4 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultRazorProjectService.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/ProjectSystem/DefaultRazorProjectService.cs
@@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
internal class DefaultRazorProjectService : RazorProjectService
{
private readonly ProjectSnapshotManagerAccessor _projectSnapshotManagerAccessor;
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly HostDocumentFactory _hostDocumentFactory;
private readonly RemoteTextLoaderFactory _remoteTextLoaderFactory;
private readonly ProjectResolver _projectResolver;
@@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
private readonly ILogger _logger;
public DefaultRazorProjectService(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
HostDocumentFactory hostDocumentFactory,
RemoteTextLoaderFactory remoteTextLoaderFactory,
DocumentResolver documentResolver,
@@ -41,9 +41,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
ProjectSnapshotManagerAccessor projectSnapshotManagerAccessor,
ILoggerFactory loggerFactory)
{
- if (foregroundDispatcher == null)
+ if (projectSnapshotManagerDispatcher == null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (hostDocumentFactory == null)
@@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
throw new ArgumentNullException(nameof(loggerFactory));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_hostDocumentFactory = hostDocumentFactory;
_remoteTextLoaderFactory = remoteTextLoaderFactory;
_documentResolver = documentResolver;
@@ -99,7 +99,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
public override void AddDocument(string filePath)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
var textDocumentPath = _filePathNormalizer.Normalize(filePath);
if (_documentResolver.TryResolveDocument(textDocumentPath, out var _))
@@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
public override void OpenDocument(string filePath, SourceText sourceText, int version)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
var textDocumentPath = _filePathNormalizer.Normalize(filePath);
if (!_documentResolver.TryResolveDocument(textDocumentPath, out _))
@@ -166,7 +166,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
public override void CloseDocument(string filePath)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
var textDocumentPath = _filePathNormalizer.Normalize(filePath);
if (!_projectResolver.TryResolveProject(textDocumentPath, out var projectSnapshot))
@@ -182,7 +182,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
public override void RemoveDocument(string filePath)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
var textDocumentPath = _filePathNormalizer.Normalize(filePath);
if (!_projectResolver.TryResolveProject(textDocumentPath, out var projectSnapshot))
@@ -204,7 +204,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
public override void UpdateDocument(string filePath, SourceText sourceText, int version)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
var textDocumentPath = _filePathNormalizer.Normalize(filePath);
if (!_projectResolver.TryResolveProject(textDocumentPath, out var projectSnapshot))
@@ -221,7 +221,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
public override void AddProject(string filePath)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
var normalizedPath = _filePathNormalizer.Normalize(filePath);
@@ -242,7 +242,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
public override void RemoveProject(string filePath)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
var normalizedPath = _filePathNormalizer.Normalize(filePath);
var project = (DefaultProjectSnapshot)_projectSnapshotManagerAccessor.Instance.GetLoadedProject(normalizedPath);
@@ -266,7 +266,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
ProjectWorkspaceState projectWorkspaceState,
IReadOnlyList documents)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
var normalizedPath = _filePathNormalizer.Normalize(filePath);
var project = (DefaultProjectSnapshot)_projectSnapshotManagerAccessor.Instance.GetLoadedProject(normalizedPath);
@@ -411,7 +411,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
// Internal for testing
internal void TryMigrateDocumentsFromRemovedProject(ProjectSnapshot project)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
var miscellaneousProject = _projectResolver.GetMiscellaneousProject();
@@ -437,7 +437,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem
// Internal for testing
internal void TryMigrateMiscellaneousDocumentsToProject()
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
var miscellaneousProject = _projectResolver.GetMiscellaneousProject();
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorDiagnosticsPublisher.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorDiagnosticsPublisher.cs
index d00e13321b..56893d9357 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorDiagnosticsPublisher.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorDiagnosticsPublisher.cs
@@ -26,20 +26,20 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
internal Timer _documentClosedTimer;
private static readonly TimeSpan s_checkForDocumentClosedDelay = TimeSpan.FromSeconds(5);
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly ITextDocumentLanguageServer _languageServer;
private readonly Dictionary _work;
private readonly ILogger _logger;
private ProjectSnapshotManager _projectManager;
public RazorDiagnosticsPublisher(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
ITextDocumentLanguageServer languageServer,
ILoggerFactory loggerFactory)
{
- if (foregroundDispatcher == null)
+ if (projectSnapshotManagerDispatcher == null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (languageServer == null)
@@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(loggerFactory));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_languageServer = languageServer;
PublishedDiagnostics = new Dictionary>(FilePathComparer.Instance);
_work = new Dictionary(FilePathComparer.Instance);
@@ -82,7 +82,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(document));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
lock (_work)
{
@@ -114,11 +114,9 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
private async void DocumentClosedTimer_Tick(object state)
#pragma warning restore VSTHRD100 // Avoid async void methods
{
- await Task.Factory.StartNew(
+ await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
ClearClosedDocuments,
- CancellationToken.None,
- TaskCreationOptions.None,
- _foregroundDispatcher.ForegroundScheduler);
+ CancellationToken.None);
}
// Internal for testing
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorDocumentSynchronizationEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorDocumentSynchronizationEndpoint.cs
index d77a30ea50..b231fe0991 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorDocumentSynchronizationEndpoint.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorDocumentSynchronizationEndpoint.cs
@@ -22,37 +22,37 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
private SynchronizationCapability _capability;
private readonly ILogger _logger;
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly DocumentResolver _documentResolver;
private readonly RazorProjectService _projectService;
public RazorDocumentSynchronizationEndpoint(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
DocumentResolver documentResolver,
RazorProjectService projectService,
ILoggerFactory loggerFactory)
{
- if (foregroundDispatcher == null)
+ if (projectSnapshotManagerDispatcher is null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
- if (documentResolver == null)
+ if (documentResolver is null)
{
throw new ArgumentNullException(nameof(documentResolver));
}
- if (projectService == null)
+ if (projectService is null)
{
throw new ArgumentNullException(nameof(projectService));
}
- if (loggerFactory == null)
+ if (loggerFactory is null)
{
throw new ArgumentNullException(nameof(loggerFactory));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_documentResolver = documentResolver;
_projectService = projectService;
_logger = loggerFactory.CreateLogger();
@@ -67,14 +67,12 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
public async Task Handle(DidChangeTextDocumentParams notification, CancellationToken token)
{
- _foregroundDispatcher.AssertBackgroundThread();
-
- var document = await Task.Factory.StartNew(() =>
+ var document = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentResolver.TryResolveDocument(notification.TextDocument.Uri.GetAbsoluteOrUNCPath(), out var documentSnapshot);
return documentSnapshot;
- }, CancellationToken.None, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
+ }, CancellationToken.None);
var sourceText = await document.GetTextAsync();
sourceText = ApplyContentChanges(notification.ContentChanges, sourceText);
@@ -84,19 +82,15 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new InvalidOperationException(RazorLS.Resources.Version_Should_Not_Be_Null);
}
- await Task.Factory.StartNew(
+ await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
() => _projectService.UpdateDocument(document.FilePath, sourceText, notification.TextDocument.Version.Value),
- CancellationToken.None,
- TaskCreationOptions.None,
- _foregroundDispatcher.ForegroundScheduler);
+ CancellationToken.None);
return Unit.Value;
}
public async Task Handle(DidOpenTextDocumentParams notification, CancellationToken token)
{
- _foregroundDispatcher.AssertBackgroundThread();
-
var sourceText = SourceText.From(notification.TextDocument.Text);
if (notification.TextDocument.Version is null)
@@ -104,24 +98,18 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new InvalidOperationException(RazorLS.Resources.Version_Should_Not_Be_Null);
}
- await Task.Factory.StartNew(
+ await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
() => _projectService.OpenDocument(notification.TextDocument.Uri.GetAbsoluteOrUNCPath(), sourceText, notification.TextDocument.Version.Value),
- CancellationToken.None,
- TaskCreationOptions.None,
- _foregroundDispatcher.ForegroundScheduler);
+ CancellationToken.None);
return Unit.Value;
}
public async Task Handle(DidCloseTextDocumentParams notification, CancellationToken token)
{
- _foregroundDispatcher.AssertBackgroundThread();
-
- await Task.Factory.StartNew(
+ await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
() => _projectService.CloseDocument(notification.TextDocument.Uri.GetAbsoluteOrUNCPath()),
- CancellationToken.None,
- TaskCreationOptions.None,
- _foregroundDispatcher.ForegroundScheduler);
+ CancellationToken.None);
return Unit.Value;
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorFileChangeDetector.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorFileChangeDetector.cs
index 850336599c..0b81432bc0 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorFileChangeDetector.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorFileChangeDetector.cs
@@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
// Internal for testing
internal readonly Dictionary PendingNotifications;
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly FilePathNormalizer _filePathNormalizer;
private readonly IEnumerable _listeners;
private readonly List _watchers;
@@ -32,13 +32,13 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
};
public RazorFileChangeDetector(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
FilePathNormalizer filePathNormalizer,
IEnumerable listeners)
{
- if (foregroundDispatcher is null)
+ if (projectSnapshotManagerDispatcher is null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (filePathNormalizer is null)
@@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(listeners));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_filePathNormalizer = filePathNormalizer;
_listeners = listeners;
_watchers = new List(s_razorFileExtensions.Count);
@@ -80,13 +80,13 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
var existingRazorFiles = GetExistingRazorFiles(workspaceDirectory);
- await Task.Factory.StartNew(() =>
+ await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
foreach (var razorFilePath in existingRazorFiles)
{
FileSystemWatcher_RazorFileEvent(razorFilePath, RazorFileChangeKind.Added);
}
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
+ }, cancellationToken);
// This is an entry point for testing
OnInitializationFinished();
@@ -211,12 +211,12 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
OnStartingDelayedNotificationWork();
- await Task.Factory.StartNew(
- () => NotifyAfterDelay_Foreground(physicalFilePath),
- CancellationToken.None, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
+ await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
+ () => NotifyAfterDelay_ProjectSnapshotManagerDispatcher(physicalFilePath),
+ CancellationToken.None);
}
- private void NotifyAfterDelay_Foreground(string physicalFilePath)
+ private void NotifyAfterDelay_ProjectSnapshotManagerDispatcher(string physicalFilePath)
{
lock (_pendingNotificationsLock)
{
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorFileSynchronizer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorFileSynchronizer.cs
index 6afee33451..e91e66e5ed 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorFileSynchronizer.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorFileSynchronizer.cs
@@ -10,16 +10,16 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
internal class RazorFileSynchronizer : IRazorFileChangeListener
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly RazorProjectService _projectService;
public RazorFileSynchronizer(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
RazorProjectService projectService)
{
- if (foregroundDispatcher is null)
+ if (projectSnapshotManagerDispatcher is null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (projectService is null)
@@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(projectService));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_projectService = projectService;
}
@@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(filePath));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
switch (kind)
{
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageEndpoint.cs
index 4397aef4ce..80af7eb585 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageEndpoint.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageEndpoint.cs
@@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
IRazorMapToDocumentRangesHandler,
IRazorMapToDocumentEditsHandler
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly DocumentResolver _documentResolver;
private readonly DocumentVersionCache _documentVersionCache;
private readonly RazorDocumentMappingService _documentMappingService;
@@ -31,16 +31,16 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
private readonly ILogger _logger;
public RazorLanguageEndpoint(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
DocumentResolver documentResolver,
DocumentVersionCache documentVersionCache,
RazorDocumentMappingService documentMappingService,
RazorFormattingService razorFormattingService,
ILoggerFactory loggerFactory)
{
- if (foregroundDispatcher == null)
+ if (projectSnapshotManagerDispatcher == null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (documentResolver == null)
@@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(loggerFactory));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_documentResolver = documentResolver;
_documentVersionCache = documentVersionCache;
_documentMappingService = documentMappingService;
@@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
int? documentVersion = null;
DocumentSnapshot documentSnapshot = null;
- await Task.Factory.StartNew(() =>
+ await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentResolver.TryResolveDocument(request.Uri.GetAbsoluteOrUNCPath(), out documentSnapshot);
@@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
}
return documentSnapshot;
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
+ }, cancellationToken);
var codeDocument = await documentSnapshot.GetGeneratedOutputAsync();
var sourceText = await documentSnapshot.GetTextAsync();
@@ -155,7 +155,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
int? documentVersion = null;
DocumentSnapshot documentSnapshot = null;
- await Task.Factory.StartNew(() =>
+ await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentResolver.TryResolveDocument(request.RazorDocumentUri.GetAbsoluteOrUNCPath(), out documentSnapshot);
@@ -166,7 +166,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
documentVersion = null;
}
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
+ }, cancellationToken);
if (request.Kind != RazorLanguageKind.CSharp)
{
@@ -215,7 +215,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
int? documentVersion = null;
DocumentSnapshot documentSnapshot = null;
- await Task.Factory.StartNew(() =>
+ await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentResolver.TryResolveDocument(request.RazorDocumentUri.GetAbsoluteOrUNCPath(), out documentSnapshot);
@@ -225,7 +225,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
documentVersion = null;
}
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
+ }, cancellationToken);
var codeDocument = await documentSnapshot.GetGeneratedOutputAsync();
if (codeDocument.IsUnsupported())
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs
index ea6038c9a3..9a99c9c6e9 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorLanguageServer.cs
@@ -81,7 +81,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
// request is made any Parallel requests will be cancelled because the assumption is that Serial requests modify state, and that
// therefore any Parallel request is now invalid and should just try again. A specific instance of this can be seen when you
// hover over a TagHelper while the switch is set to true. Hover is parallel, and a lot of our endpoints like
- // textDocument/_ms_onAutoInsert, and razor/languageQuery are Serial. I BELIEVE that specifically what happened is the serial
+ // textDocument/_vs_onAutoInsert, and razor/languageQuery are Serial. I BELIEVE that specifically what happened is the serial
// languageQuery event gets fired by our semantic tokens endpoint (which fires constantly), cancelling the hover, which red-bars.
// We can prevent that behavior entirely by doing WithContentModifiedSupport, at the possible expense of some delays due doing all requests in serial.
//
@@ -122,8 +122,6 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
.WithHandler()
.WithHandler()
.WithHandler()
- .AddHandlerLink(LanguageServerConstants.RazorSemanticTokensEditEndpoint, LanguageServerConstants.LegacyRazorSemanticTokensEditEndpoint)
- .AddHandlerLink(LanguageServerConstants.RazorSemanticTokensEndpoint, LanguageServerConstants.LegacyRazorSemanticTokensEndpoint)
.WithHandler()
.WithHandler()
.WithHandler()
@@ -138,7 +136,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
.AddLanguageProtocolLogging(logLevel));
services.AddSingleton();
- services.AddSingleton();
+ services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton((services) => services.GetRequiredService());
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorServerReadyPublisher.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorServerReadyPublisher.cs
index fca66c137e..38b48eaf62 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorServerReadyPublisher.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorServerReadyPublisher.cs
@@ -11,18 +11,18 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
{
internal class RazorServerReadyPublisher : ProjectSnapshotChangeTrigger
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private ProjectSnapshotManagerBase _projectManager;
private readonly ClientNotifierServiceBase _clientNotifierService;
private bool _hasNotified = false;
public RazorServerReadyPublisher(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
ClientNotifierServiceBase clientNotifierService)
{
- if (foregroundDispatcher is null)
+ if (projectSnapshotManagerDispatcher is null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (clientNotifierService is null)
@@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
throw new ArgumentNullException(nameof(clientNotifierService));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_clientNotifierService = clientNotifierService;
}
@@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer
private async void ProjectSnapshotManager_Changed(object sender, ProjectChangeEventArgs args)
#pragma warning restore VSTHRD100 // Avoid async void methods
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
var projectSnapshot = args.Newer;
if (projectSnapshot?.ProjectWorkspaceState != null && !_hasNotified)
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/RazorComponentRenameEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/RazorComponentRenameEndpoint.cs
index 2a186fbaf0..c3ee45c51d 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/RazorComponentRenameEndpoint.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Refactoring/RazorComponentRenameEndpoint.cs
@@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Refactoring
{
internal class RazorComponentRenameEndpoint : IRenameHandler
{
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly DocumentResolver _documentResolver;
private readonly ProjectSnapshotManager _projectSnapshotManager;
private readonly RazorComponentSearchEngine _componentSearchEngine;
@@ -35,13 +35,13 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Refactoring
private RenameCapability _capability;
public RazorComponentRenameEndpoint(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
DocumentResolver documentResolver,
RazorComponentSearchEngine componentSearchEngine,
ProjectSnapshotManagerAccessor projectSnapshotManagerAccessor,
LanguageServerFeatureOptions languageServerFeatureOptions)
{
- _foregroundDispatcher = foregroundDispatcher ?? throw new ArgumentNullException(nameof(foregroundDispatcher));
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher ?? throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
_documentResolver = documentResolver ?? throw new ArgumentNullException(nameof(documentResolver));
_componentSearchEngine = componentSearchEngine ?? throw new ArgumentNullException(nameof(componentSearchEngine));
_projectSnapshotManager = projectSnapshotManagerAccessor?.Instance ?? throw new ArgumentNullException(nameof(projectSnapshotManagerAccessor));
@@ -70,12 +70,12 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Refactoring
return null;
}
- var requestDocumentSnapshot = await Task.Factory.StartNew(() =>
+ var requestDocumentSnapshot = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
var path = request.TextDocument.Uri.GetAbsoluteOrUNCPath();
_documentResolver.TryResolveDocument(path, out var documentSnapshot);
return documentSnapshot;
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ }, cancellationToken).ConfigureAwait(false);
if (requestDocumentSnapshot is null)
{
@@ -118,7 +118,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Refactoring
var documentSnapshots = await GetAllDocumentSnapshotsAsync(requestDocumentSnapshot, cancellationToken).ConfigureAwait(false);
foreach (var documentSnapshot in documentSnapshots)
{
- await AddEditsForCodeDocumentAsync(documentChanges, originTagHelpers, request.NewName, documentSnapshot, cancellationToken);
+ await AddEditsForCodeDocumentAsync(documentChanges, originTagHelpers, request.NewName, documentSnapshot);
}
return new WorkspaceEdit
@@ -129,7 +129,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Refactoring
private async Task> GetAllDocumentSnapshotsAsync(DocumentSnapshot skipDocumentSnapshot, CancellationToken cancellationToken)
{
- return await Task.Factory.StartNew(() =>
+ return await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
var documentSnapshots = new List();
var documentPaths = new HashSet();
@@ -156,7 +156,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Refactoring
}
}
return documentSnapshots;
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ }, cancellationToken).ConfigureAwait(false);
}
public void AddFileRenameForComponent(List documentChanges, DocumentSnapshot documentSnapshot, string newPath)
@@ -188,12 +188,11 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Refactoring
return newPath;
}
- public async Task AddEditsForCodeDocumentAsync(
+ private async Task AddEditsForCodeDocumentAsync(
List documentChanges,
IReadOnlyList originTagHelpers,
string newName,
- DocumentSnapshot documentSnapshot,
- CancellationToken cancellationToken)
+ DocumentSnapshot documentSnapshot)
{
if (documentSnapshot is null)
{
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Models/LegacySemanticTokensOptions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Models/LegacySemanticTokensOptions.cs
deleted file mode 100644
index 7adf2e3957..0000000000
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Models/LegacySemanticTokensOptions.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-#pragma warning disable CS0618
-#nullable enable
-using OmniSharp.Extensions.LanguageServer.Protocol.Models.Proposals;
-
-namespace Microsoft.AspNetCore.Razor.LanguageServer.Semantic.Models
-{
- internal class LegacySemanticTokensOptions
- {
- public SemanticTokensLegend? Legend { get; set; }
-
- public bool RangeProvider { get; set; }
-
- public SemanticTokensDocumentProviderOptions? DocumentProvider { get; set; }
- }
-}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/RazorSemanticTokensEndpoint.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/RazorSemanticTokensEndpoint.cs
index 8a29f556e2..c14e9c99af 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/RazorSemanticTokensEndpoint.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/RazorSemanticTokensEndpoint.cs
@@ -5,7 +5,6 @@
using System;
using System.Threading;
using System.Threading.Tasks;
-using Microsoft.AspNetCore.Razor.LanguageServer.Common;
using Microsoft.AspNetCore.Razor.LanguageServer.Semantic.Models;
using Microsoft.Extensions.Logging;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
@@ -15,7 +14,7 @@ using OmniSharp.Extensions.LanguageServer.Protocol.Models.Proposals;
namespace Microsoft.AspNetCore.Razor.LanguageServer.Semantic
{
- internal class RazorSemanticTokensEndpoint : ISemanticTokensHandler, ISemanticTokensRangeHandler, ISemanticTokensDeltaHandler, IRegistrationExtension
+ internal class RazorSemanticTokensEndpoint : ISemanticTokensHandler, ISemanticTokensRangeHandler, ISemanticTokensDeltaHandler
{
private SemanticTokensCapability? _capability;
@@ -96,19 +95,6 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Semantic
_capability = capability;
}
- public RegistrationExtensionResult GetRegistration()
- {
- return new RegistrationExtensionResult(LanguageServerConstants.SemanticTokensProviderName, new LegacySemanticTokensOptions
- {
- DocumentProvider = new SemanticTokensDocumentProviderOptions
- {
- Edits = true,
- },
- Legend = RazorSemanticTokensLegend.Instance,
- RangeProvider = true,
- });
- }
-
private async Task HandleAsync(TextDocumentIdentifier textDocument, CancellationToken cancellationToken, Range? range = null)
{
var tokens = await _semanticTokensInfoService.GetSemanticTokensAsync(textDocument, range, cancellationToken);
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/DefaultRazorSemanticTokensInfoService.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/DefaultRazorSemanticTokensInfoService.cs
index 6e28c50a61..b60768a775 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/DefaultRazorSemanticTokensInfoService.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Semantic/Services/DefaultRazorSemanticTokensInfoService.cs
@@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Semantic
private readonly MemoryCache> _csharpGeneratedSemanticTokensCache = new(); // For C# generated docs
private readonly ClientNotifierServiceBase _languageServer;
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly DocumentResolver _documentResolver;
private readonly DocumentVersionCache _documentVersionCache;
private readonly ILogger _logger;
@@ -43,14 +43,14 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Semantic
public DefaultRazorSemanticTokensInfoService(
ClientNotifierServiceBase languageServer,
RazorDocumentMappingService documentMappingService,
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
DocumentResolver documentResolver,
DocumentVersionCache documentVersionCache,
ILoggerFactory loggerFactory)
{
_languageServer = languageServer ?? throw new ArgumentNullException(nameof(languageServer));
_documentMappingService = documentMappingService ?? throw new ArgumentNullException(nameof(documentMappingService));
- _foregroundDispatcher = foregroundDispatcher ?? throw new ArgumentNullException(nameof(foregroundDispatcher));
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher ?? throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
_documentResolver = documentResolver ?? throw new ArgumentNullException(nameof(documentResolver));
_documentVersionCache = documentVersionCache ?? throw new ArgumentNullException(nameof(documentVersionCache));
@@ -561,13 +561,13 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Semantic
private async Task<(DocumentSnapshot Snapshot, int? Version)> TryGetDocumentInfoAsync(string absolutePath, CancellationToken cancellationToken)
{
- var documentInfo = await Task.Factory.StartNew(() =>
+ var documentInfo = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
{
_documentResolver.TryResolveDocument(absolutePath, out var documentSnapshot);
_documentVersionCache.TryGetDocumentVersion(documentSnapshot, out var version);
return (documentSnapshot, version);
- }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
+ }, cancellationToken);
return documentInfo;
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/VSClassifiedTextElement.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/VSClassifiedTextElement.cs
index cbb429f97f..61a85f525e 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/VSClassifiedTextElement.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/VSClassifiedTextElement.cs
@@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Tooltip
///
internal sealed class VSClassifiedTextElement
{
- [JsonProperty("type")]
+ [JsonProperty("_vs_type")]
public static readonly string Type = "ClassifiedTextElement";
public const string TextClassificationTypeName = "text";
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/VSClassifiedTextRun.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/VSClassifiedTextRun.cs
index c8c79e338d..8bde06cc25 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/VSClassifiedTextRun.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/VSClassifiedTextRun.cs
@@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Tooltip
///
internal sealed class VSClassifiedTextRun
{
- [JsonProperty("type")]
+ [JsonProperty("_vs_type")]
public static readonly string Type = "ClassifiedTextRun";
public VSClassifiedTextRun(string classificationTypeName, string text)
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/VSContainerElement.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/VSContainerElement.cs
index 588fc90ea0..4acfd60ed7 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/VSContainerElement.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Tooltip/VSContainerElement.cs
@@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Tooltip
///
internal sealed class VSContainerElement
{
- [JsonProperty("type")]
+ [JsonProperty("_vs_type")]
public static readonly string Type = "ContainerElement";
public VSContainerElement(VSContainerElementStyle style, IEnumerable
-
+
+
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.OmniSharpPlugin/OmniSharpStrongNamedExports.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.OmniSharpPlugin/OmniSharpStrongNamedExports.cs
index da776e7b2c..6bc30e8ca0 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.OmniSharpPlugin/OmniSharpStrongNamedExports.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.OmniSharpPlugin/OmniSharpStrongNamedExports.cs
@@ -21,8 +21,8 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
}
[Shared]
- [Export(typeof(OmniSharpForegroundDispatcher))]
- internal class ExportOmniSharpForegroundDispatcher : DefaultOmniSharpForegroundDispatcher
+ [Export(typeof(OmniSharpProjectSnapshotManagerDispatcher))]
+ internal class ExportOmniSharpProjectSnapshotManagerDispatcher : DefaultOmniSharpProjectSnapshotManagerDispatcher
{
}
@@ -44,8 +44,8 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
public ExportDefaultOmniSharpProjectSnapshotManagerAccessor(
RemoteTextLoaderFactory remoteTextLoaderFactory,
[ImportMany] IEnumerable projectChangeTriggers,
- OmniSharpForegroundDispatcher foregroundDispatcher,
- OmniSharpWorkspace workspace) : base(remoteTextLoaderFactory, projectChangeTriggers, foregroundDispatcher, workspace)
+ OmniSharpProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
+ OmniSharpWorkspace workspace) : base(remoteTextLoaderFactory, projectChangeTriggers, projectSnapshotManagerDispatcher, workspace)
{
}
}
@@ -56,8 +56,8 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
{
[ImportingConstructor]
public ExportOmniSharpWorkspaceProjectStateChangeDetector(
- OmniSharpForegroundDispatcher foregroundDispatcher,
- OmniSharpProjectWorkspaceStateGenerator workspaceStateGenerator) : base(foregroundDispatcher, workspaceStateGenerator)
+ OmniSharpProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
+ OmniSharpProjectWorkspaceStateGenerator workspaceStateGenerator) : base(projectSnapshotManagerDispatcher, workspaceStateGenerator)
{
}
}
@@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
public class ExportOmniSharpProjectWorkspaceStateGenerator : OmniSharpProjectWorkspaceStateGenerator
{
[ImportingConstructor]
- public ExportOmniSharpProjectWorkspaceStateGenerator(OmniSharpForegroundDispatcher foregroundDispatcher) : base(foregroundDispatcher)
+ public ExportOmniSharpProjectWorkspaceStateGenerator(OmniSharpProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher) : base(projectSnapshotManagerDispatcher)
{
}
}
@@ -79,9 +79,9 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
{
[ImportingConstructor]
public ExportOmniSharpBackgroundDocumentGenerator(
- OmniSharpForegroundDispatcher foregroundDispatcher,
+ OmniSharpProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
RemoteTextLoaderFactory remoteTextLoaderFactory,
- [ImportMany] IEnumerable documentProcessedListeners) : base(foregroundDispatcher, remoteTextLoaderFactory, documentProcessedListeners)
+ [ImportMany] IEnumerable documentProcessedListeners) : base(projectSnapshotManagerDispatcher, remoteTextLoaderFactory, documentProcessedListeners)
{
}
}
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.OmniSharpPlugin/TagHelperRefreshTrigger.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.OmniSharpPlugin/TagHelperRefreshTrigger.cs
index fc39558537..a5c52715c4 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.OmniSharpPlugin/TagHelperRefreshTrigger.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.OmniSharpPlugin/TagHelperRefreshTrigger.cs
@@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
[Export(typeof(IOmniSharpProjectSnapshotManagerChangeTrigger))]
internal class TagHelperRefreshTrigger : IMSBuildEventSink, IRazorDocumentOutputChangeListener, IOmniSharpProjectSnapshotManagerChangeTrigger, IRazorDocumentChangeListener
{
- private readonly OmniSharpForegroundDispatcher _foregroundDispatcher;
+ private readonly OmniSharpProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly Workspace _omniSharpWorkspace;
private readonly OmniSharpProjectWorkspaceStateGenerator _workspaceStateGenerator;
private readonly Dictionary _deferredUpdates;
@@ -30,22 +30,22 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
[ImportingConstructor]
public TagHelperRefreshTrigger(
- OmniSharpForegroundDispatcher foregroundDispatcher,
+ OmniSharpProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
OmniSharpWorkspace omniSharpWorkspace,
OmniSharpProjectWorkspaceStateGenerator workspaceStateGenerator) :
- this(foregroundDispatcher, (Workspace)omniSharpWorkspace, workspaceStateGenerator)
+ this(projectSnapshotManagerDispatcher, (Workspace)omniSharpWorkspace, workspaceStateGenerator)
{
}
// Internal for testing
internal TagHelperRefreshTrigger(
- OmniSharpForegroundDispatcher foregroundDispatcher,
+ OmniSharpProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
Workspace omniSharpWorkspace,
OmniSharpProjectWorkspaceStateGenerator workspaceStateGenerator)
{
- if (foregroundDispatcher == null)
+ if (projectSnapshotManagerDispatcher == null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (omniSharpWorkspace == null)
@@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
throw new ArgumentNullException(nameof(workspaceStateGenerator));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_omniSharpWorkspace = omniSharpWorkspace;
_workspaceStateGenerator = workspaceStateGenerator;
_deferredUpdates = new Dictionary();
@@ -85,11 +85,9 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
// Project file was modified or impacted in a significant way.
- _ = Task.Factory.StartNew(
+ _ = _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
() => EnqueueUpdate(args.ProjectInstance.ProjectFileLocation.File),
- CancellationToken.None,
- TaskCreationOptions.None,
- _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ CancellationToken.None).ConfigureAwait(false);
}
public void RazorDocumentChanged(RazorFileChangeEventArgs args)
@@ -113,7 +111,7 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
},
CancellationToken.None,
TaskCreationOptions.None,
- _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ _projectSnapshotManagerDispatcher.DispatcherScheduler).ConfigureAwait(false);
}
public void RazorDocumentOutputChanged(RazorFileChangeEventArgs args)
@@ -129,7 +127,7 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
() => EnqueueUpdate(args.UnevaluatedProjectInstance.ProjectFileLocation.File),
CancellationToken.None,
TaskCreationOptions.None,
- _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ _projectSnapshotManagerDispatcher.DispatcherScheduler).ConfigureAwait(false);
}
// Internal for testing
@@ -152,7 +150,7 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
private void EnqueueUpdate(string projectFilePath)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
// A race is not possible here because we use the main thread to synchronize the updates
// by capturing the sync context.
@@ -177,7 +175,7 @@ namespace Microsoft.AspNetCore.Razor.OmniSharpPlugin
// Internal for testing
internal bool IsComponentFile(string relativeDocumentFilePath, string projectFilePath)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
var projectSnapshot = _projectManager.GetLoadedProject(projectFilePath);
if (projectSnapshot == null)
diff --git a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/DefaultProjectEngineFactory.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultProjectEngineFactory.cs
similarity index 90%
rename from src/Razor/src/Microsoft.VisualStudio.Editor.Razor/DefaultProjectEngineFactory.cs
rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultProjectEngineFactory.cs
index abe963830a..bdd8b41dc6 100644
--- a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/DefaultProjectEngineFactory.cs
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultProjectEngineFactory.cs
@@ -3,9 +3,8 @@
using System;
using Microsoft.AspNetCore.Razor.Language;
-using Microsoft.CodeAnalysis.Razor;
-namespace Microsoft.VisualStudio.Editor.Razor
+namespace Microsoft.CodeAnalysis.Razor.Workspaces
{
[ExportCustomProjectEngineFactory("Default", SupportsSerialization = true)]
internal class DefaultProjectEngineFactory : IProjectEngineFactory
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultForegroundDispatcher.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultProjectSnapshotManagerDispatcher.cs
similarity index 70%
rename from src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultForegroundDispatcher.cs
rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultProjectSnapshotManagerDispatcher.cs
index 1ffde091a8..9ef41f2eed 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultForegroundDispatcher.cs
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultProjectSnapshotManagerDispatcher.cs
@@ -5,26 +5,24 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
-using Microsoft.CodeAnalysis.Razor;
-namespace Microsoft.AspNetCore.Razor.LanguageServer.Common
+namespace Microsoft.CodeAnalysis.Razor.Workspaces
{
- internal class DefaultForegroundDispatcher : ForegroundDispatcher
+ internal class DefaultProjectSnapshotManagerDispatcher : ProjectSnapshotManagerDispatcher
{
- public override bool IsForegroundThread => Thread.CurrentThread.ManagedThreadId == ForegroundTaskScheduler.Instance.ForegroundThreadId;
+ public override bool IsDispatcherThread
+ => Thread.CurrentThread.ManagedThreadId == ProjectSnapshotManagerTaskScheduler.Instance.ThreadId;
- public override TaskScheduler ForegroundScheduler { get; } = ForegroundTaskScheduler.Instance;
+ public override TaskScheduler DispatcherScheduler { get; } = ProjectSnapshotManagerTaskScheduler.Instance;
- public override TaskScheduler BackgroundScheduler { get; } = TaskScheduler.Default;
-
- internal class ForegroundTaskScheduler : TaskScheduler
+ internal class ProjectSnapshotManagerTaskScheduler : TaskScheduler
{
- public static ForegroundTaskScheduler Instance = new ForegroundTaskScheduler();
+ public static ProjectSnapshotManagerTaskScheduler Instance = new();
private readonly Thread _thread;
- private readonly BlockingCollection _tasks = new BlockingCollection();
+ private readonly BlockingCollection _tasks = new();
- private ForegroundTaskScheduler()
+ private ProjectSnapshotManagerTaskScheduler()
{
_thread = new Thread(ThreadStart)
{
@@ -34,7 +32,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Common
_thread.Start();
}
- public int ForegroundThreadId => _thread.ManagedThreadId;
+ public int ThreadId => _thread.ManagedThreadId;
public override int MaximumConcurrencyLevel => 1;
diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultProjectWorkspaceStateGenerator.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultProjectWorkspaceStateGenerator.cs
index af94209ccc..d0ea115ab6 100644
--- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultProjectWorkspaceStateGenerator.cs
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DefaultProjectWorkspaceStateGenerator.cs
@@ -20,21 +20,21 @@ namespace Microsoft.CodeAnalysis.Razor
// Internal for testing
internal readonly Dictionary Updates;
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly SemaphoreSlim _semaphore;
private ProjectSnapshotManagerBase _projectManager;
private TagHelperResolver _tagHelperResolver;
private bool _disposed;
[ImportingConstructor]
- public DefaultProjectWorkspaceStateGenerator(ForegroundDispatcher foregroundDispatcher)
+ public DefaultProjectWorkspaceStateGenerator(ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher)
{
- if (foregroundDispatcher == null)
+ if (projectSnapshotManagerDispatcher is null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_semaphore = new SemaphoreSlim(initialCount: 1);
Updates = new Dictionary(FilePathComparer.Instance);
@@ -65,7 +65,7 @@ namespace Microsoft.CodeAnalysis.Razor
throw new ArgumentNullException(nameof(projectSnapshot));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
if (_disposed)
{
@@ -89,7 +89,7 @@ namespace Microsoft.CodeAnalysis.Razor
() => UpdateWorkspaceStateAsync(workspaceProject, projectSnapshot, lcts.Token),
lcts.Token,
TaskCreationOptions.None,
- _foregroundDispatcher.BackgroundScheduler).Unwrap();
+ TaskScheduler.Default).Unwrap();
updateTask.ConfigureAwait(false);
updateItem = new UpdateItem(updateTask, lcts);
Updates[projectSnapshot.FilePath] = updateItem;
@@ -97,8 +97,6 @@ namespace Microsoft.CodeAnalysis.Razor
public void Dispose()
{
- _foregroundDispatcher.AssertForegroundThread();
-
_disposed = true;
foreach (var update in Updates)
@@ -132,8 +130,6 @@ namespace Microsoft.CodeAnalysis.Razor
try
{
- _foregroundDispatcher.AssertBackgroundThread();
-
OnStartingBackgroundWork();
if (cancellationToken.IsCancellationRequested)
@@ -168,11 +164,10 @@ namespace Microsoft.CodeAnalysis.Razor
}
catch (Exception ex)
{
- await Task.Factory.StartNew(
+ await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
() => _projectManager.ReportError(ex, projectSnapshot),
- CancellationToken.None, // Don't allow errors to be cancelled
- TaskCreationOptions.None,
- _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ // Don't allow errors to be cancelled
+ CancellationToken.None).ConfigureAwait(false);
return;
}
@@ -182,7 +177,7 @@ namespace Microsoft.CodeAnalysis.Razor
return;
}
- await Task.Factory.StartNew(
+ await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
() =>
{
if (cancellationToken.IsCancellationRequested)
@@ -192,9 +187,7 @@ namespace Microsoft.CodeAnalysis.Razor
ReportWorkspaceStateChange(projectSnapshot.FilePath, workspaceState);
},
- cancellationToken,
- TaskCreationOptions.None,
- _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
@@ -204,11 +197,10 @@ namespace Microsoft.CodeAnalysis.Razor
catch (Exception ex)
{
// This is something totally unexpected, let's just send it over to the project manager.
- await Task.Factory.StartNew(
+ await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
() => _projectManager.ReportError(ex),
- CancellationToken.None, // Don't allow errors to be cancelled
- TaskCreationOptions.None,
- _foregroundDispatcher.ForegroundScheduler).ConfigureAwait(false);
+ // Don't allow errors to be cancelled
+ CancellationToken.None).ConfigureAwait(false);
}
finally
{
@@ -227,7 +219,7 @@ namespace Microsoft.CodeAnalysis.Razor
private void ReportWorkspaceStateChange(string projectFilePath, ProjectWorkspaceState workspaceStateChange)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
_projectManager.ProjectWorkspaceStateChanged(projectFilePath, workspaceStateChange);
}
diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ForegroundDispatcher.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ForegroundDispatcher.cs
deleted file mode 100644
index 39aea4722d..0000000000
--- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ForegroundDispatcher.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.Runtime.CompilerServices;
-using System.Threading.Tasks;
-
-namespace Microsoft.CodeAnalysis.Razor
-{
- internal abstract class ForegroundDispatcher
- {
- public abstract bool IsForegroundThread { get; }
-
- public abstract TaskScheduler ForegroundScheduler { get; }
-
- public abstract TaskScheduler BackgroundScheduler { get; }
-
- public virtual void AssertForegroundThread([CallerMemberName] string caller = null)
- {
- if (!IsForegroundThread)
- {
- caller = caller == null ? Workspaces.Resources.ForegroundDispatcher_NoMethodNamePlaceholder : $"'{caller}'";
- throw new InvalidOperationException(Workspaces.Resources.FormatForegroundDispatcher_AssertForegroundThread(caller));
- }
- }
-
- public virtual void AssertBackgroundThread([CallerMemberName] string caller = null)
- {
- if (IsForegroundThread)
- {
- caller = caller == null ? Workspaces.Resources.ForegroundDispatcher_NoMethodNamePlaceholder : $"'{caller}'";
- throw new InvalidOperationException(Workspaces.Resources.FormatForegroundDispatcher_AssertBackgroundThread(caller));
- }
- }
- }
-}
diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/JoinableTaskContextExtensions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/JoinableTaskContextExtensions.cs
new file mode 100644
index 0000000000..efc0c35969
--- /dev/null
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/JoinableTaskContextExtensions.cs
@@ -0,0 +1,21 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System;
+using System.Runtime.CompilerServices;
+using Microsoft.VisualStudio.Threading;
+
+namespace Microsoft.CodeAnalysis.Razor.Workspaces
+{
+ internal static class JoinableTaskContextExtensions
+ {
+ public static void AssertUIThread(this JoinableTaskContext joinableTaskContext, [CallerMemberName] string caller = null)
+ {
+ if (!joinableTaskContext.IsOnMainThread)
+ {
+ caller = caller is null ? "The method" : $"'{caller}'";
+ throw new InvalidOperationException($"{caller} must be called on the UI thread.");
+ }
+ }
+ }
+}
diff --git a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/LegacyProjectEngineFactory_1_0.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LegacyProjectEngineFactory_1_0.cs
similarity index 94%
rename from src/Razor/src/Microsoft.VisualStudio.Editor.Razor/LegacyProjectEngineFactory_1_0.cs
rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LegacyProjectEngineFactory_1_0.cs
index 84007ad73f..74b1004091 100644
--- a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/LegacyProjectEngineFactory_1_0.cs
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LegacyProjectEngineFactory_1_0.cs
@@ -4,9 +4,8 @@
using System;
using System.Reflection;
using Microsoft.AspNetCore.Razor.Language;
-using Microsoft.CodeAnalysis.Razor;
-namespace Microsoft.VisualStudio.Editor.Razor
+namespace Microsoft.CodeAnalysis.Razor.Workspaces
{
[ExportCustomProjectEngineFactory("MVC-1.0", SupportsSerialization = true)]
internal class LegacyProjectEngineFactory_1_0 : IProjectEngineFactory
diff --git a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/LegacyProjectEngineFactory_1_1.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LegacyProjectEngineFactory_1_1.cs
similarity index 94%
rename from src/Razor/src/Microsoft.VisualStudio.Editor.Razor/LegacyProjectEngineFactory_1_1.cs
rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LegacyProjectEngineFactory_1_1.cs
index 2e31c46990..a6781731c4 100644
--- a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/LegacyProjectEngineFactory_1_1.cs
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LegacyProjectEngineFactory_1_1.cs
@@ -4,9 +4,8 @@
using System;
using System.Reflection;
using Microsoft.AspNetCore.Razor.Language;
-using Microsoft.CodeAnalysis.Razor;
-namespace Microsoft.VisualStudio.Editor.Razor
+namespace Microsoft.CodeAnalysis.Razor.Workspaces
{
[ExportCustomProjectEngineFactory("MVC-1.1", SupportsSerialization = true)]
internal class LegacyProjectEngineFactory_1_1 : IProjectEngineFactory
diff --git a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/LegacyProjectEngineFactory_2_0.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LegacyProjectEngineFactory_2_0.cs
similarity index 94%
rename from src/Razor/src/Microsoft.VisualStudio.Editor.Razor/LegacyProjectEngineFactory_2_0.cs
rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LegacyProjectEngineFactory_2_0.cs
index 83f217d295..147bb126d0 100644
--- a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/LegacyProjectEngineFactory_2_0.cs
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LegacyProjectEngineFactory_2_0.cs
@@ -4,9 +4,8 @@
using System;
using System.Reflection;
using Microsoft.AspNetCore.Razor.Language;
-using Microsoft.CodeAnalysis.Razor;
-namespace Microsoft.VisualStudio.Editor.Razor
+namespace Microsoft.CodeAnalysis.Razor.Workspaces
{
[ExportCustomProjectEngineFactory("MVC-2.0", SupportsSerialization = true)]
internal class LegacyProjectEngineFactory_2_0 : IProjectEngineFactory
diff --git a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/LegacyProjectEngineFactory_2_1.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LegacyProjectEngineFactory_2_1.cs
similarity index 94%
rename from src/Razor/src/Microsoft.VisualStudio.Editor.Razor/LegacyProjectEngineFactory_2_1.cs
rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LegacyProjectEngineFactory_2_1.cs
index f48989904a..bba9a8bce9 100644
--- a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/LegacyProjectEngineFactory_2_1.cs
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LegacyProjectEngineFactory_2_1.cs
@@ -4,9 +4,8 @@
using System;
using System.Reflection;
using Microsoft.AspNetCore.Razor.Language;
-using Microsoft.CodeAnalysis.Razor;
-namespace Microsoft.VisualStudio.Editor.Razor
+namespace Microsoft.CodeAnalysis.Razor.Workspaces
{
// Currently we provide a fixed configuration for 2.1, but this is a point-in-time issue. We plan
// to make the 2.1 configuration more flexible and less hardcoded.
diff --git a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/LegacyProjectEngineFactory_3_0.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LegacyProjectEngineFactory_3_0.cs
similarity index 94%
rename from src/Razor/src/Microsoft.VisualStudio.Editor.Razor/LegacyProjectEngineFactory_3_0.cs
rename to src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LegacyProjectEngineFactory_3_0.cs
index 8cc36de057..23d6f77905 100644
--- a/src/Razor/src/Microsoft.VisualStudio.Editor.Razor/LegacyProjectEngineFactory_3_0.cs
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/LegacyProjectEngineFactory_3_0.cs
@@ -4,9 +4,8 @@
using System;
using System.Reflection;
using Microsoft.AspNetCore.Razor.Language;
-using Microsoft.CodeAnalysis.Razor;
-namespace Microsoft.VisualStudio.Editor.Razor
+namespace Microsoft.CodeAnalysis.Razor.Workspaces
{
[ExportCustomProjectEngineFactory("MVC-3.0", SupportsSerialization = true)]
internal class LegacyProjectEngineFactory_3_0 : IProjectEngineFactory
diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj
index 338fb2b5c1..19e685ea18 100644
--- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Microsoft.CodeAnalysis.Razor.Workspaces.csproj
@@ -14,6 +14,9 @@
+
+
+
diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSnapshotManagerDispatcher.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSnapshotManagerDispatcher.cs
new file mode 100644
index 0000000000..035d1e74db
--- /dev/null
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSnapshotManagerDispatcher.cs
@@ -0,0 +1,32 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Microsoft.CodeAnalysis.Razor
+{
+ internal abstract class ProjectSnapshotManagerDispatcher
+ {
+ public abstract bool IsDispatcherThread { get; }
+
+ public abstract TaskScheduler DispatcherScheduler { get; }
+
+ public Task RunOnDispatcherThreadAsync(Action action, CancellationToken cancellationToken)
+ => Task.Factory.StartNew(action, cancellationToken, TaskCreationOptions.None, DispatcherScheduler);
+
+ public Task RunOnDispatcherThreadAsync(Func action, CancellationToken cancellationToken)
+ => Task.Factory.StartNew(action, cancellationToken, TaskCreationOptions.None, DispatcherScheduler);
+
+ public virtual void AssertDispatcherThread([CallerMemberName] string caller = null)
+ {
+ if (!IsDispatcherThread)
+ {
+ caller = caller is null ? "The method" : $"'{caller}'";
+ throw new InvalidOperationException(caller + " must be called on the project snapshot manager's thread.");
+ }
+ }
+ }
+}
diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultProjectSnapshotManager.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultProjectSnapshotManager.cs
index d2b3b2e959..9e89e04b7f 100644
--- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultProjectSnapshotManager.cs
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultProjectSnapshotManager.cs
@@ -21,7 +21,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
public override event EventHandler Changed;
private readonly ErrorReporter _errorReporter;
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private readonly ProjectSnapshotChangeTrigger[] _triggers;
// Each entry holds a ProjectState and an optional ProjectSnapshot. ProjectSnapshots are
@@ -33,32 +33,32 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
private readonly Queue _notificationWork;
public DefaultProjectSnapshotManager(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
ErrorReporter errorReporter,
IEnumerable triggers,
Workspace workspace)
{
- if (foregroundDispatcher == null)
+ if (projectSnapshotManagerDispatcher is null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
- if (errorReporter == null)
+ if (errorReporter is null)
{
throw new ArgumentNullException(nameof(errorReporter));
}
- if (triggers == null)
+ if (triggers is null)
{
throw new ArgumentNullException(nameof(triggers));
}
- if (workspace == null)
+ if (workspace is null)
{
throw new ArgumentNullException(nameof(workspace));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_errorReporter = errorReporter;
_triggers = triggers.OrderByDescending(trigger => trigger.InitializePriority).ToArray();
Workspace = workspace;
@@ -67,9 +67,28 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
_openDocuments = new HashSet(FilePathComparer.Instance);
_notificationWork = new Queue();
- for (var i = 0; i < _triggers.Length; i++)
+ // All methods involving the project snapshot manager need to be run on the
+ // project snapshot manager's specialized thread. The LSP editor should already
+ // be on the specialized thread, however the old editor may be calling this
+ // constructor on the UI thread.
+ if (_projectSnapshotManagerDispatcher.IsDispatcherThread)
{
- _triggers[i].Initialize(this);
+ InitializeTriggers(this, _triggers);
+ }
+ else
+ {
+ _ = _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(
+ () => InitializeTriggers(this, _triggers), CancellationToken.None);
+ }
+
+ static void InitializeTriggers(
+ DefaultProjectSnapshotManager snapshotManager,
+ ProjectSnapshotChangeTrigger[] triggers)
+ {
+ for (var i = 0; i < triggers.Length; i++)
+ {
+ triggers[i].Initialize(snapshotManager);
+ }
}
}
@@ -77,7 +96,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
{
get
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
var i = 0;
var projects = new ProjectSnapshot[_projects.Count];
@@ -94,7 +113,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
{
get
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
return _openDocuments;
}
@@ -109,7 +128,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
throw new ArgumentNullException(nameof(filePath));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
if (_projects.TryGetValue(filePath, out var entry))
{
@@ -126,7 +145,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
throw new ArgumentNullException(nameof(filePath));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
return GetLoadedProject(filePath) ?? new EphemeralProjectSnapshot(Workspace.Services, filePath);
}
@@ -138,7 +157,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
throw new ArgumentNullException(nameof(documentFilePath));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
return _openDocuments.Contains(documentFilePath);
}
@@ -155,7 +174,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
throw new ArgumentNullException(nameof(document));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
if (_projects.TryGetValue(hostProject.FilePath, out var entry))
{
@@ -187,7 +206,8 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
throw new ArgumentNullException(nameof(document));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
+
if (_projects.TryGetValue(hostProject.FilePath, out var entry))
{
var state = entry.State.WithRemovedHostDocument(document);
@@ -220,7 +240,8 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
throw new ArgumentNullException(nameof(sourceText));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
+
if (_projects.TryGetValue(projectFilePath, out var entry) &&
entry.State.Documents.TryGetValue(documentFilePath, out var older))
{
@@ -275,7 +296,8 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
throw new ArgumentNullException(nameof(textLoader));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
+
if (_projects.TryGetValue(projectFilePath, out var entry) &&
entry.State.Documents.TryGetValue(documentFilePath, out var older))
{
@@ -313,7 +335,8 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
throw new ArgumentNullException(nameof(sourceText));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
+
if (_projects.TryGetValue(projectFilePath, out var entry) &&
entry.State.Documents.TryGetValue(documentFilePath, out var older))
{
@@ -366,7 +389,8 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
throw new ArgumentNullException(nameof(textLoader));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
+
if (_projects.TryGetValue(projectFilePath, out var entry) &&
entry.State.Documents.TryGetValue(documentFilePath, out var older))
{
@@ -392,7 +416,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
throw new ArgumentNullException(nameof(hostProject));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
// We don't expect to see a HostProject initialized multiple times for the same path. Just ignore it.
if (_projects.ContainsKey(hostProject.FilePath))
@@ -415,7 +439,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
throw new ArgumentNullException(nameof(hostProject));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
if (_projects.TryGetValue(hostProject.FilePath, out var entry))
{
@@ -444,7 +468,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
throw new ArgumentNullException(nameof(projectWorkspaceState));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
if (_projects.TryGetValue(projectFilePath, out var entry))
{
@@ -468,7 +492,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
throw new ArgumentNullException(nameof(hostProject));
}
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
if (_projects.TryGetValue(hostProject.FilePath, out var entry))
{
@@ -513,7 +537,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
// virtual so it can be overridden in tests
protected virtual void NotifyListeners(ProjectChangeEventArgs e)
{
- _foregroundDispatcher.AssertForegroundThread();
+ _projectSnapshotManagerDispatcher.AssertDispatcherThread();
_notificationWork.Enqueue(e);
@@ -536,7 +560,6 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
}
while (_notificationWork.Count > 0);
}
-
}
private class Entry
diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultProjectSnapshotManagerFactory.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultProjectSnapshotManagerFactory.cs
index b092174aa6..312eaaf7f7 100644
--- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultProjectSnapshotManagerFactory.cs
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultProjectSnapshotManagerFactory.cs
@@ -14,16 +14,16 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
internal class DefaultProjectSnapshotManagerFactory : ILanguageServiceFactory
{
private readonly IEnumerable _triggers;
- private readonly ForegroundDispatcher _foregroundDispatcher;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
[ImportingConstructor]
public DefaultProjectSnapshotManagerFactory(
- ForegroundDispatcher foregroundDispatcher,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
[ImportMany] IEnumerable triggers)
{
- if (foregroundDispatcher == null)
+ if (projectSnapshotManagerDispatcher == null)
{
- throw new ArgumentNullException(nameof(foregroundDispatcher));
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
}
if (triggers == null)
@@ -31,7 +31,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
throw new ArgumentNullException(nameof(triggers));
}
- _foregroundDispatcher = foregroundDispatcher;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
_triggers = triggers;
}
@@ -43,7 +43,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
}
return new DefaultProjectSnapshotManager(
- _foregroundDispatcher,
+ _projectSnapshotManagerDispatcher,
languageServices.WorkspaceServices.GetRequiredService(),
_triggers,
languageServices.WorkspaceServices.Workspace);
diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/WorkspaceProjectStateChangeDetector.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/WorkspaceProjectStateChangeDetector.cs
index 728e9137e6..53acadaf56 100644
--- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/WorkspaceProjectStateChangeDetector.cs
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/WorkspaceProjectStateChangeDetector.cs
@@ -18,6 +18,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
internal class WorkspaceProjectStateChangeDetector : ProjectSnapshotChangeTrigger
{
private readonly ProjectWorkspaceStateGenerator _workspaceStateGenerator;
+ private readonly ProjectSnapshotManagerDispatcher _projectSnapshotManagerDispatcher;
private ProjectSnapshotManagerBase _projectManager;
public int EnqueueDelay { get; set; } = 3 * 1000;
@@ -29,19 +30,31 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
internal Dictionary _deferredUpdates;
[ImportingConstructor]
- public WorkspaceProjectStateChangeDetector(ProjectWorkspaceStateGenerator workspaceStateGenerator)
+ public WorkspaceProjectStateChangeDetector(
+ ProjectWorkspaceStateGenerator workspaceStateGenerator,
+ ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher)
{
- if (workspaceStateGenerator == null)
+ if (workspaceStateGenerator is null)
{
throw new ArgumentNullException(nameof(workspaceStateGenerator));
}
+ if (projectSnapshotManagerDispatcher is null)
+ {
+ throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
+ }
+
_workspaceStateGenerator = workspaceStateGenerator;
+ _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;
}
// Used in unit tests to ensure we can control when background work starts.
public ManualResetEventSlim BlockDelayedUpdateWorkEnqueue { get; set; }
+ public ManualResetEventSlim BlockDelayedUpdateWorkAfterEnqueue { get; set; }
+
+ public ManualResetEventSlim NotifyWorkspaceChangedEventComplete { get; set; }
+
private void OnStartingDelayedUpdate()
{
if (BlockDelayedUpdateWorkEnqueue != null)
@@ -49,6 +62,11 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
BlockDelayedUpdateWorkEnqueue.Wait();
BlockDelayedUpdateWorkEnqueue.Reset();
}
+
+ if (BlockDelayedUpdateWorkAfterEnqueue != null)
+ {
+ BlockDelayedUpdateWorkAfterEnqueue.Set();
+ }
}
public override void Initialize(ProjectSnapshotManagerBase projectManager)
@@ -64,107 +82,136 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
}
// Internal for testing, virtual for temporary VSCode workaround
- internal virtual void Workspace_WorkspaceChanged(object sender, WorkspaceChangeEventArgs e)
+#pragma warning disable VSTHRD100 // Avoid async void methods
+ internal async virtual void Workspace_WorkspaceChanged(object sender, WorkspaceChangeEventArgs e)
+#pragma warning restore VSTHRD100 // Avoid async void methods
{
- Project project;
- switch (e.Kind)
+ try
{
- case WorkspaceChangeKind.ProjectAdded:
+ // Method needs to be run on the project snapshot manager's specialized thread
+ // due to project snapshot manager access.
+ await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
+ {
+ Project project;
+ switch (e.Kind)
{
- project = e.NewSolution.GetProject(e.ProjectId);
-
- Debug.Assert(project != null);
-
- if (TryGetProjectSnapshot(project.FilePath, out var projectSnapshot))
- {
- _workspaceStateGenerator.Update(project, projectSnapshot, CancellationToken.None);
- }
- break;
- }
-
- case WorkspaceChangeKind.ProjectChanged:
- case WorkspaceChangeKind.ProjectReloaded:
- {
- project = e.NewSolution.GetProject(e.ProjectId);
-
- if (TryGetProjectSnapshot(project?.FilePath, out var _))
- {
- EnqueueUpdate(e.ProjectId);
- }
- break;
- }
-
- case WorkspaceChangeKind.ProjectRemoved:
- {
- project = e.OldSolution.GetProject(e.ProjectId);
- Debug.Assert(project != null);
-
- if (TryGetProjectSnapshot(project?.FilePath, out var projectSnapshot))
- {
- _workspaceStateGenerator.Update(workspaceProject: null, projectSnapshot, CancellationToken.None);
- }
-
- break;
- }
-
- case WorkspaceChangeKind.DocumentChanged:
- case WorkspaceChangeKind.DocumentReloaded:
- {
- // This is the case when a component declaration file changes on disk. We have an MSBuild
- // generator configured by the SDK that will poke these files on disk when a component
- // is saved, or loses focus in the editor.
- project = e.OldSolution.GetProject(e.ProjectId);
- var document = project.GetDocument(e.DocumentId);
-
- if (document.FilePath == null)
- {
- return;
- }
-
- // Using EndsWith because Path.GetExtension will ignore everything before .cs
- // Using Ordinal because the SDK generates these filenames.
- // Stll have .cshtml.g.cs and .razor.g.cs for Razor.VSCode scenarios.
- if (document.FilePath.EndsWith(".cshtml.g.cs", StringComparison.Ordinal) ||
- document.FilePath.EndsWith(".razor.g.cs", StringComparison.Ordinal) ||
- document.FilePath.EndsWith(".razor", StringComparison.Ordinal) ||
-
- // VSCode's background C# document
- document.FilePath.EndsWith("__bg__virtual.cs", StringComparison.Ordinal))
- {
- EnqueueUpdate(e.ProjectId);
- return;
- }
-
- // We now know we're not operating directly on a Razor file. However, it's possible the user is operating on a partial class that is associated with a Razor file.
-
- if (IsPartialComponentClass(document))
- {
- EnqueueUpdate(e.ProjectId);
- }
-
- break;
- }
-
- case WorkspaceChangeKind.SolutionAdded:
- case WorkspaceChangeKind.SolutionChanged:
- case WorkspaceChangeKind.SolutionCleared:
- case WorkspaceChangeKind.SolutionReloaded:
- case WorkspaceChangeKind.SolutionRemoved:
-
- if (e.OldSolution != null)
- {
- foreach (var p in e.OldSolution.Projects)
- {
-
- if (TryGetProjectSnapshot(p?.FilePath, out var projectSnapshot))
+ case WorkspaceChangeKind.ProjectAdded:
{
- _workspaceStateGenerator.Update(workspaceProject: null, projectSnapshot, CancellationToken.None);
+ project = e.NewSolution.GetProject(e.ProjectId);
+
+ Debug.Assert(project != null);
+
+ if (TryGetProjectSnapshot(project.FilePath, out var projectSnapshot))
+ {
+ _workspaceStateGenerator.Update(project, projectSnapshot, CancellationToken.None);
+ }
+
+ break;
}
- }
+
+ case WorkspaceChangeKind.ProjectChanged:
+ case WorkspaceChangeKind.ProjectReloaded:
+ {
+ project = e.NewSolution.GetProject(e.ProjectId);
+
+ if (TryGetProjectSnapshot(project?.FilePath, out var _))
+ {
+ EnqueueUpdate(e.ProjectId);
+
+ var dependencyGraph = e.NewSolution.GetProjectDependencyGraph();
+ var dependentProjectIds = dependencyGraph.GetProjectsThatTransitivelyDependOnThisProject(e.ProjectId);
+ foreach (var dependentProjectId in dependentProjectIds)
+ {
+ EnqueueUpdate(dependentProjectId);
+ }
+ }
+ break;
+ }
+
+ case WorkspaceChangeKind.ProjectRemoved:
+ {
+ project = e.OldSolution.GetProject(e.ProjectId);
+ Debug.Assert(project != null);
+
+ if (TryGetProjectSnapshot(project?.FilePath, out var projectSnapshot))
+ {
+ _workspaceStateGenerator.Update(workspaceProject: null, projectSnapshot, CancellationToken.None);
+ }
+
+ break;
+ }
+
+ case WorkspaceChangeKind.DocumentChanged:
+ case WorkspaceChangeKind.DocumentReloaded:
+ {
+ // This is the case when a component declaration file changes on disk. We have an MSBuild
+ // generator configured by the SDK that will poke these files on disk when a component
+ // is saved, or loses focus in the editor.
+ project = e.OldSolution.GetProject(e.ProjectId);
+ var document = project.GetDocument(e.DocumentId);
+
+ if (document.FilePath == null)
+ {
+ break;
+ }
+
+ // Using EndsWith because Path.GetExtension will ignore everything before .cs
+ // Using Ordinal because the SDK generates these filenames.
+ // Stll have .cshtml.g.cs and .razor.g.cs for Razor.VSCode scenarios.
+ if (document.FilePath.EndsWith(".cshtml.g.cs", StringComparison.Ordinal) ||
+ document.FilePath.EndsWith(".razor.g.cs", StringComparison.Ordinal) ||
+ document.FilePath.EndsWith(".razor", StringComparison.Ordinal) ||
+
+ // VSCode's background C# document
+ document.FilePath.EndsWith("__bg__virtual.cs", StringComparison.Ordinal))
+ {
+ EnqueueUpdate(e.ProjectId);
+ break;
+ }
+
+ // We now know we're not operating directly on a Razor file. However, it's possible the user is operating on a partial class that is associated with a Razor file.
+
+ if (IsPartialComponentClass(document))
+ {
+ EnqueueUpdate(e.ProjectId);
+ }
+
+ break;
+ }
+
+ case WorkspaceChangeKind.SolutionAdded:
+ case WorkspaceChangeKind.SolutionChanged:
+ case WorkspaceChangeKind.SolutionCleared:
+ case WorkspaceChangeKind.SolutionReloaded:
+ case WorkspaceChangeKind.SolutionRemoved:
+
+ if (e.OldSolution != null)
+ {
+ foreach (var p in e.OldSolution.Projects)
+ {
+
+ if (TryGetProjectSnapshot(p?.FilePath, out var projectSnapshot))
+ {
+ _workspaceStateGenerator.Update(workspaceProject: null, projectSnapshot, CancellationToken.None);
+ }
+ }
+ }
+
+ InitializeSolution(e.NewSolution);
+ break;
}
- InitializeSolution(e.NewSolution);
- break;
+ // Let tests know that this event has completed
+ if (NotifyWorkspaceChangedEventComplete != null)
+ {
+ NotifyWorkspaceChangedEventComplete.Set();
+ }
+ }, CancellationToken.None);
+ }
+ catch (Exception ex)
+ {
+ Debug.Fail("WorkspaceProjectStateChangeDetector.Workspace_WorkspaceChanged threw exception:" +
+ Environment.NewLine + ex.Message + Environment.NewLine + "Stack trace:" + Environment.NewLine + ex.StackTrace);
}
}
diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/RazorDocumentServiceProvider.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/RazorDocumentServiceProvider.cs
index c1f0d58d8e..8cd3ad861a 100644
--- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/RazorDocumentServiceProvider.cs
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/RazorDocumentServiceProvider.cs
@@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
private readonly object _lock;
private IRazorSpanMappingService _spanMappingService;
- private IRazorDocumentExcerptService _excerptService;
+ private IRazorDocumentExcerptService _documentExcerptService;
private IRazorDocumentPropertiesService _documentPropertiesService;
public RazorDocumentServiceProvider()
@@ -37,7 +37,9 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
return this as TService;
}
- if (typeof(TService) == typeof(IRazorSpanMappingService))
+ var serviceType = typeof(TService);
+
+ if (serviceType == typeof(IRazorSpanMappingService))
{
if (_spanMappingService == null)
{
@@ -53,23 +55,23 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
return (TService)_spanMappingService;
}
- if (typeof(TService) == typeof(IRazorDocumentExcerptService))
+ if (serviceType == typeof(IRazorDocumentExcerptService))
{
- if (_excerptService == null)
+ if (_documentExcerptService == null)
{
lock (_lock)
{
- if (_excerptService == null)
+ if (_documentExcerptService == null)
{
- _excerptService = _documentContainer.GetExcerptService();
+ _documentExcerptService = _documentContainer.GetExcerptService();
}
}
}
- return (TService)_excerptService;
+ return (TService)_documentExcerptService;
}
- if (typeof(TService) == typeof(IRazorDocumentPropertiesService))
+ if (serviceType == typeof(IRazorDocumentPropertiesService))
{
if (_documentPropertiesService == null)
{
diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/RazorSpanMappingService.cs b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/RazorSpanMappingService.cs
index f10122276a..c04a682ed1 100644
--- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/RazorSpanMappingService.cs
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/RazorSpanMappingService.cs
@@ -13,7 +13,7 @@ using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Razor
{
- internal class RazorSpanMappingService: IRazorSpanMappingService
+ internal class RazorSpanMappingService : IRazorSpanMappingService
{
private readonly DocumentSnapshot _document;
diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources.resx b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources.resx
index fca5a30e15..55a253ebbe 100644
--- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources.resx
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Resources.resx
@@ -120,13 +120,4 @@
Value cannot be null or an empty string.
-
- {0} must be called on a background thread.
-
-
- {0} must be called on the foreground thread.
-
-
- The method
-
\ No newline at end of file
diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/xlf/Resources.cs.xlf b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/xlf/Resources.cs.xlf
index 95de4c5bf5..ab58c337c8 100644
--- a/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/xlf/Resources.cs.xlf
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/xlf/Resources.cs.xlf
@@ -7,21 +7,6 @@
Hodnota nesmí být null ani prázdný řetězec.
-
- {0} must be called on a background thread.
- {0} musí být voláno ve vlákně na pozadí.
-
-
-
- {0} must be called on the foreground thread.
- {0} musí být voláno ve vlákně na popředí.
-
-
-
- The method
- Metoda
-
-