temp save
This commit is contained in:
parent
4dcf8c7737
commit
98eaeba4f1
2 changed files with 85 additions and 23 deletions
|
@ -9,7 +9,7 @@ namespace ts {
|
|||
readFile(path: string, encoding?: string): string;
|
||||
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
|
||||
watchFile?(path: string, callback: (path: string) => void): FileWatcher;
|
||||
watchDirectory?(path: string, callback: (path: string) => void): FileWatcher;
|
||||
watchDirectory?(path: string, callback: (path: string) => void, recursive?: boolean): FileWatcher;
|
||||
resolvePath(path: string): string;
|
||||
fileExists(path: string): boolean;
|
||||
directoryExists(path: string): boolean;
|
||||
|
@ -406,6 +406,20 @@ namespace ts {
|
|||
close: () => watchedFileSet.removeFile(watchedFile)
|
||||
}
|
||||
},
|
||||
watchDirectory: (path, callback, recursive) => {
|
||||
// Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows
|
||||
// (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643)
|
||||
// therefore if the current node.js version is newer than 4, use `fs.watch` instead.
|
||||
if (isNode4OrLater()) {
|
||||
return _fs.watch(path, { persisten: true, recursive: !!recursive }, (eventName: string, modifiedPath: string) => callback(modifiedPath));
|
||||
}
|
||||
|
||||
// If Node version is older than 4.0, the "recursive" parameter will be ignored
|
||||
var watchedFile = watchedFileSet.addFile(path, callback);
|
||||
return {
|
||||
close: () => watchedFileSet.removeFile(watchedFile)
|
||||
}
|
||||
},
|
||||
resolvePath: function (path: string): string {
|
||||
return _path.resolve(path);
|
||||
},
|
||||
|
|
|
@ -354,6 +354,11 @@ namespace ts.server {
|
|||
compilerService: CompilerService;
|
||||
projectFilename: string;
|
||||
projectFileWatcher: FileWatcher;
|
||||
// Inferred projects have a collection of non-recursive directory watchers starting
|
||||
// from the root path (e.g. "C:\" or "/") to the current path;
|
||||
// while configured projects whose tsconfig files don't have a "files" array have one
|
||||
// recursive directory watcher starting from the current path
|
||||
directoryWatchers: FileWatcher[] = [];
|
||||
program: ts.Program;
|
||||
filenameToSourceFile: ts.Map<ts.SourceFile> = {};
|
||||
updateGraphSeq = 0;
|
||||
|
@ -532,6 +537,41 @@ namespace ts.server {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the callback function when the directory that an inferred project belongs
|
||||
* to changed. The function looks for newly added tsconfig.json files; if it found one,
|
||||
* and the tsconfig.json file contains the root file of the current inferred project,
|
||||
* it will update the project structure.
|
||||
*/
|
||||
watchedDirectoryChanged(project: Project, path: string) {
|
||||
if (project.isConfiguredProject()) {
|
||||
return;
|
||||
}
|
||||
|
||||
let configFileName = ts.combinePaths(path, "tsconfig.json");
|
||||
if (sys.fileExists(configFileName)) {
|
||||
let {succeeded, projectOptions, error} = this.configFileToProjectOptions(configFileName);
|
||||
if (!succeeded) {
|
||||
return;
|
||||
}
|
||||
|
||||
let newProjectFileNames = projectOptions.files.map(f => this.getCanonicalFileName(f));
|
||||
let rootFiles = project.getRootFiles().map(f => this.getCanonicalFileName(f));
|
||||
for (let rootFile of rootFiles) {
|
||||
if (newProjectFileNames.indexOf(rootFile) >= 0) {
|
||||
this.reloadProjects();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
getCanonicalFileName(fileName: string) {
|
||||
let name = this.host.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
|
||||
return ts.normalizePath(name);
|
||||
}
|
||||
|
||||
watchedProjectConfigFileChanged(project: Project) {
|
||||
this.log("Config File Changed: " + project.projectFilename);
|
||||
this.updateConfiguredProject(project);
|
||||
|
@ -567,11 +607,19 @@ namespace ts.server {
|
|||
}
|
||||
|
||||
createInferredProject(root: ScriptInfo) {
|
||||
var iproj = new Project(this);
|
||||
iproj.addRoot(root);
|
||||
iproj.finishGraph();
|
||||
this.inferredProjects.push(iproj);
|
||||
return iproj;
|
||||
var project = new Project(this);
|
||||
project.addRoot(root);
|
||||
|
||||
let currentPath = ts.getDirectoryPath(root.fileName);
|
||||
let parentPath = ts.getDirectoryPath(currentPath);
|
||||
while (currentPath != parentPath) {
|
||||
// To finish
|
||||
let directoryWatcher = this.host.watchDirectory(currentPath, p => this.);;
|
||||
}
|
||||
|
||||
project.finishGraph();
|
||||
this.inferredProjects.push(project);
|
||||
return project;
|
||||
}
|
||||
|
||||
fileDeletedInFilesystem(info: ScriptInfo) {
|
||||
|
@ -1217,9 +1265,9 @@ namespace ts.server {
|
|||
goSubtree: boolean;
|
||||
done: boolean;
|
||||
leaf(relativeStart: number, relativeLength: number, lineCollection: LineLeaf): void;
|
||||
pre? (relativeStart: number, relativeLength: number, lineCollection: LineCollection,
|
||||
pre?(relativeStart: number, relativeLength: number, lineCollection: LineCollection,
|
||||
parent: LineNode, nodeType: CharRangeSection): LineCollection;
|
||||
post? (relativeStart: number, relativeLength: number, lineCollection: LineCollection,
|
||||
post?(relativeStart: number, relativeLength: number, lineCollection: LineCollection,
|
||||
parent: LineNode, nodeType: CharRangeSection): LineCollection;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue