Text changes not reflected on the AST [message #1850296] |
Thu, 24 February 2022 12:39 |
|
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 #1850302 is a reply to message #1850298] |
Thu, 24 February 2022 13:44 |
|
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 #1850333 is a reply to message #1850329] |
Fri, 25 February 2022 11:59 |
|
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!
|
|
|
|
Powered by
FUDForum. Page generated in 0.04620 seconds