gpt4 book ai didi

How do you point to current file when creating a lens for Rascal in VSCode?(在VSCode中为Rascal创建镜头时,如何指向当前文件?)

转载 作者:bug小助手 更新时间:2023-10-25 17:59:04 25 4
gpt4 key购买 nike



Is there a way to point to the current file (by location) with its LanguageServer running, such that, you can:

有没有一种方法可以在当前文件的LanguageServer运行时指向当前文件(按位置),以便您可以:



  • run some arbitrary function doSomething

  • and use that pointer within such a function when trying to create a lens in VSCode?


更多回答
优秀答案推荐

The way to pass in parameters to the handler of a lense is to first extend the Command language with a new command, like so:

将参数传递给镜头的处理程序的方法是首先使用新命令扩展命令语言,如下所示:


data Command = myCommand(loc aParameter);

Next the lense detector collects all the lenses for a file, and binds all the parameters. This is an example that uses / to collect locations of expressions:

接下来,镜头检测器收集文件的所有镜头,并绑定所有参数。这是一个使用/收集表达式位置的示例:


rel[loc,Command] myLenses(start[Program] input) = {<e@\loc, myCommand(e@\loc, title="do something with this exp")> | /Exp e := input};

Finally the command handler executes the command when triggered:

最后,命令处理程序在触发时执行命令:


value myHandler(myCommand(loc e) {
// Do something with e
return ("result": true);
}

Then you register the lenses and the handler function as a contribution.

然后,您将镜头和处理程序功能注册为贡献。


Small parse trees or abstract subtract trees can be parameters to commands directly so you won't have to reparse, however if you have many large editors open it's better to pass locations and parse again for the sake of memory leaks.

较小的解析树或抽象减法树可以直接作为命令的参数,因此您不必重新解析,然而,如果您打开了许多大型编辑器,最好传递位置并再次解析,以避免内存泄漏。


更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com