Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Language server seems to trigger build twice during initialization
Language server seems to trigger build twice during initialization [message #1863128] Wed, 17 January 2024 14:20 Go to next message
Simon Cockx is currently offline Simon CockxFriend
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
Re: Language server seems to trigger build twice during initialization [message #1863132 is a reply to message #1863128] Wed, 17 January 2024 17:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14699
Registered: July 2009
Senior Member
If you open a workspace with broken files
And have no files open.
You won't know that there are broken files
In the workspace


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Language server seems to trigger build twice during initialization [message #1863134 is a reply to message #1863132] Wed, 17 January 2024 22:09 Go to previous messageGo to next message
Simon Cockx is currently offline Simon CockxFriend
Messages: 69
Registered: October 2021
Member
Okay, that makes sense. Then maybe I got it the other way around: why should the `didOpen` requests trigger a rebuild if the workspace was already built during initialization?

[Updated on: Wed, 17 January 2024 22:32]

Report message to a moderator

Re: Language server seems to trigger build twice during initialization [message #1863225 is a reply to message #1863134] Thu, 18 January 2024 04:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14699
Registered: July 2009
Senior Member
Cause did open give a new current version of the file.
Now the dirty state in the editor will shadow the file on disk


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Language server seems to trigger build twice during initialization [message #1863227 is a reply to message #1863225] Thu, 18 January 2024 07:26 Go to previous messageGo to next message
Simon Cockx is currently offline Simon CockxFriend
Messages: 69
Registered: October 2021
Member
Thanks for the explanation.

If I understand correctly, if I don't want to trigger a rebuild, I should somehow check whether the file was modified between `initialize` and `didOpen`, and if it was not (which will be the case 99.9% of the times, except if it was modified by another process/application), just skip the rebuild.

[Updated on: Thu, 18 January 2024 07:26]

Report message to a moderator

Re: Language server seems to trigger build twice during initialization [message #1863228 is a reply to message #1863227] Thu, 18 January 2024 08:57 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14699
Registered: July 2009
Senior Member
yes

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Dot '.' is not allowed inside double quote in Xtext
Next Topic:Remove the hierarchy from the name of cross reference
Goto Forum:
  


Current Time: Wed Jul 24 02:50:27 GMT 2024

Powered by FUDForum. Page generated in 0.03630 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top