Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected collectDecorators(tree: Tree): Map {
const result = new Map();
// If the tree root is undefined or the preference for the decorations is disabled, return an empty result map.
if (tree.root === undefined || !this.problemPreferences['problems.decorations.enabled']) {
return result;
}
const markers = this.appendContainerMarkers(tree, this.collectMarkers(tree));
for (const node of new DepthFirstTreeIterator(tree.root)) {
const nodeUri = FileStatNode.getUri(node);
if (nodeUri) {
const marker = markers.get(nodeUri);
if (marker) {
result.set(node.id, marker);
}
}
}
return new Map(Array.from(result.entries()).map(m => [m[0], this.toDecorator(m[1])] as [string, TreeDecoration.Data]));
}
async $showSaveDialog(options: SaveDialogOptionsMain): Promise {
const rootStat = await this.getRootUri(options.defaultUri ? options.defaultUri : undefined);
// Fail if root not fount
if (!rootStat) {
throw new Error('Unable to find the rootStat');
}
// Take the info for root node
const rootNode = DirNode.createRoot(rootStat);
try {
// Create save file dialog props
const dialogProps = {
title: 'Save',
saveLabel: options.saveLabel,
filters: options.filters
} as SaveFileDialogProps;
// Show save file dialog
const dialog = this.saveFileDialogFactory(dialogProps);
dialog.model.navigateTo(rootNode);
const result = await dialog.open();
// Return the result
if (result) {
async $showOpenDialog(options: OpenDialogOptionsMain): Promise {
const rootStat = await this.getRootUri(options.defaultUri ? options.defaultUri : undefined);
// Fail if root not fount
if (!rootStat) {
throw new Error('Unable to find the rootStat');
}
// Take the info for root node
const rootNode = DirNode.createRoot(rootStat);
try {
// Determine proper title for the dialog
const canSelectFiles = typeof options.canSelectFiles === 'boolean' ? options.canSelectFiles : true;
const canSelectFolders = typeof options.canSelectFolders === 'boolean' ? options.canSelectFolders : true;
let title;
if (canSelectFiles && canSelectFolders) {
title = 'Open';
} else {
if (canSelectFiles) {
title = 'Open File';
} else {
title = 'Open Folder';
}
let uri: URI;
if (configUri && configUri.path.base === 'tasks.json') {
uri = configUri;
} else { // fallback
uri = new URI(model.workspaceFolderUri).resolve(`${this.preferenceConfigurations.getPaths()[0]}/tasks.json`);
}
const fileStat = await this.filesystem.getFileStat(uri.toString());
if (!fileStat) {
throw new Error(`file not found: ${uri.toString()}`);
}
try {
this.filesystem.setContent(fileStat, content);
} catch (e) {
if (!FileSystemError.FileExists.is(e)) {
throw e;
}
}
return uri;
}
}
if (configUri && configUri.path.base === 'launch.json') {
uri = configUri;
} else { // fallback
uri = new URI(model.workspaceFolderUri).resolve(`${this.preferenceConfigurations.getPaths()[0]}/launch.json`);
}
const debugType = await this.selectDebugType();
const configurations = debugType ? await this.provideDebugConfigurations(debugType, model.workspaceFolderUri) : [];
const content = this.getInitialConfigurationContent(configurations);
const fileStat = await this.filesystem.getFileStat(uri.toString());
if (!fileStat) {
throw new Error(`file not found: ${uri.toString()}`);
}
try {
await this.filesystem.setContent(fileStat, content);
} catch (e) {
if (!FileSystemError.FileExists.is(e)) {
throw e;
}
}
return uri;
}
}
for (const workspace of workspaces) {
const uri = new URI(workspace);
const stat = await this.fileSystem.getFileStat(workspace);
if (!stat ||
!this.preferences['workspace.supportMultiRootWorkspace'] && !stat.isDirectory) {
continue; // skip the workspace files if multi root is not supported
}
if (tempWorkspaceFile && uri.toString() === tempWorkspaceFile.toString()) {
continue; // skip the temporary workspace files
}
const icon = this.labelProvider.getIcon(stat);
const iconClass = icon === '' ? undefined : icon + ' file-icon';
this.items.push(new QuickOpenGroupItem({
label: uri.path.base,
description: (home) ? FileSystemUtils.tildifyPath(uri.path.toString(), home) : uri.path.toString(),
groupLabel: `last modified ${moment(stat.lastModification).fromNow()}`,
iconClass,
run: (mode: QuickOpenMode): boolean => {
if (mode !== QuickOpenMode.OPEN) {
return false;
}
const current = this.workspaceService.workspace;
const uriToOpen = new URI(workspace);
if ((current && current.uri !== workspace) || !current) {
this.workspaceService.open(uriToOpen);
}
return true;
},
}));
}
protected async onDidTaskFileChange(fileChanges: FileChange[]): Promise {
for (const change of fileChanges) {
if (change.type === FileChangeType.DELETED) {
this.removeTasks(change.uri);
} else {
// re-parse the config file
await this.refreshTasks(change.uri);
}
}
}
it('Should return notify client when resource changed underneath', done => {
userStorageResource.onDidChangeContents(() => {
done();
});
mockOnFileChangedEmitter.fire([
{
type: FileChangeType.UPDATED,
uri: userStorageFolder.resolve(testFile)
}
]);
}).timeout(2000);
it('Should register a client and notifies it of the fs changesby converting them to user storage changes', done => {
userStorageService.onUserStorageChanged(event => {
const userStorageUri = event.uris[0];
expect(userStorageUri.scheme).eq(UserStorageUri.SCHEME);
expect(userStorageUri.path.toString()).eq(testFile);
done();
});
mockOnFileChangedEmitter.fire([
{
type: FileChangeType.UPDATED,
uri: userStorageFolder.resolve(testFile)
}
]);
}).timeout(2000);
canHandle(uri: object): number {
let toCheck = uri;
if (FileStat.is(toCheck)) {
toCheck = new URI(toCheck.uri);
}
if (toCheck instanceof URI) {
if (toCheck.path.ext === '.coffee') {
return 1000;
}
}
return 0;
}