Skip to content

Commit 8e036e5

Browse files
committed
If the relativeFileName ends with tilde, remove it from the event
1 parent 78377e1 commit 8e036e5

File tree

3 files changed

+67
-16
lines changed

3 files changed

+67
-16
lines changed

src/compiler/sys.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ namespace ts {
10811081
let lastDirectoryPartWithDirectorySeparator: string | undefined;
10821082
let lastDirectoryPart: string | undefined;
10831083
if (inodeWatching) {
1084-
lastDirectoryPartWithDirectorySeparator = fileOrDirectory.substr(fileOrDirectory.lastIndexOf(directorySeparator));
1084+
lastDirectoryPartWithDirectorySeparator = fileOrDirectory.substring(fileOrDirectory.lastIndexOf(directorySeparator));
10851085
lastDirectoryPart = lastDirectoryPartWithDirectorySeparator.slice(directorySeparator.length);
10861086
}
10871087
/** Watcher for the file system entry depending on whether it is missing or present */
@@ -1140,13 +1140,14 @@ namespace ts {
11401140
}
11411141

11421142
function callbackChangingToMissingFileSystemEntry(event: "rename" | "change", relativeName: string | undefined) {
1143+
if (relativeName && endsWith(relativeName, "~")) relativeName = relativeName.slice(0, relativeName.length - 1);
11431144
callback(event, relativeName);
11441145
// because relativeName is not guaranteed to be correct we need to check on each rename with few combinations
11451146
// Eg on ubuntu while watching app/node_modules the relativeName is "node_modules" which is neither relative nor full path
11461147
if (event === "rename" &&
11471148
(!relativeName ||
11481149
relativeName === lastDirectoryPart ||
1149-
(relativeName.lastIndexOf(lastDirectoryPartWithDirectorySeparator!) !== -1 && relativeName.lastIndexOf(lastDirectoryPartWithDirectorySeparator!) === relativeName.length - lastDirectoryPartWithDirectorySeparator!.length))) {
1150+
endsWith(relativeName, lastDirectoryPartWithDirectorySeparator!))) {
11501151
if (inodeWatching) {
11511152
updateWatcher(!fileSystemEntryExists(fileOrDirectory, entryKind) ? watchMissingFileSystemEntry : watchPresentFileSystemEntry);
11521153
}

src/testRunner/unittests/tscWatch/watchEnvironment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,12 +668,12 @@ namespace ts.tscWatch {
668668
{
669669
caption: "Replace file with rename event that introduces error",
670670
change: sys => sys.modifyFile(`${projectRoot}/foo.d.ts`, `export function foo2(): string;`, { invokeFileDeleteCreateAsPartInsteadOfChange: true, useTildeAsSuffixInRenameEventFileName: true }),
671-
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(1),
671+
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(2),
672672
},
673673
{
674674
caption: "Replace file with rename event that fixes error",
675675
change: sys => sys.modifyFile(`${projectRoot}/foo.d.ts`, `export function foo(): string;`, { invokeFileDeleteCreateAsPartInsteadOfChange: true, useTildeAsSuffixInRenameEventFileName: true }),
676-
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(0),
676+
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(2),
677677
},
678678
]
679679
});

tests/baselines/reference/tscWatch/watchEnvironment/fsWatch/when-using-file-watching-thats-on-inode-when-rename-event-ends-with-tilde.js

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,21 @@ Output::
102102
FileWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts 2:: WatchInfo: /user/username/projects/myproject/foo.d.ts 250 {"watchFile":4} Source file
103103
Scheduling update
104104
Elapsed:: *ms FileWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts 2:: WatchInfo: /user/username/projects/myproject/foo.d.ts 250 {"watchFile":4} Source file
105-
DirectoryWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts~ :: WatchInfo: /user/username/projects/myproject 0 {"watchFile":4} Failed Lookup Locations
106-
Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts~ :: WatchInfo: /user/username/projects/myproject 0 {"watchFile":4} Failed Lookup Locations
107-
DirectoryWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts~ :: WatchInfo: /user/username/projects/myproject 0 {"watchFile":4} Failed Lookup Locations
108-
Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts~ :: WatchInfo: /user/username/projects/myproject 0 {"watchFile":4} Failed Lookup Locations
105+
sysLog:: /user/username/projects/myproject/foo.d.ts:: Changing watcher to MissingFileSystemEntryWatcher
106+
DirectoryWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts :: WatchInfo: /user/username/projects/myproject 0 {"watchFile":4} Failed Lookup Locations
107+
Scheduling invalidateFailedLookup
108+
Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts :: WatchInfo: /user/username/projects/myproject 0 {"watchFile":4} Failed Lookup Locations
109+
FileWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts 0:: WatchInfo: /user/username/projects/myproject/foo.d.ts 250 {"watchFile":4} Source file
110+
Scheduling update
111+
Elapsed:: *ms FileWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts 0:: WatchInfo: /user/username/projects/myproject/foo.d.ts 250 {"watchFile":4} Source file
112+
sysLog:: /user/username/projects/myproject/foo.d.ts:: Changing watcher to PresentFileSystemEntryWatcher
113+
FileWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts 0:: WatchInfo: /user/username/projects/myproject/foo.d.ts 250 {"watchFile":4} Source file
114+
Scheduling update
115+
Elapsed:: *ms FileWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts 0:: WatchInfo: /user/username/projects/myproject/foo.d.ts 250 {"watchFile":4} Source file
116+
sysLog:: /user/username/projects/myproject/foo.d.ts:: Changing watcher to PresentFileSystemEntryWatcher
117+
DirectoryWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts :: WatchInfo: /user/username/projects/myproject 0 {"watchFile":4} Failed Lookup Locations
118+
Scheduling invalidateFailedLookup, Cancelled earlier one
119+
Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts :: WatchInfo: /user/username/projects/myproject 0 {"watchFile":4} Failed Lookup Locations
109120
Synchronizing program
110121
[12:00:30 AM] File change detected. Starting incremental compilation...
111122

@@ -149,14 +160,14 @@ WatchedFiles::
149160
FsWatches::
150161
/user/username/projects/myproject/tsconfig.json:
151162
{"directoryName":"/user/username/projects/myproject/tsconfig.json","inode":10}
152-
/user/username/projects/myproject/foo.d.ts:
153-
{"directoryName":"/user/username/projects/myproject/foo.d.ts","inode":9}
154163
/user/username/projects/myproject/main.ts:
155164
{"directoryName":"/user/username/projects/myproject/main.ts","inode":8}
156165
/user/username/projects/myproject:
157166
{"directoryName":"/user/username/projects/myproject","inode":7}
158167
/a/lib/lib.d.ts:
159168
{"directoryName":"/a/lib/lib.d.ts","inode":3}
169+
/user/username/projects/myproject/foo.d.ts:
170+
{"directoryName":"/user/username/projects/myproject/foo.d.ts","inode":12}
160171

161172
FsWatchesRecursive::
162173

@@ -172,11 +183,49 @@ export function foo(): string;
172183

173184

