Benni Katchy
Benni Katchy

Reputation: 83

Rascal LSP Typechecker

I am trying out figure out Rascal LSP and I have it working fine but I want to enable the TypeChecker but I can’t figure out how to construct a Builder object to pass to builder function from the code below?

@synopsis{Each kind of service contributes the implementation of one (or several) IDE features.}
data LanguageService
  = parser(Parser parser)
  | summarizer(Summarizer summarizer
    , bool providesDocumentation = true
    , bool providesDefinitions = true
    , bool providesReferences = true
    , bool providesImplementations = true)
  | outliner(Outliner outliner)
  | completer(Completer completer)
  | builder(Builder builder)
  | lenses(LensDetector detector)
  | inlayHinter(InlayHinter hinter)
  | executor(CommandExecutor executor)
  | documenter(Documenter documenter)
  | definer(Definer definer)
  | referrer(Referrer reference)
  | implementer(Implementer implementer)
  ;


set[LanguageService] aliasesContributions() = {
  parser(parser(#start[Program])) 
    build(“alias", checkAliases)// How do I construct this?
   outliner(aliasesOutliner),
   summarizer(aliasesSummarizer, providesImplementations = false)
 };

Tree checkAliases(Tree input){
  model = aliasesTModelFromTree(input); // your function that collects & solves
  types = getFacts(model);
  
 return input[@messages={*getMessages(model)}]
       [@hyperlinks=getUseDef(model)]
       [@docs=(l:"<prettyAType(types[l])>" | l <- types)]; 
}

I have gone through all the examples I can find but I haven't seen one that has it

Upvotes: 0

Views: 84

Answers (2)

Benni Katchy
Benni Katchy

Reputation: 83

I finally found out how to marshal a TModel into a Summary. Here is the code snippet:

Summary aliasesSummarizer(loc l, start[Program] input) {
    pt = parse(#start[Program], l).top;
    TModel model = aliasesTModelForTree(input); 
    definitions = model.definitions;
    return summary(l,
        messages = {<message.at, message> | message <- model.messages},
        references = {<definition, definitions[definition].defined> | definition <- definitions}
    );
  } 

Thanks to @Davy and @Jurgen for their help. I hope this helps someone else.

Upvotes: 1

Davy Landman
Davy Landman

Reputation: 15438

These two code files contains examples: https://github.com/usethesource/rascal-language-servers/blob/main/examples/pico-dsl-lsp/src/main/rascal/lang/pico/LanguageServer.rsc and https://github.com/usethesource/rascal-language-servers/blob/main/rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc

Roughly, if you register a summarizer you get called on ever save, than you have the option of typechecking it. I just checked the code, the builder is currently not hooked-up yet. But the code you have for the checkAliases can be rewrittten to return the Summary adt.

Upvotes: 1

Related Questions