Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » createProposals gets called twice within same context
createProposals gets called twice within same context [message #1753412] Mon, 06 February 2017 07:25 Go to next message
Markus Amshove is currently offline Markus AmshoveFriend
Messages: 23
Registered: March 2016
Junior Member
Hello,

I'm trying to implement completion proposals based on datatypes within the language, so that it only suggests variables with the correct datatype.

I've got it to work but I've found that it still suggests other variables which don't match the given prefix.

After some fiddling I found out that the
createProposals
method gets called twice with the same context, one time with and one time without the prefix.


Simplified grammar:

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	variables+=Variable* statements+=Statement* calls+=StatementCall*;
	
Variable: 'let' name=ID;

StatementCall: statement=[Statement] '(' parameter+=[Variable]* ')';

Statement: 'Statement' name=ID '(' parameter+=Variable* ')';

terminal ID:
	'^'? ('a'..'z' | 'A'..'Z' | '-' | '$') ('a'..'z' | 'A'..'Z' | '-' | '0'..'9')*;


My proposalprovider:

/*
 * generated by Xtext 2.10.0
 */
package org.xtext.example.mydsl.ui.contentassist

import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor

/**
 * See https://www.eclipse.org/Xtext/documentation/304_ide_concepts.html#content-assist
 * on how to customize the content assistant.
 */
class MyDslProposalProvider extends AbstractMyDslProposalProvider {
	
	override createProposals(ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		println('''curr: «context.currentModel» prev: «context.currentModel» prefix: «context.prefix»''')
		super.createProposals(context, acceptor)
	}
	
}


Test.mydsl:

let One
let $Two

Statement add(let x let y)

add(O)


When I'm hitting CTRL+SPACE after the
add(O
then the output is the following:

curr: org.xtext.example.mydsl.myDsl.impl.StatementCallImpl@6d0dcd4b prev: org.xtext.example.mydsl.myDsl.impl.StatementCallImpl@6d0dcd4b prefix: 
curr: org.xtext.example.mydsl.myDsl.impl.StatementCallImpl@6d0dcd4b prev: org.xtext.example.mydsl.myDsl.impl.StatementCallImpl@6d0dcd4b prefix: O


I expected the proposal to be called once only, because when I'm done filtering it does the same stuff without the prefix.

Expected proposals are:
One

What I got:
One
$Two


Does it have something to do with the $-prefix?



Re: createProposals gets called twice within same context [message #1753413 is a reply to message #1753412] Mon, 06 February 2017 07:55 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 222
Registered: June 2013
Senior Member
Hi Markus,
what you have done is just modifying the very basic function which is called in multiple context.
usually, you just override a very special routine in the proposal provider which starts with "complete" like:

override completeMergefile_Name(EObject model, Assignment assignment, 
		ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		completeRuleCall(((assignment.getTerminal()as RuleCall)), context, acceptor);
		for (String fileId : LxtCore::getListFileIds) {
				acceptor.accept(createCompletionProposal(fileId , context))
		}
	}

[Updated on: Mon, 06 February 2017 07:56]

Report message to a moderator

Re: createProposals gets called twice within same context [message #1753414 is a reply to message #1753413] Mon, 06 February 2017 08:09 Go to previous messageGo to next message
Markus Amshove is currently offline Markus AmshoveFriend
Messages: 23
Registered: March 2016
Junior Member
Hi Uli,

overriding the
createProposals
method was a hint that I got during a Xtext workshop.

However, using the specific overrides I still get the same results:

	override completeStatementCall_Parameter(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		println('''curr: «context.currentModel» prev: «context.currentModel» prefix: «context.prefix»''')
		super.completeStatementCall_Parameter(model, assignment, context, acceptor)
	}


Output:
curr: org.xtext.example.mydsl.myDsl.impl.StatementCallImpl@3baed0a9 prev: org.xtext.example.mydsl.myDsl.impl.StatementCallImpl@3baed0a9 prefix: O
curr: org.xtext.example.mydsl.myDsl.impl.StatementCallImpl@3baed0a9 prev: org.xtext.example.mydsl.myDsl.impl.StatementCallImpl@3baed0a9 prefix: 
Re: createProposals gets called twice within same context [message #1754049 is a reply to message #1753414] Tue, 14 February 2017 07:28 Go to previous messageGo to next message
Markus Amshove is currently offline Markus AmshoveFriend
Messages: 23
Registered: March 2016
Junior Member
Can anyone confirm that it might be a bug with the prefixer (not) handling the $ correctly?
Re: createProposals gets called twice within same context [message #1754051 is a reply to message #1754049] Tue, 14 February 2017 07:44 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 10320
Registered: July 2009
Senior Member
doesnt your grammar perfectly allow

add(x$)

which gives you two params x and $

so in your case if you have

add(x|
there could be a new var or the old var continued

?!?

since you have the $ you dont need a space to separate the params

add($$$) would be legit

=> it really depends on how you want to deal with this
Re: createProposals gets called twice within same context [message #1754065 is a reply to message #1754051] Tue, 14 February 2017 10:05 Go to previous messageGo to next message
Markus Amshove is currently offline Markus AmshoveFriend
Messages: 23
Registered: March 2016
Junior Member
Oh right, the * in the ID was supposed to be a +.

I changed it to:
terminal ID:
	'^'? ('a'..'z' | 'A'..'Z' | '-' | '$') ('a'..'z' | 'A'..'Z' | '-' | '0'..'9')*;


However, the problem still persists.

The variable prefixed with a $ always shows up, no matter what I want to autocomplete (as if the prefix matcher always returns true).


I've recorded a gif to show you what I mean.
Re: createProposals gets called twice within same context [message #1754070 is a reply to message #1754065] Tue, 14 February 2017 10:55 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 10320
Registered: July 2009
Senior Member
terminal ID:
'^'? ('a'..'z' | 'A'..'Z' | '-' | '$') ('a'..'z' | 'A'..'Z' | '-' | '0'..'9')*;
still has no +

if i change it to + it works for me
Re: createProposals gets called twice within same context [message #1754087 is a reply to message #1754070] Tue, 14 February 2017 12:58 Go to previous messageGo to next message
Markus Amshove is currently offline Markus AmshoveFriend
Messages: 23
Registered: March 2016
Junior Member
I copy-pasted it incorrectly Smile

The gif is done with the + instead of *.

I just confirmed it again.

if I type in varO and trigger completion it filters out varTwo and varThree correctly, but the variable with the $ sign is still in there
Re: createProposals gets called twice within same context [message #1754092 is a reply to message #1754087] Tue, 14 February 2017 13:27 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 10320
Registered: July 2009
Senior Member
can you please share you model
Re: createProposals gets called twice within same context [message #1754182 is a reply to message #1754092] Wed, 15 February 2017 06:18 Go to previous messageGo to next message
Markus Amshove is currently offline Markus AmshoveFriend
Messages: 23
Registered: March 2016
Junior Member
Grammar:

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"


Model:
	variables+=Variable* statements+=Statement* calls+=StatementCall*;
	
Variable: 'let' name=ID;

StatementCall: statement=[Statement] '(' parameter+=[Variable]* ')';

Statement: 'Statement' name=ID '(' parameter+=Variable* ')';

terminal ID:
	'^'? ('a'..'z' | 'A'..'Z' | '-' | '$') ('a'..'z' | 'A'..'Z' | '-' | '0'..'9')+;



Test.mydsl:

let varOne
let varTwo
let varThree
let $somethingWithDollar

Statement add(let x let y)

add(


I've also attached the 2 files from the model directory of the core dsl project. I hope thats what you asked for Smile

[Updated on: Wed, 15 February 2017 06:20]

Report message to a moderator

Re: createProposals gets called twice within same context [message #1754184 is a reply to message #1754182] Wed, 15 February 2017 06:38 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 10320
Registered: July 2009
Senior Member
still cannot reproduce. sure you regenerated the language? which xtext version do you use?
Re: createProposals gets called twice within same context [message #1754185 is a reply to message #1754184] Wed, 15 February 2017 06:58 Go to previous messageGo to next message
Markus Amshove is currently offline Markus AmshoveFriend
Messages: 23
Registered: March 2016
Junior Member
I'm using 2.10 and regenerated.

Do you not get the variable with $ in every (filtered) proposal? Thats strange.

I just created a new project from scratch with the grammar, generated the language, startet runtime eclipse and the issue still persists.

Also I just noticed that the completion (as in insertion) of the proposal behaves differently (see attached gif).

I pushed the example to Github in case you have to look at generated stuff
Re: createProposals gets called twice within same context [message #1754189 is a reply to message #1754185] Wed, 15 February 2017 07:23 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 10320
Registered: July 2009
Senior Member
i am testing with 2.11
Re: createProposals gets called twice within same context [message #1754192 is a reply to message #1754189] Wed, 15 February 2017 08:03 Go to previous messageGo to next message
Markus Amshove is currently offline Markus AmshoveFriend
Messages: 23
Registered: March 2016
Junior Member
strange, for me it behaves the same way with generating from 2.11 (again, completly new project)

What does work is pressing CTRL+SPACE first and then typing "var", the one with $ will disappear.

var<C-SPACE> still shows up the $ one and appends it on completion
Re: createProposals gets called twice within same context [message #1754201 is a reply to message #1754192] Wed, 15 February 2017 09:28 Go to previous message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 10320
Registered: July 2009
Senior Member
yes but that is still the very same problem

let varOne
let varTwo
let varThree
let var
let $somethingWithDollar

Statement add(let x let y)

add(var$somethingWithDollar)


is a legit model
Previous Topic:See all feature accesses in Xtend files using Eclipse?
Next Topic:Error: Cyclic resolution of lazy links
Goto Forum:
  


Current Time: Sun Mar 26 19:11:23 GMT 2017

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

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