如何在Visual Studio中启用LSP的诊断跟踪

问题描述 投票:0回答:1

我试图像在msdn中编写的那样在Visual Studio中启用LSP的诊断跟踪。

根据说明,我执行了以下步骤:

  1. 我已将ConfigurationSections添加到ILanguageClient

    public IEnumerable<string> ConfigurationSections
    {
        get
        {
            yield return "foo";
        }
    }
    
  2. 我在以下行中创建了VSWorkspaceSettings.json文件:

    {
       "foo.trace.server": "Verbose"
    }
    
  3. 我将VSWorkspaceSettings.json文件添加到写入ILanguageClient的.vs文件夹以及为其实施LSP的解决方案的.vs文件夹。

但是,它不起作用。我缺少什么?也许我将VSWorkspaceSettings.json文件复制到错误的文件夹中?

c# visual-studio visual-studio-2019 vsix language-server-protocol
1个回答
0
投票

我没有找到启用它的方法,但是我找到了另一种方法来从Visual Studio中获取所有JSON请求。在Language客户端,我通过创建像InterceptionStreamhere截获了Visual Studio的所有请求,并包装了PipeStream。

用法:

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);
}

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();
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.