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

pxq42qpu  于 2023-01-27  发布在  其他
关注(0)|答案(2)|浏览(164)

我试图在Visual Studio中启用LSP的诊断跟踪,就像在msdn中编写的那样。
按照说明,我做了以下步骤:
1.我已将ConfigurationSections添加到ILanguageClient

public IEnumerable<string> ConfigurationSections
{
    get
    {
        yield return "foo";
    }
}

1.我创建了VSWorkspaceSettings.json文件的以下行:

{
   "foo.trace.server": "Verbose"
}

1.我将VSWorkspaceSettings.json文件添加到写入ILanguageClient的.vs文件夹和实现LSP的解决方案的.vs文件夹。
但是,它不起作用。我错过了什么?也许我复制了VSWorkspaceSettings.json文件到错误的文件夹?

6ie5vjzr

6ie5vjzr1#

我不知道如何启用它,但我找到了另一种方法来获取来自Visual Studio的所有JSON请求。在语言客户端,我通过创建类似hereInterceptionStream来拦截来自Visual Studio的所有请求,并 Package 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();
    }
}
pokxtpni

pokxtpni2#

编辑:此答案的上半部分似乎专门针对示例项目,该项目配置自己的日志,跳到底部查找客户端日志位置。

我很难启用这个功能(也使用了您链接的指南)。我不完全确定我是否已经“解决”了这个问题,但这些步骤确实帮助我获得了日志:
我手动创建了文件夹%Temp%\VisualStudio\LSP,在使用Microsoft演示LSP项目完成此操作后,当我运行语言服务器时,出现了MockLog.svclog启动。
如果您按照建议创建VSWorkspaceSettings.json,则似乎需要将其放置在与您使用测试Visual Studio示例打开的项目相关的.vs文件夹中;我正在使用TestFiles文件夹,并将其放置在创建的.“vs”文件夹中。
这似乎反映在日志中,但似乎对初始输出没有任何影响,尽管我还没有详细探讨这一点:

编辑:这是我查找客户端日志的最接近的一次:

我还注意到,%Temp%\VSLogs文件夹中似乎生成了*.LSPClient.MockLanguageExtension.FooLanguageClient.*.svclog的某种日志文件

相关问题