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

LSP Mode does not seem to work with OmniSharp Client #1525

Closed
groogiam opened this issue Jun 14, 2019 · 2 comments
Closed

LSP Mode does not seem to work with OmniSharp Client #1525

groogiam opened this issue Jun 14, 2019 · 2 comments
Labels

Comments

@groogiam
Copy link

I am trying to use the OmniSharp C# Language Client to get diagnostic information about a C# project. So far I have been unsuccessful in this attempt.

I have been able to start the omnisharp service and initialize but OnPublishDiagnostics never seems to fire. When attempting to open and change a document I get an exception on the server.

at OmniSharp.Cake.Services.CakeScriptService.Generate(FileChange fileChange) in D:\a\1\s\src\OmniSharp.Cake\Services\CakeScriptService.cs:line 55

I am not sure if this is an issue with the server, the client or me just understanding the protocol. Any guidance you could provide on the issue would be much appreciated. The code for my sample is below.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using OmniSharp.Extensions.LanguageServer.Client;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;

namespace OmniSharpClient
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var loggerFactory = new Microsoft.Extensions.Logging.LoggerFactory();

            var omniSharpInfo = new ProcessStartInfo
            {
                FileName = @"C:\Users\username\OneDrive\Scratch\LangServer\omnisharp-win-x64\OmniSharp.exe",
                Arguments = @"-lsp cake:enabled=false"
                //Arguments = @"-s C:\Users\username\Desktop\LangServer\ConsoleTest"
            };

            var cancellationSource = new CancellationTokenSource();
            cancellationSource.CancelAfter(TimeSpan.FromSeconds(30));

            using (var client = new LanguageClient(loggerFactory, omniSharpInfo))
            {
                client.Window.OnLogMessage((string message, MessageType messageType) =>
                {
                    Console.WriteLine(message);
                });

                client.TextDocument.OnPublishDiagnostics(DiagnosticPublished);
                Console.WriteLine("Init...");
                await client.Initialize(
                                workspaceRoot: @"C:\Users\username\OneDrive\Scratch\LangServer\ConsoleTest",
                                initializationOptions: new { }, // If the server requires initialisation options, you pass them here.
                                cancellationToken: cancellationSource.Token
                            );

                await client.IsReady;

                await Task.Delay(10000);

                var fileName = @"C:\Users\username\OneDrive\Scratch\LangServer\ConsoleTest\Program.cs";

                client.TextDocument.DidOpen(fileName, "csharp"); //File.ReadAllText(fileName)
                await Task.Delay(3000);
                //client.TextDocument.DidClose(fileName);
                client.TextDocument.DidChange(fileName, "csharp", 1);

                await Task.Delay(10000);

                Console.WriteLine("Shutdown...");
                await client.Shutdown();
            }
        }

        public static void DiagnosticPublished(Uri documentUri, List<Diagnostic> diagnostics)
        {
            Console.WriteLine(documentUri);
        }
    }
}
@bjorkstromm
Copy link
Member

This was caused by an issue in the LSP libs here OmniSharp/csharp-language-server-protocol#156 will be fixed via #1562

@bjorkstromm
Copy link
Member

Fixed via #1562 and available in latest release https://github.com/OmniSharp/omnisharp-roslyn/releases/tag/v1.34.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants