Skip to content

Commit

Permalink
feat: automatically save and open profile on completion
Browse files Browse the repository at this point in the history
Fixes #432
  • Loading branch information
connor4312 committed Apr 24, 2020
1 parent d3f7da1 commit 5f55af6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ demos/web-worker/vscode-pwa-cdp.log
/testWorkspace/web/tmp
/testWorkspace/**/debug.log
/testWorkspace/webview/win/true/
*.cpuprofile
1 change: 0 additions & 1 deletion demos/node/vscode-js-profile-d82d7c73.cpuprofile

This file was deleted.

1 change: 0 additions & 1 deletion demos/node/vscode-js-profile-d93db23d.cpuprofile

This file was deleted.

40 changes: 27 additions & 13 deletions src/ui/profiling/uiProfileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import { ProfilerFactory } from '../../adapter/profiling';
import { AnyLaunchConfiguration } from '../../configuration';
import { UiProfileSession } from './uiProfileSession';
import { Commands } from '../../common/contributionUtils';
import { basename } from 'path';
import { basename, join, extname } from 'path';
import { FS, FsPromises, SessionSubStates } from '../../ioc-extras';
import { IDisposable } from '../../common/disposable';
import { ITerminationConditionFactory } from './terminationCondition';
import { homedir } from 'os';

const localize = nls.loadMessageBundle();

Expand Down Expand Up @@ -190,18 +191,31 @@ export class UiProfileManager implements IDisposable {
]);
}

const targetFile = await vscode.window.showSaveDialog({
defaultUri: session.workspaceFolder?.uri.with({
path: session.workspaceFolder.uri.path + '/' + basename(sourceFile),
}),
filters: {
[uiSession.impl.label]: [uiSession.impl.extension.slice(1)],
},
});

if (targetFile) {
this.fs.rename(sourceFile, targetFile.fsPath);
}
const directory =
session.workspaceFolder?.uri.fsPath ??
vscode.workspace.workspaceFolders?.[0].uri.fsPath ??
homedir();

const now = new Date();
const filename =
[
'vscode-profile',
now.getFullYear(),
now.getMonth() + 1,
now.getDate(),
now.getHours(),
now.getMinutes(),
now.getSeconds(),
]
.map(n => String(n).padStart(2, '0'))
.join('-') + extname(sourceFile);

// todo: open as untitled, see: https://github.com/microsoft/vscode/issues/93441
const fileUri = vscode.Uri.file(join(directory, filename));
await this.fs.rename(sourceFile, fileUri.fsPath);

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

/**
Expand Down

0 comments on commit 5f55af6

Please sign in to comment.