csharp-language-server-protocol icon indicating copy to clipboard operation
csharp-language-server-protocol copied to clipboard

While initializing an LSP client, how to set ProcessId in InitializeParams

Open yevgeni-zolotko opened this issue 4 years ago • 1 comments

While initializing an LSP client, is there a way to set InitializeParams.ProcessId? This code:

        public async Task Initialize(CancellationToken token)
        {
            var @params = new InitializeParams {
                Trace = _trace,
                ClientInfo = _clientInfo,
                Capabilities = _clientCapabilities,
                RootUri = _rootUri!,
                RootPath = _rootUri?.GetFileSystemPath() ?? string.Empty,
                WorkspaceFolders = new Container<WorkspaceFolder>(WorkspaceFoldersManager.CurrentWorkspaceFolders),
                InitializationOptions = _initializationOptions!
            };

Doesn't seem to include ProcessId from anywhere. Some servers require ProcessId to be set, so I came up with the following workaround:

        options.OnInitialize(OnInitialize);
        //...

        private Task OnInitialize(ILanguageClient client, InitializeParams request, CancellationToken cancellationToken)
        {
            request.GetType().GetProperty("ProcessId").SetValue(request, (long)System.Diagnostics.Process.GetCurrentProcess().Id);
            return Task.CompletedTask;
        }

Is there a proper way to accomplish this?

yevgeni-zolotko avatar Apr 30 '21 14:04 yevgeni-zolotko

That is an effective workaround... however this should be handled better I would think. I'll take a look.

david-driscoll avatar May 25 '21 17:05 david-driscoll