2

I'm trying to enable diagnostics tracing for LSP in Visual Studio like written in msdn.

According to the instructions, I did the following steps:

  1. I've added the ConfigurationSections to the ILanguageClient

    public IEnumerable<string> ConfigurationSections
    {
        get
        {
            yield return "foo";
        }
    }
    
  2. I created VSWorkspaceSettings.json file the following line:

    {
       "foo.trace.server": "Verbose"
    }
    
  3. I added the VSWorkspaceSettings.json file to the .vs folder where the ILanguageClient is written and the .vs folder of the solution that the LSP is implemented for.

But, it doesn't work. What I'm missing? Maybe I copy the VSWorkspaceSettings.json file to the wrong folder?

itaiy
  • 1,152
  • 1
  • 13
  • 22

2 Answers2

1

I didn't find how to enable it, but I found another way to get all the JSON requests from the visual studio. In the Language client-side, I intercepted all the requests from Visual studio by creating InterceptionStream like here and I wrap the PipeStream.

The Usage:

var readerPipe = new NamedPipeClientStream(readerPipeName);
var writerPipe = new NamedPipeClientStream(writerPipeName);
var fileStream = File.OpenWrite(logFilePath);
var interceptionStream = new InterceptionStream(writerPipe, fileStream);

if (process.Start())
{
     await Task.WhenAll(readerPipe.ConnectAsync(token), writerPipe.ConnectAsync(token));
     return new Connection(readerPipe, interceptionStream);
}

The InterceptionStream:

public class InterceptionStream : Stream
{
    public InterceptionStream(Stream innerStream, Stream copyStream)
    {
        InnerStream = innerStream ?? throw new ArgumentNullException(nameof(innerStream));
        CopyStream = copyStream ?? throw new ArgumentNullException(nameof(copyStream));

        if (!CopyStream.CanWrite)
        {
            throw new ArgumentException("copyStream is not writable");
        }
    }

    public Stream InnerStream { get; }

    public Stream CopyStream { get; }

    public override bool CanRead => InnerStream.CanRead;

    public override bool CanSeek => InnerStream.CanSeek;

    public override bool CanWrite => InnerStream.CanWrite;

    public override long Length => InnerStream.Length;

    public override long Position
    {
        get => InnerStream.Position;
        set => InnerStream.Position = value;
    }

    public override void Flush()
    {
        InnerStream.Flush();
    }

    public override long Seek(long offset, SeekOrigin origin)
    {
        return InnerStream.Seek(offset, origin);
    }

    public override void SetLength(long value)
    {
        InnerStream.SetLength(value);
    }

    public override int Read(byte[] buffer, int offset, int count)
    {
        var bytesRead = InnerStream.Read(buffer, offset, count);

        if (bytesRead != 0)
        {
            CopyStream.Write(buffer, offset, bytesRead);
        }

        return bytesRead;
    }

    public override void Write(byte[] buffer, int offset, int count)
    {
        InnerStream.Write(buffer, offset, count);
        CopyStream.Write(buffer, offset, count);
    }

    protected override void Dispose(bool disposing)
    {
        CopyStream.Dispose();
        InnerStream.Dispose();
    }
}
itaiy
  • 1,152
  • 1
  • 13
  • 22
0

EDIT: The top part of this answer seems to deal specifically with the example project, which configures its own log, skip to the bottom for the client log location.

I struggled with enabling this (also using the guide you linked). I'm not entirely sure if I've "solved" it, but these steps certainly helped me obtain logs:

I manually created the folder %Temp%\VisualStudio\LSP, after doing this using the Microsoft demo LSP project, a MockLog.svclog started appeared when I ran the language server.

If you create the VSWorkspaceSettings.json as suggested, it seems to need to be placed in the .vs folder related to the project you're opening with the test Visual Studio instance; I was using TestFiles Folder, and placing it inside the '.vs` folder created in there.

That seems to be reflected in the logs, but it did not seem to make any difference to the initial output, although I haven't explored this in detail:

enter image description here

EDIT: This is the closest I've come to finding logs for the client:

I also noted there seems are some kind of log files generated in the %Temp%\VSLogs folder of the form *.LSPClient.MockLanguageExtension.FooLanguageClient.*.svclog

Chris
  • 8,268
  • 3
  • 33
  • 46