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

Find identifiers in scope #310

Closed
dsherret opened this issue Apr 12, 2018 · 2 comments
Closed

Find identifiers in scope #310

dsherret opened this issue Apr 12, 2018 · 2 comments

Comments

@dsherret
Copy link
Owner

dsherret commented Apr 12, 2018

For example:

const var1 = ...;
const var2 = ...;

function func() {
    const var3 = ...;
    callExpr();
    const var4 = ...;

    function innerFunc() {
    }
}

Given the node for callExpr(), it should be possible to call something like getIdentifiersInScope() and it would return these identifiers in the following order: var3, innerFunc, var2, var1 (closest to furthest).

Use case: Figuring out what identifier to use as an argument in a call expression when refactoring an application.

@dsherret
Copy link
Owner Author

dsherret commented Apr 8, 2019

Looks like getSymbolsInScope in the compiler API would be useful for this.

@dsherret dsherret added this to the 2.1.0 milestone Apr 8, 2019
dsherret added a commit that referenced this issue May 19, 2019
@dsherret
Copy link
Owner Author

In 3.0.0 there is a new method Node#getSymbolsInScope(meaning: ts.SymbolFlags).

const symbols = node.getSymbolsInScope(SymbolFlags.Value);

I'm not sure what a sensible default would be for meaning. Internally in the compiler api, that's a filter on the results. I put in a request to the TS team to see if a default would make sense there. Perhaps SymbolFlags.Value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant