Skip to content

Commit

Permalink
fix: file changes on windows not registering (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnstonCode committed Feb 28, 2020
1 parent 9754f29 commit 6b3521a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ const regexNormalizeWindows = new RegExp("^\\\\(\\w:)", "g");
export function fixPathSeparator(file: string) {
file = file.replace(regexNormalizePath, path.sep);
file = file.replace(regexNormalizeWindows, "$1"); // "\t:\test" => "t:\test"

if (path.sep === "\\") {
file = file.charAt(0).toLowerCase() + file.slice(1);
}

return file;
}

Expand Down
17 changes: 11 additions & 6 deletions src/watchers/repositoryFilesWatcher.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { Event, Uri, workspace, EventEmitter } from "vscode";
import { Event, Uri, workspace, EventEmitter, RelativePattern } from "vscode";
import { watch } from "fs";
import { exists } from "../fs";
import { join, resolve } from "path";
import { join } from "path";
import { debounce } from "../decorators";
import { anyEvent, filterEvent, IDisposable, isDescendant } from "../util";
import {
anyEvent,
filterEvent,
IDisposable,
isDescendant,
fixPathSeparator
} from "../util";

export class RepositoryFilesWatcher implements IDisposable {
private disposables: IDisposable[] = [];
Expand All @@ -29,7 +35,7 @@ export class RepositoryFilesWatcher implements IDisposable {

constructor(readonly root: string) {
const fsWatcher = workspace.createFileSystemWatcher(
join(resolve(root), "**")
new RelativePattern(fixPathSeparator(root), "**")
);
this._onRepoChange = new EventEmitter<Uri>();
this._onRepoCreate = new EventEmitter<Uri>();
Expand Down Expand Up @@ -58,8 +64,7 @@ export class RepositoryFilesWatcher implements IDisposable {

const isTmp = (uri: Uri) => /[\\\/]\.svn[\\\/]tmp/.test(uri.path);

const isRelevant = (uri: Uri) =>
!isTmp(uri) && isDescendant(this.root, uri.fsPath);
const isRelevant = (uri: Uri) => !isTmp(uri);

this.onDidChange = filterEvent(fsWatcher.onDidChange, isRelevant);
this.onDidCreate = filterEvent(fsWatcher.onDidCreate, isRelevant);
Expand Down

0 comments on commit 6b3521a

Please sign in to comment.