Repository navigation
Is it possible to use Pyright to get semantic tokens for Python? #11629
|
Sorry if this is a newbie question. I am implementing my own simple Python editor and would like to use Pyright to get semantic tokens. I am using OmniSharp.Extensions.LanguageServer to communcate with the language server (LS) From what I can tell by searching, I should initialize the LS as follows: _lspClient = LanguageClient.PreInit(options =>
{
options
// _pyrightProcess is the the result of Process.Start(node.exe, langserver.index.js --stdio)
.WithInput(_pyrightProcess.StandardOutput.BaseStream)
.WithOutput(_pyrightProcess.StandardInput.BaseStream)
.WithInitializationOptions(new{})
.WithCapability(new SemanticTokensCapability()
{
Requests = new SemanticTokensCapabilityRequests
{
Full = new Supports<SemanticTokensCapabilityRequestFull>(new SemanticTokensCapabilityRequestFull { Delta = false }),
},
TokenTypes = new Container<SemanticTokenType>(SemanticTokenType.Namespace, SemanticTokenType.Class),
});
});
await _lspClient.Initialize(_cts.Token);
var uri = new Uri("file:///inmemory.py");
_lspClient.TextDocument.DidOpenTextDocument(new DidOpenTextDocumentParams
{
TextDocument = new TextDocumentItem
{
Uri = uri,
LanguageId = "python",
Version = 1,
Text = "import datetime"
}
});
var semanticTokens = await _lspClient.TextDocument.RequestSemanticTokens(new SemanticTokensParams { TextDocument = new TextDocumentIdentifier(uri) });However, RequestSemanticTokens returns an OmniSharp.Extensions.JsonRpc.Server.MethodNotSupportedException: 'Method not found: 'textDocument/semanticTokens/full'.' Is this not supported? Am I missing something? Thanks. |
Replies: 1 comment
|
Semantic tokens are supported by Pylance, not by the open-source Pyright language server. Pyright does not advertise a The Pyright VS Code extension README also calls out semantic token highlighting as one of Pylance's additional capabilities: https://github.com/microsoft/pyright/blob/main/packages/vscode-pyright/README.md#static-type-checker-for-python There are a few semantic-token references in Pyright's LSP test infrastructure, but those describe client capabilities and refresh handling; they do not implement or register a semantic-token provider. |
Semantic tokens are supported by Pylance, not by the open-source Pyright language server. Pyright does not advertise a
semanticTokensProvider, so theMethod not found: 'textDocument/semanticTokens/full'response is expected.The Pyright VS Code extension README also calls out semantic token highlighting as one of Pylance's additional capabilities: https://github.com/microsoft/pyright/blob/main/packages/vscode-pyright/README.md#static-type-checker-for-python
There are a few semantic-token references in Pyright's LSP test infrastructure, but those describe client capabilities and refresh handling; they do not implement or register a semantic-token provider.