How can I access the AST that VSCode creates

依然范特西╮ 提交于 2019-12-10 18:13:56

问题


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.

This works:

var testvar1 = new sap.m.Button();

Now i can use IntelliSense in VSCode in the testvar1.

The Problem e.g.:

sap.ui.define([
  "sap/ui/core/mvc/Controller"
  ], 
  function (Controller) {
    "use strict";
    return Controller.extend("", {

    });
  });

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.


回答1:


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) {
     ...
  });

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



来源:https://stackoverflow.com/questions/47617153/how-can-i-access-the-ast-that-vscode-creates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!