Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d0282b7
Add test to verify when source changes
sheetalkamat Jun 13, 2019
0adab89
Use source files instead of .d.ts files from project references
sheetalkamat Jun 21, 2019
c97be16
Log the config of the project
sheetalkamat Jun 21, 2019
746b01e
Check only for .d.ts files
sheetalkamat Jun 21, 2019
ecf8751
Check for language serivice enabled when including source files
sheetalkamat Jun 21, 2019
1810288
Fix tests
sheetalkamat Jun 21, 2019
f472868
Watch generated file if it doesnt exist when trying to translate it t…
sheetalkamat Jun 25, 2019
012ecda
Add sourceOf project reference redirect to filesByName list for redir…
sheetalkamat Jun 26, 2019
2f30add
More tests
sheetalkamat Jun 26, 2019
da9260c
Create original project when location is in source of project referen…
sheetalkamat Jun 26, 2019
75bd3cd
Fix more tests
sheetalkamat Jun 27, 2019
96a8c86
Merge branch 'master' into referencesPrototypeSourceFile
sheetalkamat Jun 28, 2019
f72af3b
Verify the scenarios when d.ts directory of dependency doesnt exist
sheetalkamat Jun 28, 2019
4d13f53
Merge branch 'master' into referencesPrototypeSourceFile
sheetalkamat Jul 1, 2019
f9e4b91
Fix incorrectly exported type
sheetalkamat Jul 1, 2019
f7ea0ba
Refactoring
sheetalkamat Jul 1, 2019
b5737fc
Refactor tests so its easy to edit and reason about them
sheetalkamat Jul 2, 2019
15b68a9
Skip typechecking of source of project reference redirect
sheetalkamat Jul 1, 2019
9be475b
Refactoring
sheetalkamat Jul 3, 2019
b1fa2eb
Errors using DiagnosticsSync commands
sheetalkamat Jul 5, 2019
824c22c
Source of project reference behave as if those files cannot be emitted.
sheetalkamat Jul 8, 2019
b631850
Add option disableSourceOfProjectReferenceRedirect to disable using s…
sheetalkamat Jul 10, 2019
103fe5f
Merge branch 'master' into referencesPrototypeSourceFile
sheetalkamat Jul 11, 2019
666c4be
Merge branch 'master' into referencesPrototypeSourceFile
sheetalkamat Jul 25, 2019
4c4ddf8
Merge branch 'master' into referencesPrototypeSourceFile
sheetalkamat Aug 21, 2019
c6e502b
Verify config file errors
sheetalkamat Aug 22, 2019
076dde4
Test with --out as well
sheetalkamat Aug 22, 2019
a469fd8
Should not report that files are not part of config for files that ar…
sheetalkamat Aug 22, 2019
6e09169
Merge branch 'master' into referencesPrototypeSourceFile
sheetalkamat Aug 22, 2019
54d9ce9
Merge branch 'master' into referencesPrototypeSourceFile
sheetalkamat Sep 5, 2019
b26ca16
Merge branch 'master' into referencesPrototypeSourceFile
sheetalkamat Sep 11, 2019
432da93
Add doc comments for fileExists and directoryExists implementation
sheetalkamat Sep 23, 2019
fd3ba67
Reword the option description per feedback
sheetalkamat Sep 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Watch generated file if it doesnt exist when trying to translate it t…
…o to source generated position
  • Loading branch information
