mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-09 02:30:15 -06:00
Reload contents of file from disk irrespective of project presence and file already containing its own text
Fixes #19336
This commit is contained in:
parent
fd8980830c
commit
2668f50577
@ -946,16 +946,6 @@ namespace ts.server {
|
||||
}
|
||||
}
|
||||
|
||||
reloadScript(filename: NormalizedPath, tempFileName?: NormalizedPath): boolean {
|
||||
const script = this.projectService.getScriptInfoForNormalizedPath(filename);
|
||||
if (script) {
|
||||
Debug.assert(script.isAttached(this));
|
||||
script.reloadFromFile(tempFileName);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
getChangesSinceVersion(lastKnownVersion?: number): ProjectFilesWithTSDiagnostics {
|
||||
this.updateGraph();
|
||||
|
||||
@ -67,7 +67,10 @@ namespace ts.server {
|
||||
this.lineMap = undefined;
|
||||
}
|
||||
|
||||
/** returns true if text changed */
|
||||
/**
|
||||
* Set the contents as newText
|
||||
* returns true if text changed
|
||||
*/
|
||||
public reload(newText: string) {
|
||||
Debug.assert(newText !== undefined);
|
||||
|
||||
@ -87,31 +90,31 @@ namespace ts.server {
|
||||
}
|
||||
}
|
||||
|
||||
/** returns true if text changed */
|
||||
public reloadFromDisk() {
|
||||
let reloaded = false;
|
||||
if (!this.pendingReloadFromDisk && !this.ownFileText) {
|
||||
reloaded = this.reload(this.getFileText());
|
||||
this.ownFileText = true;
|
||||
}
|
||||
/**
|
||||
* Reads the contents from tempFile(if supplied) or own file and sets it as contents
|
||||
* returns true if text changed
|
||||
*/
|
||||
public reloadWithFileText(tempFileName?: string) {
|
||||
const reloaded = this.reload(this.getFileText(tempFileName));
|
||||
this.ownFileText = !tempFileName || tempFileName === this.fileName;
|
||||
return reloaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the contents from the file if there is no pending reload from disk or the contents of file are same as file text
|
||||
* returns true if text changed
|
||||
*/
|
||||
public reloadFromDisk() {
|
||||
if (!this.pendingReloadFromDisk && !this.ownFileText) {
|
||||
return this.reloadWithFileText();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public delayReloadFromFileIntoText() {
|
||||
this.pendingReloadFromDisk = true;
|
||||
}
|
||||
|
||||
/** returns true if text changed */
|
||||
public reloadFromFile(tempFileName: string) {
|
||||
let reloaded = false;
|
||||
// Reload if different file or we dont know if we are working with own file text
|
||||
if (tempFileName !== this.fileName || !this.ownFileText) {
|
||||
reloaded = this.reload(this.getFileText(tempFileName));
|
||||
this.ownFileText = !tempFileName || tempFileName === this.fileName;
|
||||
}
|
||||
return reloaded;
|
||||
}
|
||||
|
||||
public getSnapshot(): IScriptSnapshot {
|
||||
return this.useScriptVersionCacheIfValidOrOpen()
|
||||
? this.svc.getSnapshot()
|
||||
@ -180,8 +183,7 @@ namespace ts.server {
|
||||
private getOrLoadText() {
|
||||
if (this.text === undefined || this.pendingReloadFromDisk) {
|
||||
Debug.assert(!this.svc || this.pendingReloadFromDisk, "ScriptVersionCache should not be set when reloading from disk");
|
||||
this.reload(this.getFileText());
|
||||
this.ownFileText = true;
|
||||
this.reloadWithFileText();
|
||||
}
|
||||
return this.text;
|
||||
}
|
||||
@ -385,7 +387,7 @@ namespace ts.server {
|
||||
this.markContainingProjectsAsDirty();
|
||||
}
|
||||
else {
|
||||
if (this.textStorage.reloadFromFile(tempFileName)) {
|
||||
if (this.textStorage.reloadWithFileText(tempFileName)) {
|
||||
this.markContainingProjectsAsDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1311,11 +1311,13 @@ namespace ts.server {
|
||||
private reload(args: protocol.ReloadRequestArgs, reqSeq: number) {
|
||||
const file = toNormalizedPath(args.file);
|
||||
const tempFileName = args.tmpfile && toNormalizedPath(args.tmpfile);
|
||||
const project = this.projectService.getDefaultProjectForFile(file, /*ensureProject*/ true);
|
||||
this.changeSeq++;
|
||||
// make sure no changes happen before this one is finished
|
||||
if (project.reloadScript(file, tempFileName)) {
|
||||
this.doOutput(/*info*/ undefined, CommandNames.Reload, reqSeq, /*success*/ true);
|
||||
const info = this.projectService.getScriptInfoForNormalizedPath(file);
|
||||
if (info) {
|
||||
this.changeSeq++;
|
||||
// make sure no changes happen before this one is finished
|
||||
if (info.reloadFromFile(tempFileName)) {
|
||||
this.doOutput(/*info*/ undefined, CommandNames.Reload, reqSeq, /*success*/ true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user