Description
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
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