metaborg / nabl

Spoofax' Name Binding Language
Apache License 2.0
7 stars 12 forks source link

Extension info in Tooltip #64

Open AZWN opened 3 years ago

AZWN commented 3 years ago

Short description Show scope extensions in tooltips on user-defined constraints and references to those. For rules, only scope extensions of that rule should be shown.

Problem description. When a specification has circular dependencies on declaration and query constraints, these end up as "unsolved" errors. These problems are notoriously hard to debug. Additional information on the scope extensions of rules/constraints can make debugging these easier.

Describe the solution you'd like Consider the following specification:

rules
  /* 1 */ declareVar: scope * ID * TYPE
  /* 2 */ declareVar(s, x, T) :- !var[x, T] in s.

  /* 3 */ declOk: scope * Decl
  /* 4 */ declOk(s, VarDecl(x, t)) :- 
    /* 5 */ declareVar(s, x, typeOfType(s, t)).
  /* 6 */ declOk(s, ModDecl(x, decls)) :- {s_mod}
    new s_mod, s_mod -P-> s,
    !mod[x, MOD(s_mod)] in s,
    /* 7 */ declsOk(s_mod, decls). 

Now, the tooltips should show the following for each predicate (reference) at the numbered positions:

  1. "extends: 1 with 'var'"
  2. "extends: s with 'var'"
  3. "extends: 1 with 'var', 'mod'"
  4. "extends: s with 'var'"
  5. "extends: s with 'var'"
  6. "extends: s with 'mod'"
  7. "extends: s_mod with 'mod', 'var"

Describe alternatives you've considered

A first alternative would be to explain people how to inspect the scope extensions term in a compiled specification, but that is both too complicated for many users, and too repetitive.

Additional context

Scope extension properties are stored in the nabl2 custom analysis value, and can be retrieved from there. Open question: How to access extension analysis for individual rules.