sheetalkamat committed Jun 25, 2019
commit f4728682b7f6a8275b034fb9be5a2f64b84e0aea
8 changes: 7 additions & 1 deletion src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2240,7 +2240,13 @@ namespace ts.server {
getDocumentPositionMapper(project: Project, generatedFileName: string, sourceFileName?: string): DocumentPositionMapper | undefined {
// Since declaration info and map file watches arent updating project's directory structure host (which can cache file structure) use host
const declarationInfo = this.getOrCreateScriptInfoNotOpenedByClient(generatedFileName, project.currentDirectory, this.host);
if (!declarationInfo) return undefined;
if (!declarationInfo) {
if (sourceFileName) {
// Project contains source file and it generates the generated file name
project.addGeneratedFileWatch(generatedFileName, sourceFileName);
}
return undefined;
}

// Try to get from cache
declarationInfo.getSnapshot(); // Ensure synchronized
Expand Down
100 changes: 100 additions & 0 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,22 @@ namespace ts.server {
return value instanceof ScriptInfo;
}

interface GeneratedFileWatcher {
generatedFilePath: Path;
watcher: FileWatcher;
}
type GeneratedFileWatcherMap = GeneratedFileWatcher | Map<GeneratedFileWatcher>;
function isGeneratedFileWatcher(watch: GeneratedFileWatcherMap): watch is GeneratedFileWatcher {
return (watch as GeneratedFileWatcher).generatedFilePath !== undefined;
}

export abstract class Project implements LanguageServiceHost, ModuleResolutionHost {
private rootFiles: ScriptInfo[] = [];
private rootFilesMap: Map<ProjectRoot> = createMap<ProjectRoot>();
private program: Program | undefined;
private externalFiles: SortedReadonlyArray<string> | undefined;
private missingFilesMap: Map<FileWatcher> | undefined;
private generatedFilesMap: GeneratedFileWatcherMap | undefined;
private plugins: PluginModuleWithName[] = [];

/*@internal*/
Expand Down Expand Up @@ -573,6 +583,7 @@ namespace ts.server {
this.lastFileExceededProgramSize = lastFileExceededProgramSize;
this.builderState = undefined;
this.resolutionCache.closeTypeRootsWatch();
this.clearGeneratedFileWatch();
this.projectService.onUpdateLanguageServiceStateForProject(this, /*languageServiceEnabled*/ false);
}

Expand Down Expand Up @@ -654,6 +665,7 @@ namespace ts.server {
clearMap(this.missingFilesMap, closeFileWatcher);
this.missingFilesMap = undefined!;
}
this.clearGeneratedFileWatch();

// signal language service to release source files acquired from document registry
this.languageService.dispose();
Expand Down Expand Up @@ -947,6 +959,39 @@ namespace ts.server {
missingFilePath => this.addMissingFileWatcher(missingFilePath)
);

if (this.generatedFilesMap) {
const outPath = this.compilerOptions.outFile && this.compilerOptions.out;
if (isGeneratedFileWatcher(this.generatedFilesMap)) {
// --out
if (!outPath || !this.isValidGeneratedFileWatcher(
removeFileExtension(outPath) + Extension.Dts,
this.generatedFilesMap,
)) {
this.clearGeneratedFileWatch();
}
}
else {
// MultiFile
if (outPath) {
this.clearGeneratedFileWatch();
}
else {
this.generatedFilesMap.forEach((watcher, source) => {
const sourceFile = this.program!.getSourceFileByPath(source as Path);
if (!sourceFile ||
sourceFile.resolvedPath !== source ||
!this.isValidGeneratedFileWatcher(
getDeclarationEmitOutputFilePathWorker(sourceFile.fileName, this.compilerOptions, this.currentDirectory, this.program!.getCommonSourceDirectory(), this.getCanonicalFileName),
watcher
)) {
closeFileWatcherOf(watcher);
(this.generatedFilesMap as Map<GeneratedFileWatcher>).delete(source);
}
});
}
}
}

// Watch the type locations that would be added to program as part of automatic type resolutions
if (this.languageServiceEnabled) {
this.resolutionCache.updateTypeRootsWatch();
Expand Down Expand Up @@ -1011,6 +1056,61 @@ namespace ts.server {
return !!this.missingFilesMap && this.missingFilesMap.has(path);
}

/* @internal */
addGeneratedFileWatch(generatedFile: string, sourceFile: string) {
if (this.compilerOptions.outFile || this.compilerOptions.out) {
// Single watcher
if (!this.generatedFilesMap) {
this.generatedFilesMap = this.createGeneratedFileWatcher(generatedFile);
}
}
else {
// Map
const path = this.toPath(sourceFile);
if (this.generatedFilesMap) {
if (isGeneratedFileWatcher(this.generatedFilesMap)) {
Debug.fail(`${this.projectName} Expected not to have --out watcher for generated file with options: ${JSON.stringify(this.compilerOptions)}`);
return;
}
if (this.generatedFilesMap.has(path)) return;
}
else {
this.generatedFilesMap = createMap();
}
this.generatedFilesMap.set(path, this.createGeneratedFileWatcher(generatedFile));
}
}

private createGeneratedFileWatcher(generatedFile: string): GeneratedFileWatcher {
return {
generatedFilePath: this.toPath(generatedFile),
watcher: this.projectService.watchFactory.watchFile(
this.projectService.host,
generatedFile,
() => this.projectService.delayUpdateProjectGraphAndEnsureProjectStructureForOpenFiles(this),
PollingInterval.High,
WatchType.MissingGeneratedFile,
this
)
};
}

private isValidGeneratedFileWatcher(generateFile: string, watcher: GeneratedFileWatcher) {
return this.toPath(generateFile) === watcher.generatedFilePath;
}

private clearGeneratedFileWatch() {
if (this.generatedFilesMap) {
if (isGeneratedFileWatcher(this.generatedFilesMap)) {
closeFileWatcherOf(this.generatedFilesMap);
}
else {
clearMap(this.generatedFilesMap, closeFileWatcherOf);
}
this.generatedFilesMap = undefined;
}
}

getScriptInfoForNormalizedPath(fileName: NormalizedPath): ScriptInfo | undefined {
const scriptInfo = this.projectService.getScriptInfoForPath(this.toPath(fileName));
if (scriptInfo && !scriptInfo.isAttached(this)) {
Expand Down
1 change: 1 addition & 0 deletions src/server/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,6 @@ namespace ts {
NodeModulesForClosedScriptInfo = "node_modules for closed script infos in them",
MissingSourceMapFile = "Missing source map file",
NoopConfigFileForInferredRoot = "Noop Config file for the inferred project root",
MissingGeneratedFile = "Missing generated file"
}
}
Loading