0

I'm trying to make a content assist in my RCP application. For that, I'm using Xtend and AbstractJavaBasedContentProposalProvider. So, I made my AbstratMyDSLProposalProvider and now I'm writting the MyDSLProposalProvider class. Below, the xtend file and an extract of my grammar :

//Xtend file

override void completeKeyword(Keyword keyword,ContentAssistContextcontentAssistContext, ICompletionProposalAcceptor acceptor) {
    //acceptor.accept(createCompletionProposal(keyword, context))
    if(keyword.getValue().equals("const")){
        return;
    }
    super.completeKeyword(keyword, contentAssistContext, acceptor);
}

// Grammar File

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

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

Model:
     NEWLINE*
    (sections+=Options_sect?)?
    (sections+=Parameters_sect)?
;

Options_sect
 : name=SEC_OPTIONS QUOTE_COMMENT? NEWLINE+ suiteOpt=Suite_options? 
 ;

Suite_options
:  {Suite_options} INDENT (options+=Opt)* DEDENT NEWLINE?
;

Opt
: name=OPTION_NAME EQUAL (value=DECIMALINTEGER) NEWLINE+
;

Parameters_sect
 : name=SEC_PARAMETERS QUOTE_COMMENT? NEWLINE+ suiteParam=Suite_parameters?
 ;

Suite_parameters
: {Suite_parameters} INDENT (params+=Param)* DEDENT NEWLINE?
;

Param
 : CONST name=NAME EQUAL value=DECIMALINTEGER NEWLINE+
 ;

terminal SEC_OPTIONS : 'options'SPACES*':';
terminal SEC_PARAMETERS : 'parameters'SPACES*':';
terminal EQUAL : '=';
terminal DECIMALINTEGER : '0'|('1'..'9'(('_'|'0'..'9')*'0'..'9')?);
terminal NAME
 : ( ( PP_LABEL* ID_START ID_CONTINUE* PP_LABEL* ) | PP_LABEL )( '.' (PP_LABEL|ID_CONTINUE)* )*
 ;
terminal PP_LABEL
 : '%'ID_START ID_CONTINUE*'%'
 ;
terminal fragment ID_START
 : '_'
 | 'A'..'Z'
 | 'a'..'z'
 ;
 terminal fragment ID_CONTINUE
 : ID_START
 | '0'..'9'
 ;
terminal OPTION_NAME : '$'NAME;
terminal CONST : 'const';
terminal NEWLINE : ((NLINE SPACES?)+);
terminal fragment NLINE:( '\r'? '\n' | '\r' );
terminal  SPACES: (' '|'\t')+;

terminal QUOTE_COMMENT : INVERTED_COMMA -> INVERTED_COMMA;
terminal INVERTED_COMMA : '\"';

 // Indentation
terminal INDENT :'µµµ';
terminal DEDENT : '£££';

But the content assist doesn't work. Is it the good way to make a content assist in Xtext?

Thank you

alexmouth
  • 11
  • 3

1 Answers1

0

You have to override the complete method specific for your terminal rule complete_CONST - not complete keyword. If you go to the place where you would write the new method you get proposals for the method you can override

Christian Dietrich
  • 11,778
  • 4
  • 24
  • 32
  • Like this ? : override void complete_CONST(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor){ acceptor.accept(createCompletionProposal("const", context)) super.complete_CONST(model,ruleCall,context,acceptor) } – alexmouth Jun 13 '16 at 08:14
  • Okay but It doesn't work always... maybe it's the grammar? In my case the 'const' is only used in 'parameters' section : `Param : CONST name=NAME EQUAL value=Expr NEWLINE+ ;` – alexmouth Jun 13 '16 at 09:00
  • Can you give a complete minimal grammar – Christian Dietrich Jun 13 '16 at 09:02
  • `Model : NEWLINE* Inserted_lines? (sections+=Options_sect Inserted_lines?)? (sections+=Parameters_sect Inserted_lines?)? (sections+=Inputs_sect Inserted_lines?)? (sections+=Outputs_sect Inserted_lines?)? sections+=Scenario_sect; Parameters_sect : name=SEC_PARAMETERS QUOTE_COMMENT? NEWLINE+ suiteParam=Suite_parameters?; Suite_parameters : {Suite_parameters} INDENT (preproc+=Preproc_stmt|params+=Param|Persistent_comment)* DEDENT NEWLINE?; Param:CONST name=NAME EQUAL value=Expr NEWLINE+;` – alexmouth Jun 13 '16 at 09:07
  • i cannot reproduce this using eclipse. can you please try it with a hello word grammar. i dont know what your other stuff like IDENT and NEWLINE does. – Christian Dietrich Jun 13 '16 at 09:13
  • Sorry I don't understand what do you mean by Hello World grammar? I found an issue : the content assist is working but only one time. If I try to autocomplete a second time, at the next line, it's doesn't work. But If I try to complete the previous line, It's working. Do you have any idea? Thank a lot – alexmouth Jun 14 '16 at 14:19
  • Can you please give a grammar that I can copy and paste and step by step what you do in the model. I think your grammar is so restrictive that error recovery won't work so that your proposal provider is not called at all for the const terminal – Christian Dietrich Jun 14 '16 at 14:24
  • Sorry for the late, I update the grammar in my first post. I hope that it will be helpfull for you. My problem is : I can't write more than one instruction in my Options Section with the content assist. When I debug I'm out of the section but I'm not in the next section : Parameters section. – alexmouth Jun 22 '16 at 09:02