Skip to content

Commit 079aaaf

Browse files
author
N. Taylor Mullen
authored
Start Razor Language Server when new Razor LSP editor opens. (#1487)
- Included the LanguageServer core dlls as part of the VSIX install. To do this I had to expose the language server's output path via a target and then dynamically include its outputs in the VSIX output. - Given how VSIX's are built I could not privately reference our language server to ensure that it's built when the VSIX is built. To work around this limitation I added a `_BuildLanguageServer` target that calls MSBuild directly on the language server as part of build. - For now I'm dynamically booting the currently built language server that's deployed with the extension. I haven't given a lot of thought to what flavor of OS (x64 vs. x86) the server can run on; or if we need to ensure dotnet.exe is available. - Found that the VS LSP client and the O# language server library that we use don't inter-operate as we'd expect. The server ends up telling the client that it doesn't care about text document change events (we do). I've created a separate PR in O# to fix this: OmniSharp/csharp-language-server-protocol#199 - Add OmniSharp 3rd party library to signing information for VSIX insertions. dotnet/aspnetcore#17789
1 parent ebb4980 commit 079aaaf

File tree

4 files changed

+112
-2
lines changed

4 files changed

+112
-2
lines changed

eng/Signing.props

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<!--
44
The `Condition` in this Import was added because publishing pipelines rely
55
on importing this file but it doesn't import MPack.props.
6-
The condition can be removed once this issue is fixed:
6+
The condition can be removed once this issue is fixed:
77
https://github.com/dotnet/arcade/issues/2371
88
-->
99
<Import Project="MPack.props" Condition="Exists('MPack.props')" />
@@ -14,6 +14,11 @@
1414
-->
1515
<ItemGroup>
1616
<FileSignInfo Include="Newtonsoft.Json.dll" CertificateName="3PartySHA2" />
17+
<FileSignInfo Include="MediatR.dll" CertificateName="3PartySHA2" />
18+
<FileSignInfo Include="MediatR.Extensions.Microsoft.DependencyInjection.dll" CertificateName="3PartySHA2" />
19+
<FileSignInfo Include="OmniSharp.Extensions.JsonRpc.dll" CertificateName="3PartySHA2" />
20+
<FileSignInfo Include="OmniSharp.Extensions.LanguageProtocol.dll" CertificateName="3PartySHA2" />
21+
<FileSignInfo Include="OmniSharp.Extensions.LanguageServer.dll" CertificateName="3PartySHA2" />
1722
</ItemGroup>
1823

1924
<ItemGroup>

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Microsoft.AspNetCore.Razor.LanguageServer.csproj

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
<ProjectReference Include="..\Microsoft.AspNetCore.Razor.LanguageServer.Common\Microsoft.AspNetCore.Razor.LanguageServer.Common.csproj" />
1818
</ItemGroup>
1919

20+
<Target Name="_GetOutputPath" Returns="@(_ServerOutputPath)">
21+
<ItemGroup>
22+
<_ServerOutputPath Include="$(OutputPath)">
23+
</_ServerOutputPath>
24+
</ItemGroup>
25+
</Target>
26+
2027
<Target Name="_IncludeOmniSharpPlugin" Condition="Exists('$(PublishDir)')">
2128
<PropertyGroup>
2229
<TargetPluginOutputPath>$(PublishDir)\OmniSharpPlugin</TargetPluginOutputPath>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.Composition;
4+
using System.Diagnostics;
5+
using System.IO;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.VisualStudio.LanguageServer.Client;
9+
using Microsoft.VisualStudio.Threading;
10+
using Microsoft.VisualStudio.Utilities;
11+
12+
namespace Microsoft.VisualStudio.LanguageServerClient.Razor
13+
{
14+
[Export(typeof(ILanguageClient))]
15+
[ContentType(RazorLSPContentTypeDefinition.Name)]
16+
internal class RazorLanguageServerClient : ILanguageClient
17+
{
18+
public string Name => "Razor Language Server Client";
19+
20+
public IEnumerable<string> ConfigurationSections => null;
21+
22+
public object InitializationOptions => null;
23+
24+
public IEnumerable<string> FilesToWatch => null;
25+
26+
public event AsyncEventHandler<EventArgs> StartAsync;
27+
public event AsyncEventHandler<EventArgs> StopAsync
28+
{
29+
add { }
30+
remove { }
31+
}
32+
33+
public async Task<Connection> ActivateAsync(CancellationToken token)
34+
{
35+
await Task.Yield();
36+
37+
var currentAssembly = typeof(RazorLanguageServerClient).Assembly;
38+
var currentAssemblyLocation = currentAssembly.Location;
39+
var extensionDirectory = Path.GetDirectoryName(currentAssemblyLocation);
40+
var languageServerPath = Path.Combine(extensionDirectory, "LanguageServer", "rzls.exe");
41+
var info = new ProcessStartInfo();
42+
info.FileName = languageServerPath;
43+
info.Arguments = "-lsp --logLevel Trace";
44+
info.RedirectStandardInput = true;
45+
info.RedirectStandardOutput = true;
46+
info.UseShellExecute = false;
47+
info.CreateNoWindow = true;
48+
49+
Process process = new Process();
50+
process.StartInfo = info;
51+
52+
if (process.Start())
53+
{
54+
return new Connection(process.StandardOutput.BaseStream, process.StandardInput.BaseStream);
55+
}
56+
57+
return null;
58+
}
59+
60+
public async Task OnLoadedAsync()
61+
{
62+
await StartAsync.InvokeAsync(this, EventArgs.Empty);
63+
}
64+
65+
public Task OnServerInitializeFailedAsync(Exception e)
66+
{
67+
return Task.CompletedTask;
68+
}
69+
70+
public Task OnServerInitializedAsync()
71+
{
72+
return Task.CompletedTask;
73+
}
74+
}
75+
}

src/Razor/src/Microsoft.VisualStudio.RazorExtension/Microsoft.VisualStudio.RazorExtension.csproj

+24-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<IsPackable>false</IsPackable>
2424
</PropertyGroup>
2525

26-
<!-- Include Razor SDK design time assets in the VSIX -->
26+
<!-- Include Razor SDK design time assets in the VSIX -->
2727
<ItemGroup>
2828
<Content Include="..\Microsoft.NET.Sdk.Razor\build\netstandard2.0\Microsoft.NET.Sdk.Razor.DesignTime.targets">
2929
<IncludeInVsix>true</IncludeInVsix>
@@ -113,6 +113,29 @@
113113
<_GeneratedVSIXBindingRedirectFile>$(IntermediateOutputPath)$(MSBuildProjectName).BindingRedirects.cs</_GeneratedVSIXBindingRedirectFile>
114114
</PropertyGroup>
115115

116+
<Target Name="_BuildLanguageServer">
117+
<MSBuild Projects="..\Microsoft.AspNetCore.Razor.LanguageServer\Microsoft.AspNetCore.Razor.LanguageServer.csproj"
118+
Targets="Build" />
119+
</Target>
120+
121+
<Target Name="_IncludeLanguageServer" DependsOnTargets="PrepareForBuild;_BuildLanguageServer" BeforeTargets="CoreCompile">
122+
<MSBuild Projects="..\Microsoft.AspNetCore.Razor.LanguageServer\Microsoft.AspNetCore.Razor.LanguageServer.csproj"
123+
Targets="_GetOutputPath">
124+
<Output TaskParameter="TargetOutputs" ItemName="_ResolvedPackageVersionInfo" />
125+
</MSBuild>
126+
127+
<PropertyGroup>
128+
<_ResolvedPackageVersionInfoProperty>@(_ResolvedPackageVersionInfo)</_ResolvedPackageVersionInfoProperty>
129+
</PropertyGroup>
130+
131+
<ItemGroup>
132+
<Content Include="$(_ResolvedPackageVersionInfoProperty)\*">
133+
<IncludeInVsix>true</IncludeInVsix>
134+
<VSIXSubPath>LanguageServer\</VSIXSubPath>
135+
</Content>
136+
</ItemGroup>
137+
</Target>
138+
116139
<Target Name="_GenerateVSIXBindingRedirects" DependsOnTargets="PrepareForBuild;GetAssemblyVersion" BeforeTargets="CoreCompile" Inputs="$(MSBuildAllProjects)" Outputs="$(_GeneratedVSIXBindingRedirectFile)">
117140
<ItemGroup>
118141
<BindingRedirectAssemblies Include="@(ProjectReference)" AssemblyName="%(Filename)" />

0 commit comments

Comments
 (0)