Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ export function activate(context: vscode.ExtensionContext) {
watcher.onDidDelete(uri => parsedDocumentCollection.disposeDocumentByUri(uri));
context.subscriptions.push(watcher);

// In case the file watcher does not notify about deleted files
context.subscriptions.push(vscode.workspace.onDidDeleteFiles(event => {
for (const uri of event.files) {
if (uri.path.endsWith('.zs')) {
parsedDocumentCollection.disposeDocumentByUri(uri);
}
}
}));

context.subscriptions.push(vscode.workspace.onDidOpenTextDocument(document => parsedDocumentCollection.parseDocument(document)));

context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(editor => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function main() {
await runTests({
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [testWorkspace, '--disable-extensions', '--log', 'trace', '--verbose'],
launchArgs: [testWorkspace, '--disable-extensions', '--log', 'trace'],
});
} catch (err) {
console.error(err);
Expand Down
15 changes: 14 additions & 1 deletion src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,20 @@ suite('Extension Test Suite', function () {

test('File watcher handles file deletion', async () => {
const testFileToDelete = vscode.Uri.joinPath(testWorkspaceFolder, 'testFileToDelete.zs');

// Ensure the OS file watcher registers the creation before we delete it.
// On MacOS, fsevents will coalesce rapid create+delete pairs and drop the events entirely.
const creationWatcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(testWorkspaceFolder, 'testFileToDelete.zs'), false, true, true);
const creationPromise = new Promise<void>(resolve => {
creationWatcher.onDidCreate(() => resolve());
});

await vscode.workspace.fs.writeFile(testFileToDelete, Buffer.from('abc'));

// Wait for the OS to report the creation so the deletion becomes a new watcher event
await creationPromise;
creationWatcher.dispose();

const document = await vscode.workspace.openTextDocument(testFileToDelete);
await vscode.window.showTextDocument(document);

Expand All @@ -63,7 +76,7 @@ suite('Extension Test Suite', function () {

// Allow time for watcher to process
let success = false;
for (let i = 0; i < 50; i++) {
for (let i = 0; i < 10; i++) {
await new Promise(resolve => setTimeout(resolve, 100));
const diagnosticsAfterDeletion = vscode.languages.getDiagnostics(testFileToDelete);
console.log(`Polling for diagnostics cleared (attempt ${i + 1}): ${diagnosticsAfterDeletion.length} diagnostics remaining.`);
Expand Down
Loading