Skip to content
This repository was archived by the owner on Dec 1, 2019. It is now read-only.

Commit b768c24

Browse files
author
Stanislav Panferov
committed
fix(host): add ad-hoc files lookup to support typings scenario
1 parent 0fa2adf commit b768c24

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/host.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,17 @@ export class Host implements ts.LanguageServiceHost {
9696

9797
getScriptSnapshot(fileName) {
9898
let file = this.state.getFile(fileName);
99-
if (file) {
100-
return this.state.ts.ScriptSnapshot.fromString(file.text);
99+
if (!file) {
100+
try {
101+
this.state.readFileAndUpdateSync(fileName);
102+
file = this.state.getFile(fileName);
103+
}
104+
catch (e) {
105+
return;
106+
}
101107
}
108+
109+
return this.state.ts.ScriptSnapshot.fromString(file.text);
102110
}
103111

104112
getCurrentDirectory() {
@@ -293,9 +301,9 @@ export class State {
293301
return changed
294302
}
295303

296-
addFile(fileName: string, text: string): void {
304+
addFile(fileName: string, text: string): IFile {
297305
fileName = this.normalizePath(fileName);
298-
this.files[fileName] = {
306+
return this.files[fileName] = {
299307
text: text,
300308
version: 0
301309
}

0 commit comments

Comments
 (0)