-
Notifications
You must be signed in to change notification settings - Fork 228
Start Razor Language Server when new Razor LSP editor opens. #1487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.ComponentModel.Composition; | ||
| using System.Diagnostics; | ||
| using System.IO; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.VisualStudio.LanguageServer.Client; | ||
| using Microsoft.VisualStudio.Threading; | ||
| using Microsoft.VisualStudio.Utilities; | ||
|
|
||
| namespace Microsoft.VisualStudio.LanguageServerClient.Razor | ||
| { | ||
| [Export(typeof(ILanguageClient))] | ||
| [ContentType(RazorLSPContentTypeDefinition.Name)] | ||
| internal class RazorLanguageServerClient : ILanguageClient | ||
| { | ||
| public string Name => "Razor Language Server Client"; | ||
|
|
||
| public IEnumerable<string> ConfigurationSections => null; | ||
|
|
||
| public object InitializationOptions => null; | ||
|
|
||
| public IEnumerable<string> FilesToWatch => null; | ||
|
|
||
| public event AsyncEventHandler<EventArgs> StartAsync; | ||
| public event AsyncEventHandler<EventArgs> StopAsync | ||
| { | ||
| add { } | ||
| remove { } | ||
| } | ||
|
|
||
| public async Task<Connection> ActivateAsync(CancellationToken token) | ||
| { | ||
| await Task.Yield(); | ||
|
|
||
| var currentAssembly = typeof(RazorLanguageServerClient).Assembly; | ||
| var currentAssemblyLocation = currentAssembly.Location; | ||
| var extensionDirectory = Path.GetDirectoryName(currentAssemblyLocation); | ||
| var languageServerPath = Path.Combine(extensionDirectory, "LanguageServer", "rzls.exe"); | ||
| var info = new ProcessStartInfo(); | ||
| info.FileName = languageServerPath; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possible nit: var info = new ProcessStartInfo{
info.FileName = languageServerPath,
// ...
} |
||
| info.Arguments = "-lsp --logLevel Trace"; | ||
| info.RedirectStandardInput = true; | ||
| info.RedirectStandardOutput = true; | ||
| info.UseShellExecute = false; | ||
| info.CreateNoWindow = true; | ||
|
|
||
| Process process = new Process(); | ||
| process.StartInfo = info; | ||
|
|
||
| if (process.Start()) | ||
| { | ||
| return new Connection(process.StandardOutput.BaseStream, process.StandardInput.BaseStream); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| public async Task OnLoadedAsync() | ||
| { | ||
| await StartAsync.InvokeAsync(this, EventArgs.Empty); | ||
| } | ||
|
|
||
| public Task OnServerInitializeFailedAsync(Exception e) | ||
| { | ||
| return Task.CompletedTask; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All three of these functions strike me as in need of diagnostic logging (but especially
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're definitely right. We'll expand on the implementation of this class in the coming months. For now it's just basic boiler plate to get the ball rolling 😄 |
||
| } | ||
|
|
||
| public Task OnServerInitializedAsync() | ||
| { | ||
| return Task.CompletedTask; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the add/remove explicitly defined here but implicitly defined for
StartAsync?Also, I don't see anywhere that
StopAsyncis actually called? I suspect I misunderstand the workflow of ILanguageClient. Could you go into the expected flow a bit?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StartAsyncis called when we actually start the language server but we don't actually take control of stopping the language server currently. We rely on the ILanguageClient infrastructure to stop us. The gist here is that our ILanguageClient is very "dumb" currently. It's just the boiler plate to start a basic language server and then I plan to fill it out later as we flesh it all out more.