Language server seems to trigger build twice during initialization [message #1863128] |
Wed, 17 January 2024 14:20 |
Simon Cockx Messages: 69 Registered: October 2021 |
Member |
|
|
During profiling of the language server, I noticed that the Xtext language server seems to trigger a build (i.e., validation + code generation) twice during initialization; one time after receiving the `initialize` request, and one time after receiving all `didOpen` requests. This results in unnecessary computations and doubled `textDocument/publishDiagnostics` events.
Is there a reason for this? Why is validation initially triggered before any `didOpen` requests? Is it safe to disable it?
Snippet of the code I'm using to test this:
// Initialization
System.out.println("initialize");
InitializeParams initParams = new InitializeParams();
initParams.setWorkspaceFolders(List.of(
new WorkspaceFolder(
workspacePath.toUri().toString(),
workspaceName
)
));
server.initialize(initParams).get();
System.out.println("initialized");
server.initialized(new InitializedParams());
System.out.println("Setup done");
// Open files
System.out.println("didOpens");
for (String uri : workspaceURIs) {
DidOpenTextDocumentParams openParams = new DidOpenTextDocumentParams(
new TextDocumentItem(
uri,
"rosetta",
1,
Resources.toString(new URL(uri), Charsets.UTF_8)
));
server.getTextDocumentService().didOpen(openParams);
}
// Wait for diagnostics
System.out.println("Wait for diagnostics");
server.getRequestManager().runRead((cancelIndicator) -> client.getDiagnostics()).get();
System.out.println("Got diagnostics");
// Close files
System.out.println("didCloses");
for (String uri : workspaceURIs) {
DidCloseTextDocumentParams closeParams = new DidCloseTextDocumentParams(
new TextDocumentIdentifier(
uri
));
server.getTextDocumentService().didClose(closeParams);
}
// Shutdown
System.out.println("shutdown");
server.getRequestManager().shutdown();
server.shutdown().get();
I also added log lines on the client whenever it receives a message, and on the generator whenever it starts generating. This results in the following log:
initialize
Generating for file:///xxx/annotations.rosetta
Generating for file:///xxx/basictypes.rosetta
Generating for file:///xxx/reg-model.rosetta
Generating for file:///xxx/reg.rosetta
initialized
Received message: textDocument/publishDiagnostics
Received message: textDocument/publishDiagnostics
Received message: textDocument/publishDiagnostics
Received message: textDocument/publishDiagnostics
Setup done
didOpen file:///xxx/basictypes.rosetta
didOpen file:///xxx/annotations.rosetta
didOpen file:///xxx/reg-model.rosetta
didOpen file:///xxx/reg.rosetta
Wait for diagnostics
Received message: textDocument/publishDiagnostics
Generating for file:///xxx/basictypes.rosetta
Received message: textDocument/publishDiagnostics
Generating for file:///xxx/reg-model.rosetta
Received message: textDocument/publishDiagnostics
Generating for file:///xxx/annotations.rosetta
Received message: textDocument/publishDiagnostics
Generating for file:///xxx/reg.rosetta
Got diagnostics
didClose file:///xxx/basictypes.rosetta
didClose file:///xxx/annotations.rosetta
didClose file:///xxx/reg-model.rosetta
didClose file:///xxx/reg.rosetta
shutdown
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04225 seconds