Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (/^workspaceContains:/.test(activationEvent)) {
const fileNameOrGlob = activationEvent.substr('workspaceContains:'.length);
if (fileNameOrGlob.indexOf('*') >= 0 || fileNameOrGlob.indexOf('?') >= 0) {
includePatterns.push(fileNameOrGlob);
} else {
paths.push(fileNameOrGlob);
}
}
}
const activatePlugin = () => manager.$activateByEvent(`onPlugin:${plugin.metadata.model.id}`);
const promises: Promise[] = [];
if (paths.length) {
promises.push(this.workspaceService.containsSome(paths));
}
if (includePatterns.length) {
const tokenSource = new CancellationTokenSource();
const searchTimeout = setTimeout(() => {
tokenSource.cancel();
// activate eagerly if took to long to search
activatePlugin();
}, 7000);
promises.push((async () => {
try {
const result = await this.fileSearchService.find('', {
rootUris: this.workspaceService.tryGetRoots().map(r => r.uri),
includePatterns,
limit: 1
}, tokenSource.token);
return result.length > 0;
} catch (e) {
if (!isCancelled(e)) {
console.error(e);
toDispose.push(this.commands.registerCommand(command, handler));
const { when } = action;
const whenKeys = when && this.contextKeyService.parseKeys(when);
let onDidChange;
if (whenKeys && whenKeys.size) {
const onDidChangeEmitter = new Emitter();
toDispose.push(onDidChangeEmitter);
onDidChange = onDidChangeEmitter.event;
this.contextKeyService.onDidChange.maxListeners = this.contextKeyService.onDidChange.maxListeners + 1;
toDispose.push(this.contextKeyService.onDidChange(event => {
if (event.affects(whenKeys)) {
onDidChangeEmitter.fire(undefined);
}
}));
toDispose.push(Disposable.create(() => {
this.contextKeyService.onDidChange.maxListeners = this.contextKeyService.onDidChange.maxListeners - 1;
}));
}
// handle group and priority
// if group is empty or white space is will be set to navigation
// ' ' => ['navigation', 0]
// 'navigation@1' => ['navigation', 1]
// '1_rest-client@2' => ['1_rest-client', 2]
// if priority is not a number it will be set to 0
// navigation@test => ['navigation', 0]
const [group, sort] = (action.group || 'navigation').split('@');
const item: Mutable = { id, command: id, group: group.trim() || 'navigation', priority: ~~sort || undefined, when, onDidChange };
toDispose.push(this.tabBarToolbar.registerItem(item));
toDispose.push(this.onDidRegisterCommand(action.command, pluginCommand => {
} else {
this.pdfContainer.style.display = 'none';
this.frame.style.display = 'block';
this.frame.src = url;
// The load indicator will hide itself if the content of the iframe was loaded.
if (!preserveFocus) {
this.frame.addEventListener('load', () => {
const window = this.frame.contentWindow;
if (window) {
window.focus();
}
}, { once: true });
}
}
// Delegate all the `keypress` events from the `iframe` to the application.
this.toDisposeOnGo.push(addEventListener(this.frame, 'load', () => {
try {
const { contentDocument } = this.frame;
if (contentDocument) {
const keypressHandler = (e: KeyboardEvent) => this.keybindings.run(e);
contentDocument.addEventListener('keypress', keypressHandler, true);
this.toDisposeOnDetach.push(Disposable.create(() => contentDocument.removeEventListener('keypress', keypressHandler)));
}
} catch {
// There is not much we could do with the security exceptions due to CORS.
}
}));
} catch (e) {
clearTimeout(this.frameLoadTimeout);
this.hideLoadIndicator();
this.showErrorBar(String(e));
console.log(e);
private async getContainerRepository(repositoryPath: string): Promise {
// Do not log an error if we are not contained in a Git repository. Treat exit code 128 as a success too.
const options = { successExitCodes: new Set([0, 128]) };
const result = await git(['rev-parse', '--show-toplevel'], repositoryPath, 'rev-parse', options);
const out = result.stdout;
if (out && out.length !== 0) {
const localUri = FileUri.create(out.trim()).toString();
return { localUri };
}
return undefined;
}
it('modifying a staged file should result in two changes', async () => {
// Init repository.
const root = await createTestRepository(track.mkdirSync('status-test'));
const localUri = FileUri.create(root).toString();
const repository = { localUri };
const git = await createGit();
// // Check status. Expect empty.
let status = await git.status(repository);
expect(status.changes).to.be.empty;
// Modify a file.
const filePath = path.join(root, 'A.txt');
const fileUri = FileUri.create(filePath).toString();
fs.writeFileSync(filePath, 'new content');
expect(fs.readFileSync(filePath, { encoding: 'utf8' })).to.be.equal('new content');
await git.add(repository, fileUri);
// Check the status again. Expect one single change.
status = await git.status(repository);
expect(status.changes).to.be.have.lengthOf(1);
expect(status.changes[0].uri).to.be.equal(fileUri);
expect(status.changes[0].staged).to.be.true;
// Change the same file again.
fs.writeFileSync(filePath, 'yet another new content');
expect(fs.readFileSync(filePath, { encoding: 'utf8' })).to.be.equal('yet another new content');
// We expect two changes; one is staged, the other is in the working directory.
status = await git.status(repository);
protected openFile(change: GitFileChange, commitSha: string): void {
const uri: URI = new URI(change.uri);
let fromURI = change.oldUri ? new URI(change.oldUri) : uri; // set oldUri on renamed and copied
fromURI = fromURI.withScheme(GIT_RESOURCE_SCHEME).withQuery(commitSha + '~1');
const toURI = uri.withScheme(GIT_RESOURCE_SCHEME).withQuery(commitSha);
let uriToOpen = uri;
if (change.status === GitFileStatus.Deleted) {
uriToOpen = fromURI;
} else if (change.status === GitFileStatus.New) {
uriToOpen = toURI;
} else {
uriToOpen = DiffUris.encode(fromURI, toURI);
}
open(this.openerService, uriToOpen, { mode: 'reveal' });
}
}
protected onDidRegisterCommand(id: string, cb: (command: Command) => void): Disposable {
const command = this.commands.getCommand(id);
if (command) {
cb(command);
return Disposable.NULL;
}
const toDispose = new DisposableCollection();
// Registering a menu action requires the related command to be already registered.
// But Theia plugin registers the commands dynamically via the Commands API.
// Let's wait for ~2 sec. It should be enough to finish registering all the contributed commands.
// FIXME: remove this workaround (timer) once the https://github.com/theia-ide/theia/issues/3344 is fixed
const handle = setTimeout(() => toDispose.push(this.onDidRegisterCommand(id, cb)), 2000);
toDispose.push(Disposable.create(() => clearTimeout(handle)));
return toDispose;
}
register(theme: MonacoTheme, pending: { [uri: string]: Promise } = {}): Disposable {
const toDispose = new DisposableCollection(Disposable.create(() => { /* mark as not disposed */ }));
this.doRegister(theme, pending, toDispose);
return toDispose;
}
private async confirmOverwrite(uri: URI): Promise {
// Electron already handles the confirmation so do not prompt again.
if (this.isElectron()) {
return true;
}
// Prompt users for confirmation before overwriting.
const confirmed = await new ConfirmDialog({
title: 'Overwrite',
msg: `Do you really want to overwrite "${uri.toString()}"?`
}).open();
return !!confirmed;
}
function compareSearchResults(expected: SearchInWorkspaceResult[], actual: SearchInWorkspaceResult[]): void {
expect(actual.length).eq(expected.length);
if (actual.length !== expected.length) {
return;
}
for (let i = 0; i < actual.length; i++) {
const e = expected[i];
const lines = fileLines.get(e.fileUri);
if (lines) {
const line = lines[e.line - 1];
e.lineText = line;
e.fileUri = FileUri.create(path.join(getRootPathFromName(e.fileUri), e.fileUri)).toString();
const a = actual.find(l => l.fileUri === e.fileUri && l.line === e.line && l.character === e.character);
expect(a).deep.eq(e);
} else {
// We don't know this file...
expect.fail();
}
}
}