Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Text changes not reflected on the AST
Text changes not reflected on the AST [message #1850296] Thu, 24 February 2022 12:39 Go to next message
Alejandro González is currently offline Alejandro GonzálezFriend
Messages: 8
Registered: November 2021
Location: Aachen, Germany
Junior Member
We're currently experiencing a strange behavior in the internal AST of an Xtext language server when working with different clients (VSCode and Eclipse). More precisely, when using the Xtext language server with the VSCode client, the internal AST seems to not reflect the changes done on the client side. The following is a workflow that summarizes the problem (following the Greetings grammar for better understanding):

- Create a new file *.greet on VSCode -> Automatically starts the Xtext language server and initializes the communication
- Fill the new file with some greetings:

Hello Foo !
Hello Bar !


- Save the file on VSCode -> Triggers a didSave call to the server -> On the server we check that the greeting values (Foo and Bar) are correctly part of the AST.
- Modify the *.greet file and change the greetings:

Hello Foo !
Hello Baz !


- Save the file on VSCode -> Triggers a didSave call to the server -> The greeting values on the AST are not changed and remain (Foo and Bar).
- From now on, further changes on the client will not be reflected on the AST.

If we restart the client server and change our greetings file, we'll be able to see the changes only the first time.

- Open our *.greet file again.
- Modify the *.greet file by changing the greetings:

Hello Foo !
Hello Baz !


- Save the file on VSCode -> Triggers a didSave call to the server -> On the server we check the greeting values (Foo and Baz) on the AST.
- From now on (again), further changes on the client will not be reflected on the AST.

This behavior does not appear when we use the language server from Eclipse (as explained here -> https://www.eclipse.org/Xtext/documentation/340_lsp_support.html)

So far we've tried to explain this behavior with the following hypothesis:

Different clients, different behavior -> take a look to the initialization parameters
In the bunch of parameters used to initialize a language server, it seems that the Xtext language server only considers the "TextDocument" and the "Workspace" capabilities. When comparing both initialization requests, we're not able to see a clear difference that could explain the problem.

Different clients, different behavior -> take a look to the message exchange between client and server
Focused on the didChange method, we can see that in both cases the changes done on the client side are correctly forwarded to the server side. Of course, there are differences on the number and order of the messages exchanged but we've been focused on the didChange (others are hover, documentSymbol, semanticTokens, completion, publishDiagnostics, ... which seem to be not related with the problem)

Does anybody have any hint that could indicate us where the problem could be? I'd like to remark that the same workflow works correctly in Eclipse. Perhaps it is an initialization parameter coming from VSCode the one that makes the difference and we have ignored it?

Attached you can find the initialization messages on the VSCode and Eclipse cases.

A similar question has be asked on SO

[Updated on: Thu, 24 February 2022 12:41]

Report message to a moderator

Re: Text changes not reflected on the AST [message #1850298 is a reply to message #1850296] Thu, 24 February 2022 13:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14349
Registered: July 2009
Senior Member
Hi, i have zero idea. maybe you can write a unit test and example that produces the problem

Save the file on VSCode -> Triggers a didSave call to the server -> On the server we check that the greeting values (Foo and Bar) are correctly part of the AST.

what did you do there?

also: did you investigate didChangeWatchedFiles

maybe there is a problem with version number in VersionedTextDocumentIdentifier

also: which xtext versions, lsp4j version, lsp version in vscode client do you use

do you face the same problem with
https://marketplace.visualstudio.com/items?itemName=itemis.xtext-vscode-example


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 24 February 2022 13:26]

Report message to a moderator

Re: Text changes not reflected on the AST [message #1850302 is a reply to message #1850298] Thu, 24 February 2022 13:44 Go to previous messageGo to next message
Alejandro González is currently offline Alejandro GonzálezFriend
Messages: 8
Registered: November 2021
Location: Aachen, Germany
Junior Member
Hi Christian, thanks for your help

Christian Dietrich wrote on Thu, 24 February 2022 13:16

Hi, i have zero idea. maybe you can write a unit test and example that produces the problem


We'll work on that

Christian Dietrich wrote on Thu, 24 February 2022 13:16

Save the file on VSCode -> Triggers a didSave call to the server -> On the server we check that the greeting values (Foo and Bar) are correctly part of the AST.

what did you do there?


Currently we've overwritten the didSave method of the LanguageServerImpl and we printout the values of the AST we're interested in (not actually our code but basically it shows what we do):

@Override
public void didSave(DidSaveTextDocumentParams params) {

	URI uri = URI.createURI(params.getTextDocument().getUri());

	XtextResource resource = (XtextResource) getWorkspaceManager().getProjectManager(uri).getResource(uri);

	EList<EObject> modelObjects = resource.getContents();

	System.out.println("SAVING MODEL " + " (" + resource.getContents().size() + ") -> "
			+ ((Greetings) modelObjects.get(0)).getGreetings().get(1).getName())


}


Christian Dietrich wrote on Thu, 24 February 2022 13:16

also: did you investigate didChangeWatchedFiles

maybe there is a problem with version number in VersionedTextDocumentIdentifier


We haven't tried the didChangeWatchedFiles, however I don't think that the problem is the versioning because it seems that Xtext ignores it in the didChange method (see didChangeTextDocumentContent in the WorkspaceManager)

Christian Dietrich wrote on Thu, 24 February 2022 13:16

also: which xtext versions, lsp4j version, lsp version in vscode client do you use


Xtext version -> 2.26.0.M2
LSP4J version -> 0.12.0
vscode-languageclient -> 7.0.0
Re: Text changes not reflected on the AST [message #1850303 is a reply to message #1850302] Thu, 24 February 2022 14:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14349
Registered: July 2009
Senior Member
the read looks wired. normally you read in a transaction
requestManager.runRead -> workspaceManager.doRead -> access resource here
or
ilanguageserveraccess.doread -> access resource here

can you also check with rc1


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 24 February 2022 14:55]

Report message to a moderator

Re: Text changes not reflected on the AST [message #1850326 is a reply to message #1850303] Fri, 25 February 2022 08:01 Go to previous messageGo to next message
Alejandro González is currently offline Alejandro GonzálezFriend
Messages: 8
Registered: November 2021
Location: Aachen, Germany
Junior Member
Provided example as attached ZIP
Re: Text changes not reflected on the AST [message #1850329 is a reply to message #1850326] Fri, 25 February 2022 09:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14349
Registered: July 2009
Senior Member
did you try my proposal?

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Text changes not reflected on the AST [message #1850333 is a reply to message #1850329] Fri, 25 February 2022 11:59 Go to previous messageGo to next message
Alejandro González is currently offline Alejandro GonzálezFriend
Messages: 8
Registered: November 2021
Location: Aachen, Germany
Junior Member
Christian, your assumptions were correct, the access to the XtextResource was done in an incorrect way. By accessing the resource in the following way, the values match the expectation
...
getLanguageServerAccess().doRead(params.getTextDocument().getUri(),
	(ILanguageServerAccess.Context context) -> {
		Resource resource = context.getResource();
		System.out.println("SAVING MODEL " + " (" + resource.getContents().size() + ") -> "
			+ ((Greetings) modelObjects.get(0)).getGreetings().get(1).getName())
		return null;
	});
...


I guess that the fact that using an Eclipse client the problem did not occur was just circumstantial?

Is there any resource where this transactional operation is a little bit more explained? We're really interested on creating our own custom language server implementation and it would be nice to know more about the internals of the language server

Many thanks for your quick and helpful support!
Re: Text changes not reflected on the AST [message #1850334 is a reply to message #1850333] Fri, 25 February 2022 12:27 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14349
Registered: July 2009
Senior Member
sorry i have no idea. you need to reverse engineer the code. i also cannot tell why it worked for you in eclipse.
you also may need to debug both cases and see
what happens on follow requests in both cases


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Xtext&Xtend Milestone 2.26.0.RC1 is available now
Next Topic:Generate correct code in xtend
Goto Forum:
  


Current Time: Sun Sep 25 08:38:31 GMT 2022

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

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

Back to the top