Skip to content

Commit

Permalink
use FileSystemWatcher for document watching
Browse files Browse the repository at this point in the history
  • Loading branch information
iliazeus committed Jan 29, 2021
1 parent ff78422 commit 998ee22
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.1

- Fixed a bug with corrupting previews of files that have been deleted and re-created

## 1.1.0

- Implemented own ANSI escape parser
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publisher": "iliazeus",
"displayName": "ANSI Colors",
"description": "ANSI color styling for text documents",
"version": "1.1.0",
"version": "1.1.1",
"license": "MIT",
"repository": {
"url": "https://github.com/iliazeus/vscode-ansi"
Expand Down
22 changes: 19 additions & 3 deletions src/PrettyAnsiContentProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { posix as posixPath } from "path";

import { EventEmitter, TextDocumentContentProvider, Uri, workspace } from "vscode";
import { EventEmitter, FileSystemWatcher, TextDocumentContentProvider, Uri, workspace } from "vscode";

import * as ansi from "./ansi";
import { extensionId } from "./extension";
Expand Down Expand Up @@ -31,6 +31,7 @@ export class PrettyAnsiContentProvider implements TextDocumentContentProvider {
public readonly onDidChange = this._onDidChange.event;

private readonly _watchedUris = new Set<string>();
private readonly _fileSystemWatcher: FileSystemWatcher;

private readonly _editorRedrawWatcher: EditorRedrawWatcher;

Expand All @@ -48,9 +49,24 @@ export class PrettyAnsiContentProvider implements TextDocumentContentProvider {
})
);

this._fileSystemWatcher = workspace.createFileSystemWatcher("**/*", false, false, true);
this._disposables.push(this._fileSystemWatcher);

this._disposables.push(
workspace.onDidCloseTextDocument((document) => {
this._watchedUris.delete(document.uri.toString());
this._fileSystemWatcher.onDidChange((actualUri) => {
if (this._watchedUris.has(actualUri.toString())) {
const providerUri = PrettyAnsiContentProvider.toProviderUri(actualUri);
this._onDidChange.fire(providerUri);
}
})
);

this._disposables.push(
this._fileSystemWatcher.onDidCreate((actualUri) => {
if (this._watchedUris.has(actualUri.toString())) {
const providerUri = PrettyAnsiContentProvider.toProviderUri(actualUri);
this._onDidChange.fire(providerUri);
}
})
);
}
Expand Down

0 comments on commit 998ee22

Please sign in to comment.