Skip to content
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

Update LanguageServerHost to use NamedPipe #69816

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
using System.Collections.Immutable;
using System.CommandLine;
using System.Diagnostics;
using System.IO.Pipes;
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis.Contracts.Telemetry;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.LanguageServer.BrokeredServices;
using Microsoft.CodeAnalysis.LanguageServer.BrokeredServices.Services.HelloWorld;
using Microsoft.CodeAnalysis.LanguageServer.HostWorkspace;
using Microsoft.CodeAnalysis.LanguageServer.LanguageServer;
using Microsoft.CodeAnalysis.LanguageServer.Logging;
Expand Down Expand Up @@ -100,7 +100,11 @@ static async Task RunAsync(ServerConfiguration serverConfiguration, Cancellation
// TODO: Remove, the path should match exactly. Workaround for https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1830914.
Microsoft.CodeAnalysis.EditAndContinue.EditAndContinueMethodDebugInfoReader.IgnoreCaseWhenComparingDocumentNames = Path.DirectorySeparatorChar == '\\';

var server = new LanguageServerHost(Console.OpenStandardInput(), Console.OpenStandardOutput(), exportProvider, loggerFactory.CreateLogger(nameof(LanguageServerHost)));
// Named pipe server is actually created from the client, so here we create a client stream.
beccamc marked this conversation as resolved.
Show resolved Hide resolved
var pipeServer = new NamedPipeClientStream(".", GetDotNetPipeConnectionString(serverConfiguration.PipeName), PipeDirection.InOut, PipeOptions.Asynchronous);
beccamc marked this conversation as resolved.
Show resolved Hide resolved
await pipeServer.ConnectAsync(cancellationToken);

var server = new LanguageServerHost(pipeServer, pipeServer, exportProvider, loggerFactory.CreateLogger(nameof(LanguageServerHost)));
server.Start();

try
Expand Down Expand Up @@ -171,6 +175,12 @@ static CliRootCommand CreateCommandLineParser()
Required = false
};

var pipeNameOption = new CliOption<string>("--pipe")
{
Description = "The name of the pipe to use for RPC with the parent process.",
Required = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we still allow for stdin/stdout for a bit longer, if only so that way we don't have to merge/flow this simultaneously with the VS Code side of things?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

David and I discussed this, and determined it would be fine to merge both PRs close together. The only risk is that someone else updates roslyn version before I get PR in, correct?

};

var rootCommand = new CliRootCommand()
{
debugOption,
Expand All @@ -181,7 +191,8 @@ static CliRootCommand CreateCommandLineParser()
sessionIdOption,
sharedDependenciesOption,
extensionAssemblyPathsOption,
extensionLogDirectoryOption
extensionLogDirectoryOption,
pipeNameOption
};
rootCommand.SetAction((parseResult, cancellationToken) =>
{
Expand All @@ -193,6 +204,7 @@ static CliRootCommand CreateCommandLineParser()
var sharedDependenciesPath = parseResult.GetValue(sharedDependenciesOption);
var extensionAssemblyPaths = parseResult.GetValue(extensionAssemblyPathsOption) ?? Array.Empty<string>();
var extensionLogDirectory = parseResult.GetValue(extensionLogDirectoryOption)!;
var pipe = parseResult.GetValue(pipeNameOption)!;

var serverConfiguration = new ServerConfiguration(
LaunchDebugger: launchDebugger,
Expand All @@ -202,11 +214,17 @@ static CliRootCommand CreateCommandLineParser()
SessionId: sessionId,
SharedDependenciesPath: sharedDependenciesPath,
ExtensionAssemblyPaths: extensionAssemblyPaths,
ExtensionLogDirectory: extensionLogDirectory);
ExtensionLogDirectory: extensionLogDirectory,
PipeName: pipe);

return RunAsync(serverConfiguration, cancellationToken);
});

return rootCommand;
}

static string GetDotNetPipeConnectionString(string pipeName)
{
return "\\\\.\\" + pipeName;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this syntax also work on Mac/Linux pipes? Or should we expect that the host is providing the Win32 name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure! Attempting to test on mac now


Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ internal record class ServerConfiguration(
string? SessionId,
string? SharedDependenciesPath,
IEnumerable<string> ExtensionAssemblyPaths,
string ExtensionLogDirectory);
string ExtensionLogDirectory,
string PipeName);
Loading