174185
Output::
175-
DirectoryWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts~ :: WatchInfo: /user/username/projects/myproject 0 {"watchFile":4} Failed Lookup Locations
176-
Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts~ :: WatchInfo: /user/username/projects/myproject 0 {"watchFile":4} Failed Lookup Locations
177-
DirectoryWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts~ :: WatchInfo: /user/username/projects/myproject 0 {"watchFile":4} Failed Lookup Locations
178-
Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts~ :: WatchInfo: /user/username/projects/myproject 0 {"watchFile":4} Failed Lookup Locations
186+
FileWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts 2:: WatchInfo: /user/username/projects/myproject/foo.d.ts 250 {"watchFile":4} Source file
187+
Scheduling update
188+
Elapsed:: *ms FileWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts 2:: WatchInfo: /user/username/projects/myproject/foo.d.ts 250 {"watchFile":4} Source file
189+
sysLog:: /user/username/projects/myproject/foo.d.ts:: Changing watcher to MissingFileSystemEntryWatcher
190+
DirectoryWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts :: WatchInfo: /user/username/projects/myproject 0 {"watchFile":4} Failed Lookup Locations
191+
Scheduling invalidateFailedLookup
192+
Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts :: WatchInfo: /user/username/projects/myproject 0 {"watchFile":4} Failed Lookup Locations
193+
FileWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts 0:: WatchInfo: /user/username/projects/myproject/foo.d.ts 250 {"watchFile":4} Source file
194+
Scheduling update
195+
Elapsed:: *ms FileWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts 0:: WatchInfo: /user/username/projects/myproject/foo.d.ts 250 {"watchFile":4} Source file
196+
sysLog:: /user/username/projects/myproject/foo.d.ts:: Changing watcher to PresentFileSystemEntryWatcher
197+
FileWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts 0:: WatchInfo: /user/username/projects/myproject/foo.d.ts 250 {"watchFile":4} Source file
198+
Scheduling update
199+
Elapsed:: *ms FileWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts 0:: WatchInfo: /user/username/projects/myproject/foo.d.ts 250 {"watchFile":4} Source file
200+
sysLog:: /user/username/projects/myproject/foo.d.ts:: Changing watcher to PresentFileSystemEntryWatcher
201+
DirectoryWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts :: WatchInfo: /user/username/projects/myproject 0 {"watchFile":4} Failed Lookup Locations
202+
Scheduling invalidateFailedLookup, Cancelled earlier one
203+
Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/myproject/foo.d.ts :: WatchInfo: /user/username/projects/myproject 0 {"watchFile":4} Failed Lookup Locations
204+
Synchronizing program
205+
[12:00:38 AM] File change detected. Starting incremental compilation...
206+
207+
CreatingProgramWith::
208+
roots: ["/user/username/projects/myproject/foo.d.ts","/user/username/projects/myproject/main.ts"]
209+
options: {"watch":true,"extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
210+
[12:00:42 AM] Found 0 errors. Watching for file changes.
211+
212+
213+
214+
Program root files: ["/user/username/projects/myproject/foo.d.ts","/user/username/projects/myproject/main.ts"]
215+
Program options: {"watch":true,"extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
216+
Program structureReused: SafeModules
217+
Program files::
218+
/a/lib/lib.d.ts
219+
/user/username/projects/myproject/foo.d.ts
220+
/user/username/projects/myproject/main.ts
221+
222+
Semantic diagnostics in builder refreshed for::
223+
/user/username/projects/myproject/foo.d.ts
224+
/user/username/projects/myproject/main.ts
179225

226+
Shape signatures in builder refreshed for::
227+
/user/username/projects/myproject/foo.d.ts (used version)
228+
/user/username/projects/myproject/main.ts (computed .d.ts)
180229

181230
WatchedFiles::
182231
/user/username/projects/myproject/node_modules/@types:
@@ -185,16 +234,17 @@ WatchedFiles::
185234
FsWatches::
186235
/user/username/projects/myproject/tsconfig.json:
187236
{"directoryName":"/user/username/projects/myproject/tsconfig.json","inode":10}
188-
/user/username/projects/myproject/foo.d.ts:
189-
{"directoryName":"/user/username/projects/myproject/foo.d.ts","inode":9}
190237
/user/username/projects/myproject/main.ts:
191238
{"directoryName":"/user/username/projects/myproject/main.ts","inode":8}
192239
/user/username/projects/myproject:
193240
{"directoryName":"/user/username/projects/myproject","inode":7}
194241
/a/lib/lib.d.ts:
195242
{"directoryName":"/a/lib/lib.d.ts","inode":3}
243+
/user/username/projects/myproject/foo.d.ts:
244+
{"directoryName":"/user/username/projects/myproject/foo.d.ts","inode":13}
196245

197246
FsWatchesRecursive::
198247

199248
exitCode:: ExitStatus.undefined
200249

250+
//// [/user/username/projects/myproject/main.js] file written with same contents Inode:: 11

0 commit comments

Comments
 (0)