Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XBASE content assist inconsistent behavior(XBASE content assist inconsistent behavior)
XBASE content assist inconsistent behavior [message #1786426] Thu, 03 May 2018 08:22 Go to next message
Thomas Petrou is currently offline Thomas PetrouFriend
Messages: 12
Registered: April 2018
Junior Member
Dear all,

Sorry for bothering you again but i have encountered strange (=newbie) problem that is bothering me for more than a week now.

I have the following simple grammar
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase

import "http://www.eclipse.org/xtext/xbase/Xbase"

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

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' name=ID '!';



AS you can see it simply the one generated by eclipse but i have replaced the usage of terminals with the usage of XBase.

In the first screenshot (with terminals no Xbase )
index.php/fa/32747/0/
you can clearly see that content assist works after the work hello and suggests the word 'name' as a possible option. Same after the word name it suggests the symbol "!"

After i introduce Xbase content assist stops working for both name and the "1".
index.php/fa/32748/0/
index.php/fa/32749/0/

Console is clean from any errors and i cant find any other errors anywhere.

Any ideas about this specific problem?

Also i assume that there is somekind of way to introduce more detailed logging in order to troubleshoot this type of problems (e.g. force eclipse to stop as soon as it encounters an exception, tracing etc). Can someone give me a direction on an introductory level article about debugging/troubleshooting my dsl?

Thank you again!
Thomas

Re: XBASE content assist inconsistent behavior [message #1786428 is a reply to message #1786426] Thu, 03 May 2018 08:25 Go to previous messageGo to next message
Thomas Petrou is currently offline Thomas PetrouFriend
Messages: 12
Registered: April 2018
Junior Member
Please note that the images havent been rendered properly. There is more to see on the right :)
Re: XBASE content assist inconsistent behavior [message #1786435 is a reply to message #1786428] Thu, 03 May 2018 09:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
MyDslProposalProvider now inherits from XbaseProposalProvider and not TerminalsProposalProvider which behaves diffently.
e.g. if you move stuff like org.eclipse.xtext.common.ui.contentassist.TerminalsProposalProvider.complete_ID(EObject, RuleCall, ContentAssistContext, ICompletionProposalAcceptor)
back to your proposal provider it will work again.

alternatively simply customize the completeX_y methods e.g. completeGreeting_Name


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XBASE content assist inconsistent behavior [message #1786479 is a reply to message #1786435] Fri, 04 May 2018 05:57 Go to previous messageGo to next message
Thomas Petrou is currently offline Thomas PetrouFriend
Messages: 12
Registered: April 2018
Junior Member
Thanks Christian, some more clarification if you don't mind

i have copied and pasted (modified java to be xtend) the whole implementation from the terminals abstract provider in my MyDslProposalProvider (since i didn't have anything myself) here it is
[code]
/*
* generated by Xtext 2.12.0
*/
package org.xtext.example.mydsl.ui.contentassist

import org.eclipse.emf.ecore.EObject
import org.eclipse.jface.text.contentassist.ICompletionProposal
import org.eclipse.xtext.Assignment
import org.eclipse.xtext.GrammarUtil
import org.eclipse.xtext.RuleCall
import org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor
import org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher
import org.eclipse.xtext.util.Strings


public class MyDslProposalProvider extends AbstractMyDslProposalProvider {

override public void complete_ID(EObject model, RuleCall ruleCall, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
if (doCreateIdProposals()) {
var PrefixMatcher newMatcher = new PrefixMatcher() {

override public boolean isCandidateMatchingPrefix(String name, String prefix) {
var String strippedName = name;
if (name.startsWith("^") && !prefix.startsWith("^")) {
strippedName = name.substring(1);
}
return context.getMatcher().isCandidateMatchingPrefix(strippedName, prefix);
}
};
var ContentAssistContext myContext = context.copy().setMatcher(newMatcher).toContext();
var String feature = getAssignedFeature(ruleCall);
var String proposalText = if (feature !== null)
feature
else
Strings.toFirstUpper(ruleCall.getRule().getName().toLowerCase());
var String displayText = proposalText;
if (feature !== null)
displayText = proposalText + " - " + ruleCall.getRule().getName();
proposalText = getValueConverter().toString(proposalText, ruleCall.getRule().getName());
var ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, myContext);
if (proposal instanceof ConfigurableCompletionProposal) {
var ConfigurableCompletionProposal configurable = proposal as ConfigurableCompletionProposal;
configurable.setSelectionStart(configurable.getReplacementOffset());
configurable.setSelectionLength(proposalText.length());
configurable.setAutoInsertable(false);
configurable.setSimpleLinkedMode(myContext.getViewer(), '\t', ' ');
}
acceptor.accept(proposal);
}
}

def private String getAssignedFeature(RuleCall call) {
var Assignment ass = GrammarUtil.containingAssignment(call);
if (ass !== null) {
var String result = ass.getFeature();
if (result.equals(result.toLowerCase()))
result = Strings.toFirstUpper(result);
return result;
}
return null;
}

override public void complete_STRING(EObject model, RuleCall ruleCall, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
if (doCreateStringProposals()) {
var String feature = getAssignedFeature(ruleCall);
createStringProposal(context, acceptor, feature, ruleCall);
}
}

def private void createStringProposal(ContentAssistContext context, ICompletionProposalAcceptor acceptor,
String feature, RuleCall ruleCall) {
var String proposalText = if (feature !== null)
feature
else
Strings.toFirstUpper(ruleCall.getRule().getName().toLowerCase());
proposalText = getValueConverter().toString(proposalText, ruleCall.getRule().getName());
var String displayText = proposalText;
if (feature !== null)
displayText = displayText + " - " + ruleCall.getRule().getName();
var ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context);
if (proposal instanceof ConfigurableCompletionProposal) {
var ConfigurableCompletionProposal configurable = proposal as ConfigurableCompletionProposal;
configurable.setSelectionStart(configurable.getReplacementOffset() + 1);
configurable.setSelectionLength(proposalText.length() - 2);
configurable.setAutoInsertable(false);
configurable.setSimpleLinkedMode(context.getViewer(), proposalText.charAt(0), '\t');

}
acceptor.accept(proposal);
}

override public void complete_INT(EObject model, RuleCall ruleCall, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
var String feature = getAssignedFeature(ruleCall);
if (doCreateIntProposals()) {
// createIntProposal(context, acceptor, feature, "0");
createIntProposal(context, acceptor, ruleCall, feature, 1);
// createIntProposal(context, acceptor, feature, "2");
// createIntProposal(context, acceptor, feature, "5");
// createIntProposal(context, acceptor, feature, "10");
// createIntProposal(context, acceptor, feature, "50");
// createIntProposal(context, acceptor, feature, "100");
// createIntProposal(context, acceptor, feature, "1000");
}
}

def protected boolean doCreateIntProposals() {
return true;
}

def protected boolean doCreateStringProposals() {
return true;
}

def protected boolean doCreateIdProposals() {
return true;
}

def private void createIntProposal(ContentAssistContext context, ICompletionProposalAcceptor acceptor,
RuleCall ruleCall, String feature, int i) {
var String proposalText = getValueConverter().toString(i, ruleCall.getRule().getName());
var String displayText = proposalText + " - " + ruleCall.getRule().getName();
if (feature != null)
displayText = proposalText + " - " + feature;
var ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context);
if (proposal instanceof ConfigurableCompletionProposal) {
var ConfigurableCompletionProposal
configurable = proposal as ConfigurableCompletionProposal;
configurable.setSelectionStart(configurable.getReplacementOffset());
configurable.setSelectionLength(proposalText.length());
configurable.setAutoInsertable(false);
configurable.setSimpleLinkedMode(context.getViewer(), '\t', ' ');
}
acceptor.accept(proposal);
}

override public void complete_ML_COMMENT
(EObject model
, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}

override public void complete_SL_COMMENT(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}

override public void complete_WS(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}

override public void complete_ANY_OTHER(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}

}

[code]


Name proposal now works. Unfortunately the proposal for the "!" does not work. I understand that i will need to create a new method for that. If yes which which is the method?

After checking the above i have also modified the grammar a little bit (an XBlockExpression has been added). It now looks
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase

import "http://www.eclipse.org/xtext/xbase/Xbase"

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

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' name=ID expr = XBlockExpression '!';


ID (=name) proposal works but the proposal of the opening curly brackets of the XBlockExpression proposal does not work, same for the ending '!'

Does this mean that i need to implement the methods for the openning and closing curly brackets? What kind of behaviour should i expect within XBase expresions?

Kind regards and thank you again
Thomas
Re: XBASE content assist inconsistent behavior [message #1786481 is a reply to message #1786479] Fri, 04 May 2018 07:12 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12237
Registered: July 2009
Senior Member
well this is the next xbase specialty :

org.eclipse.xtext.xbase.ui.contentassist.XbaseProposalProvider.isKeywordWorthyToPropose(Keyword)


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:XBASE content assist inconsistent behavior
Next Topic:Define grammar in Xtext for optional array dimensions
Goto Forum:
  


Current Time: Sun Sep 23 10:58:22 GMT 2018

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

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

Back to the top