Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XText Web - assist cancels validation(Help needed with XTextServlet/XText Web document synchnonization )
XText Web - assist cancels validation [message #1794658] Tue, 04 September 2018 14:57 Go to next message
Mykola Makhin is currently offline Mykola MakhinFriend
Messages: 17
Registered: July 2018
Junior Member
Hi

I've run into a problem with XText web editor using Ace editor.

I want to trigger auto-completion automatically whenever user changes content of the editor, or changes position of the cursor in the editor.

I've found ways to do that, but, apparently, this has created another issue - concurrent call to assist endpoint cancels currently running validate call. Validate simply returns
{ "conflict": "canceled" }

and ACE editor doesn't seem to do anything about it.

As a result, validation has practically stopped working.

It seems that cancellation is peformed by org.eclipse.xtext.web.server.model.DocumentSynchronizer, but it's hard to tell because of the weird way XTextServlet is implemented (with abstract set of "services" called via dispatcher, and everything being implemented in Xtend instead of Java doesn't help the case either).

Looking at DocumentSynchronizer it seems that it's acting as an optimistic lock of sorts, essentially failing any job on parallel execution.

It's not clear how is it possible to use XText Web at all then, since all AJAX calls to it would be asynchronous and concurrent, and they're going to cancel each other. Moreover, it's not clear why this synchronization takes effect for services like content assist and validation, that don't actually change the content - they only need read access to current state of AST.

Can anyone tell me how to circumvent the issue? Where do I even being with all this?

Thanks!

[Updated on: Tue, 04 September 2018 15:00]

Report message to a moderator

