-
Notifications
You must be signed in to change notification settings - Fork 30k
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
VSCode doesn't send textDocument & semantic highlighting requests #204906
Comments
the client needs to receive the requests and forward them onto the server context.subscriptions.push(
vscode.workspace.onDidOpenTextDocument((document: vscode.TextDocument) => {
// forward onto LSP
})
);
context.subscriptions.push(
vscode.languages.registerDocumentSemanticTokensProvider(DocumentSelector, DocumentSemanticTokensProvider, SemanticTokensLegend)
); |
Can you tell me how exactly do I forward these requests to the server. I've written this code const provider : DocumentSemanticTokensProvider = {
provideDocumentSemanticTokens: function (document: TextDocument, token: CancellationToken): ProviderResult<SemanticTokens> {
throw new Error("Function not implemented.");
},
onDidChangeSemanticTokens : null,
provideDocumentSemanticTokensEdits : null,
}
const legend : SemanticTokensLegend = {
tokenTypes: [
SemanticTokenTypes.namespace,
SemanticTokenTypes.type,
SemanticTokenTypes.class,
SemanticTokenTypes.enum,
SemanticTokenTypes.interface,
SemanticTokenTypes.struct,
SemanticTokenTypes.typeParameter,
SemanticTokenTypes.parameter,
SemanticTokenTypes.variable,
SemanticTokenTypes.property,
SemanticTokenTypes.enumMember,
SemanticTokenTypes.event,
SemanticTokenTypes.function,
SemanticTokenTypes.method,
SemanticTokenTypes.macro,
SemanticTokenTypes.keyword,
SemanticTokenTypes.modifier,
SemanticTokenTypes.comment,
SemanticTokenTypes.string,
SemanticTokenTypes.number,
SemanticTokenTypes.regexp,
SemanticTokenTypes.operator,
SemanticTokenTypes.decorator
],
tokenModifiers: [
SemanticTokenModifiers.declaration,
SemanticTokenModifiers.definition,
SemanticTokenModifiers.readonly,
SemanticTokenModifiers.static,
SemanticTokenModifiers.deprecated,
SemanticTokenModifiers.abstract,
SemanticTokenModifiers.async,
SemanticTokenModifiers.modification,
SemanticTokenModifiers.documentation,
SemanticTokenModifiers.defaultLibrary
]
}
context.subscriptions.push(
languages.registerDocumentSemanticTokensProvider(['ch'], provider, legend)
); |
putting that in
here you will need to contact your server and then |
I can't seem to find a implementation of an LSP that has such code. Plus they are so complicated ! |
In the There should be a sample that provides semantic tokens through server by making request using the language server client ! The semantic tokens request is still not being sent, even with this Code, I've added console logs, This is what I get in console I am not getting the It seems the extension is not even attempting to send the request, even after hooking the document semantic tokens provider export function activate(context: ExtensionContext) {
let serverOptions = () => {
// Connect to language server via socket
let socket = net.connect({ port: 5007 })
let result: StreamInfo = {
writer: socket,
reader: socket
};
return Promise.resolve(result);
};
let clientOptions: LanguageClientOptions = {
documentSelector: ['ch'],
synchronize: {
fileEvents: workspace.createFileSystemWatcher('**/*.ch')
}
};
// Create the language client and start the client.
lc = new LanguageClient('Chemical Server', serverOptions, clientOptions);
context.subscriptions.push(
workspace.onDidOpenTextDocument((document: TextDocument) => {
console.log("[Request] onDidOpenTextDocument Not Being Sent To LSP Server")
})
);
context.subscriptions.push(vscode.languages.registerDocumentSemanticTokensProvider(['ch'], new DocumentSemanticTokensProvider(), legend));
lc.setTrace(Trace.Verbose);
lc.start().then(() => {
console.log("[Debug] ChemicalLSP Running")
}).catch((e) => {
console.error("[Debug] Error running ChemicalLSP", e)
});
}
export function deactivate() {
return lc.stop().then(() => {
console.log("[Debug] ChemicalLSP Stopped")
}).catch((e) => {
console.error("[Debug] Error Stopping ChemicalLSP", e)
});
}
// interface IParsedToken {
// line: number;
// startCharacter: number;
// length: number;
// tokenType: string;
// tokenModifiers: string[];
// }
class DocumentSemanticTokensProvider implements vscode.DocumentSemanticTokensProvider {
async provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.SemanticTokens> {
console.log("[Request] textDocument/semanticTokens/full");
return lc.sendRequest("textDocument/semanticTokens/full", { textDocument : document }).catch(e => {
console.error("Error sending semantic tokens request", e)
return e
})
}
// TODO
// onDidChangeSemanticTokens ?: vscode.Event<void> = function (e) {
// Not implemented Yet
// Also the return type is Disposable
// }
// TODO
// async provideDocumentSemanticTokensEdits(document: vscode.TextDocument, previousResultId: string, token: vscode.CancellationToken): vscode.ProviderResult<vscode.SemanticTokens | vscode.SemanticTokensEdits> {
// Not implemented Yet
// }
private _encodeTokenType(tokenType: string): number {
if (tokenTypes.has(tokenType)) {
return tokenTypes.get(tokenType)!;
} else if (tokenType === 'notInLegend') {
return tokenTypes.size + 2;
}
return 0;
}
private _encodeTokenModifiers(strTokenModifiers: string[]): number {
let result = 0;
for (let i = 0; i < strTokenModifiers.length; i++) {
const tokenModifier = strTokenModifiers[i];
if (tokenModifiers.has(tokenModifier)) {
result = result | (1 << tokenModifiers.get(tokenModifier)!);
} else if (tokenModifier === 'notInLegend') {
result = result | (1 << tokenModifiers.size + 2);
}
}
return result;
}
// private async _convertParsedTokens(allTokens : IParsedToken[]) : Promise<vscode.SemanticTokens> {
// const builder = new vscode.SemanticTokensBuilder();
// allTokens.forEach((token) => {
// builder.push(token.line, token.startCharacter, token.length, this._encodeTokenType(token.tokenType), this._encodeTokenModifiers(token.tokenModifiers));
// });
// return builder.build();
// }
} |
Ok, I've found the error, The error is that you need |
I guess I'm still not done, I'm getting the request on server, I can also BUT -> no syntax highlighting ! Here's what my server is returning for the full semanticTokens Request : Server Returns:std::vector<SemanticToken> toks;
toks.push_back(SemanticToken{
0, 0, 4, SemanticTokenType::ls_keyword, 0
});
toks.push_back(SemanticToken{
0, 5, 1, SemanticTokenType::ls_variable, 0
});
toks.push_back(SemanticToken{
0, 2, 1, SemanticTokenType::ls_operator, 0
});
toks.push_back(SemanticToken{
0, 2, 1, SemanticTokenType::ls_number, 0
});
toks.push_back(SemanticToken{
0, 1, 1, SemanticTokenType::ls_operator, 0
}); Client ConsoleSample Code
Update : Server Exception Occurred
|
Fixed With : async provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.SemanticTokens> {
console.log("[Request] textDocument/semanticTokens/full");
const params : SemanticTokensParams = {
textDocument : {
uri : document.uri.toString()
}
}
// @ts-ignore
return lc.sendRequest("textDocument/semanticTokens/full", params).catch(e => {
console.error("Error sending semantic tokens request", e)
return Promise.reject(e)
})
} |
Microsoft : Hire me please... |
VSCode is not sending didOpen , didChange & didClose requests as well, To fix this I tried these things with semantic highlighting full request, I can provide the semantic tokens when the user opens the file for the first time, BUT making changes to source code is known to VSCode only which is not saved in the file on disk, which is read by my server providing tokens. To provide the very fresh tokens for fresh edits user made, I must track the source code changes done by the user, vscode will send these changes to my server, I'll keep it in memory as 1 - Catch and send requests from client to the server in the extension, however this results in errors2 - VSCode has lsp user input sample, which has a
|
Okay I fixed it, The way you do it this :
I also used this as the document selector so vscode knows the language
|
Does this issue occur when all extensions are disabled?: Yes
I am trying to build a Language Server, For that I used LspCpp in C++ to build the language server, so it would be really fast. I started out the basic implementation and I am not receiving the textDocument requests (didOpen, change), also not receiving the semantic highlighting request for which I am interested in. I tried looking for other issues and made similar changes to my configuration file but nothing fixed it.
This doesn't seem like server issue, The request is just not being sent !
Notes
What I've tried
Projects
Here's my LSP client extension :
https://github.com/Qinetik/chemical-vscode
Here's my LSP server implementation :
https://github.com/Qinetik/chemical
Chat with the owner of LSPCpp :
kuafuwang/LspCpp#35 (comment)
The text was updated successfully, but these errors were encountered: