Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add access to Abstract Syntax Tree #1982

Closed
ackava opened this issue May 25, 2020 · 6 comments
Closed

Please add access to Abstract Syntax Tree #1982

ackava opened this issue May 25, 2020 · 6 comments
Labels
feature-request Request for new features or functionality typescript
Milestone

Comments

@ackava
Copy link

ackava commented May 25, 2020

Please expose Abstract Syntax Tree from Language service for TypeScript. It will be of great help to analyze code model rather then reparsing it again (as there is no way to access internal model), I want to access imported modules.

Update

Can you add a method that goes inside worker and can access the model and return the result?

        function nodeVisitor(root) {
            // .. ast related code without any closure...
            return // ... some result...
        }

        // source of nodeVisitor is passed to 
        // typescript worker
        const result = await worker.processAst( nodeVisitor.toString() );

The underlying code simply passed this function as source code, which is executed in worker's context and result is returned either as string or or some JSON.

@orta
Copy link
Contributor

orta commented Jun 19, 2020

The AST can't be passed through the web worker as it can only send JSON

@luminaxster
Copy link
Contributor

It would be nice to add some API (like plugins or dynamic imports) to the workers, so we can expand the visitors and access their ASTs. I currently have to get the editor content and then parse the AST via JScodeshift (recast).

@ackava
Copy link
Author

ackava commented Jun 28, 2020

@orta Can you expose a method to access AST within the worker context? as shown in updated description of this issue?

@orta
Copy link
Contributor

orta commented Jun 29, 2020

A worker is async background code which you don't really have access to in a general sense from your user-land code.

@luminaxster's idea of being able to add your own dynamic import is probably the best option here - perhaps a new function in here: https://github.com/microsoft/monaco-typescript/blob/master/src/tsWorker.ts#L235 which calls importScripts with your own URL which has a default export as a function which receives a copy of ts and and the TypeScriptWorker this instance.

@ackava
Copy link
Author

ackava commented Jun 30, 2020

@orta Yes I know what is background worker, this is the reason the function is passed as a string, which is evaluated in worker and executed. Your recommendation is little longer way to do same thing, and there is no much documentation and sample on how to do it exactly, how to access AST and when and what to do?

@orta
Copy link
Contributor

orta commented Sep 4, 2020

microsoft/monaco-typescript#65 would allow you to create your own webworker which can do AST stuff I the background

@alexdima alexdima added feature-request Request for new features or functionality typescript labels Sep 12, 2020
@alexdima alexdima added this to the August 2020 milestone Sep 12, 2020
@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality typescript
Projects
None yet
Development

No branches or pull requests

4 participants