Re: XText Web - assist cancels validation [message #1794660 is a reply to message #1794658] Tue, 04 September 2018 15:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12254
Registered: July 2009
Senior Member
hi, can you please provide a reproducible example? do you use the full text or the incremental mode?
org.eclipse.xtext.web.server.contentassist.ContentAssistService.createProposals(XtextWebDocumentAccess, ITextRegion, int, int) indeed does a prio readonly
=> this will cancel other readers.
i assume this will be done cause you dont want to wait for ca.

since both can have side effects on the ast they cannot run in parallel


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

[Updated on: Tue, 04 September 2018 15:49]

Report message to a moderator

Re: XText Web - assist cancels validation [message #1794672 is a reply to message #1794660] Tue, 04 September 2018 17:58 Go to previous messageGo to next message
Mykola Makhin is currently offline Mykola MakhinFriend
Messages: 17
Registered: July 2018
Junior Member
Hi. I'm using the defaults thus incremental mode.

The content assist is only triggered by pressing ctrl+space by default though, so I've made a change to make it run on every update to the editor content and on every cursor move:
		require(["webjars/ace/1.2.3/src/ace"], function() {
			require(["xtext/xtext-ace"], function(xtext) {
				window.editor = xtext.createEditor({
					baseUrl: baseUrl,
					syntaxDefinition: "xtext-resources/generated/mode-mylang"
				});
				window.editor.xtextServices.editorContext.addServerStateListener(function() { 
					var cursorPosition = editor.getCursorPosition();
					editor.xtextServices.getContentAssist().done(function(proposals){ updateProposals(proposals, cursorPosition); });
				});
				
				window.editor.getSelection().addEventListener("changeCursor", function() {
					var cursorPosition = editor.getCursorPosition();
					editor.xtextServices.getContentAssist().done(function(proposals){ updateProposals(proposals, cursorPosition); });
				});
			});
		});

The updateProposals function will populate separate window with list of proposals that user can click and have inserted at the recorded cursor position.

It's somewhat surprising to me that creating proposals for content assist has some side effects on AST. I'm not sure why AST would change on retrieving list of proposals - seems that should've been a completely "read only" operation for AST.
Is this related to some caching or lazy parsing? o_O

[Updated on: Tue, 04 September 2018 17:59]

Report message to a moderator

Re: XText Web - assist cancels validation [message #1794674 is a reply to message #1794672] Tue, 04 September 2018 18:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12254
Registered: July 2009
Senior Member
no its the lazy resolving of cross references.
=> at start you have only proxies in the ast for cross references. they will be replaced with the real objects on access.
=> that can happen during validation and during content assist


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText Web - assist cancels validation [message #1794676 is a reply to message #1794674] Tue, 04 September 2018 18:44 Go to previous messageGo to next message
Mykola Makhin is currently offline Mykola MakhinFriend
Messages: 17
Registered: July 2018
Junior Member
I see.

The remaining question is how to circumvent this issue.

For now the only idea I have is to make a dirty hack by setting up a filter before Xtext servlet that would synchronize those calls by state ID. But that's not very pretty.

[Updated on: Tue, 04 September 2018 18:45]

Report message to a moderator

Re: XText Web - assist cancels validation [message #1794678 is a reply to message #1794676] Tue, 04 September 2018 19:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12254
Registered: July 2009
Senior Member
The question is. Why does your validation take so long that it has no chance to finish

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText Web - assist cancels validation [message #1794679 is a reply to message #1794678] Tue, 04 September 2018 20:13 Go to previous messageGo to next message
Mykola Makhin is currently offline Mykola MakhinFriend
Messages: 17
Registered: July 2018
Junior Member
Well, I've implemented it using advices I've got in this forum ( https://www.eclipse.org/forums/index.php/m/1793516/#msg_1793516 ). So...

But it doesn't actually take long - I have no idea why do you assume it has "no chance to finish" - if I remove the completion calls, validation calls finish very quickly on their own.

Thing is both completion and validation are triggered at the same time by the same event - which is change of the contents of editor.

[Updated on: Tue, 04 September 2018 20:14]

Report message to a moderator

Re: XText Web - assist cancels validation [message #1794680 is a reply to message #1794679] Tue, 04 September 2018 20:18 Go to previous messageGo to next message
Mykola Makhin is currently offline Mykola MakhinFriend
Messages: 17
Registered: July 2018
Junior Member
I've commented out completion calls and checked in the browser console how long does validation take - seems to be around 15 milliseconds on average.
http://i66.tinypic.com/dlp5rb.png

[Updated on: Tue, 04 September 2018 20:23]

Report message to a moderator

Re: XText Web - assist cancels validation [message #1794681 is a reply to message #1794680] Tue, 04 September 2018 20:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12254
Registered: July 2009
Senior Member
So maybe you should delay the auto content assist thingy a few ms. I don't really understand what's your usecase about that.
If the user does not enter anything manually then there is no need for a model


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText Web - assist cancels validation [message #1794682 is a reply to message #1794681] Tue, 04 September 2018 20:45 Go to previous messageGo to next message
Mykola Makhin is currently offline Mykola MakhinFriend
Messages: 17
Registered: July 2018
Junior Member
Quote:
delay the auto content assist thingy a few ms

I can do this for sure, but this clearly is a very bad and unreliable workaround - not a kind of design one could use in production quality code.

The usecase is pretty simple actually: user can type code in or choose (where applicable) options from an autocompletion section. It's pretty much just like an ordinary autocompletion, except user doesn't have to press ctrl+space to see it - it's triggered automatically - and it's not displayed in an overlay popup, but in a separate section near the editor. It's actually very convenient, especially for a new users who don't know the DSL well yet.

Pity I can't seem to easily synchronize update to document and references resolution (in general, anything that has sideeffects on AST).
Re: XText Web - assist cancels validation [message #1794683 is a reply to message #1794682] Tue, 04 September 2018 20:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12254
Registered: July 2009
Senior Member
What do you mean by synchronize. Do you mean sequentialize or do you mean order

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText Web - assist cancels validation [message #1794684 is a reply to message #1794683] Tue, 04 September 2018 21:03 Go to previous messageGo to next message
Mykola Makhin is currently offline Mykola MakhinFriend
Messages: 17
Registered: July 2018
Junior Member
Have a document (resource) specific mutex on server side for those operations to make them wait for each other to complete instead of cancelling each other.
Re: XText Web - assist cancels validation [message #1794685 is a reply to message #1794684] Tue, 04 September 2018 21:12 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12254
Registered: July 2009
Senior Member
As I said you might replace the prio readonly with a normal readonly.
But without an example I cannot do any experiments.
I am not even sure where the validation service is actually cancelled


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Generation based on DSL files in classpath
Next Topic:Can't instantiate byte/long due to"Bad" conversion by ValueConverter
Goto Forum:
  


Current Time: Wed Sep 26 14:20:25 GMT 2018

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

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

Back to the top