Skip to content

Commit

Permalink
Refresh newly opened spl2 documents and cells via didOpen. (#120)
Browse files Browse the repository at this point in the history
* Refresh newly opened spl2 documents and cells via didOpen.
This eliminates the hack that added " " edit to force language server updates across documents.

* Fix version
  • Loading branch information
fantavlik authored Apr 9, 2024
1 parent 55f6f52 commit 71b2733
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions out/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,20 @@ async function handleSpl2Document(context, progressBar) {
console.log(`handleSpl2Document`);
if (spl2Client) {
console.log(`spl2Client detected`);
// Client and server are already running, try refreshing for case of new document
const range = new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 1));
const text = vscode.window.activeTextEditor.document.getText(range) || " ";
vscode.window.activeTextEditor.edit((editBuilder) => {
// To refresh language server make a harmless edit by replacing the first character
editBuilder.replace(range, text);
});
// send new didOpen message to refresh language server (even if already open)
// this workaround is needed as SPL2 language server doesn't currently cache
// all open documents and will only re-parse when new documents are opened
spl2Client.client.sendRequest(
'textDocument/didOpen',
{
textDocument: {
uri: vscode.window.activeTextEditor.document.uri.toString(),
languageId: vscode.window.activeTextEditor.document.languageId,
version: vscode.window.activeTextEditor.document.version,
text: vscode.window.activeTextEditor.document.getText(),
}
}
);
return;
}
try {
Expand Down

0 comments on commit 71b2733

Please sign in to comment.