|
3 | 3 | // See the LICENSE file in the project root for more information. |
4 | 4 |
|
5 | 5 | using System; |
| 6 | +using System.Collections.Generic; |
6 | 7 | using System.Composition; |
7 | 8 | using System.IO; |
8 | 9 | using System.Linq; |
| 10 | +using System.ServiceModel.Syndication; |
9 | 11 | using System.Threading; |
10 | 12 | using System.Threading.Tasks; |
11 | 13 | using System.Xml.Linq; |
12 | 14 | using Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript; |
13 | 15 | using Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api; |
14 | 16 | using Microsoft.CodeAnalysis.Host.Mef; |
| 17 | +using Microsoft.CodeAnalysis.LanguageServer; |
15 | 18 | using Microsoft.CodeAnalysis.Simplification; |
16 | 19 | using Microsoft.CodeAnalysis.Test.Utilities; |
17 | | -using Roslyn.LanguageServer.Protocol; |
| 20 | +using Microsoft.CommonLanguageServerProtocol.Framework; |
18 | 21 | using Nerdbank.Streams; |
| 22 | +using Roslyn.LanguageServer.Protocol; |
19 | 23 | using Roslyn.Test.Utilities; |
20 | 24 | using StreamJsonRpc; |
21 | 25 | using Xunit; |
22 | 26 | using Xunit.Abstractions; |
23 | | -using Microsoft.CodeAnalysis.LanguageServer; |
24 | 27 |
|
25 | 28 | namespace Microsoft.CodeAnalysis.Editor.UnitTests.LanguageServer; |
26 | 29 | public class VSTypeScriptHandlerTests : AbstractLanguageServerProtocolTests |
@@ -90,43 +93,50 @@ public async Task TestGetSimplifierOptionsOnTypeScriptDocument() |
90 | 93 | Assert.Same(SimplifierOptions.CommonDefaults, simplifierOptions); |
91 | 94 | } |
92 | 95 |
|
93 | | - private async Task<TestLspServer> CreateTsTestLspServerAsync(string workspaceXml, InitializationOptions? options = null) |
| 96 | + private async Task<VSTypeScriptTestLspServer> CreateTsTestLspServerAsync(string workspaceXml, InitializationOptions? options = null) |
94 | 97 | { |
95 | | - var (clientStream, serverStream) = FullDuplexStream.CreatePair(); |
96 | | - |
97 | 98 | var testWorkspace = CreateWorkspace(options, mutatingLspWorkspace: false, workspaceKind: null); |
98 | 99 | testWorkspace.InitializeDocuments(XElement.Parse(workspaceXml), openDocuments: false); |
99 | 100 |
|
100 | | - // Ensure workspace operations are completed so we don't get unexpected workspace changes while running. |
101 | | - await WaitForWorkspaceOperationsAsync(testWorkspace); |
102 | | - var languageServerTarget = CreateLanguageServer(serverStream, serverStream, testWorkspace); |
103 | | - |
104 | | - return await TestLspServer.CreateAsync(testWorkspace, new ClientCapabilities(), languageServerTarget, clientStream); |
| 101 | + return await VSTypeScriptTestLspServer.CreateAsync(testWorkspace, new InitializationOptions(), TestOutputLspLogger); |
105 | 102 | } |
106 | 103 |
|
107 | | - private static RoslynLanguageServer CreateLanguageServer(Stream inputStream, Stream outputStream, LspTestWorkspace workspace) |
| 104 | + private class VSTypeScriptTestLspServer : AbstractTestLspServer<LspTestWorkspace, TestHostDocument, TestHostProject, TestHostSolution> |
108 | 105 | { |
109 | | - var capabilitiesProvider = workspace.ExportProvider.GetExportedValue<ExperimentalCapabilitiesProvider>(); |
110 | | - var servicesProvider = workspace.ExportProvider.GetExportedValue<VSTypeScriptLspServiceProvider>(); |
111 | | - |
112 | | - var messageFormatter = RoslynLanguageServer.CreateJsonMessageFormatter(); |
113 | | - var jsonRpc = new JsonRpc(new HeaderDelimitedMessageHandler(outputStream, inputStream, messageFormatter)) |
| 106 | + public VSTypeScriptTestLspServer(LspTestWorkspace testWorkspace, Dictionary<string, IList<Roslyn.LanguageServer.Protocol.Location>> locations, InitializationOptions options, AbstractLspLogger logger) : base(testWorkspace, locations, options, logger) |
114 | 107 | { |
115 | | - ExceptionStrategy = ExceptionProcessing.ISerializable, |
116 | | - }; |
117 | | - |
118 | | - var logger = NoOpLspLogger.Instance; |
| 108 | + } |
119 | 109 |
|
120 | | - var languageServer = new RoslynLanguageServer( |
121 | | - servicesProvider, jsonRpc, messageFormatter.JsonSerializerOptions, |
122 | | - capabilitiesProvider, |
123 | | - logger, |
124 | | - workspace.Services.HostServices, |
125 | | - [InternalLanguageNames.TypeScript], |
126 | | - WellKnownLspServerKinds.RoslynTypeScriptLspServer); |
| 110 | + protected override RoslynLanguageServer CreateLanguageServer(Stream inputStream, Stream outputStream, WellKnownLspServerKinds serverKind, AbstractLspLogger logger) |
| 111 | + { |
| 112 | + var capabilitiesProvider = TestWorkspace.ExportProvider.GetExportedValue<ExperimentalCapabilitiesProvider>(); |
| 113 | + var servicesProvider = TestWorkspace.ExportProvider.GetExportedValue<VSTypeScriptLspServiceProvider>(); |
| 114 | + |
| 115 | + var messageFormatter = RoslynLanguageServer.CreateJsonMessageFormatter(); |
| 116 | + var jsonRpc = new JsonRpc(new HeaderDelimitedMessageHandler(outputStream, inputStream, messageFormatter)) |
| 117 | + { |
| 118 | + ExceptionStrategy = ExceptionProcessing.ISerializable, |
| 119 | + }; |
| 120 | + |
| 121 | + var languageServer = new RoslynLanguageServer( |
| 122 | + servicesProvider, jsonRpc, messageFormatter.JsonSerializerOptions, |
| 123 | + capabilitiesProvider, |
| 124 | + logger, |
| 125 | + TestWorkspace.Services.HostServices, |
| 126 | + [InternalLanguageNames.TypeScript], |
| 127 | + WellKnownLspServerKinds.RoslynTypeScriptLspServer); |
| 128 | + |
| 129 | + jsonRpc.StartListening(); |
| 130 | + return languageServer; |
| 131 | + } |
127 | 132 |
|
128 | | - jsonRpc.StartListening(); |
129 | | - return languageServer; |
| 133 | + public static async Task<VSTypeScriptTestLspServer> CreateAsync(LspTestWorkspace testWorkspace, InitializationOptions options, AbstractLspLogger logger) |
| 134 | + { |
| 135 | + var locations = await GetAnnotatedLocationsAsync(testWorkspace, testWorkspace.CurrentSolution); |
| 136 | + var server = new VSTypeScriptTestLspServer(testWorkspace, locations, options, logger); |
| 137 | + await server.InitializeAsync(); |
| 138 | + return server; |
| 139 | + } |
130 | 140 | } |
131 | 141 |
|
132 | 142 | internal record TSRequest(Uri Document, string Project); |
|
0 commit comments