-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for proposed signature for workspace.createFileSystemWatc…
…her (#14303) Fixes #13957 Contributed on behalf of STMicroelectronics Signed-off-by: Thomas Mäder <t.s.maeder@gmail.com>
- Loading branch information
Showing
5 changed files
with
220 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
packages/plugin-ext/src/plugin/file-system-watcher.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2019 Red Hat, Inc. and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
|
||
import * as assert from 'assert'; | ||
import { FileSystemWatcher } from './file-system-event-service-ext-impl'; | ||
import { DisposableCollection, Emitter } from '@theia/core'; | ||
import { FileSystemEvents } from '../common'; | ||
import { URI } from './types-impl'; | ||
|
||
const eventSource = new Emitter<FileSystemEvents>(); | ||
let disposables = new DisposableCollection(); | ||
|
||
function checkIgnore(ignoreCreate: number, ignoreChange: number, ignoreDelete: number): void { | ||
const watcher = new FileSystemWatcher(eventSource.event, '**/*.js', !ignoreCreate, !ignoreChange, !ignoreDelete); | ||
disposables.push(watcher); | ||
const matching = URI.file('/foo/bar/zoz.js'); | ||
|
||
const changed: URI[] = []; | ||
const created: URI[] = []; | ||
const deleted: URI[] = []; | ||
watcher.onDidChange(e => { | ||
changed.push(e); | ||
}); | ||
|
||
watcher.onDidCreate(e => { | ||
created.push(e); | ||
}); | ||
|
||
watcher.onDidDelete(e => { | ||
deleted.push(e); | ||
}); | ||
|
||
eventSource.fire({ changed: [matching], created: [matching], deleted: [matching] }); | ||
|
||
assert.equal(created.length, ignoreCreate); | ||
assert.equal(deleted.length, ignoreDelete); | ||
assert.equal(changed.length, ignoreChange); | ||
|
||
} | ||
|
||
describe('File Watcher Test', () => { | ||
afterEach(() => { | ||
disposables.dispose(); | ||
disposables = new DisposableCollection(); | ||
}); | ||
|
||
it('Should match files', () => { | ||
const watcher = new FileSystemWatcher(eventSource.event, '**/*.js'); | ||
disposables.push(watcher); | ||
const matching = URI.file('/foo/bar/zoz.js'); | ||
const notMatching = URI.file('/foo/bar/zoz.ts'); | ||
const changed: URI[] = []; | ||
const created: URI[] = []; | ||
const deleted: URI[] = []; | ||
watcher.onDidChange(e => { | ||
changed.push(e); | ||
}); | ||
|
||
watcher.onDidCreate(e => { | ||
created.push(e); | ||
}); | ||
|
||
watcher.onDidDelete(e => { | ||
deleted.push(e); | ||
}); | ||
|
||
const URIs = [matching, notMatching]; | ||
eventSource.fire({ changed: URIs, created: URIs, deleted: URIs }); | ||
assert.equal(matching.toString(), changed[0]?.toString()); | ||
assert.equal(matching.toString(), created[0]?.toString()); | ||
assert.equal(matching.toString(), deleted[0]?.toString()); | ||
}); | ||
|
||
it('Should ignore created', () => { | ||
checkIgnore(0, 1, 1); | ||
}); | ||
|
||
it('Should ignore changed', () => { | ||
checkIgnore(1, 0, 1); | ||
}); | ||
|
||
it('Should ignore deleted', () => { | ||
checkIgnore(1, 1, 0); | ||
}); | ||
|
||
it('Should exclude files', () => { | ||
const watcher = new FileSystemWatcher(eventSource.event, '**/*.js', false, false, false, ['**/bar/**']); | ||
disposables.push(watcher); | ||
const notMatching = URI.file('/foo/bar/zoz.js'); | ||
const matching = URI.file('/foo/gux/zoz.js'); | ||
const changed: URI[] = []; | ||
const created: URI[] = []; | ||
const deleted: URI[] = []; | ||
watcher.onDidChange(e => { | ||
changed.push(e); | ||
}); | ||
|
||
watcher.onDidCreate(e => { | ||
created.push(e); | ||
}); | ||
|
||
watcher.onDidDelete(e => { | ||
deleted.push(e); | ||
}); | ||
|
||
const URIs = [matching, notMatching]; | ||
eventSource.fire({ changed: URIs, created: URIs, deleted: URIs }); | ||
assert.equal(matching.toString(), changed[0]?.toString()); | ||
assert.equal(matching.toString(), created[0]?.toString()); | ||
assert.equal(matching.toString(), deleted[0]?.toString()); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
packages/plugin/src/theia.proposed.createFileSystemWatcher.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2024 STMicroelectronics and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
// code copied and modified from https://github.com/microsoft/vscode/blob/release/1.93/src/vscode-dts/vscode.proposed.createFileSystemWatcher.d.ts | ||
|
||
declare module '@theia/plugin' { | ||
|
||
export interface FileSystemWatcherOptions { | ||
|
||
/** | ||
* Ignore when files have been created. | ||
*/ | ||
readonly ignoreCreateEvents?: boolean; | ||
|
||
/** | ||
* Ignore when files have been changed. | ||
*/ | ||
readonly ignoreChangeEvents?: boolean; | ||
|
||
/** | ||
* Ignore when files have been deleted. | ||
*/ | ||
readonly ignoreDeleteEvents?: boolean; | ||
|
||
/** | ||
* An optional set of glob patterns to exclude from watching. | ||
* Glob patterns are always matched relative to the watched folder. | ||
*/ | ||
readonly excludes: string[]; | ||
} | ||
|
||
export namespace workspace { | ||
|
||
/** | ||
* A variant of {@link workspace.createFileSystemWatcher} that optionally allows to specify | ||
* a set of glob patterns to exclude from watching. | ||
* | ||
* It provides the following advantages over the other {@link workspace.createFileSystemWatcher} | ||
* method: | ||
* - the configured excludes from `files.watcherExclude` setting are NOT applied | ||
* - requests for recursive file watchers inside the opened workspace are NOT ignored | ||
* - the watcher is ONLY notified for events from this request and not from any other watcher | ||
* | ||
* As such, this method is prefered in cases where you want full control over the watcher behavior | ||
* without being impacted by settings or other watchers that are installed. | ||
*/ | ||
export function createFileSystemWatcher(pattern: RelativePattern, options?: FileSystemWatcherOptions): FileSystemWatcher; | ||
} | ||
} |