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

LanguageServerHost fileExists / readFile no longer optional? #18753

Closed
tomv564 opened this issue Sep 25, 2017 · 3 comments
Closed

LanguageServerHost fileExists / readFile no longer optional? #18753

tomv564 opened this issue Sep 25, 2017 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@tomv564
Copy link

tomv564 commented Sep 25, 2017

TypeScript Version: 2.4.2, also in master

This issue was encountered when upgrading javascript-typescript-langserver from typescript 2.3.4 (see sourcegraph/javascript-typescript-langserver#356)

Code

When implementing a LanguageServiceHost without implementing optional fileExists or readFile, the compilerHost instance silently skips import statements:

export class InMemoryLanguageServiceHost implements ts.LanguageServiceHost {
  // only required members implemented here..
}

The above implementation compiled without errors against 2.4.2, but all import statements in source files added to the language server failed to resolve, resulting in diagnostics, missing definitions, completions, etc.

Expected behavior:

Either:

  • Compilation failure indicating that LanguageServiceHost is now incomplete
  • Module resolver falls back to ModuleResolutionHost to access fileExists / readFile

Actual behavior:

Imports fail to resolve where they do exist, in nodeModuleResolverWorker, following the path:

nodeLoadModuleByRelativeName -> loadModuleFromFile
loadModuleFromFile ->  tryExtension -> tryFile -> state.host.fileExists

Debugger screenshot showing the issue at runtime at https://github.com/Microsoft/TypeScript/blob/21bbdd33c51f07a46663e9b50fff62e9c007c806/src/services/services.ts#L1166

screen shot 2017-09-25 at 19 37 12

The typings published at https://github.com/Microsoft/TypeScript/blob/master/lib/typescript.d.ts#L3764-L3765 show that the two members are still optional.

This dependency appears to have been introduced at: 2ec92b9

@mhegazy mhegazy assigned ghost Sep 25, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Sep 25, 2017

@andy-ms can you take a look.

@mhegazy mhegazy added the API Relates to the public API for TypeScript label Sep 25, 2017
@DanielRosenwasser
Copy link
Member

Looks like a dupe of #16616

@mhegazy mhegazy added Duplicate An existing issue was already created and removed API Relates to the public API for TypeScript labels Sep 25, 2017
@mhegazy mhegazy unassigned ghost Sep 25, 2017
@tomv564
Copy link
Author

tomv564 commented Sep 25, 2017

Thanks for the quick update. A comment about why those members are optional in the published typescript.d.ts might be nice for future implementers?

I'm satisfied with the explanation, feel free to close!

@tomv564 tomv564 closed this as completed Sep 25, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants