如何访问 VSCode 创建的 AST [英] How can I access the AST that VSCode creates
问题描述
我为 UI5 JavaScript 编写了一个 VSCode 扩展.最缺少的功能是为 UI5 提供 IntelliSense.使用 UI5 类型它会起作用,但不是全部.
I write a VSCode Extension for UI5 JavaScript. The most missing Feature is to have IntelliSense for UI5. Using UI5 typings it will work but not in all.
这有效:
var testvar1 = new sap.m.Button();
现在我可以在 testvar1 的 VSCode 中使用 IntelliSense.
Now i can use IntelliSense in VSCode in the testvar1.
问题例如:
sap.ui.define([
"sap/ui/core/mvc/Controller"
],
function (Controller) {
"use strict";
return Controller.extend("", {
});
});
本例中函数中有一个Controller变量,这个变量是之前用Namespace定义的.我现在搜索在我的扩展中使用命名空间分配这个变量的可能性.我知道这可以在 AST 中完成,但我现在知道如何访问 AST 以进行设置:
In this case there is a Controller variable in the function, this variable is defined with the Namespace before. I search now for a possibility to assign this variable in my Extension with the Namespace. I know this can be done in the AST but i have now idear how to get access to the AST to set:
Controller = sap.ui.core.mvc.Controller
目标是现在在变量控制器中拥有完整的智能感知
The goal is to have the full IntelliSense now in the variable Controller
我希望到目前为止我想要什么.
I hope it is clear what i want, so far.
推荐答案
如果你只需要给 Controller
一个类型,请尝试使用 jsdocs:
If you only need to give a type to Controller
, try using jsdocs:
sap.ui.define([
"sap/ui/core/mvc/Controller"
],
function (/** @type {sap.m.Controller} */ Controller) {
...
});
要回答原始问题,您可以使用 TypeScript 服务器插件.这不是微不足道的,所以我会尽量避免这样做,除非你真的需要
To answer the original question, you can access/modify the AST with a TypeScript server plugin. This is not trivial so I would try to avoid doing this unless you really need to
这篇关于如何访问 VSCode 创建的 AST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!