Hi,

I’m trying to come up with code completion for my MiniJava lab. On most of code positions i get NOCONTEXT(COMPLETION(…

For example for

someVar = this.

i get:

:: Completion triggered for: NOCONTEXT(COMPLETION(""))
   (context could not be parsed with this grammar; consider experimenting
   with additional productions for this partial construct, possibly
   marked with a {recover} annotation.) (candidate sorts: [VarDec, MethodDecl])

For things where i just need a variable such as:

someVar = ...

it works.

What am i doing wrong? The console out suggests to use recover rules, but very little documentation on that. I presume i should somehow modify my grammar to support partial constructs, but for trying something like:

VariableExpression "." ID "(" {Expression ","}* ")"				-> VariableExpression {cons("FunctionCall")}
VariableExpression "."	-> VariableExpression {cons("PartialFunctionCall"),recover}

doesn’t change anything.

I would appreciate any suggestions. Thank you.

Submitted by Vlad Vergu on 12 November 2010 at 20:37

On 16 November 2010 at 11:52 Vlad Vergu commented:

As suggested by Lennart and Guido a valid context is given if the completion is triggered on a complete AST.

This is sufficient answer for me; i.e. question answered.

Details for others (MiniJava colleagues) running into this:

A complete AST in this case means a valid AST generated from (syntactically) valid MiniJava code:

MethodDecl(
    IntType()
  , "fac"
  , [Arg(IntType(), "num")]
  , []
  , []
  , ReturnStatement(
      FunctionCall(
        This()
      , "fa"
      , [MinusExpression(IntLit("1"), IntLit("1"))]
      )
    )
  )

If completion is triggered following “fa” in the function call a valid context will be given:
FunctionCall(This(),COMPLETION(“fa”),[MinusExpression(IntLit(“1”),IntLit(“1”))])

An incomplete AST would be something that is generated from syntactically invalid code. For example in my case triggering completion (at _) on:

class Fac extends _

gives NOCONTEXT whereas triggering on:

class Fac extends _ {
	
} 

gives:

Super(COMPLETION(""))

On 17 November 2010 at 09:55 Lennart Kats closed this issue.

On 17 November 2010 at 09:55 Lennart Kats commented:

Thanks for posting your resolution here. This is an area for future improvement though; at some point we want to get rid of most of those NOCONTEXT cases or at least handle the case where the parser has insufficient information differently.


On 23 March 2011 at 14:51 Tobi Vollebregt tagged completion

Log in to post comments