createProposals gets called twice within same context [message #1753412] |
Mon, 06 February 2017 02:25  |
Eclipse User |
|
|
|
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 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 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 02:55   |
Eclipse User |
|
|
|
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 02:56] by Moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05574 seconds