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

Question: Lookup external module names #2593

Closed
basarat opened this issue Apr 2, 2015 · 3 comments
Closed

Question: Lookup external module names #2593

basarat opened this issue Apr 2, 2015 · 3 comments
Labels
API Relates to the public API for TypeScript Question An issue which isn't directly actionable in code

Comments

@basarat
Copy link
Contributor

basarat commented Apr 2, 2015

I already provide a decent experience for relative paths https://github.com/TypeStrong/atom-typescript#relative-paths

Want to expand it to also list the available external module declarations. But struggling to find the different between these two types:

declare module foo{
}

vs

declare module 'foo'{
}

Is there some LS API I could use to just get 'foo' and not foo?

Note: I have access to program so if its not possible using LS feel free to guide me a bit toward the program based solution 🌹

refs :TypeStrong/atom-typescript#230

@basarat
Copy link
Contributor Author

basarat commented Apr 2, 2015

What I've look at : they both seem to be SyntaxKind.ModuleDeclaration

@mhegazy
Copy link
Contributor

mhegazy commented Apr 2, 2015

yes. the external module have a name that is SyntaxKind.StringLiteral. so the check would be

  1. in Ambient context
  2. name of the module is stringLiteral

I had a PR (#2173) that did external module name completions, this might be helpful.

@mhegazy mhegazy added Question An issue which isn't directly actionable in code API Relates to the public API for TypeScript labels Apr 2, 2015
@basarat
Copy link
Contributor Author

basarat commented Apr 3, 2015

PR helped a lot. Thanks ❤️

export function getExternalModuleNames(program: Program): string[] {
    var entries: string[] = [];

    program.getSourceFiles().forEach(sourceFile => {

        // Look for ambient external module declarations
        forEachChild(sourceFile, child => {
            if (child.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>child).name.kind === SyntaxKind.StringLiteral) {
                entries.push((<ModuleDeclaration>child).name.text);
            }
        });
    });

    return entries;
}

@basarat basarat closed this as completed Apr 3, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
API Relates to the public API for TypeScript Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

2 participants