Merge from vscode 5b9869eb02fa4c96205a74d05cad9164dfd06d60 (#5607)

This commit is contained in:
Anthony Dresser
2019-05-24 12:20:30 -07:00
committed by GitHub
parent 361ada4963
commit bcc449b524
126 changed files with 3096 additions and 2255 deletions

View File

@@ -1272,6 +1272,12 @@
"default": false, "default": false,
"description": "%config.fetchOnPull%" "description": "%config.fetchOnPull%"
}, },
"git.pullTags": {
"type": "boolean",
"scope": "resource",
"default": true,
"description": "%config.pullTags%"
},
"git.autoStash": { "git.autoStash": {
"type": "boolean", "type": "boolean",
"scope": "resource", "scope": "resource",

View File

@@ -112,6 +112,7 @@
"config.rebaseWhenSync": "Force git to use rebase when running the sync command.", "config.rebaseWhenSync": "Force git to use rebase when running the sync command.",
"config.confirmEmptyCommits": "Always confirm the creation of empty commits.", "config.confirmEmptyCommits": "Always confirm the creation of empty commits.",
"config.fetchOnPull": "Fetch all branches when pulling or just the current one.", "config.fetchOnPull": "Fetch all branches when pulling or just the current one.",
"config.pullTags": "Fetch all tags when pulling.",
"config.autoStash": "Stash any changes before pulling and restore them after successful pull.", "config.autoStash": "Stash any changes before pulling and restore them after successful pull.",
"config.allowForcePush": "Controls whether force push (with or without lease) is enabled.", "config.allowForcePush": "Controls whether force push (with or without lease) is enabled.",
"config.useForcePushWithLease": "Controls whether force pushing uses the safer force-with-lease variant.", "config.useForcePushWithLease": "Controls whether force pushing uses the safer force-with-lease variant.",

View File

@@ -12,7 +12,7 @@ import { EventEmitter } from 'events';
import iconv = require('iconv-lite'); import iconv = require('iconv-lite');
import * as filetype from 'file-type'; import * as filetype from 'file-type';
import { assign, groupBy, denodeify, IDisposable, toDisposable, dispose, mkdirp, readBytes, detectUnicodeEncoding, Encoding, onceEvent } from './util'; import { assign, groupBy, denodeify, IDisposable, toDisposable, dispose, mkdirp, readBytes, detectUnicodeEncoding, Encoding, onceEvent } from './util';
import { CancellationToken, Uri } from 'vscode'; import { CancellationToken, Uri, workspace } from 'vscode';
import { detectEncoding } from './encoding'; import { detectEncoding } from './encoding';
import { Ref, RefType, Branch, Remote, GitErrorCodes, LogOptions, Change, Status } from './api/git'; import { Ref, RefType, Branch, Remote, GitErrorCodes, LogOptions, Change, Status } from './api/git';
@@ -1362,7 +1362,12 @@ export class Repository {
} }
async pull(rebase?: boolean, remote?: string, branch?: string, options: PullOptions = {}): Promise<void> { async pull(rebase?: boolean, remote?: string, branch?: string, options: PullOptions = {}): Promise<void> {
const args = ['pull', '--tags']; const args = ['pull'];
const config = workspace.getConfiguration('git', Uri.file(this.root));
if (config.get<boolean>('pullTags')) {
args.push('--tags');
}
if (options.unshallow) { if (options.unshallow) {
args.push('--unshallow'); args.push('--unshallow');

View File

@@ -10,40 +10,34 @@ VSCODE_PATH="$(dirname "$(dirname "$(realpath "$0")")")"
ELECTRON="$VSCODE_PATH/$NAME.exe" ELECTRON="$VSCODE_PATH/$NAME.exe"
if grep -qi Microsoft /proc/version; then if grep -qi Microsoft /proc/version; then
# in a wsl shell # in a wsl shell
fallback() { WSL_BUILD=$(uname -r | sed -E 's/^.+-([0-9]+)-[Mm]icrosoft/\1/')
if [ $WSL_BUILD -ge 17063 ] 2> /dev/null; then
# WSLPATH is available since WSL build 17046
# WSLENV is available since WSL build 17063
export WSLENV=ELECTRON_RUN_AS_NODE/w:$WSLENV
# use the Remote WSL extension if installed
pushd "$VSCODE_PATH" > /dev/null
WSL_EXT_ID="ms-vscode-remote.remote-wsl"
WSL_EXT_WLOC=$(ELECTRON_RUN_AS_NODE=1 "$ELECTRON" ".\resources\app\out\cli.js" --locate-extension $WSL_EXT_ID)
popd > /dev/null
if ! [ -z "$WSL_EXT_WLOC" ]; then
# replace \r\n with \n in WSL_EXT_WLOC
WSL_CODE=$(wslpath -u "${WSL_EXT_WLOC%%[[:cntrl:]]}")/scripts/wslCode.sh
WIN_CODE_CMD=$(wslpath -w "$VSCODE_PATH/bin/$APP_NAME.cmd")
"$WSL_CODE" $COMMIT $QUALITY "$WIN_CODE_CMD" "$APP_NAME" "$@"
exit $?
else
CLI=$(wslpath -m "$VSCODE_PATH/resources/app/out/cli.js")
fi
else
# If running under older WSL, don't pass cli.js to Electron as # If running under older WSL, don't pass cli.js to Electron as
# environment vars cannot be transferred from WSL to Windows # environment vars cannot be transferred from WSL to Windows
# See: https://github.com/Microsoft/BashOnWindows/issues/1363 # See: https://github.com/Microsoft/BashOnWindows/issues/1363
# https://github.com/Microsoft/BashOnWindows/issues/1494 # https://github.com/Microsoft/BashOnWindows/issues/1494
"$ELECTRON" "$@" "$ELECTRON" "$@"
exit $? exit $?
}
WSL_BUILD=$(uname -r | sed -E 's/^.+-([0-9]+)-Microsoft/\1/')
# wslpath is not available prior to WSL build 17046
# See: https://docs.microsoft.com/en-us/windows/wsl/release-notes#build-17046
if [ -x /bin/wslpath ]; then
WIN_CODE_CMD=$(wslpath -w "$(dirname "$(realpath "$0")")/$APP_NAME.cmd")
# make sure the cwd is in the windows fs, otherwise there will be a warning from cmd
pushd "$(dirname "$0")" > /dev/null
WSL_EXT_ID="ms-vscode-remote.remote-wsl"
WSL_EXT_WLOC=$(cmd.exe /c "$WIN_CODE_CMD" --locate-extension $WSL_EXT_ID)
popd > /dev/null
if ! [ -z "$WSL_EXT_WLOC" ]; then
# replace \r\n with \n in WSL_EXT_WLOC, get linux path for
WSL_CODE=$(wslpath -u "${WSL_EXT_WLOC%%[[:cntrl:]]}")/scripts/wslCode.sh
"$WSL_CODE" $COMMIT $QUALITY "$WIN_CODE_CMD" "$APP_NAME" "$@"
exit $?
elif [ $WSL_BUILD -ge 17063 ] 2> /dev/null; then
# Since WSL build 17063, we just need to set WSLENV so that
# ELECTRON_RUN_AS_NODE is visible to the win32 process
# See: https://docs.microsoft.com/en-us/windows/wsl/release-notes#build-17063
export WSLENV=ELECTRON_RUN_AS_NODE/w:$WSLENV
CLI=$(wslpath -m "$VSCODE_PATH/resources/app/out/cli.js")
else # $WSL_BUILD ∈ [17046, 17063) OR $WSL_BUILD is indeterminate
fallback "$@"
fi
else
fallback "$@"
fi fi
elif [ -x "$(command -v cygpath)" ]; then elif [ -x "$(command -v cygpath)" ]; then
CLI=$(cygpath -m "$VSCODE_PATH/resources/app/out/cli.js") CLI=$(cygpath -m "$VSCODE_PATH/resources/app/out/cli.js")

View File

@@ -242,6 +242,9 @@ export class ContextView extends Disposable {
// if view intersects vertically with anchor, shift it horizontally // if view intersects vertically with anchor, shift it horizontally
if (Range.intersects({ start: top, end: top + viewSizeHeight }, { start: verticalAnchor.offset, end: verticalAnchor.offset + verticalAnchor.size })) { if (Range.intersects({ start: top, end: top + viewSizeHeight }, { start: verticalAnchor.offset, end: verticalAnchor.offset + verticalAnchor.size })) {
horizontalAnchor.size = around.width; horizontalAnchor.size = around.width;
if (anchorAlignment === AnchorAlignment.RIGHT) {
horizontalAnchor.offset = around.left;
}
} }
const left = layout(window.innerWidth, viewSizeWidth, horizontalAnchor); const left = layout(window.innerWidth, viewSizeWidth, horizontalAnchor);

View File

@@ -191,18 +191,19 @@ export class ActionRunner extends Disposable implements IActionRunner {
private _onDidRun = this._register(new Emitter<IRunEvent>()); private _onDidRun = this._register(new Emitter<IRunEvent>());
readonly onDidRun: Event<IRunEvent> = this._onDidRun.event; readonly onDidRun: Event<IRunEvent> = this._onDidRun.event;
run(action: IAction, context?: any): Promise<any> { async run(action: IAction, context?: any): Promise<any> {
if (!action.enabled) { if (!action.enabled) {
return Promise.resolve(null); return Promise.resolve(null);
} }
this._onDidBeforeRun.fire({ action: action }); this._onDidBeforeRun.fire({ action: action });
return this.runAction(action, context).then((result: any) => { try {
const result = await this.runAction(action, context);
this._onDidRun.fire({ action: action, result: result }); this._onDidRun.fire({ action: action, result: result });
}, (error: any) => { } catch (error) {
this._onDidRun.fire({ action: action, error: error }); this._onDidRun.fire({ action: action, error: error });
}); }
} }
protected runAction(action: IAction, context?: any): Promise<any> { protected runAction(action: IAction, context?: any): Promise<any> {

View File

@@ -362,6 +362,31 @@ export function matchesFuzzy2(pattern: string, word: string): IMatch[] | null {
return score ? createMatches(score) : null; return score ? createMatches(score) : null;
} }
export function anyScore(pattern: string, lowPattern: string, _patternPos: number, word: string, lowWord: string, _wordPos: number): FuzzyScore {
const result = fuzzyScore(pattern, lowPattern, 0, word, lowWord, 0, true);
if (result) {
return result;
}
let matches = 0;
let score = 0;
let idx = _wordPos;
for (let patternPos = 0; patternPos < lowPattern.length && patternPos < _maxLen; ++patternPos) {
const wordPos = lowWord.indexOf(lowPattern.charAt(patternPos), idx);
if (wordPos >= 0) {
score += 1;
matches += 2 ** wordPos;
idx = wordPos + 1;
} else if (matches !== 0) {
// once we have started matching things
// we need to match the remaining pattern
// characters
break;
}
}
return [score, matches, _wordPos];
}
//#region --- fuzzyScore --- //#region --- fuzzyScore ---
export function createMatches(score: undefined | FuzzyScore): IMatch[] { export function createMatches(score: undefined | FuzzyScore): IMatch[] {
@@ -491,7 +516,7 @@ export namespace FuzzyScore {
/** /**
* No matches and value `-100` * No matches and value `-100`
*/ */
export const Default: [-100, 0, 0] = [-100, 0, 0]; export const Default: [-100, 0, 0] = <[-100, 0, 0]>Object.freeze([-100, 0, 0]);
export function isDefault(score?: FuzzyScore): score is [-100, 0, 0] { export function isDefault(score?: FuzzyScore): score is [-100, 0, 0] {
return !score || (score[0] === -100 && score[1] === 0 && score[2] === 0); return !score || (score[0] === -100 && score[1] === 0 && score[2] === 0);

View File

@@ -9,7 +9,8 @@ import * as objects from 'vs/base/common/objects';
import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { Event, Emitter } from 'vs/base/common/event'; import { Event, Emitter } from 'vs/base/common/event';
import * as json from 'vs/base/common/json'; import * as json from 'vs/base/common/json';
import { readlink, statLink } from 'vs/base/node/pfs'; import { statLink } from 'vs/base/node/pfs';
import { realpath } from 'vs/base/node/extpath';
import { watchFolder, watchFile } from 'vs/base/node/watcher'; import { watchFolder, watchFile } from 'vs/base/node/watcher';
export interface IConfigurationChangeEvent<T> { export interface IConfigurationChangeEvent<T> {
@@ -130,7 +131,7 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
private async handleSymbolicLink(): Promise<void> { private async handleSymbolicLink(): Promise<void> {
const { stat, isSymbolicLink } = await statLink(this._path); const { stat, isSymbolicLink } = await statLink(this._path);
if (isSymbolicLink && !stat.isDirectory()) { if (isSymbolicLink && !stat.isDirectory()) {
const realPath = await readlink(this._path); const realPath = await realpath(this._path);
this.watch(realPath, false); this.watch(realPath, false);
} }

View File

@@ -213,10 +213,6 @@ export function symlink(target: string, path: string, type?: string): Promise<vo
return promisify(fs.symlink)(target, path, type); return promisify(fs.symlink)(target, path, type);
} }
export function readlink(path: string): Promise<string> {
return promisify(fs.readlink)(path);
}
export function truncate(path: string, len: number): Promise<void> { export function truncate(path: string, len: number): Promise<void> {
return promisify(fs.truncate)(path, len); return promisify(fs.truncate)(path, len);
} }

View File

@@ -554,10 +554,12 @@ export class SQLiteStorageDatabase implements IStorageDatabase {
return integrity; return integrity;
} }
private connect(path: string, retryOnBusy: boolean = true): Promise<IDatabaseConnection> { private async connect(path: string, retryOnBusy: boolean = true): Promise<IDatabaseConnection> {
this.logger.trace(`[storage ${this.name}] open(${path}, retryOnBusy: ${retryOnBusy})`); this.logger.trace(`[storage ${this.name}] open(${path}, retryOnBusy: ${retryOnBusy})`);
return this.doConnect(path).then(undefined, error => { try {
return await this.doConnect(path);
} catch (error) {
this.logger.error(`[storage ${this.name}] open(): Unable to open DB due to ${error}`); this.logger.error(`[storage ${this.name}] open(): Unable to open DB due to ${error}`);
// SQLITE_BUSY should only arise if another process is locking the same DB we want // SQLITE_BUSY should only arise if another process is locking the same DB we want
@@ -569,7 +571,9 @@ export class SQLiteStorageDatabase implements IStorageDatabase {
// In this case we simply wait for some time and retry once to establish the connection. // In this case we simply wait for some time and retry once to establish the connection.
// //
if (error.code === 'SQLITE_BUSY' && retryOnBusy) { if (error.code === 'SQLITE_BUSY' && retryOnBusy) {
return timeout(SQLiteStorageDatabase.BUSY_OPEN_TIMEOUT).then(() => this.connect(path, false /* not another retry */)); await timeout(SQLiteStorageDatabase.BUSY_OPEN_TIMEOUT);
return this.connect(path, false /* not another retry */);
} }
// Otherwise, best we can do is to recover from a backup if that exists, as such we // Otherwise, best we can do is to recover from a backup if that exists, as such we
@@ -579,17 +583,19 @@ export class SQLiteStorageDatabase implements IStorageDatabase {
// The final fallback is to use an in-memory DB which should only happen if the target // The final fallback is to use an in-memory DB which should only happen if the target
// folder is really not writeable for us. // folder is really not writeable for us.
// //
return unlink(path) try {
.then(() => renameIgnoreError(this.toBackupPath(path), path)) await unlink(path);
.then(() => this.doConnect(path)) await renameIgnoreError(this.toBackupPath(path), path);
.then(undefined, error => {
this.logger.error(`[storage ${this.name}] open(): Unable to use backup due to ${error}`);
// In case of any error to open the DB, use an in-memory return await this.doConnect(path);
// DB so that we always have a valid DB to talk to. } catch (error) {
return this.doConnect(SQLiteStorageDatabase.IN_MEMORY_PATH); this.logger.error(`[storage ${this.name}] open(): Unable to use backup due to ${error}`);
});
}); // In case of any error to open the DB, use an in-memory
// DB so that we always have a valid DB to talk to.
return this.doConnect(SQLiteStorageDatabase.IN_MEMORY_PATH);
}
}
} }
private handleSQLiteError(connection: IDatabaseConnection, error: Error & { code?: string }, msg: string): void { private handleSQLiteError(connection: IDatabaseConnection, error: Error & { code?: string }, msg: string): void {

View File

@@ -9,20 +9,19 @@ import * as stream from 'vs/base/node/stream';
import { getPathFromAmdModule } from 'vs/base/common/amd'; import { getPathFromAmdModule } from 'vs/base/common/amd';
suite('Stream', () => { suite('Stream', () => {
test('readToMatchingString - ANSI', function () { test('readToMatchingString - ANSI', async () => {
const file = getPathFromAmdModule(require, './fixtures/file.css'); const file = getPathFromAmdModule(require, './fixtures/file.css');
return stream.readToMatchingString(file, '\n', 10, 100).then((result: string) => { const result = await stream.readToMatchingString(file, '\n', 10, 100);
// \r may be present on Windows
assert.equal(result.replace('\r', ''), '/*---------------------------------------------------------------------------------------------'); // \r may be present on Windows
}); assert.equal(result!.replace('\r', ''), '/*---------------------------------------------------------------------------------------------');
}); });
test('readToMatchingString - empty', function () { test('readToMatchingString - empty', async () => {
const file = getPathFromAmdModule(require, './fixtures/empty.txt'); const file = getPathFromAmdModule(require, './fixtures/empty.txt');
return stream.readToMatchingString(file, '\n', 10, 100).then((result: string) => { const result = await stream.readToMatchingString(file, '\n', 10, 100);
assert.equal(result, null); assert.equal(result, null);
});
}); });
}); });

View File

@@ -42,7 +42,7 @@ import { Button } from 'vs/base/browser/ui/button/button';
import { withUndefinedAsNull } from 'vs/base/common/types'; import { withUndefinedAsNull } from 'vs/base/common/types';
import { SystemInfo, isRemoteDiagnosticError } from 'vs/platform/diagnostics/common/diagnosticsService'; import { SystemInfo, isRemoteDiagnosticError } from 'vs/platform/diagnostics/common/diagnosticsService';
const MAX_URL_LENGTH = platform.isWindows ? 2081 : 5400; const MAX_URL_LENGTH = 2045;
interface SearchResult { interface SearchResult {
html_url: string; html_url: string;
@@ -440,11 +440,11 @@ export class IssueReporter extends Disposable {
} }
}); });
document.onkeydown = (e: KeyboardEvent) => { document.onkeydown = async (e: KeyboardEvent) => {
const cmdOrCtrlKey = platform.isMacintosh ? e.metaKey : e.ctrlKey; const cmdOrCtrlKey = platform.isMacintosh ? e.metaKey : e.ctrlKey;
// Cmd/Ctrl+Enter previews issue and closes window // Cmd/Ctrl+Enter previews issue and closes window
if (cmdOrCtrlKey && e.keyCode === 13) { if (cmdOrCtrlKey && e.keyCode === 13) {
if (this.createIssue()) { if (await this.createIssue()) {
ipcRenderer.send('vscode:closeIssueReporter'); ipcRenderer.send('vscode:closeIssueReporter');
} }
} }
@@ -844,7 +844,7 @@ export class IssueReporter extends Disposable {
return isValid; return isValid;
} }
private createIssue(): boolean { private async createIssue(): Promise<boolean> {
if (!this.validateInputs()) { if (!this.validateInputs()) {
// If inputs are invalid, set focus to the first one and add listeners on them // If inputs are invalid, set focus to the first one and add listeners on them
// to detect further changes // to detect further changes
@@ -888,14 +888,32 @@ export class IssueReporter extends Disposable {
let url = baseUrl + `&body=${encodeURIComponent(issueBody)}`; let url = baseUrl + `&body=${encodeURIComponent(issueBody)}`;
if (url.length > MAX_URL_LENGTH) { if (url.length > MAX_URL_LENGTH) {
clipboard.writeText(issueBody); try {
url = baseUrl + `&body=${encodeURIComponent(localize('pasteData', "We have written the needed data into your clipboard because it was too large to send. Please paste."))}`; url = await this.writeToClipboard(baseUrl, issueBody);
} catch (_) {
return false;
}
} }
ipcRenderer.send('vscode:openExternal', url); ipcRenderer.send('vscode:openExternal', url);
return true; return true;
} }
private async writeToClipboard(baseUrl: string, issueBody: string): Promise<string> {
return new Promise((resolve, reject) => {
ipcRenderer.once('vscode:issueReporterClipboardResponse', (_: unknown, shouldWrite: boolean) => {
if (shouldWrite) {
clipboard.writeText(issueBody);
resolve(baseUrl + `&body=${encodeURIComponent(localize('pasteData', "We have written the needed data into your clipboard because it was too large to send. Please paste."))}`);
} else {
reject();
}
});
ipcRenderer.send('vscode:issueReporterClipboard');
});
}
private getExtensionGitHubUrl(): string { private getExtensionGitHubUrl(): string {
let repositoryUrl = ''; let repositoryUrl = '';
const bugsUrl = this.getExtensionBugsUrl(); const bugsUrl = this.getExtensionBugsUrl();

View File

@@ -144,7 +144,7 @@ function main(server: Server, initData: ISharedProcessInitData, configuration: I
} }
server.registerChannel('telemetryAppender', new TelemetryAppenderChannel(appInsightsAppender)); server.registerChannel('telemetryAppender', new TelemetryAppenderChannel(appInsightsAppender));
services.set(IExtensionManagementService, new SyncDescriptor(ExtensionManagementService, [false])); services.set(IExtensionManagementService, new SyncDescriptor(ExtensionManagementService));
services.set(IExtensionGalleryService, new SyncDescriptor(ExtensionGalleryService)); services.set(IExtensionGalleryService, new SyncDescriptor(ExtensionGalleryService));
services.set(ILocalizationsService, new SyncDescriptor(LocalizationsService)); services.set(ILocalizationsService, new SyncDescriptor(LocalizationsService));

View File

@@ -38,7 +38,6 @@ import { areSameExtensions, adoptToGalleryExtensionId, getGalleryExtensionId } f
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
import { getManifest } from 'vs/platform/extensionManagement/node/extensionManagementUtil'; import { getManifest } from 'vs/platform/extensionManagement/node/extensionManagementUtil';
import { IExtensionManifest, ExtensionType, isLanguagePackExtension } from 'vs/platform/extensions/common/extensions'; import { IExtensionManifest, ExtensionType, isLanguagePackExtension } from 'vs/platform/extensions/common/extensions';
import { isUIExtension } from 'vs/platform/extensions/node/extensionsUtil';
import { CancellationToken } from 'vs/base/common/cancellation'; import { CancellationToken } from 'vs/base/common/cancellation';
import { LocalizationsService } from 'vs/platform/localizations/node/localizations'; import { LocalizationsService } from 'vs/platform/localizations/node/localizations';
import { Schemas } from 'vs/base/common/network'; import { Schemas } from 'vs/base/common/network';
@@ -69,10 +68,8 @@ export function getIdAndVersion(id: string): [string, string | undefined] {
export class Main { export class Main {
constructor( constructor(
private readonly remote: boolean,
@IInstantiationService private readonly instantiationService: IInstantiationService, @IInstantiationService private readonly instantiationService: IInstantiationService,
@IEnvironmentService private readonly environmentService: IEnvironmentService, @IEnvironmentService private readonly environmentService: IEnvironmentService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IExtensionManagementService private readonly extensionManagementService: IExtensionManagementService, @IExtensionManagementService private readonly extensionManagementService: IExtensionManagementService,
@IExtensionGalleryService private readonly extensionGalleryService: IExtensionGalleryService @IExtensionGalleryService private readonly extensionGalleryService: IExtensionGalleryService
) { } ) { }
@@ -138,10 +135,6 @@ export class Main {
extension = path.isAbsolute(extension) ? extension : path.join(process.cwd(), extension); extension = path.isAbsolute(extension) ? extension : path.join(process.cwd(), extension);
const manifest = await getManifest(extension); const manifest = await getManifest(extension);
if (this.remote && (!isLanguagePackExtension(manifest) && isUIExtension(manifest, [], this.configurationService))) {
console.log(localize('notSupportedUIExtension', "Can't install extension {0} since UI Extensions are not supported", getBaseLabel(extension)));
return null;
}
const valid = await this.validate(manifest, force); const valid = await this.validate(manifest, force);
if (valid) { if (valid) {
@@ -180,11 +173,6 @@ export class Main {
} }
const manifest = await this.extensionGalleryService.getManifest(extension, CancellationToken.None); const manifest = await this.extensionGalleryService.getManifest(extension, CancellationToken.None);
if (this.remote && manifest && (!isLanguagePackExtension(manifest) && isUIExtension(manifest, [], this.configurationService))) {
console.log(localize('notSupportedUIExtension', "Can't install extension {0} since UI Extensions are not supported", extension.identifier.id));
return null;
}
const [installedExtension] = installed.filter(e => areSameExtensions(e.identifier, { id })); const [installedExtension] = installed.filter(e => areSameExtensions(e.identifier, { id }));
if (installedExtension) { if (installedExtension) {
if (extension.version === installedExtension.manifest.version) { if (extension.version === installedExtension.manifest.version) {
@@ -312,7 +300,7 @@ export function main(argv: ParsedArgs): Promise<void> {
const services = new ServiceCollection(); const services = new ServiceCollection();
services.set(IConfigurationService, new SyncDescriptor(ConfigurationService, [environmentService.appSettingsPath])); services.set(IConfigurationService, new SyncDescriptor(ConfigurationService, [environmentService.appSettingsPath]));
services.set(IRequestService, new SyncDescriptor(RequestService)); services.set(IRequestService, new SyncDescriptor(RequestService));
services.set(IExtensionManagementService, new SyncDescriptor(ExtensionManagementService, [false])); services.set(IExtensionManagementService, new SyncDescriptor(ExtensionManagementService));
services.set(IExtensionGalleryService, new SyncDescriptor(ExtensionGalleryService)); services.set(IExtensionGalleryService, new SyncDescriptor(ExtensionGalleryService));
const appenders: AppInsightsAppender[] = []; const appenders: AppInsightsAppender[] = [];
@@ -334,7 +322,7 @@ export function main(argv: ParsedArgs): Promise<void> {
} }
const instantiationService2 = instantiationService.createChild(services); const instantiationService2 = instantiationService.createChild(services);
const main = instantiationService2.createInstance(Main, false); const main = instantiationService2.createInstance(Main);
return main.run(argv).then(() => { return main.run(argv).then(() => {
// Dispose the AI adapter so that remaining data gets flushed. // Dispose the AI adapter so that remaining data gets flushed.

View File

@@ -1288,6 +1288,7 @@ export interface CommentThread2 {
resource: string | null; resource: string | null;
range: IRange; range: IRange;
label: string; label: string;
contextValue: string | undefined;
comments: Comment[] | undefined; comments: Comment[] | undefined;
onDidChangeComments: Event<Comment[] | undefined>; onDidChangeComments: Event<Comment[] | undefined>;
collapsibleState?: CommentThreadCollapsibleState; collapsibleState?: CommentThreadCollapsibleState;
@@ -1326,6 +1327,7 @@ export interface CommentThread {
collapsibleState?: CommentThreadCollapsibleState; collapsibleState?: CommentThreadCollapsibleState;
reply?: Command; reply?: Command;
isDisposed?: boolean; isDisposed?: boolean;
contextValue?: string;
} }
/** /**
@@ -1347,14 +1349,24 @@ export interface CommentReaction {
readonly canEdit?: boolean; readonly canEdit?: boolean;
} }
/**
* @internal
*/
export enum CommentMode {
Editing = 0,
Preview = 1
}
/** /**
* @internal * @internal
*/ */
export interface Comment { export interface Comment {
readonly commentId: string; readonly commentId: string;
readonly uniqueIdInThread?: number;
readonly body: IMarkdownString; readonly body: IMarkdownString;
readonly userName: string; readonly userName: string;
readonly userIconPath?: string; readonly userIconPath?: string;
readonly contextValue?: string;
readonly canEdit?: boolean; readonly canEdit?: boolean;
readonly canDelete?: boolean; readonly canDelete?: boolean;
readonly selectCommand?: Command; readonly selectCommand?: Command;
@@ -1363,6 +1375,7 @@ export interface Comment {
readonly isDraft?: boolean; readonly isDraft?: boolean;
readonly commentReactions?: CommentReaction[]; readonly commentReactions?: CommentReaction[];
readonly label?: string; readonly label?: string;
readonly mode?: CommentMode;
} }
/** /**

View File

@@ -152,17 +152,22 @@ export async function formatDocumentRangeWithProvider(
cts = new TextModelCancellationTokenSource(editorOrModel, token); cts = new TextModelCancellationTokenSource(editorOrModel, token);
} }
const rawEdits = await provider.provideDocumentRangeFormattingEdits( let edits: TextEdit[] | undefined;
model, try {
range, const rawEdits = await provider.provideDocumentRangeFormattingEdits(
model.getFormattingOptions(), model,
cts.token range,
); model.getFormattingOptions(),
cts.token
);
edits = await workerService.computeMoreMinimalEdits(model.uri, rawEdits);
const edits = await workerService.computeMoreMinimalEdits(model.uri, rawEdits); if (cts.token.isCancellationRequested) {
return true;
}
if (cts.token.isCancellationRequested) { } finally {
return true; cts.dispose();
} }
if (!edits || edits.length === 0) { if (!edits || edits.length === 0) {
@@ -235,16 +240,22 @@ export async function formatDocumentWithProvider(
cts = new TextModelCancellationTokenSource(editorOrModel, token); cts = new TextModelCancellationTokenSource(editorOrModel, token);
} }
const rawEdits = await provider.provideDocumentFormattingEdits( let edits: TextEdit[] | undefined;
model, try {
model.getFormattingOptions(), const rawEdits = await provider.provideDocumentFormattingEdits(
cts.token model,
); model.getFormattingOptions(),
cts.token
);
const edits = await workerService.computeMoreMinimalEdits(model.uri, rawEdits); edits = await workerService.computeMoreMinimalEdits(model.uri, rawEdits);
if (cts.token.isCancellationRequested) { if (cts.token.isCancellationRequested) {
return true; return true;
}
} finally {
cts.dispose();
} }
if (!edits || edits.length === 0) { if (!edits || edits.length === 0) {

View File

@@ -29,6 +29,7 @@ import { IProgressService } from 'vs/platform/progress/common/progress';
import { getDefinitionsAtPosition, getImplementationsAtPosition, getTypeDefinitionsAtPosition, getDeclarationsAtPosition } from './goToDefinition'; import { getDefinitionsAtPosition, getImplementationsAtPosition, getTypeDefinitionsAtPosition, getDeclarationsAtPosition } from './goToDefinition';
import { CommandsRegistry } from 'vs/platform/commands/common/commands'; import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { EditorStateCancellationTokenSource, CodeEditorStateFlag } from 'vs/editor/browser/core/editorState'; import { EditorStateCancellationTokenSource, CodeEditorStateFlag } from 'vs/editor/browser/core/editorState';
import { ISymbolNavigationService } from 'vs/editor/contrib/goToDefinition/goToDefinitionResultsNavigation';
export class DefinitionActionConfig { export class DefinitionActionConfig {
@@ -58,6 +59,7 @@ export class DefinitionAction extends EditorAction {
const notificationService = accessor.get(INotificationService); const notificationService = accessor.get(INotificationService);
const editorService = accessor.get(ICodeEditorService); const editorService = accessor.get(ICodeEditorService);
const progressService = accessor.get(IProgressService); const progressService = accessor.get(IProgressService);
const symbolNavService = accessor.get(ISymbolNavigationService);
const model = editor.getModel(); const model = editor.getModel();
const pos = editor.getPosition(); const pos = editor.getPosition();
@@ -102,7 +104,7 @@ export class DefinitionAction extends EditorAction {
} else { } else {
// handle multile results // handle multile results
return this._onResult(editorService, editor, new ReferencesModel(result)); return this._onResult(editorService, symbolNavService, editor, new ReferencesModel(result));
} }
}, (err) => { }, (err) => {
@@ -130,7 +132,7 @@ export class DefinitionAction extends EditorAction {
return model.references.length > 1 ? nls.localize('meta.title', " {0} definitions", model.references.length) : ''; return model.references.length > 1 ? nls.localize('meta.title', " {0} definitions", model.references.length) : '';
} }
private async _onResult(editorService: ICodeEditorService, editor: ICodeEditor, model: ReferencesModel): Promise<void> { private async _onResult(editorService: ICodeEditorService, symbolNavService: ISymbolNavigationService, editor: ICodeEditor, model: ReferencesModel): Promise<void> {
const msg = model.getAriaMessage(); const msg = model.getAriaMessage();
alert(msg); alert(msg);
@@ -150,6 +152,12 @@ export class DefinitionAction extends EditorAction {
} else { } else {
model.dispose(); model.dispose();
} }
// keep remaining locations around when using
// 'goto'-mode
if (gotoLocation.multiple === 'goto') {
symbolNavService.put(next);
}
} }
} }

View File

@@ -0,0 +1,212 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ReferencesModel, OneReference } from 'vs/editor/contrib/referenceSearch/referencesModel';
import { RawContextKey, IContextKeyService, IContextKey, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { createDecorator, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { KeybindingWeight, KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { KeyCode } from 'vs/base/common/keyCodes';
import { registerEditorCommand, EditorCommand } from 'vs/editor/browser/editorExtensions';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { Range } from 'vs/editor/common/core/range';
import { Disposable, dispose, combinedDisposable, IDisposable } from 'vs/base/common/lifecycle';
import { Emitter, Event } from 'vs/base/common/event';
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
import { localize } from 'vs/nls';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
export const ctxHasSymbols = new RawContextKey('hasSymbols', false);
export const ISymbolNavigationService = createDecorator<ISymbolNavigationService>('ISymbolNavigationService');
export interface ISymbolNavigationService {
_serviceBrand: any;
reset(): void;
put(anchor: OneReference): void;
revealNext(source: ICodeEditor): Promise<any>;
}
class SymbolNavigationService implements ISymbolNavigationService {
_serviceBrand: any;
private readonly _ctxHasSymbols: IContextKey<boolean>;
private _currentModel?: ReferencesModel = undefined;
private _currentIdx: number = -1;
private _currentDisposables: IDisposable[] = [];
private _currentMessage?: IDisposable = undefined;
private _ignoreEditorChange: boolean = false;
constructor(
@IContextKeyService contextKeyService: IContextKeyService,
@ICodeEditorService private readonly _editorService: ICodeEditorService,
@IStatusbarService private readonly _statusbarService: IStatusbarService,
@IKeybindingService private readonly _keybindingService: IKeybindingService,
) {
this._ctxHasSymbols = ctxHasSymbols.bindTo(contextKeyService);
}
reset(): void {
this._ctxHasSymbols.reset();
dispose(this._currentDisposables);
dispose(this._currentMessage);
this._currentModel = undefined;
this._currentIdx = -1;
}
put(anchor: OneReference): void {
const refModel = anchor.parent.parent;
if (refModel.references.length <= 1) {
this.reset();
return;
}
this._currentModel = refModel;
this._currentIdx = refModel.references.indexOf(anchor);
this._ctxHasSymbols.set(true);
this._showMessage();
const editorStatus = new EditorStatus(this._editorService);
const listener = editorStatus.onDidChange(_ => {
if (this._ignoreEditorChange) {
return;
}
const editor = this._editorService.getActiveCodeEditor();
if (!editor) {
return;
}
const model = editor.getModel();
const position = editor.getPosition();
if (!model || !position) {
return;
}
let seenUri: boolean = false;
let seenPosition: boolean = false;
for (const reference of refModel.references) {
if (reference.uri.toString() === model.uri.toString()) {
seenUri = true;
seenPosition = seenPosition || Range.containsPosition(reference.range, position);
} else if (seenUri) {
break;
}
}
if (!seenUri || !seenPosition) {
this.reset();
}
});
this._currentDisposables = [editorStatus, listener];
}
revealNext(source: ICodeEditor): Promise<any> {
if (!this._currentModel) {
return Promise.resolve();
}
// get next result and advance
this._currentIdx += 1;
this._currentIdx %= this._currentModel.references.length;
const reference = this._currentModel.references[this._currentIdx];
// status
this._showMessage();
// open editor, ignore events while that happens
this._ignoreEditorChange = true;
return this._editorService.openCodeEditor({
resource: reference.uri,
options: {
selection: Range.collapseToStart(reference.range),
revealInCenterIfOutsideViewport: true,
revealIfOpened: true
}
}, source).finally(() => {
this._ignoreEditorChange = false;
});
}
private _showMessage(): void {
dispose(this._currentMessage);
const kb = this._keybindingService.lookupKeybinding('editor.gotoNextSymbolFromResult');
const message = kb
? localize('location.kb', "Symbol {0} of {1}, press {2} to reveal next", this._currentIdx + 1, this._currentModel!.references.length, kb.getLabel())
: localize('location', "Symbol {0} of {1}", this._currentIdx + 1, this._currentModel!.references.length);
this._currentMessage = this._statusbarService.setStatusMessage(message);
}
}
registerSingleton(ISymbolNavigationService, SymbolNavigationService, true);
registerEditorCommand(new class extends EditorCommand {
constructor() {
super({
id: 'editor.gotoNextSymbolFromResult',
precondition: ContextKeyExpr.and(
ctxHasSymbols,
ContextKeyExpr.equals('config.editor.gotoLocation.multiple', 'goto')
),
kbOpts: {
weight: KeybindingWeight.EditorContrib,
primary: KeyCode.F12
}
});
}
runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor): void | Promise<void> {
return accessor.get(ISymbolNavigationService).revealNext(editor);
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'editor.gotoNextSymbolFromResult.cancel',
weight: KeybindingWeight.EditorContrib,
when: ctxHasSymbols,
primary: KeyCode.Escape,
handler(accessor) {
accessor.get(ISymbolNavigationService).reset();
}
});
//
class EditorStatus extends Disposable {
private readonly _listener = new Map<ICodeEditor, IDisposable>();
private readonly _onDidChange = new Emitter<{ editor: ICodeEditor }>();
readonly onDidChange: Event<{ editor: ICodeEditor }> = this._onDidChange.event;
constructor(@ICodeEditorService editorService: ICodeEditorService) {
super();
this._register(this._onDidChange);
this._register(editorService.onCodeEditorRemove(this._onDidRemoveEditor, this));
this._register(editorService.onCodeEditorAdd(this._onDidAddEditor, this));
editorService.listCodeEditors().forEach(this._onDidAddEditor, this);
}
private _onDidAddEditor(editor: ICodeEditor): void {
this._listener.set(editor, combinedDisposable([
editor.onDidChangeCursorPosition(_ => this._onDidChange.fire({ editor })),
editor.onDidChangeModelContent(_ => this._onDidChange.fire({ editor })),
]));
}
private _onDidRemoveEditor(editor: ICodeEditor): void {
dispose(this._listener.get(editor));
this._listener.delete(editor);
}
}

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information. * Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { fuzzyScore, fuzzyScoreGracefulAggressive, FuzzyScorer, FuzzyScore } from 'vs/base/common/filters'; import { fuzzyScore, fuzzyScoreGracefulAggressive, FuzzyScorer, FuzzyScore, anyScore } from 'vs/base/common/filters';
import { isDisposable } from 'vs/base/common/lifecycle'; import { isDisposable } from 'vs/base/common/lifecycle';
import { CompletionList, CompletionItemProvider, CompletionItemKind } from 'vs/editor/common/modes'; import { CompletionList, CompletionItemProvider, CompletionItemKind } from 'vs/editor/common/modes';
import { CompletionItem } from './suggest'; import { CompletionItem } from './suggest';
@@ -222,7 +222,7 @@ export class CompletionModel {
} else { } else {
// re-run the scorer on the label in the hope of a result BUT use the rank // re-run the scorer on the label in the hope of a result BUT use the rank
// of the filterText-match // of the filterText-match
item.score = scoreFn(word, wordLow, wordPos, item.completion.label, item.labelLow, 0, false) || FuzzyScore.Default; item.score = anyScore(word, wordLow, wordPos, item.completion.label, item.labelLow, 0);
item.score[0] = match[0]; // use score from filterText item.score[0] = match[0]; // use score from filterText
} }

View File

@@ -100,6 +100,10 @@ export const enum MenuId {
NotebookToolbar, NotebookToolbar,
DataExplorerContext, DataExplorerContext,
DataExplorerAction, DataExplorerAction,
CommentThreadTitle,
CommentThreadActions,
CommentTitle,
CommentActions
} }
export interface IMenuActionOptions { export interface IMenuActionOptions {

View File

@@ -8,7 +8,7 @@ import * as path from 'vs/base/common/path';
import * as pfs from 'vs/base/node/pfs'; import * as pfs from 'vs/base/node/pfs';
import { assign } from 'vs/base/common/objects'; import { assign } from 'vs/base/common/objects';
import { toDisposable, Disposable } from 'vs/base/common/lifecycle'; import { toDisposable, Disposable } from 'vs/base/common/lifecycle';
import { flatten } from 'vs/base/common/arrays'; import { flatten, isNonEmptyArray } from 'vs/base/common/arrays';
import { extract, ExtractError, zip, IFile } from 'vs/base/node/zip'; import { extract, ExtractError, zip, IFile } from 'vs/base/node/zip';
import { import {
IExtensionManagementService, IExtensionGalleryService, ILocalExtension, IExtensionManagementService, IExtensionGalleryService, ILocalExtension,
@@ -44,9 +44,7 @@ import { Schemas } from 'vs/base/common/network';
import { CancellationToken } from 'vs/base/common/cancellation'; import { CancellationToken } from 'vs/base/common/cancellation';
import { getPathFromAmdModule } from 'vs/base/common/amd'; import { getPathFromAmdModule } from 'vs/base/common/amd';
import { getManifest } from 'vs/platform/extensionManagement/node/extensionManagementUtil'; import { getManifest } from 'vs/platform/extensionManagement/node/extensionManagementUtil';
import { IExtensionManifest, ExtensionType, ExtensionIdentifierWithVersion, isLanguagePackExtension } from 'vs/platform/extensions/common/extensions'; import { IExtensionManifest, ExtensionType, ExtensionIdentifierWithVersion } from 'vs/platform/extensions/common/extensions';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { isUIExtension } from 'vs/platform/extensions/node/extensionsUtil';
// {{SQL CARBON EDIT} // {{SQL CARBON EDIT}
import product from 'vs/platform/product/node/product'; import product from 'vs/platform/product/node/product';
@@ -132,9 +130,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
onDidUninstallExtension: Event<DidUninstallExtensionEvent> = this._onDidUninstallExtension.event; onDidUninstallExtension: Event<DidUninstallExtensionEvent> = this._onDidUninstallExtension.event;
constructor( constructor(
private readonly remote: boolean,
@IEnvironmentService private readonly environmentService: IEnvironmentService, @IEnvironmentService private readonly environmentService: IEnvironmentService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IExtensionGalleryService private readonly galleryService: IExtensionGalleryService, @IExtensionGalleryService private readonly galleryService: IExtensionGalleryService,
@ILogService private readonly logService: ILogService, @ILogService private readonly logService: ILogService,
@optional(IDownloadService) private downloadService: IDownloadService, @optional(IDownloadService) private downloadService: IDownloadService,
@@ -270,7 +266,18 @@ export class ExtensionManagementService extends Disposable implements IExtension
private installFromZipPath(identifierWithVersion: ExtensionIdentifierWithVersion, zipPath: string, metadata: IGalleryMetadata | null, type: ExtensionType, operation: InstallOperation, token: CancellationToken): Promise<ILocalExtension> { private installFromZipPath(identifierWithVersion: ExtensionIdentifierWithVersion, zipPath: string, metadata: IGalleryMetadata | null, type: ExtensionType, operation: InstallOperation, token: CancellationToken): Promise<ILocalExtension> {
return this.toNonCancellablePromise(this.installExtension({ zipPath, identifierWithVersion, metadata }, type, token) return this.toNonCancellablePromise(this.installExtension({ zipPath, identifierWithVersion, metadata }, type, token)
.then(local => this.installDependenciesAndPackExtensions(local, null).then(() => local, error => this.uninstall(local, true).then(() => Promise.reject(error), () => Promise.reject(error)))) .then(local => this.installDependenciesAndPackExtensions(local, null)
.then(
() => local,
error => {
if (isNonEmptyArray(local.manifest.extensionDependencies)) {
this.logService.warn(`Cannot install dependencies of extension:`, local.identifier.id, error.message);
}
if (isNonEmptyArray(local.manifest.extensionPack)) {
this.logService.warn(`Cannot install packed extensions of extension:`, local.identifier.id, error.message);
}
return local;
}))
.then( .then(
local => { this._onDidInstallExtension.fire({ identifier: identifierWithVersion.identifier, zipPath, local, operation }); return local; }, local => { this._onDidInstallExtension.fire({ identifier: identifierWithVersion.identifier, zipPath, local, operation }); return local; },
error => { this._onDidInstallExtension.fire({ identifier: identifierWithVersion.identifier, zipPath, operation, error }); return Promise.reject(error); } error => { this._onDidInstallExtension.fire({ identifier: identifierWithVersion.identifier, zipPath, operation, error }); return Promise.reject(error); }
@@ -526,16 +533,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
return this.galleryService.query({ names, pageSize: dependenciesAndPackExtensions.length }, CancellationToken.None) return this.galleryService.query({ names, pageSize: dependenciesAndPackExtensions.length }, CancellationToken.None)
.then(galleryResult => { .then(galleryResult => {
const extensionsToInstall = galleryResult.firstPage; const extensionsToInstall = galleryResult.firstPage;
return Promise.all(extensionsToInstall.map(async e => { return Promise.all(extensionsToInstall.map(e => this.installFromGallery(e)))
if (this.remote) {
const manifest = await this.galleryService.getManifest(e, CancellationToken.None);
if (manifest && isUIExtension(manifest, [], this.configurationService) && !isLanguagePackExtension(manifest)) {
this.logService.info('Ignored installing the UI dependency', e.identifier.id);
return;
}
}
return this.installFromGallery(e);
}))
.then(() => null, errors => this.rollback(extensionsToInstall).then(() => Promise.reject(errors), () => Promise.reject(errors))); .then(() => null, errors => this.rollback(extensionsToInstall).then(() => Promise.reject(errors), () => Promise.reject(errors)));
}); });
} }

View File

@@ -1,51 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IExtensionManifest } from 'vs/platform/extensions/common/extensions';
import { getGalleryExtensionId, areSameExtensions } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { isNonEmptyArray } from 'vs/base/common/arrays';
import product from 'vs/platform/product/node/product';
export function isUIExtension(manifest: IExtensionManifest, uiContributions: string[], configurationService: IConfigurationService): boolean {
const extensionId = getGalleryExtensionId(manifest.publisher, manifest.name);
const extensionKind = getExtensionKind(manifest, configurationService);
switch (extensionKind) {
case 'ui': return true;
case 'workspace': return false;
default: {
// Tagged as UI extension in product
if (isNonEmptyArray(product.uiExtensions) && product.uiExtensions.some(id => areSameExtensions({ id }, { id: extensionId }))) {
return true;
}
// Not an UI extension if it has main
if (manifest.main) {
return false;
}
// Not an UI extension if it has dependencies or an extension pack
if (isNonEmptyArray(manifest.extensionDependencies) || isNonEmptyArray(manifest.extensionPack)) {
return false;
}
if (manifest.contributes) {
// Not an UI extension if it has no ui contributions
if (!uiContributions.length || Object.keys(manifest.contributes).some(contribution => uiContributions.indexOf(contribution) === -1)) {
return false;
}
}
return true;
}
}
}
function getExtensionKind(manifest: IExtensionManifest, configurationService: IConfigurationService): string | undefined {
const extensionId = getGalleryExtensionId(manifest.publisher, manifest.name);
const configuredExtensionKinds = configurationService.getValue<{ [key: string]: string }>('remote.extensionKind') || {};
for (const id of Object.keys(configuredExtensionKinds)) {
if (areSameExtensions({ id: extensionId }, { id })) {
return configuredExtensionKinds[id];
}
}
return manifest.extensionKind;
}

View File

@@ -75,6 +75,23 @@ export class IssueService implements IIssueService {
event.sender.send('vscode:listProcessesResponse', processes); event.sender.send('vscode:listProcessesResponse', processes);
}); });
ipcMain.on('vscode:issueReporterClipboard', (event: Event) => {
const messageOptions = {
message: localize('issueReporterWriteToClipboard', "There is too much data to send to GitHub. Would you like to write the information to the clipboard so that it can be pasted?"),
type: 'warning',
buttons: [
localize('yes', "Yes"),
localize('cancel', "Cancel")
]
};
if (this._issueWindow) {
dialog.showMessageBox(this._issueWindow, messageOptions, response => {
event.sender.send('vscode:issueReporterClipboardResponse', response === 0);
});
}
});
ipcMain.on('vscode:issuePerformanceInfoRequest', (event: Event) => { ipcMain.on('vscode:issuePerformanceInfoRequest', (event: Event) => {
this.getPerformanceInfo().then(msg => { this.getPerformanceInfo().then(msg => {
event.sender.send('vscode:issuePerformanceInfoResponse', msg); event.sender.send('vscode:issuePerformanceInfoResponse', msg);

View File

@@ -58,9 +58,9 @@ export abstract class AbstractLifecycleService extends Disposable implements ILi
} }
} }
when(phase: LifecyclePhase): Promise<void> { async when(phase: LifecyclePhase): Promise<void> {
if (phase <= this._phase) { if (phase <= this._phase) {
return Promise.resolve(); return;
} }
let barrier = this.phaseWhen.get(phase); let barrier = this.phaseWhen.get(phase);
@@ -69,6 +69,6 @@ export abstract class AbstractLifecycleService extends Disposable implements ILi
this.phaseWhen.set(phase, barrier); this.phaseWhen.set(phase, barrier);
} }
return barrier.wait().then(undefined); await barrier.wait();
} }
} }

View File

@@ -75,18 +75,17 @@ export class LifecycleService extends AbstractLifecycleService {
}); });
// Main side indicates that we will indeed shutdown // Main side indicates that we will indeed shutdown
ipc.on('vscode:onWillUnload', (_event: unknown, reply: { replyChannel: string, reason: ShutdownReason }) => { ipc.on('vscode:onWillUnload', async (_event: unknown, reply: { replyChannel: string, reason: ShutdownReason }) => {
this.logService.trace(`lifecycle: onWillUnload (reason: ${reply.reason})`); this.logService.trace(`lifecycle: onWillUnload (reason: ${reply.reason})`);
// trigger onWillShutdown events and joining // trigger onWillShutdown events and joining
return this.handleWillShutdown(reply.reason).then(() => { await this.handleWillShutdown(reply.reason);
// trigger onShutdown event now that we know we will quit // trigger onShutdown event now that we know we will quit
this._onShutdown.fire(); this._onShutdown.fire();
// acknowledge to main side // acknowledge to main side
ipc.send(reply.replyChannel, windowId); ipc.send(reply.replyChannel, windowId);
});
}); });
// Save shutdown reason to retrieve on next startup // Save shutdown reason to retrieve on next startup
@@ -111,7 +110,7 @@ export class LifecycleService extends AbstractLifecycleService {
}); });
} }
private handleWillShutdown(reason: ShutdownReason): Promise<void> { private async handleWillShutdown(reason: ShutdownReason): Promise<void> {
const joiners: Promise<void>[] = []; const joiners: Promise<void>[] = [];
this._onWillShutdown.fire({ this._onWillShutdown.fire({
@@ -123,9 +122,11 @@ export class LifecycleService extends AbstractLifecycleService {
reason reason
}); });
return Promise.all(joiners).then(() => undefined, err => { try {
this.notificationService.error(toErrorMessage(err)); await Promise.all(joiners);
onUnexpectedError(err); } catch (error) {
}); this.notificationService.error(toErrorMessage(error));
onUnexpectedError(error);
}
} }
} }

View File

@@ -291,7 +291,7 @@ export class LifecycleService extends Disposable implements ILifecycleService {
}); });
} }
unload(window: ICodeWindow, reason: UnloadReason): Promise<boolean /* veto */> { async unload(window: ICodeWindow, reason: UnloadReason): Promise<boolean /* veto */> {
// Always allow to unload a window that is not yet ready // Always allow to unload a window that is not yet ready
if (!window.isReady) { if (!window.isReady) {
@@ -302,27 +302,27 @@ export class LifecycleService extends Disposable implements ILifecycleService {
// first ask the window itself if it vetos the unload // first ask the window itself if it vetos the unload
const windowUnloadReason = this._quitRequested ? UnloadReason.QUIT : reason; const windowUnloadReason = this._quitRequested ? UnloadReason.QUIT : reason;
return this.onBeforeUnloadWindowInRenderer(window, windowUnloadReason).then(veto => { let veto = await this.onBeforeUnloadWindowInRenderer(window, windowUnloadReason);
if (veto) { if (veto) {
this.logService.trace(`Lifecycle#unload() - veto in renderer (window ID ${window.id})`); this.logService.trace(`Lifecycle#unload() - veto in renderer (window ID ${window.id})`);
return this.handleWindowUnloadVeto(veto); return this.handleWindowUnloadVeto(veto);
} }
// then check for vetos in the main side // then check for vetos in the main side
return this.onBeforeUnloadWindowInMain(window, windowUnloadReason).then(veto => { veto = await this.onBeforeUnloadWindowInMain(window, windowUnloadReason);
if (veto) { if (veto) {
this.logService.trace(`Lifecycle#unload() - veto in main (window ID ${window.id})`); this.logService.trace(`Lifecycle#unload() - veto in main (window ID ${window.id})`);
return this.handleWindowUnloadVeto(veto); return this.handleWindowUnloadVeto(veto);
} }
this.logService.trace(`Lifecycle#unload() - no veto (window ID ${window.id})`); this.logService.trace(`Lifecycle#unload() - no veto (window ID ${window.id})`);
// finally if there are no vetos, unload the renderer // finally if there are no vetos, unload the renderer
return this.onWillUnloadWindowInRenderer(window, windowUnloadReason).then(() => false); await this.onWillUnloadWindowInRenderer(window, windowUnloadReason);
});
}); return false;
} }
private handleWindowUnloadVeto(veto: boolean): boolean { private handleWindowUnloadVeto(veto: boolean): boolean {

View File

@@ -26,21 +26,23 @@ export class FileStorage {
return this._database; return this._database;
} }
init(): Promise<void> { async init(): Promise<void> {
return readFile(this.dbPath).then(contents => { try {
const contents = await readFile(this.dbPath);
try { try {
this.lastFlushedSerializedDatabase = contents.toString(); this.lastFlushedSerializedDatabase = contents.toString();
this._database = JSON.parse(this.lastFlushedSerializedDatabase); this._database = JSON.parse(this.lastFlushedSerializedDatabase);
} catch (error) { } catch (error) {
this._database = {}; this._database = {};
} }
}, error => { } catch (error) {
if (error.code !== 'ENOENT') { if (error.code !== 'ENOENT') {
this.onError(error); this.onError(error);
} }
this._database = {}; this._database = {};
}); }
} }
private loadSync(): object { private loadSync(): object {

View File

@@ -14,38 +14,37 @@ suite('StateService', () => {
const parentDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'stateservice'); const parentDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'stateservice');
const storageFile = path.join(parentDir, 'storage.json'); const storageFile = path.join(parentDir, 'storage.json');
teardown(done => { teardown(async () => {
rimraf(parentDir, RimRafMode.MOVE).then(done, done); await rimraf(parentDir, RimRafMode.MOVE);
}); });
test('Basics', () => { test('Basics', async () => {
return mkdirp(parentDir).then(() => { await mkdirp(parentDir);
writeFileSync(storageFile, ''); writeFileSync(storageFile, '');
let service = new FileStorage(storageFile, () => null); let service = new FileStorage(storageFile, () => null);
service.setItem('some.key', 'some.value'); service.setItem('some.key', 'some.value');
assert.equal(service.getItem('some.key'), 'some.value'); assert.equal(service.getItem('some.key'), 'some.value');
service.removeItem('some.key'); service.removeItem('some.key');
assert.equal(service.getItem('some.key', 'some.default'), 'some.default'); assert.equal(service.getItem('some.key', 'some.default'), 'some.default');
assert.ok(!service.getItem('some.unknonw.key')); assert.ok(!service.getItem('some.unknonw.key'));
service.setItem('some.other.key', 'some.other.value'); service.setItem('some.other.key', 'some.other.value');
service = new FileStorage(storageFile, () => null); service = new FileStorage(storageFile, () => null);
assert.equal(service.getItem('some.other.key'), 'some.other.value'); assert.equal(service.getItem('some.other.key'), 'some.other.value');
service.setItem('some.other.key', 'some.other.value'); service.setItem('some.other.key', 'some.other.value');
assert.equal(service.getItem('some.other.key'), 'some.other.value'); assert.equal(service.getItem('some.other.key'), 'some.other.value');
service.setItem('some.undefined.key', undefined); service.setItem('some.undefined.key', undefined);
assert.equal(service.getItem('some.undefined.key', 'some.default'), 'some.default'); assert.equal(service.getItem('some.undefined.key', 'some.default'), 'some.default');
service.setItem('some.null.key', null); service.setItem('some.null.key', null);
assert.equal(service.getItem('some.null.key', 'some.default'), 'some.default'); assert.equal(service.getItem('some.null.key', 'some.default'), 'some.default');
});
}); });
}); });

View File

@@ -45,20 +45,21 @@ export class GlobalStorageDatabaseChannel extends Disposable implements IServerC
this.whenReady = this.init(); this.whenReady = this.init();
} }
private init(): Promise<void> { private async init(): Promise<void> {
return this.storageMainService.initialize().then(undefined, error => { try {
await this.storageMainService.initialize();
} catch (error) {
onUnexpectedError(error); onUnexpectedError(error);
this.logService.error(error); this.logService.error(error);
}).then(() => { }
// Apply global telemetry values as part of the initialization // Apply global telemetry values as part of the initialization
// These are global across all windows and thereby should be // These are global across all windows and thereby should be
// written from the main process once. // written from the main process once.
this.initTelemetry(); this.initTelemetry();
// Setup storage change listeners // Setup storage change listeners
this.registerListeners(); this.registerListeners();
});
} }
private initTelemetry(): void { private initTelemetry(): void {
@@ -112,33 +113,39 @@ export class GlobalStorageDatabaseChannel extends Disposable implements IServerC
throw new Error(`Event not found: ${event}`); throw new Error(`Event not found: ${event}`);
} }
call(_: unknown, command: string, arg?: any): Promise<any> { async call(_: unknown, command: string, arg?: any): Promise<any> {
// ensure to always wait for ready
await this.whenReady;
// handle call
switch (command) { switch (command) {
case 'getItems': { case 'getItems': {
return this.whenReady.then(() => mapToSerializable(this.storageMainService.items)); return mapToSerializable(this.storageMainService.items);
} }
case 'updateItems': { case 'updateItems': {
return this.whenReady.then(() => { const items: ISerializableUpdateRequest = arg;
const items: ISerializableUpdateRequest = arg; if (items.insert) {
if (items.insert) { for (const [key, value] of items.insert) {
for (const [key, value] of items.insert) { this.storageMainService.store(key, value);
this.storageMainService.store(key, value);
}
} }
}
if (items.delete) { if (items.delete) {
items.delete.forEach(key => this.storageMainService.remove(key)); items.delete.forEach(key => this.storageMainService.remove(key));
} }
});
break;
} }
case 'checkIntegrity': { case 'checkIntegrity': {
return this.whenReady.then(() => this.storageMainService.checkIntegrity(arg)); return this.storageMainService.checkIntegrity(arg);
} }
}
throw new Error(`Call not found: ${command}`); default:
throw new Error(`Call not found: ${command}`);
}
} }
} }
@@ -167,8 +174,10 @@ export class GlobalStorageDatabaseChannelClient extends Disposable implements IS
} }
} }
getItems(): Promise<Map<string, string>> { async getItems(): Promise<Map<string, string>> {
return this.channel.call('getItems').then((data: Item[]) => serializableToMap(data)); const items: Item[] = await this.channel.call('getItems');
return serializableToMap(items);
} }
updateItems(request: IUpdateRequest): Promise<void> { updateItems(request: IUpdateRequest): Promise<void> {

View File

@@ -10,7 +10,6 @@ import { ILogService, LogLevel } from 'vs/platform/log/common/log';
import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IStorage, Storage, SQLiteStorageDatabase, ISQLiteStorageDatabaseLoggingOptions, InMemoryStorageDatabase } from 'vs/base/node/storage'; import { IStorage, Storage, SQLiteStorageDatabase, ISQLiteStorageDatabaseLoggingOptions, InMemoryStorageDatabase } from 'vs/base/node/storage';
import { join } from 'vs/base/common/path'; import { join } from 'vs/base/common/path';
import { exists } from 'vs/base/node/pfs';
export const IStorageMainService = createDecorator<IStorageMainService>('storageMainService'); export const IStorageMainService = createDecorator<IStorageMainService>('storageMainService');
@@ -121,25 +120,14 @@ export class StorageMainService extends Disposable implements IStorageMainServic
} }
private doInitialize(): Promise<void> { private doInitialize(): Promise<void> {
const useInMemoryStorage = this.storagePath === SQLiteStorageDatabase.IN_MEMORY_PATH; this.storage.dispose();
this.storage = new Storage(new SQLiteStorageDatabase(this.storagePath, {
logging: this.createLogginOptions()
}));
let globalStorageExists: Promise<boolean>; this._register(this.storage.onDidChangeStorage(key => this._onDidChangeStorage.fire({ key })));
if (useInMemoryStorage) {
globalStorageExists = Promise.resolve(true);
} else {
globalStorageExists = exists(this.storagePath);
}
return globalStorageExists.then(exists => { return this.storage.init();
this.storage.dispose();
this.storage = new Storage(new SQLiteStorageDatabase(this.storagePath, {
logging: this.createLogginOptions()
}));
this._register(this.storage.onDidChangeStorage(key => this._onDidChangeStorage.fire({ key })));
return this.storage.init();
});
} }
get(key: string, fallbackValue: string): string; get(key: string, fallbackValue: string): string;

View File

@@ -62,38 +62,38 @@ export class StorageService extends Disposable implements IStorageService {
return this.initializePromise; return this.initializePromise;
} }
private doInitialize(payload: IWorkspaceInitializationPayload): Promise<void> { private async doInitialize(payload: IWorkspaceInitializationPayload): Promise<void> {
return Promise.all([ await Promise.all([
this.initializeGlobalStorage(), this.initializeGlobalStorage(),
this.initializeWorkspaceStorage(payload) this.initializeWorkspaceStorage(payload)
]).then(() => undefined); ]);
} }
private initializeGlobalStorage(): Promise<void> { private initializeGlobalStorage(): Promise<void> {
return this.globalStorage.init(); return this.globalStorage.init();
} }
private initializeWorkspaceStorage(payload: IWorkspaceInitializationPayload): Promise<void> { private async initializeWorkspaceStorage(payload: IWorkspaceInitializationPayload): Promise<void> {
// Prepare workspace storage folder for DB // Prepare workspace storage folder for DB
return this.prepareWorkspaceStorageFolder(payload).then(result => { try {
const result = await this.prepareWorkspaceStorageFolder(payload);
const useInMemoryStorage = !!this.environmentService.extensionTestsLocationURI; // no storage during extension tests! const useInMemoryStorage = !!this.environmentService.extensionTestsLocationURI; // no storage during extension tests!
// Create workspace storage and initalize // Create workspace storage and initalize
mark('willInitWorkspaceStorage'); mark('willInitWorkspaceStorage');
return this.createWorkspaceStorage(useInMemoryStorage ? SQLiteStorageDatabase.IN_MEMORY_PATH : join(result.path, StorageService.WORKSPACE_STORAGE_NAME), result.wasCreated ? StorageHint.STORAGE_DOES_NOT_EXIST : undefined).init().then(() => { try {
await this.createWorkspaceStorage(useInMemoryStorage ? SQLiteStorageDatabase.IN_MEMORY_PATH : join(result.path, StorageService.WORKSPACE_STORAGE_NAME), result.wasCreated ? StorageHint.STORAGE_DOES_NOT_EXIST : undefined).init();
} finally {
mark('didInitWorkspaceStorage'); mark('didInitWorkspaceStorage');
}, error => { }
mark('didInitWorkspaceStorage'); } catch (error) {
return Promise.reject(error);
});
}).then(undefined, error => {
onUnexpectedError(error); onUnexpectedError(error);
// Upon error, fallback to in-memory storage // Upon error, fallback to in-memory storage
return this.createWorkspaceStorage(SQLiteStorageDatabase.IN_MEMORY_PATH).init(); return this.createWorkspaceStorage(SQLiteStorageDatabase.IN_MEMORY_PATH).init();
}); }
} }
private createWorkspaceStorage(workspaceStoragePath: string, hint?: StorageHint): IStorage { private createWorkspaceStorage(workspaceStoragePath: string, hint?: StorageHint): IStorage {
@@ -120,22 +120,20 @@ export class StorageService extends Disposable implements IStorageService {
return join(this.environmentService.workspaceStorageHome, payload.id); // workspace home + workspace id; return join(this.environmentService.workspaceStorageHome, payload.id); // workspace home + workspace id;
} }
private prepareWorkspaceStorageFolder(payload: IWorkspaceInitializationPayload): Promise<{ path: string, wasCreated: boolean }> { private async prepareWorkspaceStorageFolder(payload: IWorkspaceInitializationPayload): Promise<{ path: string, wasCreated: boolean }> {
const workspaceStorageFolderPath = this.getWorkspaceStorageFolderPath(payload); const workspaceStorageFolderPath = this.getWorkspaceStorageFolderPath(payload);
return exists(workspaceStorageFolderPath).then<{ path: string, wasCreated: boolean }>(exists => { const storageExists = await exists(workspaceStorageFolderPath);
if (exists) { if (storageExists) {
return { path: workspaceStorageFolderPath, wasCreated: false }; return { path: workspaceStorageFolderPath, wasCreated: false };
} }
return mkdirp(workspaceStorageFolderPath).then(() => { await mkdirp(workspaceStorageFolderPath);
// Write metadata into folder // Write metadata into folder
this.ensureWorkspaceStorageFolderMeta(payload); this.ensureWorkspaceStorageFolderMeta(payload);
return { path: workspaceStorageFolderPath, wasCreated: true }; return { path: workspaceStorageFolderPath, wasCreated: true };
});
});
} }
private ensureWorkspaceStorageFolderMeta(payload: IWorkspaceInitializationPayload): void { private ensureWorkspaceStorageFolderMeta(payload: IWorkspaceInitializationPayload): void {
@@ -148,13 +146,16 @@ export class StorageService extends Disposable implements IStorageService {
if (meta) { if (meta) {
const workspaceStorageMetaPath = join(this.getWorkspaceStorageFolderPath(payload), StorageService.WORKSPACE_META_NAME); const workspaceStorageMetaPath = join(this.getWorkspaceStorageFolderPath(payload), StorageService.WORKSPACE_META_NAME);
exists(workspaceStorageMetaPath).then(exists => { (async function () {
if (exists) { try {
return undefined; // already existing const storageExists = await exists(workspaceStorageMetaPath);
if (!storageExists) {
await writeFile(workspaceStorageMetaPath, JSON.stringify(meta, undefined, 2));
}
} catch (error) {
onUnexpectedError(error);
} }
})();
return writeFile(workspaceStorageMetaPath, JSON.stringify(meta, undefined, 2));
}).then(undefined, error => onUnexpectedError(error));
} }
} }
@@ -184,16 +185,16 @@ export class StorageService extends Disposable implements IStorageService {
this.getStorage(scope).delete(key); this.getStorage(scope).delete(key);
} }
close(): Promise<void> { async close(): Promise<void> {
// Signal as event so that clients can still store data // Signal as event so that clients can still store data
this._onWillSaveState.fire({ reason: WillSaveStateReason.SHUTDOWN }); this._onWillSaveState.fire({ reason: WillSaveStateReason.SHUTDOWN });
// Do it // Do it
return Promise.all([ await Promise.all([
this.globalStorage.close(), this.globalStorage.close(),
this.workspaceStorage.close() this.workspaceStorage.close()
]).then(() => undefined); ]);
} }
private getStorage(scope: StorageScope): IStorage { private getStorage(scope: StorageScope): IStorage {
@@ -208,77 +209,75 @@ export class StorageService extends Disposable implements IStorageService {
return scope === StorageScope.GLOBAL ? this.globalStorage.checkIntegrity(full) : this.workspaceStorage.checkIntegrity(full); return scope === StorageScope.GLOBAL ? this.globalStorage.checkIntegrity(full) : this.workspaceStorage.checkIntegrity(full);
} }
logStorage(): Promise<void> { async logStorage(): Promise<void> {
return Promise.all([ const result = await Promise.all([
this.globalStorage.items, this.globalStorage.items,
this.workspaceStorage.items, this.workspaceStorage.items,
this.globalStorage.checkIntegrity(true /* full */), this.globalStorage.checkIntegrity(true /* full */),
this.workspaceStorage.checkIntegrity(true /* full */) this.workspaceStorage.checkIntegrity(true /* full */)
]).then(result => { ]);
const safeParse = (value: string) => {
try {
return JSON.parse(value);
} catch (error) {
return value;
}
};
const globalItems = new Map<string, string>(); const safeParse = (value: string) => {
const globalItemsParsed = new Map<string, string>(); try {
result[0].forEach((value, key) => { return JSON.parse(value);
globalItems.set(key, value); } catch (error) {
globalItemsParsed.set(key, safeParse(value)); return value;
}); }
};
const workspaceItems = new Map<string, string>(); const globalItems = new Map<string, string>();
const workspaceItemsParsed = new Map<string, string>(); const globalItemsParsed = new Map<string, string>();
result[1].forEach((value, key) => { result[0].forEach((value, key) => {
workspaceItems.set(key, value); globalItems.set(key, value);
workspaceItemsParsed.set(key, safeParse(value)); globalItemsParsed.set(key, safeParse(value));
});
console.group(`Storage: Global (integrity: ${result[2]}, path: ${this.environmentService.globalStorageHome})`);
let globalValues: { key: string, value: string }[] = [];
globalItems.forEach((value, key) => {
globalValues.push({ key, value });
});
console.table(globalValues);
console.groupEnd();
console.log(globalItemsParsed);
console.group(`Storage: Workspace (integrity: ${result[3]}, load: ${getDuration('willInitWorkspaceStorage', 'didInitWorkspaceStorage')}, path: ${this.workspaceStoragePath})`);
let workspaceValues: { key: string, value: string }[] = [];
workspaceItems.forEach((value, key) => {
workspaceValues.push({ key, value });
});
console.table(workspaceValues);
console.groupEnd();
console.log(workspaceItemsParsed);
}); });
const workspaceItems = new Map<string, string>();
const workspaceItemsParsed = new Map<string, string>();
result[1].forEach((value, key) => {
workspaceItems.set(key, value);
workspaceItemsParsed.set(key, safeParse(value));
});
console.group(`Storage: Global (integrity: ${result[2]}, path: ${this.environmentService.globalStorageHome})`);
let globalValues: { key: string, value: string }[] = [];
globalItems.forEach((value, key) => {
globalValues.push({ key, value });
});
console.table(globalValues);
console.groupEnd();
console.log(globalItemsParsed);
console.group(`Storage: Workspace (integrity: ${result[3]}, load: ${getDuration('willInitWorkspaceStorage', 'didInitWorkspaceStorage')}, path: ${this.workspaceStoragePath})`);
let workspaceValues: { key: string, value: string }[] = [];
workspaceItems.forEach((value, key) => {
workspaceValues.push({ key, value });
});
console.table(workspaceValues);
console.groupEnd();
console.log(workspaceItemsParsed);
} }
migrate(toWorkspace: IWorkspaceInitializationPayload): Promise<void> { async migrate(toWorkspace: IWorkspaceInitializationPayload): Promise<void> {
if (this.workspaceStoragePath === SQLiteStorageDatabase.IN_MEMORY_PATH) { if (this.workspaceStoragePath === SQLiteStorageDatabase.IN_MEMORY_PATH) {
return Promise.resolve(); // no migration needed if running in memory return Promise.resolve(); // no migration needed if running in memory
} }
// Close workspace DB to be able to copy // Close workspace DB to be able to copy
return this.workspaceStorage.close().then(() => { await this.workspaceStorage.close();
// Prepare new workspace storage folder // Prepare new workspace storage folder
return this.prepareWorkspaceStorageFolder(toWorkspace).then(result => { const result = await this.prepareWorkspaceStorageFolder(toWorkspace);
const newWorkspaceStoragePath = join(result.path, StorageService.WORKSPACE_STORAGE_NAME);
// Copy current storage over to new workspace storage const newWorkspaceStoragePath = join(result.path, StorageService.WORKSPACE_STORAGE_NAME);
return copy(this.workspaceStoragePath, newWorkspaceStoragePath).then(() => {
// Recreate and init workspace storage // Copy current storage over to new workspace storage
return this.createWorkspaceStorage(newWorkspaceStoragePath).init(); await copy(this.workspaceStoragePath, newWorkspaceStoragePath);
});
}); // Recreate and init workspace storage
}); return this.createWorkspaceStorage(newWorkspaceStoragePath).init();
} }
} }

View File

@@ -89,15 +89,15 @@ export class TelemetryService implements ITelemetryService {
return this._userOptIn && this._enabled; return this._userOptIn && this._enabled;
} }
getTelemetryInfo(): Promise<ITelemetryInfo> { async getTelemetryInfo(): Promise<ITelemetryInfo> {
return this._commonProperties.then(values => { const values = await this._commonProperties;
// well known properties
let sessionId = values['sessionID'];
let instanceId = values['common.instanceId'];
let machineId = values['common.machineId'];
return { sessionId, instanceId, machineId }; // well known properties
}); let sessionId = values['sessionID'];
let instanceId = values['common.instanceId'];
let machineId = values['common.machineId'];
return { sessionId, instanceId, machineId };
} }
dispose(): void { dispose(): void {

View File

@@ -10,8 +10,9 @@ import { readFile } from 'vs/base/node/pfs';
// {{SQL CARBON EDIT}} // {{SQL CARBON EDIT}}
import product from 'vs/platform/product/node/product'; import product from 'vs/platform/product/node/product';
const productObject = product;
export function resolveCommonProperties(commit: string | undefined, version: string | undefined, machineId: string | undefined, installSourcePath: string): Promise<{ [name: string]: string | undefined; }> { export async function resolveCommonProperties(commit: string | undefined, version: string | undefined, machineId: string | undefined, installSourcePath: string, product?: string): Promise<{ [name: string]: string | undefined; }> {
const result: { [name: string]: string | undefined; } = Object.create(null); const result: { [name: string]: string | undefined; } = Object.create(null);
// {{SQL CARBON EDIT}} // {{SQL CARBON EDIT}}
@@ -36,8 +37,8 @@ export function resolveCommonProperties(commit: string | undefined, version: str
result['common.nodeArch'] = process.arch; result['common.nodeArch'] = process.arch;
// __GDPR__COMMON__ "common.product" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" } // __GDPR__COMMON__ "common.product" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
// {{SQL CARBON EDIT}} // {{SQL CARBON EDIT}}
result['common.product'] = product.nameShort || 'desktop'; result['common.product'] = productObject.nameShort || 'desktop';
result['common.application.name'] = product.nameLong; result['common.application.name'] = productObject.nameLong;
// dynamic properties which value differs on each call // dynamic properties which value differs on each call
let seq = 0; let seq = 0;
@@ -65,13 +66,14 @@ export function resolveCommonProperties(commit: string | undefined, version: str
result['common.snap'] = 'true'; result['common.snap'] = 'true';
} }
return readFile(installSourcePath, 'utf8').then(contents => { try {
const contents = await readFile(installSourcePath, 'utf8');
// __GDPR__COMMON__ "common.source" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" } // __GDPR__COMMON__ "common.source" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
result['common.source'] = contents.slice(0, 30); result['common.source'] = contents.slice(0, 30);
} catch (error) {
// ignore error
}
return result; return result;
}, error => {
return result;
});
} }

View File

@@ -3,20 +3,18 @@
* Licensed under the Source EULA. See License.txt in the project root for license information. * Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
import product from 'vs/platform/product/node/product'; import product from 'vs/platform/product/node/product';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { IEnvironmentService } from 'vs/platform/environment/common/environment';
export function addGAParameters(telemetryService: ITelemetryService, environmentService: IEnvironmentService, uri: URI, origin: string, experiment = '1'): Promise<URI> { export async function addGAParameters(telemetryService: ITelemetryService, environmentService: IEnvironmentService, uri: URI, origin: string, experiment = '1'): Promise<URI> {
if (environmentService.isBuilt && !environmentService.isExtensionDevelopment && !environmentService.args['disable-telemetry'] && !!product.enableTelemetry) { if (environmentService.isBuilt && !environmentService.isExtensionDevelopment && !environmentService.args['disable-telemetry'] && !!product.enableTelemetry) {
if (uri.scheme === 'https' && uri.authority === 'code.visualstudio.com') { if (uri.scheme === 'https' && uri.authority === 'code.visualstudio.com') {
return telemetryService.getTelemetryInfo() const info = await telemetryService.getTelemetryInfo();
.then(info => {
return uri.with({ query: `${uri.query ? uri.query + '&' : ''}utm_source=VsCode&utm_medium=${encodeURIComponent(origin)}&utm_campaign=${encodeURIComponent(info.instanceId)}&utm_content=${encodeURIComponent(experiment)}` }); return uri.with({ query: `${uri.query ? uri.query + '&' : ''}utm_source=VsCode&utm_medium=${encodeURIComponent(origin)}&utm_campaign=${encodeURIComponent(info.instanceId)}&utm_content=${encodeURIComponent(experiment)}` });
});
} }
} }
return Promise.resolve(uri); return uri;
} }

View File

@@ -14,35 +14,38 @@ export const lastSessionDateStorageKey = 'telemetry.lastSessionDate';
// {{ SQL CARBON EDIT }} // {{ SQL CARBON EDIT }}
import product from 'vs/platform/product/node/product'; import product from 'vs/platform/product/node/product';
export function resolveWorkbenchCommonProperties(storageService: IStorageService, commit: string | undefined, version: string | undefined, machineId: string, installSourcePath: string): Promise<{ [name: string]: string | undefined }> { export async function resolveWorkbenchCommonProperties(storageService: IStorageService, commit: string | undefined, version: string | undefined, machineId: string, installSourcePath: string): Promise<{ [name: string]: string | undefined }> {
return resolveCommonProperties(commit, version, machineId, installSourcePath).then(result => { const result = await resolveCommonProperties(commit, version, machineId, installSourcePath);
const instanceId = storageService.get(instanceStorageKey, StorageScope.GLOBAL)!; const instanceId = storageService.get(instanceStorageKey, StorageScope.GLOBAL)!;
const firstSessionDate = storageService.get(firstSessionDateStorageKey, StorageScope.GLOBAL)!; const firstSessionDate = storageService.get(firstSessionDateStorageKey, StorageScope.GLOBAL)!;
const lastSessionDate = storageService.get(lastSessionDateStorageKey, StorageScope.GLOBAL)!; const lastSessionDate = storageService.get(lastSessionDateStorageKey, StorageScope.GLOBAL)!;
// __GDPR__COMMON__ "common.version.shell" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" } // __GDPR__COMMON__ "common.version.shell" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
result['common.version.shell'] = process.versions && process.versions['electron']; // result['common.version.shell'] = process.versions && process.versions['electron'];
// __GDPR__COMMON__ "common.version.renderer" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" } // __GDPR__COMMON__ "common.version.renderer" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
result['common.version.renderer'] = process.versions && process.versions['chrome']; // result['common.version.renderer'] = process.versions && process.versions['chrome'];
// {{SQL CARBON EDIT}} // __GDPR__COMMON__ "common.firstSessionDate" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
result['common.application.name'] = product.nameLong; // result['common.firstSessionDate'] = firstSessionDate;
// {{SQL CARBON EDIT}} // __GDPR__COMMON__ "common.lastSessionDate" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
result['common.userId'] = ''; // result['common.lastSessionDate'] = lastSessionDate || '';
// __GDPR__COMMON__ "common.isNewSession" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
// result['common.isNewSession'] = !lastSessionDate ? '1' : '0';
// __GDPR__COMMON__ "common.instanceId" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
// result['common.instanceId'] = instanceId;
// {{SQL CARBON EDIT}} // __GDPR__COMMON__ "common.version.shell" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
// // __GDPR__COMMON__ "common.firstSessionDate" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" } result['common.version.shell'] = process.versions && process.versions['electron'];
// result['common.firstSessionDate'] = firstSessionDate; // __GDPR__COMMON__ "common.version.renderer" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
// // __GDPR__COMMON__ "common.lastSessionDate" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" } result['common.version.renderer'] = process.versions && process.versions['chrome'];
// result['common.lastSessionDate'] = lastSessionDate || ''; // {{SQL CARBON EDIT}}
// // __GDPR__COMMON__ "common.isNewSession" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" } result['common.application.name'] = product.nameLong;
// result['common.isNewSession'] = !lastSessionDate ? '1' : '0'; // {{SQL CARBON EDIT}}
// // __GDPR__COMMON__ "common.instanceId" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" } result['common.userId'] = '';
// result['common.instanceId'] = instanceId;
// {{SQL CARBON EDIT}} // {{SQL CARBON EDIT}}
setUsageDates(storageService); setUsageDates(storageService);
return result;
}); return result;
} }
// {{SQL CARBON EDIT}} // {{SQL CARBON EDIT}}

View File

@@ -74,13 +74,13 @@ export class WindowsService implements IWindowsService {
return this.channel.call('closeWorkspace', windowId); return this.channel.call('closeWorkspace', windowId);
} }
enterWorkspace(windowId: number, path: URI): Promise<IEnterWorkspaceResult | undefined> { async enterWorkspace(windowId: number, path: URI): Promise<IEnterWorkspaceResult | undefined> {
return this.channel.call('enterWorkspace', [windowId, path]).then((result: IEnterWorkspaceResult) => { const result: IEnterWorkspaceResult = await this.channel.call('enterWorkspace', [windowId, path]);
if (result) { if (result) {
result.workspace = reviveWorkspaceIdentifier(result.workspace); result.workspace = reviveWorkspaceIdentifier(result.workspace);
} }
return result;
}); return result;
} }
toggleFullScreen(windowId: number): Promise<void> { toggleFullScreen(windowId: number): Promise<void> {
@@ -103,13 +103,12 @@ export class WindowsService implements IWindowsService {
return this.channel.call('clearRecentlyOpened'); return this.channel.call('clearRecentlyOpened');
} }
getRecentlyOpened(windowId: number): Promise<IRecentlyOpened> { async getRecentlyOpened(windowId: number): Promise<IRecentlyOpened> {
return this.channel.call('getRecentlyOpened', windowId) const recentlyOpened: IRecentlyOpened = await this.channel.call('getRecentlyOpened', windowId);
.then((recentlyOpened: IRecentlyOpened) => { recentlyOpened.workspaces.forEach(recent => isRecentWorkspace(recent) ? recent.workspace = reviveWorkspaceIdentifier(recent.workspace) : recent.folderUri = URI.revive(recent.folderUri));
recentlyOpened.workspaces.forEach(recent => isRecentWorkspace(recent) ? recent.workspace = reviveWorkspaceIdentifier(recent.workspace) : recent.folderUri = URI.revive(recent.folderUri)); recentlyOpened.files.forEach(recent => recent.fileUri = URI.revive(recent.fileUri));
recentlyOpened.files.forEach(recent => recent.fileUri = URI.revive(recent.fileUri));
return recentlyOpened; return recentlyOpened;
});
} }
newWindowTab(): Promise<void> { newWindowTab(): Promise<void> {
@@ -196,18 +195,26 @@ export class WindowsService implements IWindowsService {
return this.channel.call('openNewWindow', options); return this.channel.call('openNewWindow', options);
} }
getWindows(): Promise<{ id: number; workspace?: IWorkspaceIdentifier; folderUri?: ISingleFolderWorkspaceIdentifier; title: string; filename?: string; }[]> { async getWindows(): Promise<{ id: number; workspace?: IWorkspaceIdentifier; folderUri?: ISingleFolderWorkspaceIdentifier; title: string; filename?: string; }[]> {
return this.channel.call<{ id: number; workspace?: IWorkspaceIdentifier; folderUri?: ISingleFolderWorkspaceIdentifier; title: string; filename?: string; }[]>('getWindows').then(result => { const result = await this.channel.call<{
for (const win of result) { id: number;
if (win.folderUri) { workspace?: IWorkspaceIdentifier;
win.folderUri = URI.revive(win.folderUri); folderUri?: ISingleFolderWorkspaceIdentifier;
} title: string;
if (win.workspace) { filename?: string;
win.workspace = reviveWorkspaceIdentifier(win.workspace); }[]>('getWindows');
}
for (const win of result) {
if (win.folderUri) {
win.folderUri = URI.revive(win.folderUri);
} }
return result;
}); if (win.workspace) {
win.workspace = reviveWorkspaceIdentifier(win.workspace);
}
}
return result;
} }
getWindowCount(): Promise<number> { getWindowCount(): Promise<number> {

View File

@@ -103,13 +103,14 @@ export class WorkspacesMainService extends Disposable implements IWorkspacesMain
return isEqualOrParent(path, this.environmentService.untitledWorkspacesHome); return isEqualOrParent(path, this.environmentService.untitledWorkspacesHome);
} }
createUntitledWorkspace(folders?: IWorkspaceFolderCreationData[], remoteAuthority?: string): Promise<IWorkspaceIdentifier> { async createUntitledWorkspace(folders?: IWorkspaceFolderCreationData[], remoteAuthority?: string): Promise<IWorkspaceIdentifier> {
const { workspace, storedWorkspace } = this.newUntitledWorkspace(folders, remoteAuthority); const { workspace, storedWorkspace } = this.newUntitledWorkspace(folders, remoteAuthority);
const configPath = workspace.configPath.fsPath; const configPath = workspace.configPath.fsPath;
return mkdirp(dirname(configPath)).then(() => { await mkdirp(dirname(configPath));
return writeFile(configPath, JSON.stringify(storedWorkspace, null, '\t')).then(() => workspace); await writeFile(configPath, JSON.stringify(storedWorkspace, null, '\t'));
});
return workspace;
} }
createUntitledWorkspaceSync(folders?: IWorkspaceFolderCreationData[], remoteAuthority?: string): IWorkspaceIdentifier { createUntitledWorkspaceSync(folders?: IWorkspaceFolderCreationData[], remoteAuthority?: string): IWorkspaceIdentifier {

236
src/vs/vscode.d.ts vendored
View File

@@ -5763,8 +5763,11 @@ declare module 'vscode' {
* to allow using a static localhost port inside the webview that is resolved to random port that a service is * to allow using a static localhost port inside the webview that is resolved to random port that a service is
* running on. * running on.
* *
* If a webview accesses localhost content, we recomend that you specify port mappings even if * If a webview accesses localhost content, we recommend that you specify port mappings even if
* the `webviewPort` and `extensionHostPort` ports are the same. * the `webviewPort` and `extensionHostPort` ports are the same.
*
* *Note* that port mappings only work for `http` or `https` urls. Websocket urls (e.g. `ws://localhost:3000`)
* cannot be mapped to another port.
*/ */
readonly portMapping?: ReadonlyArray<WebviewPortMapping>; readonly portMapping?: ReadonlyArray<WebviewPortMapping>;
} }
@@ -8940,6 +8943,237 @@ declare module 'vscode' {
*/ */
export const onDidChange: Event<void>; export const onDidChange: Event<void>;
} }
//#region Comments
/**
* Collapsible state of a [comment thread](#CommentThread)
*/
export enum CommentThreadCollapsibleState {
/**
* Determines an item is collapsed
*/
Collapsed = 0,
/**
* Determines an item is expanded
*/
Expanded = 1
}
/**
* Comment mode of a [comment](#Comment)
*/
export enum CommentMode {
/**
* Displays the comment editor
*/
Editing = 0,
/**
* Displays the preview of the comment
*/
Preview = 1
}
/**
* A collection of [comments](#Comment) representing a conversation at a particular range in a document.
*/
export interface CommentThread {
/**
* The uri of the document the thread has been created on.
*/
readonly resource: Uri;
/**
* The range the comment thread is located within the document. The thread icon will be shown
* at the first line of the range.
*/
range: Range;
/**
* The ordered comments of the thread.
*/
comments: ReadonlyArray<Comment>;
/**
* Whether the thread should be collapsed or expanded when opening the document.
* Defaults to Collapsed.
*/
collapsibleState: CommentThreadCollapsibleState;
/**
* Context value of the comment thread. This can be used to contribute thread specific actions.
* For example, a comment thread is given a context value as `editable`. When contributing actions to `comments/commentThread/title`
* using `menus` extension point, you can specify context value for key `commentThread` in `when` expression like `commentThread == editable`.
* ```
* "contributes": {
* "menus": {
* "comments/commentThread/title": [
* {
* "command": "extension.deleteCommentThread",
* "when": "commentThread == editable"
* }
* ]
* }
* }
* ```
* This will show action `extension.deleteCommentThread` only for comment threads with `contextValue` is `editable`.
*/
contextValue?: string;
/**
* The optional human-readable label describing the [Comment Thread](#CommentThread)
*/
label?: string;
/**
* Dispose this comment thread.
*
* Once disposed, this comment thread will be removed from visible editors and Comment Panel when approriate.
*/
dispose(): void;
}
/**
* Author information of a [comment](#Comment)
*/
export interface CommentAuthorInformation {
/**
* The display name of the author of the comment
*/
name: string;
/**
* The optional icon path for the author
*/
iconPath?: Uri;
}
/**
* A comment is displayed within the editor or the Comments Panel, depending on how it is provided.
*/
export interface Comment {
/**
* The human-readable comment body
*/
body: string | MarkdownString;
/**
* [Comment mode](#CommentMode) of the comment
*/
mode: CommentMode;
/**
* The [author information](#CommentAuthorInformation) of the comment
*/
author: CommentAuthorInformation;
/**
* Context value of the comment. This can be used to contribute comment specific actions.
* For example, a comment is given a context value as `editable`. When contributing actions to `comments/comment/title`
* using `menus` extension point, you can specify context value for key `comment` in `when` expression like `comment == editable`.
* ```
* "contributes": {
* "menus": {
* "comments/comment/title": [
* {
* "command": "extension.deleteComment",
* "when": "comment == editable"
* }
* ]
* }
* }
* ```
* This will show action `extension.deleteComment` only for comments with `contextValue` is `editable`.
*/
contextValue?: string;
/**
* Optional label describing the [Comment](#Comment)
* Label will be rendered next to authorName if exists.
*/
label?: string;
}
/**
* Command argument for actions registered in `comments/commentThread/actions`.
*/
export interface CommentReply {
/**
* The active [comment thread](#CommentThread)
*/
thread: CommentThread;
/**
* The value in the comment editor
*/
text: string;
}
/**
* Commenting range provider for a [comment controller](#CommentController).
*/
export interface CommentingRangeProvider {
/**
* Provide a list of ranges which allow new comment threads creation or null for a given document
*/
provideCommentingRanges(document: TextDocument, token: CancellationToken): ProviderResult<Range[]>;
}
/**
* A comment controller is able to provide [comments](#CommentThread) support to the editor and
* provide users various ways to interact with comments.
*/
export interface CommentController {
/**
* The id of this comment controller.
*/
readonly id: string;
/**
* The human-readable label of this comment controller.
*/
readonly label: string;
/**
* Optional commenting range provider. Provide a list [ranges](#Range) which support commenting to any given resource uri.
*
* If not provided, users can leave comments in any document opened in the editor.
*/
commentingRangeProvider?: CommentingRangeProvider;
/**
* Create a [comment thread](#CommentThread). The comment thread will be displayed in visible text editors (if the resource matches)
* and Comments Panel once created.
*
* @param resource The uri of the document the thread has been created on.
* @param range The range the comment thread is located within the document.
* @param comments The ordered comments of the thread.
*/
createCommentThread(uri: Uri, range: Range, comments: Comment[]): CommentThread;
/**
* Dispose this comment controller.
*
* Once disposed, all [comment threads](#CommentThread) created by this comment controller will also be removed from the editor
* and Comments Panel.
*/
dispose(): void;
}
namespace comments {
/**
* Creates a new [comment controller](#CommentController) instance.
*
* @param id An `id` for the comment controller.
* @param label A human-readable string for the comment controller.
* @return An instance of [comment controller](#CommentController).
*/
export function createCommentController(id: string, label: string): CommentController;
}
//#endregion
} }
/** /**

View File

@@ -957,15 +957,6 @@ declare module 'vscode' {
reactionProvider?: CommentReactionProvider; reactionProvider?: CommentReactionProvider;
} }
export interface CommentController {
/**
* The active [comment thread](#CommentThread) or `undefined`. The `activeCommentThread` is the comment thread of
* the comment widget that currently has focus. It's `undefined` when the focus is not in any comment thread widget, or
* the comment widget created from [comment thread template](#CommentThreadTemplate).
*/
readonly activeCommentThread: CommentThread | undefined;
}
namespace workspace { namespace workspace {
/** /**
* DEPRECATED * DEPRECATED
@@ -979,21 +970,6 @@ declare module 'vscode' {
export function registerWorkspaceCommentProvider(provider: WorkspaceCommentProvider): Disposable; export function registerWorkspaceCommentProvider(provider: WorkspaceCommentProvider): Disposable;
} }
/**
* Collapsible state of a [comment thread](#CommentThread)
*/
export enum CommentThreadCollapsibleState {
/**
* Determines an item is collapsed
*/
Collapsed = 0,
/**
* Determines an item is expanded
*/
Expanded = 1
}
/** /**
* A collection of [comments](#Comment) representing a conversation at a particular range in a document. * A collection of [comments](#Comment) representing a conversation at a particular range in a document.
*/ */
@@ -1008,28 +984,6 @@ declare module 'vscode' {
*/ */
readonly uri: Uri; readonly uri: Uri;
/**
* The range the comment thread is located within the document. The thread icon will be shown
* at the first line of the range.
*/
readonly range: Range;
/**
* The ordered comments of the thread.
*/
comments: Comment[];
/**
* Whether the thread should be collapsed or expanded when opening the document.
* Defaults to Collapsed.
*/
collapsibleState: CommentThreadCollapsibleState;
/**
* The optional human-readable label describing the [Comment Thread](#CommentThread)
*/
label?: string;
/** /**
* Optional accept input command * Optional accept input command
* *
@@ -1038,46 +992,6 @@ declare module 'vscode' {
* This command will disabled when the comment editor is empty. * This command will disabled when the comment editor is empty.
*/ */
acceptInputCommand?: Command; acceptInputCommand?: Command;
/**
* Dispose this comment thread.
*
* Once disposed, this comment thread will be removed from visible editors and Comment Panel when approriate.
*/
dispose(): void;
}
/**
* Author information of a [comment](#Comment)
*/
export interface CommentAuthorInformation {
/**
* The display name of the author of the comment
*/
name: string;
/**
* The optional icon path for the author
*/
iconPath?: Uri;
}
/**
* Author information of a [comment](#Comment)
*/
export interface CommentAuthorInformation {
/**
* The display name of the author of the comment
*/
name: string;
/**
* The optional icon path for the author
*/
iconPath?: Uri;
} }
/** /**
@@ -1089,22 +1003,6 @@ declare module 'vscode' {
*/ */
id: string; id: string;
/**
* The human-readable comment body
*/
body: MarkdownString;
/**
* The author information of the comment
*/
author: CommentAuthorInformation;
/**
* Optional label describing the [Comment](#Comment)
* Label will be rendered next to authorName if exists.
*/
label?: string;
/** /**
* The command to be executed if the comment is selected in the Comments Panel * The command to be executed if the comment is selected in the Comments Panel
*/ */
@@ -1124,16 +1022,6 @@ declare module 'vscode' {
* Setter and getter for the contents of the comment input box * Setter and getter for the contents of the comment input box
*/ */
value: string; value: string;
/**
* The uri of the document comment input box has been created on
*/
resource: Uri;
/**
* The range the comment input box is located within the document
*/
range: Range;
} }
/** /**
@@ -1146,36 +1034,12 @@ declare module 'vscode' {
provideCommentingRanges(document: TextDocument, token: CancellationToken): ProviderResult<Range[]>; provideCommentingRanges(document: TextDocument, token: CancellationToken): ProviderResult<Range[]>;
} }
/** export interface EmptyCommentThreadFactory {
* Comment thread template for new comment thread creation.
*/
export interface CommentThreadTemplate {
/** /**
* The human-readable label describing the [Comment Thread](#CommentThread) * The method `createEmptyCommentThread` is called when users attempt to create new comment thread from the gutter or command palette.
* Extensions still need to call `createCommentThread` inside this call when appropriate.
*/ */
readonly label: string; createEmptyCommentThread(document: TextDocument, range: Range): ProviderResult<void>;
/**
* Optional accept input command
*
* `acceptInputCommand` is the default action rendered on Comment Widget, which is always placed rightmost.
* This command will be invoked when users the user accepts the value in the comment editor.
* This command will disabled when the comment editor is empty.
*/
readonly acceptInputCommand?: Command;
/**
* Optional additonal commands.
*
* `additionalCommands` are the secondary actions rendered on Comment Widget.
*/
readonly additionalCommands?: Command[];
/**
* The command to be executed when users try to delete the comment thread. Currently, this is only called
* when the user collapses a comment thread that has no comments in it.
*/
readonly deleteCommand?: Command;
} }
/** /**
@@ -1183,41 +1047,12 @@ declare module 'vscode' {
* provide users various ways to interact with comments. * provide users various ways to interact with comments.
*/ */
export interface CommentController { export interface CommentController {
/**
* The id of this comment controller.
*/
readonly id: string;
/**
* The human-readable label of this comment controller.
*/
readonly label: string;
/** /**
* The active [comment input box](#CommentInputBox) or `undefined`. The active `inputBox` is the input box of * The active [comment input box](#CommentInputBox) or `undefined`. The active `inputBox` is the input box of
* the comment thread widget that currently has focus. It's `undefined` when the focus is not in any CommentInputBox. * the comment thread widget that currently has focus. It's `undefined` when the focus is not in any CommentInputBox.
*/ */
readonly inputBox: CommentInputBox | undefined; readonly inputBox?: CommentInputBox;
/**
* Optional comment thread template information.
*
* The comment controller will use this information to create the comment widget when users attempt to create new comment thread
* from the gutter or command palette.
*
* When users run `CommentThreadTemplate.acceptInputCommand` or `CommentThreadTemplate.additionalCommands`, extensions should create
* the approriate [CommentThread](#CommentThread).
*
* If not provided, users won't be able to create new comment threads in the editor.
*/
template?: CommentThreadTemplate;
/**
* Optional commenting range provider. Provide a list [ranges](#Range) which support commenting to any given resource uri.
*
* If not provided and `emptyCommentThreadFactory` exits, users can leave comments in any document opened in the editor.
*/
commentingRangeProvider?: CommentingRangeProvider;
/** /**
* Create a [comment thread](#CommentThread). The comment thread will be displayed in visible text editors (if the resource matches) * Create a [comment thread](#CommentThread). The comment thread will be displayed in visible text editors (if the resource matches)
@@ -1230,6 +1065,16 @@ declare module 'vscode' {
*/ */
createCommentThread(id: string, uri: Uri, range: Range, comments: Comment[]): CommentThread; createCommentThread(id: string, uri: Uri, range: Range, comments: Comment[]): CommentThread;
/**
* Optional new comment thread factory.
*/
emptyCommentThreadFactory?: EmptyCommentThreadFactory;
/**
* Optional reaction provider
*/
reactionProvider?: CommentReactionProvider;
/** /**
* Dispose this comment controller. * Dispose this comment controller.
* *

View File

@@ -106,6 +106,16 @@ export class MainThreadCommentThread implements modes.CommentThread2 {
this._onDidChangeLabel.fire(this._label); this._onDidChangeLabel.fire(this._label);
} }
private _contextValue: string | undefined;
get contextValue(): string | undefined {
return this._contextValue;
}
set contextValue(context: string | undefined) {
this._contextValue = context;
}
private _onDidChangeLabel = new Emitter<string>(); private _onDidChangeLabel = new Emitter<string>();
get onDidChangeLabel(): Event<string> { return this._onDidChangeLabel.event; } get onDidChangeLabel(): Event<string> { return this._onDidChangeLabel.event; }
@@ -204,6 +214,7 @@ export class MainThreadCommentThread implements modes.CommentThread2 {
batchUpdate( batchUpdate(
range: IRange, range: IRange,
label: string, label: string,
contextValue: string | undefined,
comments: modes.Comment[], comments: modes.Comment[],
acceptInputCommand: modes.Command | undefined, acceptInputCommand: modes.Command | undefined,
additionalCommands: modes.Command[], additionalCommands: modes.Command[],
@@ -211,6 +222,7 @@ export class MainThreadCommentThread implements modes.CommentThread2 {
collapsibleState: modes.CommentThreadCollapsibleState) { collapsibleState: modes.CommentThreadCollapsibleState) {
this._range = range; this._range = range;
this._label = label; this._label = label;
this._contextValue = contextValue;
this._comments = comments; this._comments = comments;
this._acceptInputCommand = acceptInputCommand; this._acceptInputCommand = acceptInputCommand;
this._additionalCommands = additionalCommands; this._additionalCommands = additionalCommands;
@@ -247,6 +259,10 @@ export class MainThreadCommentController {
return this._id; return this._id;
} }
get contextValue(): string {
return this._id;
}
get proxy(): ExtHostCommentsShape { get proxy(): ExtHostCommentsShape {
return this._proxy; return this._proxy;
} }
@@ -319,13 +335,14 @@ export class MainThreadCommentController {
resource: UriComponents, resource: UriComponents,
range: IRange, range: IRange,
label: string, label: string,
contextValue: string | undefined,
comments: modes.Comment[], comments: modes.Comment[],
acceptInputCommand: modes.Command | undefined, acceptInputCommand: modes.Command | undefined,
additionalCommands: modes.Command[], additionalCommands: modes.Command[],
deleteCommand: modes.Command | undefined, deleteCommand: modes.Command | undefined,
collapsibleState: modes.CommentThreadCollapsibleState): void { collapsibleState: modes.CommentThreadCollapsibleState): void {
let thread = this.getKnownThread(commentThreadHandle); let thread = this.getKnownThread(commentThreadHandle);
thread.batchUpdate(range, label, comments, acceptInputCommand, additionalCommands, deleteCommand, collapsibleState); thread.batchUpdate(range, label, contextValue, comments, acceptInputCommand, additionalCommands, deleteCommand, collapsibleState);
this._commentService.updateComments(this._uniqueId, { this._commentService.updateComments(this._uniqueId, {
added: [], added: [],
@@ -349,6 +366,14 @@ export class MainThreadCommentController {
thread.dispose(); thread.dispose();
} }
deleteCommentThreadMain(commentThreadId: string) {
this._threads.forEach(thread => {
if (thread.threadId === commentThreadId) {
this._proxy.$deleteCommentThread(this._handle, thread.commentThreadHandle);
}
});
}
updateInput(input: string) { updateInput(input: string) {
let thread = this.activeCommentThread; let thread = this.activeCommentThread;
@@ -377,31 +402,26 @@ export class MainThreadCommentController {
} }
let commentingRanges = await this._proxy.$provideCommentingRanges(this.handle, resource, token); let commentingRanges = await this._proxy.$provideCommentingRanges(this.handle, resource, token);
let staticContribution = await this._proxy.$checkStaticContribution(this.handle);
return <ICommentInfo>{ return <ICommentInfo>{
owner: this._uniqueId, owner: this._uniqueId,
label: this.label, label: this.label,
threads: ret, threads: ret,
commentingRanges: commentingRanges ? commentingRanges: commentingRanges ? {
{ resource: resource,
resource: resource, ranges: commentingRanges, newCommentThreadCallback: async (uri: UriComponents, range: IRange) => { ranges: commentingRanges,
let threadHandle = await this._proxy.$createNewCommentWidgetCallback(this.handle, uri, range, token); newCommentThreadCallback: staticContribution ? undefined : async (uri: UriComponents, range: IRange) => {
let threadHandle = await this._proxy.$createNewCommentWidgetCallback(this.handle, uri, range, token);
// if (threadHandle !== undefined) { {{SQL CARBON EDIT}} @anthonydresser this never happens but throws error because of strict null checks // if (threadHandle !== undefined) { {{SQL CARBON EDIT}} @anthonydresser this never happens but throws error because of strict null checks
// return this.getKnownThread(threadHandle); // return this.getKnownThread(threadHandle);
// } // }
return undefined; // {{SQL CARBON EDIT}} @anthonydresser revert back after strict-null-check return undefined; // {{SQL CARBON EDIT}} @anthonydresser revert back after strict-null-check
} }
} : [], } : [],
draftMode: modes.DraftMode.NotSupported, draftMode: modes.DraftMode.NotSupported
template: this._features.commentThreadTemplate ? {
controllerHandle: this.handle,
label: this._features.commentThreadTemplate.label,
acceptInputCommand: this._features.commentThreadTemplate.acceptInputCommand,
additionalCommands: this._features.commentThreadTemplate.additionalCommands,
deleteCommand: this._features.commentThreadTemplate.deleteCommand
} : undefined
}; };
} }
@@ -427,26 +447,8 @@ export class MainThreadCommentController {
return ret; return ret;
} }
getCommentThreadFromTemplate(resource: UriComponents, range: IRange): MainThreadCommentThread { createCommentThreadTemplate(resource: UriComponents, range: IRange): void {
let thread = new MainThreadCommentThread( this._proxy.$createCommentThreadTemplate(this.handle, resource, range);
-1,
this.handle,
'',
'',
URI.revive(resource).toString(),
range
);
let template = this._features.commentThreadTemplate;
if (template) {
thread.acceptInputCommand = template.acceptInputCommand;
thread.additionalCommands = template.additionalCommands;
thread.deleteCommand = template.deleteCommand;
thread.label = template.label;
}
return thread;
} }
toJSON(): any { toJSON(): any {
@@ -467,8 +469,6 @@ export class MainThreadComments extends Disposable implements MainThreadComments
private _handlers = new Map<number, string>(); private _handlers = new Map<number, string>();
private _commentControllers = new Map<number, MainThreadCommentController>(); private _commentControllers = new Map<number, MainThreadCommentController>();
private _activeCommentThread?: MainThreadCommentThread;
private _input?: modes.CommentInput;
private _openPanelListener: IDisposable | null; private _openPanelListener: IDisposable | null;
constructor( constructor(
@@ -477,32 +477,12 @@ export class MainThreadComments extends Disposable implements MainThreadComments
@ICommentService private readonly _commentService: ICommentService, @ICommentService private readonly _commentService: ICommentService,
@IPanelService private readonly _panelService: IPanelService, @IPanelService private readonly _panelService: IPanelService,
@ITelemetryService private readonly _telemetryService: ITelemetryService, @ITelemetryService private readonly _telemetryService: ITelemetryService,
@IConfigurationService private readonly _configurationService: IConfigurationService @IConfigurationService private readonly _configurationService: IConfigurationService,
) { ) {
super(); super();
this._disposables = []; this._disposables = [];
this._activeCommentThreadDisposables = []; this._activeCommentThreadDisposables = [];
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostComments); this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostComments);
this._disposables.push(this._commentService.onDidChangeActiveCommentThread(async thread => {
let handle = (thread as MainThreadCommentThread).controllerHandle;
let controller = this._commentControllers.get(handle);
if (!controller) {
return;
}
this._activeCommentThreadDisposables = dispose(this._activeCommentThreadDisposables);
this._activeCommentThread = thread as MainThreadCommentThread;
controller.activeCommentThread = this._activeCommentThread;
this._activeCommentThreadDisposables.push(this._activeCommentThread.onDidChangeInput(input => { // todo, dispose
this._input = input;
this._proxy.$onCommentWidgetInputChange(handle, URI.parse(this._activeCommentThread!.resource), this._activeCommentThread!.range, this._input ? this._input.value : undefined);
}));
await this._proxy.$onActiveCommentThreadChange(controller.handle, controller.activeCommentThread.commentThreadHandle);
await this._proxy.$onCommentWidgetInputChange(controller.handle, URI.parse(this._activeCommentThread!.resource), this._activeCommentThread.range, this._input ? this._input.value : undefined);
}));
} }
$registerCommentController(handle: number, id: string, label: string): void { $registerCommentController(handle: number, id: string, label: string): void {
@@ -562,6 +542,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments
resource: UriComponents, resource: UriComponents,
range: IRange, range: IRange,
label: string, label: string,
contextValue: string | undefined,
comments: modes.Comment[], comments: modes.Comment[],
acceptInputCommand: modes.Command | undefined, acceptInputCommand: modes.Command | undefined,
additionalCommands: modes.Command[], additionalCommands: modes.Command[],
@@ -573,7 +554,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments
return undefined; return undefined;
} }
return provider.updateCommentThread(commentThreadHandle, threadId, resource, range, label, comments, acceptInputCommand, additionalCommands, deleteCommand, collapsibleState); return provider.updateCommentThread(commentThreadHandle, threadId, resource, range, label, contextValue, comments, acceptInputCommand, additionalCommands, deleteCommand, collapsibleState);
} }
$deleteCommentThread(handle: number, commentThreadHandle: number) { $deleteCommentThread(handle: number, commentThreadHandle: number) {

View File

@@ -141,7 +141,7 @@ export interface MainThreadCommentsShape extends IDisposable {
$unregisterCommentController(handle: number): void; $unregisterCommentController(handle: number): void;
$updateCommentControllerFeatures(handle: number, features: CommentProviderFeatures): void; $updateCommentControllerFeatures(handle: number, features: CommentProviderFeatures): void;
$createCommentThread(handle: number, commentThreadHandle: number, threadId: string, resource: UriComponents, range: IRange): modes.CommentThread2 | undefined; $createCommentThread(handle: number, commentThreadHandle: number, threadId: string, resource: UriComponents, range: IRange): modes.CommentThread2 | undefined;
$updateCommentThread(handle: number, commentThreadHandle: number, threadId: string, resource: UriComponents, range: IRange, label: string, comments: modes.Comment[], acceptInputCommand: modes.Command | undefined, additionalCommands: modes.Command[], deleteCommand: modes.Command | undefined, collapseState: modes.CommentThreadCollapsibleState): void; $updateCommentThread(handle: number, commentThreadHandle: number, threadId: string, resource: UriComponents, range: IRange, label: string, contextValue: string | undefined, comments: modes.Comment[], acceptInputCommand: modes.Command | undefined, additionalCommands: modes.Command[], deleteCommand: modes.Command | undefined, collapseState: modes.CommentThreadCollapsibleState): void;
$deleteCommentThread(handle: number, commentThreadHandle: number): void; $deleteCommentThread(handle: number, commentThreadHandle: number): void;
$setInputValue(handle: number, input: string): void; $setInputValue(handle: number, input: string): void;
$registerDocumentCommentProvider(handle: number, features: CommentProviderFeatures): void; $registerDocumentCommentProvider(handle: number, features: CommentProviderFeatures): void;
@@ -1211,9 +1211,11 @@ export interface ExtHostProgressShape {
export interface ExtHostCommentsShape { export interface ExtHostCommentsShape {
$provideDocumentComments(handle: number, document: UriComponents): Promise<modes.CommentInfo | null>; $provideDocumentComments(handle: number, document: UriComponents): Promise<modes.CommentInfo | null>;
$createNewCommentThread(handle: number, document: UriComponents, range: IRange, text: string): Promise<modes.CommentThread | null>; $createNewCommentThread(handle: number, document: UriComponents, range: IRange, text: string): Promise<modes.CommentThread | null>;
$createCommentThreadTemplate(commentControllerHandle: number, uriComponents: UriComponents, range: IRange): void;
$onCommentWidgetInputChange(commentControllerHandle: number, document: UriComponents, range: IRange, input: string | undefined): Promise<number | undefined>; $onCommentWidgetInputChange(commentControllerHandle: number, document: UriComponents, range: IRange, input: string | undefined): Promise<number | undefined>;
$onActiveCommentThreadChange(commentControllerHandle: number, threadHandle: number | undefined): Promise<number | undefined>; $deleteCommentThread(commentControllerHandle: number, commentThreadHandle: number): void;
$provideCommentingRanges(commentControllerHandle: number, uriComponents: UriComponents, token: CancellationToken): Promise<IRange[] | undefined>; $provideCommentingRanges(commentControllerHandle: number, uriComponents: UriComponents, token: CancellationToken): Promise<IRange[] | undefined>;
$checkStaticContribution(commentControllerHandle: number): Promise<boolean>;
$provideReactionGroup(commentControllerHandle: number): Promise<modes.CommentReaction[] | undefined>; $provideReactionGroup(commentControllerHandle: number): Promise<modes.CommentReaction[] | undefined>;
$toggleReaction(commentControllerHandle: number, threadHandle: number, uri: UriComponents, comment: modes.Comment, reaction: modes.CommentReaction): Promise<void>; $toggleReaction(commentControllerHandle: number, threadHandle: number, uri: UriComponents, comment: modes.Comment, reaction: modes.CommentReaction): Promise<void>;
$createNewCommentWidgetCallback(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, token: CancellationToken): Promise<void>; $createNewCommentWidgetCallback(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, token: CancellationToken): Promise<void>;

View File

@@ -69,6 +69,70 @@ export class ExtHostComments implements ExtHostCommentsShape {
} }
return commentThread; return commentThread;
} else if (arg && arg.$mid === 8) {
const commentController = this._commentControllers.get(arg.thread.commentControlHandle);
if (!commentController) {
return arg;
}
const commentThread = commentController.getCommentThread(arg.thread.commentThreadHandle);
if (!commentThread) {
return arg;
}
return {
thread: commentThread,
text: arg.text
};
} else if (arg && arg.$mid === 9) {
const commentController = this._commentControllers.get(arg.thread.commentControlHandle);
if (!commentController) {
return arg;
}
const commentThread = commentController.getCommentThread(arg.thread.commentThreadHandle);
if (!commentThread) {
return arg;
}
let commentUniqueId = arg.commentUniqueId;
let comment = commentThread.getCommentByUniqueId(commentUniqueId);
if (!comment) {
return arg;
}
return comment;
} else if (arg && arg.$mid === 10) {
const commentController = this._commentControllers.get(arg.thread.commentControlHandle);
if (!commentController) {
return arg;
}
const commentThread = commentController.getCommentThread(arg.thread.commentThreadHandle);
if (!commentThread) {
return arg;
}
let body = arg.text;
let commentUniqueId = arg.commentUniqueId;
let comment = commentThread.getCommentByUniqueId(commentUniqueId);
if (!comment) {
return arg;
}
comment.body = body;
return comment;
} }
return arg; return arg;
@@ -88,6 +152,16 @@ export class ExtHostComments implements ExtHostCommentsShape {
return commentController; return commentController;
} }
$createCommentThreadTemplate(commentControllerHandle: number, uriComponents: UriComponents, range: IRange): void {
const commentController = this._commentControllers.get(commentControllerHandle);
if (!commentController) {
return;
}
commentController.$createCommentThreadTemplate(uriComponents, range);
}
$onCommentWidgetInputChange(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, input: string): Promise<number | undefined> { $onCommentWidgetInputChange(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, input: string): Promise<number | undefined> {
const commentController = this._commentControllers.get(commentControllerHandle); const commentController = this._commentControllers.get(commentControllerHandle);
@@ -99,15 +173,12 @@ export class ExtHostComments implements ExtHostCommentsShape {
return Promise.resolve(commentControllerHandle); return Promise.resolve(commentControllerHandle);
} }
$onActiveCommentThreadChange(commentControllerHandle: number, threadHandle: number): Promise<number | undefined> { $deleteCommentThread(commentControllerHandle: number, commentThreadHandle: number) {
const commentController = this._commentControllers.get(commentControllerHandle); const commentController = this._commentControllers.get(commentControllerHandle);
if (!commentController) { if (commentController) {
return Promise.resolve(undefined); commentController.$deleteCommentThread(commentThreadHandle);
} }
commentController.$onActiveCommentThreadChange(threadHandle);
return Promise.resolve(threadHandle);
} }
$provideCommentingRanges(commentControllerHandle: number, uriComponents: UriComponents, token: CancellationToken): Promise<IRange[] | undefined> { $provideCommentingRanges(commentControllerHandle: number, uriComponents: UriComponents, token: CancellationToken): Promise<IRange[] | undefined> {
@@ -164,7 +235,7 @@ export class ExtHostComments implements ExtHostCommentsShape {
return Promise.resolve(); return Promise.resolve();
} }
if (!(commentController as any).emptyCommentThreadFactory && !(commentController.commentingRangeProvider && commentController.commentingRangeProvider.createEmptyCommentThread)) { if (!(commentController as any).emptyCommentThreadFactory) {
return Promise.resolve(); return Promise.resolve();
} }
@@ -173,13 +244,23 @@ export class ExtHostComments implements ExtHostCommentsShape {
if ((commentController as any).emptyCommentThreadFactory) { if ((commentController as any).emptyCommentThreadFactory) {
return (commentController as any).emptyCommentThreadFactory!.createEmptyCommentThread(document, extHostTypeConverter.Range.to(range)); return (commentController as any).emptyCommentThreadFactory!.createEmptyCommentThread(document, extHostTypeConverter.Range.to(range));
} }
if (commentController.commentingRangeProvider && commentController.commentingRangeProvider.createEmptyCommentThread) {
return commentController.commentingRangeProvider.createEmptyCommentThread(document, extHostTypeConverter.Range.to(range));
}
}).then(() => Promise.resolve()); }).then(() => Promise.resolve());
} }
$checkStaticContribution(commentControllerHandle: number): Promise<boolean> {
const commentController = this._commentControllers.get(commentControllerHandle);
if (!commentController) {
return Promise.resolve(false);
}
if (!(commentController as any).emptyCommentThreadFactory) {
return Promise.resolve(true);
}
return Promise.resolve(false);
}
registerWorkspaceCommentProvider( registerWorkspaceCommentProvider(
extensionId: ExtensionIdentifier, extensionId: ExtensionIdentifier,
provider: vscode.WorkspaceCommentProvider provider: vscode.WorkspaceCommentProvider
@@ -376,12 +457,18 @@ export class ExtHostComments implements ExtHostCommentsShape {
export class ExtHostCommentThread implements vscode.CommentThread { export class ExtHostCommentThread implements vscode.CommentThread {
private static _handlePool: number = 0; private static _handlePool: number = 0;
readonly handle = ExtHostCommentThread._handlePool++; readonly handle = ExtHostCommentThread._handlePool++;
public commentHandle: number = 0;
set threadId(id: string) {
this._id = id;
}
get threadId(): string { get threadId(): string {
return this._id; return this._id!;
} }
get id(): string { get id(): string {
return this._id; return this._id!;
} }
get resource(): vscode.Uri { get resource(): vscode.Uri {
@@ -417,6 +504,17 @@ export class ExtHostCommentThread implements vscode.CommentThread {
this._onDidUpdateCommentThread.fire(); this._onDidUpdateCommentThread.fire();
} }
private _contextValue: string | undefined;
get contextValue(): string | undefined {
return this._contextValue;
}
set contextValue(context: string | undefined) {
this._contextValue = context;
this._onDidUpdateCommentThread.fire();
}
get comments(): vscode.Comment[] { get comments(): vscode.Comment[] {
return this._comments; return this._comments;
} }
@@ -475,15 +573,21 @@ export class ExtHostCommentThread implements vscode.CommentThread {
return this._isDiposed; return this._isDiposed;
} }
private _commentsMap: Map<vscode.Comment, number> = new Map<vscode.Comment, number>();
constructor( constructor(
private _proxy: MainThreadCommentsShape, private _proxy: MainThreadCommentsShape,
private readonly _commandsConverter: CommandsConverter, private readonly _commandsConverter: CommandsConverter,
private _commentController: ExtHostCommentController, private _commentController: ExtHostCommentController,
private _id: string, private _id: string | undefined,
private _uri: vscode.Uri, private _uri: vscode.Uri,
private _range: vscode.Range, private _range: vscode.Range,
private _comments: vscode.Comment[] private _comments: vscode.Comment[]
) { ) {
if (this._id === undefined) {
this._id = `${_commentController.id}.${this.handle}`;
}
this._proxy.$createCommentThread( this._proxy.$createCommentThread(
this._commentController.handle, this._commentController.handle,
this.handle, this.handle,
@@ -507,7 +611,8 @@ export class ExtHostCommentThread implements vscode.CommentThread {
eventuallyUpdateCommentThread(): void { eventuallyUpdateCommentThread(): void {
const commentThreadRange = extHostTypeConverter.Range.from(this._range); const commentThreadRange = extHostTypeConverter.Range.from(this._range);
const label = this.label; const label = this.label;
const comments = this._comments.map(cmt => { return convertToModeComment(this._commentController, cmt, this._commandsConverter); }); const contextValue = this.contextValue;
const comments = this._comments.map(cmt => { return convertToModeComment2(this, this._commentController, cmt, this._commandsConverter, this._commentsMap); });
const acceptInputCommand = this._acceptInputCommand ? this._commandsConverter.toInternal(this._acceptInputCommand) : undefined; const acceptInputCommand = this._acceptInputCommand ? this._commandsConverter.toInternal(this._acceptInputCommand) : undefined;
const additionalCommands = this._additionalCommands ? this._additionalCommands.map(x => this._commandsConverter.toInternal(x)) : []; const additionalCommands = this._additionalCommands ? this._additionalCommands.map(x => this._commandsConverter.toInternal(x)) : [];
const deleteCommand = this._deleteCommand ? this._commandsConverter.toInternal(this._deleteCommand) : undefined; const deleteCommand = this._deleteCommand ? this._commandsConverter.toInternal(this._deleteCommand) : undefined;
@@ -516,10 +621,11 @@ export class ExtHostCommentThread implements vscode.CommentThread {
this._proxy.$updateCommentThread( this._proxy.$updateCommentThread(
this._commentController.handle, this._commentController.handle,
this.handle, this.handle,
this._id, this._id!,
this._uri, this._uri,
commentThreadRange, commentThreadRange,
label, label,
contextValue,
comments, comments,
acceptInputCommand, acceptInputCommand,
additionalCommands, additionalCommands,
@@ -538,6 +644,18 @@ export class ExtHostCommentThread implements vscode.CommentThread {
return undefined; return undefined;
} }
getCommentByUniqueId(uniqueId: number): vscode.Comment | undefined {
for (let key of this._commentsMap) {
let comment = key[0];
let id = key[1];
if (uniqueId === id) {
return comment;
}
}
return undefined; // {{SQL CARBON EDIT}} @anthonydresser strict-null-check
}
dispose() { dispose() {
this._localDisposables.forEach(disposable => disposable.dispose()); this._localDisposables.forEach(disposable => disposable.dispose());
this._proxy.$deleteCommentThread( this._proxy.$deleteCommentThread(
@@ -599,15 +717,6 @@ class ExtHostCommentController implements vscode.CommentController {
} }
public inputBox: ExtHostCommentInputBox | undefined; public inputBox: ExtHostCommentInputBox | undefined;
private _activeCommentThread: ExtHostCommentThread | undefined;
public get activeCommentThread(): ExtHostCommentThread | undefined {
if (this._activeCommentThread && this._activeCommentThread.isDisposed) {
this._activeCommentThread = undefined;
}
return this._activeCommentThread;
}
public activeCommentingRange?: vscode.Range; public activeCommentingRange?: vscode.Range;
@@ -618,30 +727,6 @@ class ExtHostCommentController implements vscode.CommentController {
private _threads: Map<number, ExtHostCommentThread> = new Map<number, ExtHostCommentThread>(); private _threads: Map<number, ExtHostCommentThread> = new Map<number, ExtHostCommentThread>();
commentingRangeProvider?: vscode.CommentingRangeProvider & { createEmptyCommentThread: (document: vscode.TextDocument, range: types.Range) => Promise<vscode.CommentThread>; }; commentingRangeProvider?: vscode.CommentingRangeProvider & { createEmptyCommentThread: (document: vscode.TextDocument, range: types.Range) => Promise<vscode.CommentThread>; };
private _template: vscode.CommentThreadTemplate | undefined;
get template(): vscode.CommentThreadTemplate | undefined {
return this._template;
}
set template(newTemplate: vscode.CommentThreadTemplate | undefined) {
this._template = newTemplate;
if (newTemplate) {
const acceptInputCommand = newTemplate.acceptInputCommand ? this._commandsConverter.toInternal(newTemplate.acceptInputCommand) : undefined;
const additionalCommands = newTemplate.additionalCommands ? newTemplate.additionalCommands.map(x => this._commandsConverter.toInternal(x)) : [];
const deleteCommand = newTemplate.deleteCommand ? this._commandsConverter.toInternal(newTemplate.deleteCommand) : undefined;
this._proxy.$updateCommentControllerFeatures(this.handle, {
commentThreadTemplate: {
label: newTemplate.label,
acceptInputCommand,
additionalCommands,
deleteCommand
}
});
}
}
private _commentReactionProvider?: vscode.CommentReactionProvider; private _commentReactionProvider?: vscode.CommentReactionProvider;
get reactionProvider(): vscode.CommentReactionProvider | undefined { get reactionProvider(): vscode.CommentReactionProvider | undefined {
@@ -666,12 +751,37 @@ class ExtHostCommentController implements vscode.CommentController {
this._proxy.$registerCommentController(this.handle, _id, _label); this._proxy.$registerCommentController(this.handle, _id, _label);
} }
createCommentThread(id: string, resource: vscode.Uri, range: vscode.Range, comments: vscode.Comment[]): vscode.CommentThread { createCommentThread(resource: vscode.Uri, range: vscode.Range, comments: vscode.Comment[]): vscode.CommentThread;
const commentThread = new ExtHostCommentThread(this._proxy, this._commandsConverter, this, id, resource, range, comments); createCommentThread(id: string, resource: vscode.Uri, range: vscode.Range, comments: vscode.Comment[]): vscode.CommentThread;
createCommentThread(arg0: vscode.Uri | string, arg1: vscode.Uri | vscode.Range, arg2: vscode.Range | vscode.Comment[], arg3?: vscode.Comment[]): vscode.CommentThread {
if (typeof arg0 === 'string') {
const commentThread = new ExtHostCommentThread(this._proxy, this._commandsConverter, this, arg0, arg1 as vscode.Uri, arg2 as vscode.Range, arg3 as vscode.Comment[]);
this._threads.set(commentThread.handle, commentThread);
return commentThread;
} else {
const commentThread = new ExtHostCommentThread(this._proxy, this._commandsConverter, this, undefined, arg0 as vscode.Uri, arg1 as vscode.Range, arg2 as vscode.Comment[]);
this._threads.set(commentThread.handle, commentThread);
return commentThread;
}
}
$createCommentThreadTemplate(uriComponents: UriComponents, range: IRange) {
const commentThread = new ExtHostCommentThread(this._proxy, this._commandsConverter, this, undefined, URI.revive(uriComponents), extHostTypeConverter.Range.to(range), []);
commentThread.collapsibleState = modes.CommentThreadCollapsibleState.Expanded;
this._threads.set(commentThread.handle, commentThread); this._threads.set(commentThread.handle, commentThread);
return commentThread; return commentThread;
} }
$deleteCommentThread(threadHandle: number) {
let thread = this._threads.get(threadHandle);
if (thread) {
thread.dispose();
}
this._threads.delete(threadHandle);
}
$onCommentWidgetInputChange(uriComponents: UriComponents, range: IRange, input: string) { $onCommentWidgetInputChange(uriComponents: UriComponents, range: IRange, input: string) {
if (!this.inputBox) { if (!this.inputBox) {
this.inputBox = new ExtHostCommentInputBox(this._proxy, this.handle, URI.revive(uriComponents), extHostTypeConverter.Range.to(range), input); this.inputBox = new ExtHostCommentInputBox(this._proxy, this.handle, URI.revive(uriComponents), extHostTypeConverter.Range.to(range), input);
@@ -680,10 +790,6 @@ class ExtHostCommentController implements vscode.CommentController {
} }
} }
$onActiveCommentThreadChange(threadHandle: number) {
this._activeCommentThread = this.getCommentThread(threadHandle);
}
getCommentThread(handle: number) { getCommentThread(handle: number) {
return this._threads.get(handle); return this._threads.get(handle);
} }
@@ -759,16 +865,25 @@ function convertFromComment(comment: modes.Comment): vscode.Comment {
count: reaction.count, count: reaction.count,
hasReacted: reaction.hasReacted hasReacted: reaction.hasReacted
}; };
}) : undefined }) : undefined,
mode: comment.mode ? comment.mode : modes.CommentMode.Preview
}; };
} }
function convertToModeComment(commentController: ExtHostCommentController, vscodeComment: vscode.Comment, commandsConverter: CommandsConverter): modes.Comment { function convertToModeComment2(thread: ExtHostCommentThread, commentController: ExtHostCommentController, vscodeComment: vscode.Comment, commandsConverter: CommandsConverter, commentsMap: Map<vscode.Comment, number>): modes.Comment {
const iconPath = vscodeComment.author && vscodeComment.author.iconPath ? vscodeComment.author.iconPath.toString() : let commentUniqueId = commentsMap.get(vscodeComment)!;
(vscodeComment.userIconPath ? vscodeComment.userIconPath.toString() : vscodeComment.gravatar); if (!commentUniqueId) {
commentUniqueId = ++thread.commentHandle;
commentsMap.set(vscodeComment, commentUniqueId);
}
const iconPath = vscodeComment.author && vscodeComment.author.iconPath ? vscodeComment.author.iconPath.toString() : undefined;
return { return {
commentId: vscodeComment.id || vscodeComment.commentId, commentId: vscodeComment.id || vscodeComment.commentId,
mode: vscodeComment.mode,
contextValue: vscodeComment.contextValue,
uniqueIdInThread: commentUniqueId,
body: extHostTypeConverter.MarkdownString.from(vscodeComment.body), body: extHostTypeConverter.MarkdownString.from(vscodeComment.body),
userName: vscodeComment.author ? vscodeComment.author.name : vscodeComment.userName, userName: vscodeComment.author ? vscodeComment.author.name : vscodeComment.userName,
userIconPath: iconPath, userIconPath: iconPath,

View File

@@ -2297,6 +2297,12 @@ export enum CommentThreadCollapsibleState {
*/ */
Expanded = 1 Expanded = 1
} }
export enum CommentMode {
Editing = 0,
Preview = 1
}
//#endregion //#endregion
@es5ClassCompat @es5ClassCompat

View File

@@ -51,6 +51,10 @@ namespace schema {
case 'notebook/toolbar': return MenuId.NotebookToolbar; case 'notebook/toolbar': return MenuId.NotebookToolbar;
case 'dataExplorer/context': return MenuId.DataExplorerContext; case 'dataExplorer/context': return MenuId.DataExplorerContext;
case 'dataExplorer/action': return MenuId.DataExplorerAction; case 'dataExplorer/action': return MenuId.DataExplorerAction;
case 'comments/commentThread/title': return MenuId.CommentThreadTitle;
case 'comments/commentThread/context': return MenuId.CommentThreadActions;
case 'comments/comment/title': return MenuId.CommentTitle;
case 'comments/comment/context': return MenuId.CommentActions;
} }
return undefined; return undefined;
@@ -196,7 +200,27 @@ namespace schema {
description: localize('view.itemContext', "The contributed view item context menu"), description: localize('view.itemContext', "The contributed view item context menu"),
type: 'array', type: 'array',
items: menuItem items: menuItem
} },
'comments/commentThread/title': {
description: localize('commentThread.title', "The contributed comment thread title menu"),
type: 'array',
items: menuItem
},
'comments/commentThread/actions': {
description: localize('commentThread.actions', "The contributed comment thread actions"),
type: 'array',
items: menuItem
},
'comments/comment/title': {
description: localize('comment.title', "The contributed comment title menu"),
type: 'array',
items: menuItem
},
'comments/comment/actions': {
description: localize('comment.actions', "The contributed comment actions"),
type: 'array',
items: menuItem
},
} }
}; };

View File

@@ -681,6 +681,8 @@ export function createApiFactory(
} }
}; };
const comments = comment;
// {{SQL CARBON EDIT}} -- no-op debug extensibility API // {{SQL CARBON EDIT}} -- no-op debug extensibility API
// namespace: debug // namespace: debug
const debug: typeof vscode.debug = { const debug: typeof vscode.debug = {
@@ -766,6 +768,7 @@ export function createApiFactory(
languages, languages,
scm, scm,
comment, comment,
comments,
tasks, tasks,
window, window,
workspace, workspace,
@@ -781,6 +784,7 @@ export function createApiFactory(
ColorInformation: extHostTypes.ColorInformation, ColorInformation: extHostTypes.ColorInformation,
ColorPresentation: extHostTypes.ColorPresentation, ColorPresentation: extHostTypes.ColorPresentation,
CommentThreadCollapsibleState: extHostTypes.CommentThreadCollapsibleState, CommentThreadCollapsibleState: extHostTypes.CommentThreadCollapsibleState,
CommentMode: extHostTypes.CommentMode,
CompletionItem: extHostTypes.CompletionItem, CompletionItem: extHostTypes.CompletionItem,
CompletionItemKind: extHostTypes.CompletionItemKind, CompletionItemKind: extHostTypes.CompletionItemKind,
CompletionList: extHostTypes.CompletionList, CompletionList: extHostTypes.CompletionList,

View File

@@ -302,6 +302,24 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
} }
}); });
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'list.collapseAll',
weight: KeybindingWeight.WorkbenchContrib,
when: WorkbenchListFocusContextKey,
primary: KeyMod.CtrlCmd | KeyCode.LeftArrow,
mac: {
primary: KeyMod.CtrlCmd | KeyCode.LeftArrow,
secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.UpArrow]
},
handler: (accessor) => {
const focusedTree = accessor.get(IListService).lastFocusedList;
if (focusedTree && !(focusedTree instanceof List || focusedTree instanceof PagedList)) {
focusedTree.collapseAll();
}
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({ KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'list.expand', id: 'list.expand',
weight: KeybindingWeight.WorkbenchContrib, weight: KeybindingWeight.WorkbenchContrib,

View File

@@ -73,7 +73,7 @@ abstract class BaseNavigationAction extends Action {
return this.panelService.openPanel(activePanelId, true)!; return this.panelService.openPanel(activePanelId, true)!;
} }
protected navigateToSidebar(): Promise<IViewlet | boolean> { protected async navigateToSidebar(): Promise<IViewlet | boolean> {
if (!this.layoutService.isVisible(Parts.SIDEBAR_PART)) { if (!this.layoutService.isVisible(Parts.SIDEBAR_PART)) {
return Promise.resolve(false); return Promise.resolve(false);
} }
@@ -84,8 +84,8 @@ abstract class BaseNavigationAction extends Action {
} }
const activeViewletId = activeViewlet.getId(); const activeViewletId = activeViewlet.getId();
return this.viewletService.openViewlet(activeViewletId, true) const value = await this.viewletService.openViewlet(activeViewletId, true);
.then(value => value === null ? false : value); return value === null ? false : value;
} }
protected navigateAcrossEditorGroup(direction: GroupDirection): boolean { protected navigateAcrossEditorGroup(direction: GroupDirection): boolean {

View File

@@ -160,21 +160,18 @@ export class GlobalRemoveRootFolderAction extends Action {
super(id, label); super(id, label);
} }
run(): Promise<any> { async run(): Promise<any> {
const state = this.contextService.getWorkbenchState(); const state = this.contextService.getWorkbenchState();
// Workspace / Folder // Workspace / Folder
if (state === WorkbenchState.WORKSPACE || state === WorkbenchState.FOLDER) { if (state === WorkbenchState.WORKSPACE || state === WorkbenchState.FOLDER) {
return this.commandService.executeCommand<IWorkspaceFolder>(PICK_WORKSPACE_FOLDER_COMMAND_ID).then(folder => { const folder = await this.commandService.executeCommand<IWorkspaceFolder>(PICK_WORKSPACE_FOLDER_COMMAND_ID);
if (folder) { if (folder) {
return this.workspaceEditingService.removeFolders([folder.uri]).then(() => true); await this.workspaceEditingService.removeFolders([folder.uri]);
} }
return true;
});
} }
return Promise.resolve(true); return true;
} }
} }
@@ -193,20 +190,18 @@ export class SaveWorkspaceAsAction extends Action {
super(id, label); super(id, label);
} }
run(): Promise<any> { async run(): Promise<any> {
return this.workspaceEditingService.pickNewWorkspacePath().then((configPathUri): Promise<void> | void => { const configPathUri = await this.workspaceEditingService.pickNewWorkspacePath();
if (configPathUri) { if (configPathUri) {
switch (this.contextService.getWorkbenchState()) { switch (this.contextService.getWorkbenchState()) {
case WorkbenchState.EMPTY: case WorkbenchState.EMPTY:
case WorkbenchState.FOLDER: case WorkbenchState.FOLDER:
const folders = this.contextService.getWorkspace().folders.map(folder => ({ uri: folder.uri })); const folders = this.contextService.getWorkspace().folders.map(folder => ({ uri: folder.uri }));
return this.workspaceEditingService.createAndEnterWorkspace(folders, configPathUri); return this.workspaceEditingService.createAndEnterWorkspace(folders, configPathUri);
case WorkbenchState.WORKSPACE:
case WorkbenchState.WORKSPACE: return this.workspaceEditingService.saveAndEnterWorkspace(configPathUri);
return this.workspaceEditingService.saveAndEnterWorkspace(configPathUri);
}
} }
}); }
} }
} }
@@ -296,14 +291,13 @@ export class DuplicateWorkspaceInNewWindowAction extends Action {
super(id, label); super(id, label);
} }
run(): Promise<any> { async run(): Promise<any> {
const folders = this.workspaceContextService.getWorkspace().folders; const folders = this.workspaceContextService.getWorkspace().folders;
const remoteAuthority = this.environmentService.configuration.remoteAuthority; const remoteAuthority = this.environmentService.configuration.remoteAuthority;
return this.workspacesService.createUntitledWorkspace(folders, remoteAuthority).then(newWorkspace => { const newWorkspace = await this.workspacesService.createUntitledWorkspace(folders, remoteAuthority);
return this.workspaceEditingService.copyWorkspaceSettings(newWorkspace).then(() => { await this.workspaceEditingService.copyWorkspaceSettings(newWorkspace);
return this.windowService.openWindow([{ workspaceUri: newWorkspace.configPath }], { forceNewWindow: true });
}); return this.windowService.openWindow([{ workspaceUri: newWorkspace.configPath }], { forceNewWindow: true });
});
} }
} }

View File

@@ -54,30 +54,28 @@ CommandsRegistry.registerCommand({
CommandsRegistry.registerCommand({ CommandsRegistry.registerCommand({
id: ADD_ROOT_FOLDER_COMMAND_ID, id: ADD_ROOT_FOLDER_COMMAND_ID,
handler: (accessor) => { handler: async (accessor) => {
const viewletService = accessor.get(IViewletService); const viewletService = accessor.get(IViewletService);
const workspaceEditingService = accessor.get(IWorkspaceEditingService); const workspaceEditingService = accessor.get(IWorkspaceEditingService);
const dialogsService = accessor.get(IFileDialogService); const dialogsService = accessor.get(IFileDialogService);
return dialogsService.showOpenDialog({ const folders = await dialogsService.showOpenDialog({
openLabel: mnemonicButtonLabel(nls.localize({ key: 'add', comment: ['&& denotes a mnemonic'] }, "&&Add")), openLabel: mnemonicButtonLabel(nls.localize({ key: 'add', comment: ['&& denotes a mnemonic'] }, "&&Add")),
title: nls.localize('addFolderToWorkspaceTitle', "Add Folder to Workspace"), title: nls.localize('addFolderToWorkspaceTitle', "Add Folder to Workspace"),
canSelectFolders: true, canSelectFolders: true,
canSelectMany: true, canSelectMany: true,
defaultUri: dialogsService.defaultFolderPath() defaultUri: dialogsService.defaultFolderPath()
}).then((folders): Promise<any> | null => {
if (!folders || !folders.length) {
return null;
}
// Add and show Files Explorer viewlet
return workspaceEditingService.addFolders(folders.map(folder => ({ uri: resources.removeTrailingPathSeparator(folder) })))
.then(() => viewletService.openViewlet(viewletService.getDefaultViewletId(), true))
.then(() => undefined);
}); });
if (!folders || !folders.length) {
return;
}
await workspaceEditingService.addFolders(folders.map(folder => ({ uri: resources.removeTrailingPathSeparator(folder) })));
await viewletService.openViewlet(viewletService.getDefaultViewletId(), true);
} }
}); });
CommandsRegistry.registerCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, function (accessor, args?: [IPickOptions<IQuickPickItem>, CancellationToken]) { CommandsRegistry.registerCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, async function (accessor, args?: [IPickOptions<IQuickPickItem>, CancellationToken]) {
const quickInputService = accessor.get(IQuickInputService); const quickInputService = accessor.get(IQuickInputService);
const labelService = accessor.get(ILabelService); const labelService = accessor.get(ILabelService);
const contextService = accessor.get(IWorkspaceContextService); const contextService = accessor.get(IWorkspaceContextService);
@@ -86,7 +84,7 @@ CommandsRegistry.registerCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, function (acc
const folders = contextService.getWorkspace().folders; const folders = contextService.getWorkspace().folders;
if (!folders.length) { if (!folders.length) {
return undefined; return undefined; // {{SQL CARBON EDIT}} @anthonydresser strict-null-check
} }
const folderPicks: IQuickPickItem[] = folders.map(folder => { const folderPicks: IQuickPickItem[] = folders.map(folder => {
@@ -113,12 +111,11 @@ CommandsRegistry.registerCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, function (acc
} }
const token: CancellationToken = (args ? args[1] : undefined) || CancellationToken.None; const token: CancellationToken = (args ? args[1] : undefined) || CancellationToken.None;
const pick = await quickInputService.pick(folderPicks, options, token);
return quickInputService.pick(folderPicks, options, token).then(pick => { if (pick) {
if (!pick) {
return undefined;
}
return folders[folderPicks.indexOf(pick)]; return folders[folderPicks.indexOf(pick)];
}); }
return undefined; // {{SQL CARBON EDIT}} @anthonydresser strict-null-check
}); });

View File

@@ -170,53 +170,52 @@ export class ResourcesDropHandler {
) { ) {
} }
handleDrop(event: DragEvent, resolveTargetGroup: () => IEditorGroup | undefined, afterDrop: (targetGroup: IEditorGroup | undefined) => void, targetIndex?: number): void { async handleDrop(event: DragEvent, resolveTargetGroup: () => IEditorGroup | undefined, afterDrop: (targetGroup: IEditorGroup | undefined) => void, targetIndex?: number): Promise<void> {
const untitledOrFileResources = extractResources(event).filter(r => this.fileService.canHandleResource(r.resource) || r.resource.scheme === Schemas.untitled); const untitledOrFileResources = extractResources(event).filter(r => this.fileService.canHandleResource(r.resource) || r.resource.scheme === Schemas.untitled);
if (!untitledOrFileResources.length) { if (!untitledOrFileResources.length) {
return; return;
} }
// Make the window active to handle the drop properly within // Make the window active to handle the drop properly within
this.windowService.focusWindow().then(() => { await this.windowService.focusWindow();
// Check for special things being dropped // Check for special things being dropped
return this.doHandleDrop(untitledOrFileResources).then(isWorkspaceOpening => { const isWorkspaceOpening = await this.doHandleDrop(untitledOrFileResources);
if (isWorkspaceOpening) {
return undefined; // return early if the drop operation resulted in this window changing to a workspace
}
// Add external ones to recently open list unless dropped resource is a workspace if (isWorkspaceOpening) {
const recents: IRecentFile[] = untitledOrFileResources.filter(d => d.isExternal && d.resource.scheme === Schemas.file).map(d => ({ fileUri: d.resource })); return; // return early if the drop operation resulted in this window changing to a workspace
if (recents.length) { }
this.windowsService.addRecentlyOpened(recents);
}
const editors: IResourceEditor[] = untitledOrFileResources.map(untitledOrFileResource => ({ // Add external ones to recently open list unless dropped resource is a workspace
resource: untitledOrFileResource.resource, const recents: IRecentFile[] = untitledOrFileResources.filter(d => d.isExternal && d.resource.scheme === Schemas.file).map(d => ({ fileUri: d.resource }));
options: { if (recents.length) {
pinned: true, this.windowsService.addRecentlyOpened(recents);
index: targetIndex, }
viewState: (untitledOrFileResource as IDraggedEditor).viewState
}
}));
// Open in Editor const editors: IResourceEditor[] = untitledOrFileResources.map(untitledOrFileResource => ({
const targetGroup = resolveTargetGroup(); resource: untitledOrFileResource.resource,
return this.editorService.openEditors(editors, targetGroup).then(() => { options: {
pinned: true,
index: targetIndex,
viewState: (untitledOrFileResource as IDraggedEditor).viewState
}
}));
// Finish with provided function // Open in Editor
afterDrop(targetGroup); const targetGroup = resolveTargetGroup();
}); await this.editorService.openEditors(editors, targetGroup);
});
}); // Finish with provided function
afterDrop(targetGroup);
} }
private doHandleDrop(untitledOrFileResources: Array<IDraggedResource | IDraggedEditor>): Promise<boolean> { private async doHandleDrop(untitledOrFileResources: Array<IDraggedResource | IDraggedEditor>): Promise<boolean> {
// Check for dirty editors being dropped // Check for dirty editors being dropped
const resourcesWithBackups: IDraggedEditor[] = untitledOrFileResources.filter(resource => !resource.isExternal && !!(resource as IDraggedEditor).backupResource); const resourcesWithBackups: IDraggedEditor[] = untitledOrFileResources.filter(resource => !resource.isExternal && !!(resource as IDraggedEditor).backupResource);
if (resourcesWithBackups.length > 0) { if (resourcesWithBackups.length > 0) {
return Promise.all(resourcesWithBackups.map(resourceWithBackup => this.handleDirtyEditorDrop(resourceWithBackup))).then(() => false); await Promise.all(resourcesWithBackups.map(resourceWithBackup => this.handleDirtyEditorDrop(resourceWithBackup)));
return false;
} }
// Check for workspace file being dropped if we are allowed to do so // Check for workspace file being dropped if we are allowed to do so
@@ -227,10 +226,10 @@ export class ResourcesDropHandler {
} }
} }
return Promise.resolve(false); return false;
} }
private handleDirtyEditorDrop(droppedDirtyEditor: IDraggedEditor): Promise<boolean> { private async handleDirtyEditorDrop(droppedDirtyEditor: IDraggedEditor): Promise<boolean> {
// Untitled: always ensure that we open a new untitled for each file we drop // Untitled: always ensure that we open a new untitled for each file we drop
if (droppedDirtyEditor.resource.scheme === Schemas.untitled) { if (droppedDirtyEditor.resource.scheme === Schemas.untitled) {
@@ -239,15 +238,18 @@ export class ResourcesDropHandler {
// Return early if the resource is already dirty in target or opened already // Return early if the resource is already dirty in target or opened already
if (this.textFileService.isDirty(droppedDirtyEditor.resource) || this.editorService.isOpen({ resource: droppedDirtyEditor.resource })) { if (this.textFileService.isDirty(droppedDirtyEditor.resource) || this.editorService.isOpen({ resource: droppedDirtyEditor.resource })) {
return Promise.resolve(false); return false;
} }
// Resolve the contents of the dropped dirty resource from source // Resolve the contents of the dropped dirty resource from source
return this.backupFileService.resolveBackupContent(droppedDirtyEditor.backupResource!).then(content => { try {
const content = await this.backupFileService.resolveBackupContent((droppedDirtyEditor.backupResource!));
await this.backupFileService.backupResource(droppedDirtyEditor.resource, content.value.create(this.getDefaultEOL()).createSnapshot(true));
} catch (e) {
// Ignore error
}
// Set the contents of to the resource to the target return false;
return this.backupFileService.backupResource(droppedDirtyEditor.resource, content.value.create(this.getDefaultEOL()).createSnapshot(true));
}).then(() => false, () => false /* ignore any error */);
} }
private getDefaultEOL(): DefaultEndOfLine { private getDefaultEOL(): DefaultEndOfLine {
@@ -259,44 +261,50 @@ export class ResourcesDropHandler {
return DefaultEndOfLine.LF; return DefaultEndOfLine.LF;
} }
private handleWorkspaceFileDrop(fileOnDiskResources: URI[]): Promise<boolean> { private async handleWorkspaceFileDrop(fileOnDiskResources: URI[]): Promise<boolean> {
const urisToOpen: IURIToOpen[] = []; const urisToOpen: IURIToOpen[] = [];
const folderURIs: IWorkspaceFolderCreationData[] = []; const folderURIs: IWorkspaceFolderCreationData[] = [];
return Promise.all(fileOnDiskResources.map(fileOnDiskResource => { await Promise.all(fileOnDiskResources.map(async fileOnDiskResource => {
// Check for Workspace // Check for Workspace
if (hasWorkspaceFileExtension(fileOnDiskResource)) { if (hasWorkspaceFileExtension(fileOnDiskResource)) {
urisToOpen.push({ workspaceUri: fileOnDiskResource }); urisToOpen.push({ workspaceUri: fileOnDiskResource });
return undefined; return;
} }
// Check for Folder // Check for Folder
return this.fileService.resolve(fileOnDiskResource).then(stat => { try {
const stat = await this.fileService.resolve(fileOnDiskResource);
if (stat.isDirectory) { if (stat.isDirectory) {
urisToOpen.push({ folderUri: stat.resource }); urisToOpen.push({ folderUri: stat.resource });
folderURIs.push({ uri: stat.resource }); folderURIs.push({ uri: stat.resource });
} }
}, error => undefined); } catch (error) {
})).then(_ => { // Ignore error
// Return early if no external resource is a folder or workspace
if (urisToOpen.length === 0) {
return false;
} }
}));
// Pass focus to window // Return early if no external resource is a folder or workspace
this.windowService.focusWindow(); if (urisToOpen.length === 0) {
return false;
}
// Open in separate windows if we drop workspaces or just one folder // Pass focus to window
if (urisToOpen.length > folderURIs.length || folderURIs.length === 1) { this.windowService.focusWindow();
return this.windowService.openWindow(urisToOpen, { forceReuseWindow: true }).then(_ => true);
}
// folders.length > 1: Multiple folders: Create new workspace with folders and open // Open in separate windows if we drop workspaces or just one folder
return this.workspaceEditingService.createAndEnterWorkspace(folderURIs).then(_ => true); if (urisToOpen.length > folderURIs.length || folderURIs.length === 1) {
}); await this.windowService.openWindow(urisToOpen, { forceReuseWindow: true });
}
// folders.length > 1: Multiple folders: Create new workspace with folders and open
else {
await this.workspaceEditingService.createAndEnterWorkspace(folderURIs);
}
return true;
} }
} }

View File

@@ -42,15 +42,15 @@ export class ViewletActivityAction extends ActivityAction {
super(activity); super(activity);
} }
run(event: any): Promise<any> { async run(event: any): Promise<any> {
if (event instanceof MouseEvent && event.button === 2) { if (event instanceof MouseEvent && event.button === 2) {
return Promise.resolve(false); // do not run on right click return false; // do not run on right click
} }
// prevent accident trigger on a doubleclick (to help nervous people) // prevent accident trigger on a doubleclick (to help nervous people)
const now = Date.now(); const now = Date.now();
if (now > this.lastRun /* https://github.com/Microsoft/vscode/issues/25830 */ && now - this.lastRun < ViewletActivityAction.preventDoubleClickDelay) { if (now > this.lastRun /* https://github.com/Microsoft/vscode/issues/25830 */ && now - this.lastRun < ViewletActivityAction.preventDoubleClickDelay) {
return Promise.resolve(true); return true;
} }
this.lastRun = now; this.lastRun = now;
@@ -61,11 +61,12 @@ export class ViewletActivityAction extends ActivityAction {
if (sideBarVisible && activeViewlet && activeViewlet.getId() === this.activity.id) { if (sideBarVisible && activeViewlet && activeViewlet.getId() === this.activity.id) {
this.logAction('hide'); this.logAction('hide');
this.layoutService.setSideBarHidden(true); this.layoutService.setSideBarHidden(true);
return Promise.resolve(); return true;
} }
this.logAction('show'); this.logAction('show');
return this.viewletService.openViewlet(this.activity.id, true).then(() => this.activate()); await this.viewletService.openViewlet(this.activity.id, true);
return this.activate();
} }
private logAction(action: string) { private logAction(action: string) {

View File

@@ -204,12 +204,13 @@ export class CompositeBar extends Widget implements ICompositeBar {
return toDisposable(() => this.model.removeActivity(compositeId, activity)); return toDisposable(() => this.model.removeActivity(compositeId, activity));
} }
pin(compositeId: string, open?: boolean): void { async pin(compositeId: string, open?: boolean): Promise<void> {
if (this.model.setPinned(compositeId, true)) { if (this.model.setPinned(compositeId, true)) {
this.updateCompositeSwitcher(); this.updateCompositeSwitcher();
if (open) { if (open) {
this.options.openComposite(compositeId).then(() => this.activateComposite(compositeId)); // Activate after opening await this.options.openComposite(compositeId);
this.activateComposite(compositeId); // Activate after opening
} }
} }
} }

View File

@@ -74,44 +74,33 @@ export abstract class BaseBinaryResourceEditor extends BaseEditor {
parent.appendChild(this.scrollbar.getDomNode()); parent.appendChild(this.scrollbar.getDomNode());
} }
setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> { async setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
return super.setInput(input, options, token).then(() => { await super.setInput(input, options, token);
return input.resolve().then(model => { const model = await input.resolve();
// Check for cancellation // Check for cancellation
if (token.isCancellationRequested) { if (token.isCancellationRequested) {
return undefined; return;
} }
// Assert Model instance // Assert Model instance
if (!(model instanceof BinaryEditorModel)) { if (!(model instanceof BinaryEditorModel)) {
return Promise.reject(new Error('Unable to open file as binary')); throw new Error('Unable to open file as binary');
} }
// Render Input // Render Input
this.resourceViewerContext = ResourceViewer.show( this.resourceViewerContext = ResourceViewer.show({ name: model.getName(), resource: model.getResource(), size: model.getSize(), etag: model.getETag(), mime: model.getMime() }, this.textFileService, this.binaryContainer, this.scrollbar, {
{ name: model.getName(), resource: model.getResource(), size: model.getSize(), etag: model.getETag(), mime: model.getMime() }, openInternalClb: () => this.handleOpenInternalCallback(input, options),
this.textFileService, openExternalClb: this.environmentService.configuration.remoteAuthority ? undefined : resource => this.callbacks.openExternal(resource),
this.binaryContainer, metadataClb: meta => this.handleMetadataChanged(meta)
this.scrollbar,
{
openInternalClb: _ => this.handleOpenInternalCallback(input, options),
openExternalClb: this.environmentService.configuration.remoteAuthority ? undefined : resource => this.callbacks.openExternal(resource),
metadataClb: meta => this.handleMetadataChanged(meta)
}
);
return undefined;
});
}); });
} }
private handleOpenInternalCallback(input: EditorInput, options: EditorOptions) { private async handleOpenInternalCallback(input: EditorInput, options: EditorOptions): Promise<void> {
this.callbacks.openInternal(input, options).then(() => { await this.callbacks.openInternal(input, options);
// Signal to listeners that the binary editor has been opened in-place // Signal to listeners that the binary editor has been opened in-place
this._onDidOpenInPlace.fire(); this._onDidOpenInPlace.fire();
});
} }
private handleMetadataChanged(meta: string | undefined): void { private handleMetadataChanged(meta: string | undefined): void {

View File

@@ -539,23 +539,27 @@ export class RevertAndCloseEditorAction extends Action {
super(id, label); super(id, label);
} }
run(): Promise<any> { async run(): Promise<any> {
const activeControl = this.editorService.activeControl; const activeControl = this.editorService.activeControl;
if (activeControl) { if (activeControl) {
const editor = activeControl.input; const editor = activeControl.input;
const group = activeControl.group; const group = activeControl.group;
// first try a normal revert where the contents of the editor are restored // first try a normal revert where the contents of the editor are restored
return editor.revert().then(() => group.closeEditor(editor), error => { try {
await editor.revert();
} catch (error) {
// if that fails, since we are about to close the editor, we accept that // if that fails, since we are about to close the editor, we accept that
// the editor cannot be reverted and instead do a soft revert that just // the editor cannot be reverted and instead do a soft revert that just
// enables us to close the editor. With this, a user can always close a // enables us to close the editor. With this, a user can always close a
// dirty editor even when reverting fails. // dirty editor even when reverting fails.
return editor.revert({ soft: true }).then(() => group.closeEditor(editor)); await editor.revert({ soft: true });
}); }
group.closeEditor(editor);
} }
return Promise.resolve(false); return true;
} }
} }
@@ -618,7 +622,7 @@ export abstract class BaseCloseAllAction extends Action {
return groupsToClose; return groupsToClose;
} }
run(): Promise<any> { async run(): Promise<any> {
// Just close all if there are no or one dirty editor // Just close all if there are no or one dirty editor
if (this.textFileService.getDirty().length < 2) { if (this.textFileService.getDirty().length < 2) {
@@ -626,26 +630,23 @@ export abstract class BaseCloseAllAction extends Action {
} }
// Otherwise ask for combined confirmation // Otherwise ask for combined confirmation
return this.textFileService.confirmSave().then(confirm => { const confirm = await this.textFileService.confirmSave();
if (confirm === ConfirmResult.CANCEL) { if (confirm === ConfirmResult.CANCEL) {
return undefined; return;
} }
let saveOrRevertPromise: Promise<boolean>; let saveOrRevert: boolean;
if (confirm === ConfirmResult.DONT_SAVE) { if (confirm === ConfirmResult.DONT_SAVE) {
saveOrRevertPromise = this.textFileService.revertAll(undefined, { soft: true }).then(() => true); await this.textFileService.revertAll(undefined, { soft: true });
} else { saveOrRevert = true;
saveOrRevertPromise = this.textFileService.saveAll(true).then(res => res.results.every(r => !!r.success)); } else {
} const res = await this.textFileService.saveAll(true);
saveOrRevert = res.results.every(r => !!r.success);
}
return saveOrRevertPromise.then(success => { if (saveOrRevert) {
if (success) { return this.doCloseAll();
return this.doCloseAll(); }
}
return undefined;
});
});
} }
protected abstract doCloseAll(): Promise<any>; protected abstract doCloseAll(): Promise<any>;
@@ -684,10 +685,10 @@ export class CloseAllEditorGroupsAction extends BaseCloseAllAction {
super(id, label, undefined, textFileService, editorGroupService); super(id, label, undefined, textFileService, editorGroupService);
} }
protected doCloseAll(): Promise<any> { protected async doCloseAll(): Promise<any> {
return Promise.all(this.groupsToClose.map(g => g.closeAllEditors())).then(() => { await Promise.all(this.groupsToClose.map(group => group.closeAllEditors()));
this.groupsToClose.forEach(group => this.editorGroupService.removeGroup(group));
}); this.groupsToClose.forEach(group => this.editorGroupService.removeGroup(group));
} }
} }

View File

@@ -670,19 +670,17 @@ function registerCloseEditorCommands() {
} }
}); });
CommandsRegistry.registerCommand(CLOSE_EDITORS_AND_GROUP_COMMAND_ID, (accessor: ServicesAccessor, resourceOrContext: URI | IEditorCommandsContext, context?: IEditorCommandsContext) => { CommandsRegistry.registerCommand(CLOSE_EDITORS_AND_GROUP_COMMAND_ID, async (accessor: ServicesAccessor, resourceOrContext: URI | IEditorCommandsContext, context?: IEditorCommandsContext) => {
const editorGroupService = accessor.get(IEditorGroupsService); const editorGroupService = accessor.get(IEditorGroupsService);
const { group } = resolveCommandsContext(editorGroupService, getCommandsContext(resourceOrContext, context)); const { group } = resolveCommandsContext(editorGroupService, getCommandsContext(resourceOrContext, context));
if (group) { if (group) {
return group.closeAllEditors().then(() => { await group.closeAllEditors();
if (group.count === 0 && editorGroupService.getGroup(group.id) /* could be gone by now */) {
editorGroupService.removeGroup(group); // only remove group if it is now empty
}
});
}
return undefined; if (group.count === 0 && editorGroupService.getGroup(group.id) /* could be gone by now */) {
editorGroupService.removeGroup(group); // only remove group if it is now empty
}
}
}); });
} }

View File

@@ -58,7 +58,7 @@ export class EditorControl extends Disposable {
return this._activeControl as IVisibleEditor | null; return this._activeControl as IVisibleEditor | null;
} }
openEditor(editor: EditorInput, options?: EditorOptions): Promise<IOpenEditorResult> { async openEditor(editor: EditorInput, options?: EditorOptions): Promise<IOpenEditorResult> {
// Editor control // Editor control
const descriptor = Registry.as<IEditorRegistry>(EditorExtensions.Editors).getEditor(editor); const descriptor = Registry.as<IEditorRegistry>(EditorExtensions.Editors).getEditor(editor);
@@ -68,7 +68,8 @@ export class EditorControl extends Disposable {
const control = this.doShowEditorControl(descriptor); const control = this.doShowEditorControl(descriptor);
// Set input // Set input
return this.doSetInput(control, editor, withUndefinedAsNull(options)).then((editorChanged => (({ control, editorChanged })))); const editorChanged = await this.doSetInput(control, editor, withUndefinedAsNull(options));
return { control, editorChanged };
} }
private doShowEditorControl(descriptor: IEditorDescriptor): BaseEditor { private doShowEditorControl(descriptor: IEditorDescriptor): BaseEditor {
@@ -150,7 +151,7 @@ export class EditorControl extends Disposable {
this._onDidSizeConstraintsChange.fire(undefined); this._onDidSizeConstraintsChange.fire(undefined);
} }
private doSetInput(control: BaseEditor, editor: EditorInput, options: EditorOptions | null): Promise<boolean> { private async doSetInput(control: BaseEditor, editor: EditorInput, options: EditorOptions | null): Promise<boolean> {
// If the input did not change, return early and only apply the options // If the input did not change, return early and only apply the options
// unless the options instruct us to force open it even if it is the same // unless the options instruct us to force open it even if it is the same
@@ -167,7 +168,7 @@ export class EditorControl extends Disposable {
control.focus(); control.focus();
} }
return Promise.resolve(false); return false;
} }
// Show progress while setting input after a certain timeout. If the workbench is opening // Show progress while setting input after a certain timeout. If the workbench is opening
@@ -176,7 +177,8 @@ export class EditorControl extends Disposable {
// Call into editor control // Call into editor control
const editorWillChange = !inputMatches; const editorWillChange = !inputMatches;
return control.setInput(editor, options, operation.token).then(() => { try {
await control.setInput(editor, options, operation.token);
// Focus (unless prevented or another operation is running) // Focus (unless prevented or another operation is running)
if (operation.isCurrent()) { if (operation.isCurrent()) {
@@ -186,17 +188,10 @@ export class EditorControl extends Disposable {
} }
} }
// Operation done
operation.stop();
return editorWillChange; return editorWillChange;
}, e => { } finally {
// Operation done
operation.stop(); operation.stop();
}
return Promise.reject(e);
});
} }
private doHideActiveEditorControl(): void { private doHideActiveEditorControl(): void {

View File

@@ -406,7 +406,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
} }
} }
private restoreEditors(from: IEditorGroupView | ISerializedEditorGroup): Promise<void> { private async restoreEditors(from: IEditorGroupView | ISerializedEditorGroup): Promise<void> {
if (this._group.count === 0) { if (this._group.count === 0) {
return Promise.resolve(); // nothing to show return Promise.resolve(); // nothing to show
} }
@@ -430,16 +430,15 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
const activeElement = document.activeElement; const activeElement = document.activeElement;
// Show active editor // Show active editor
return this.doShowEditor(activeEditor, true, options).then(() => { await this.doShowEditor(activeEditor, true, options);
// Set focused now if this is the active group and focus has // Set focused now if this is the active group and focus has
// not changed meanwhile. This prevents focus from being // not changed meanwhile. This prevents focus from being
// stolen accidentally on startup when the user already // stolen accidentally on startup when the user already
// clicked somewhere. // clicked somewhere.
if (this.accessor.activeGroup === this && activeElement === document.activeElement) { if (this.accessor.activeGroup === this && activeElement === document.activeElement) {
this.focus(); this.focus();
} }
});
} }
//#region event handling //#region event handling
@@ -821,34 +820,33 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
return this.doShowEditor(editor, !!openEditorOptions.active, options); return this.doShowEditor(editor, !!openEditorOptions.active, options);
} }
private doShowEditor(editor: EditorInput, active: boolean, options?: EditorOptions): Promise<IEditor | null> { private async doShowEditor(editor: EditorInput, active: boolean, options?: EditorOptions): Promise<IEditor | null> {
// Show in editor control if the active editor changed // Show in editor control if the active editor changed
let openEditorPromise: Promise<IEditor | null>; let openEditor: IEditor | null = null;
if (active) { if (active) {
openEditorPromise = this.editorControl.openEditor(editor, options).then(result => { try {
const result = await this.editorControl.openEditor(editor, options);
// Editor change event // Editor change event
if (result.editorChanged) { if (result.editorChanged) {
this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_ACTIVE, editor }); this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_ACTIVE, editor });
} }
return result.control; openEditor = result.control;
}, error => { } catch (error) {
// Handle errors but do not bubble them up // Handle errors but do not bubble them up
this.doHandleOpenEditorError(error, editor, options); this.doHandleOpenEditorError(error, editor, options);
}
return null; // error: return NULL as result to signal this
});
} else { } else {
openEditorPromise = Promise.resolve(null); // inactive: return NULL as result to signal this openEditor = null; // inactive: return NULL as result to signal this
} }
// Show in title control after editor control because some actions depend on it // Show in title control after editor control because some actions depend on it
this.titleAreaControl.openEditor(editor); this.titleAreaControl.openEditor(editor);
return openEditorPromise; return openEditor;
} }
private doHandleOpenEditorError(error: Error, editor: EditorInput, options?: EditorOptions): void { private doHandleOpenEditorError(error: Error, editor: EditorInput, options?: EditorOptions): void {
@@ -884,37 +882,33 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
//#region openEditors() //#region openEditors()
openEditors(editors: { editor: EditorInput, options?: EditorOptions }[]): Promise<IEditor | null> { async openEditors(editors: { editor: EditorInput, options?: EditorOptions }[]): Promise<IEditor | null> {
if (!editors.length) { if (!editors.length) {
return Promise.resolve(null); return null;
} }
// Do not modify original array // Do not modify original array
editors = editors.slice(0); editors = editors.slice(0);
let result: IEditor | null;
// Use the first editor as active editor // Use the first editor as active editor
const { editor, options } = editors.shift()!; const { editor, options } = editors.shift()!;
return this.openEditor(editor, options).then(activeEditor => { let firstEditor = await this.openEditor(editor, options);
result = activeEditor; // this can be NULL if the opening failed
const startingIndex = this.getIndexOfEditor(editor) + 1; // Open the other ones inactive
const startingIndex = this.getIndexOfEditor(editor) + 1;
await Promise.all(editors.map(async ({ editor, options }, index) => {
const adjustedEditorOptions = options || new EditorOptions();
adjustedEditorOptions.inactive = true;
adjustedEditorOptions.pinned = true;
adjustedEditorOptions.index = startingIndex + index;
// Open the other ones inactive const openedEditor = await this.openEditor(editor, adjustedEditorOptions);
return Promise.all(editors.map(({ editor, options }, index) => { if (!firstEditor) {
const adjustedEditorOptions = options || new EditorOptions(); firstEditor = openedEditor; // only take if the first editor opening failed
adjustedEditorOptions.inactive = true; }
adjustedEditorOptions.pinned = true; }));
adjustedEditorOptions.index = startingIndex + index;
return this.openEditor(editor, adjustedEditorOptions).then(activeEditor => { return firstEditor;
if (!result) {
result = activeEditor; // only take if the first editor opening failed
}
});
})).then(() => result);
});
} }
//#endregion //#endregion
@@ -995,20 +989,19 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
//#region closeEditor() //#region closeEditor()
closeEditor(editor: EditorInput | undefined = this.activeEditor || undefined, options?: ICloseEditorOptions): Promise<void> { async closeEditor(editor: EditorInput | undefined = this.activeEditor || undefined, options?: ICloseEditorOptions): Promise<void> {
if (!editor) { if (!editor) {
return Promise.resolve(); return;
} }
// Check for dirty and veto // Check for dirty and veto
return this.handleDirty([editor]).then(veto => { const veto = await this.handleDirty([editor]);
if (veto) { if (veto) {
return; return;
} }
// Do close // Do close
this.doCloseEditor(editor, options && options.preserveFocus ? false : undefined); this.doCloseEditor(editor, options && options.preserveFocus ? false : undefined);
});
} }
private doCloseEditor(editor: EditorInput, focusNext = (this.accessor.activeGroup === this), fromError?: boolean): void { private doCloseEditor(editor: EditorInput, focusNext = (this.accessor.activeGroup === this), fromError?: boolean): void {
@@ -1113,7 +1106,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
this._group.closeEditor(editor); this._group.closeEditor(editor);
} }
private handleDirty(editors: EditorInput[]): Promise<boolean /* veto */> { private async handleDirty(editors: EditorInput[]): Promise<boolean /* veto */> {
if (!editors.length) { if (!editors.length) {
return Promise.resolve(false); // no veto return Promise.resolve(false); // no veto
} }
@@ -1128,22 +1121,21 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
this.mapEditorToPendingConfirmation.set(editor, handleDirtyPromise); this.mapEditorToPendingConfirmation.set(editor, handleDirtyPromise);
} }
return handleDirtyPromise.then(veto => { const veto = await handleDirtyPromise;
// Make sure to remove from our map of cached pending confirmations // Make sure to remove from our map of cached pending confirmations
this.mapEditorToPendingConfirmation.delete(editor); this.mapEditorToPendingConfirmation.delete(editor);
// Return for the first veto we got // Return for the first veto we got
if (veto) { if (veto) {
return veto; return veto;
} }
// Otherwise continue with the remainders // Otherwise continue with the remainders
return this.handleDirty(editors); return this.handleDirty(editors);
});
} }
private doHandleDirty(editor: EditorInput): Promise<boolean /* veto */> { private async doHandleDirty(editor: EditorInput): Promise<boolean /* veto */> {
if ( if (
!editor.isDirty() || // editor must be dirty !editor.isDirty() || // editor must be dirty
this.accessor.groups.some(groupView => groupView !== this && groupView.group.contains(editor, true /* support side by side */)) || // editor is opened in other group this.accessor.groups.some(groupView => groupView !== this && groupView.group.contains(editor, true /* support side by side */)) || // editor is opened in other group
@@ -1153,59 +1145,65 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
} }
// Switch to editor that we want to handle and confirm to save/revert // Switch to editor that we want to handle and confirm to save/revert
return this.openEditor(editor).then(() => editor.confirmSave().then(res => { await this.openEditor(editor);
// It could be that the editor saved meanwhile, so we check again const res = await editor.confirmSave();
// to see if anything needs to happen before closing for good.
// This can happen for example if autoSave: onFocusChange is configured
// so that the save happens when the dialog opens.
if (!editor.isDirty()) {
return res === ConfirmResult.CANCEL ? true : false;
}
// Otherwise, handle accordingly // It could be that the editor saved meanwhile, so we check again
switch (res) { // to see if anything needs to happen before closing for good.
case ConfirmResult.SAVE: // This can happen for example if autoSave: onFocusChange is configured
return editor.save().then(ok => !ok); // so that the save happens when the dialog opens.
if (!editor.isDirty()) {
return res === ConfirmResult.CANCEL ? true : false;
}
case ConfirmResult.DONT_SAVE: // Otherwise, handle accordingly
switch (res) {
case ConfirmResult.SAVE:
const result = await editor.save();
return !result;
case ConfirmResult.DONT_SAVE:
try {
// first try a normal revert where the contents of the editor are restored // first try a normal revert where the contents of the editor are restored
return editor.revert().then(ok => !ok, error => { const result = await editor.revert();
// if that fails, since we are about to close the editor, we accept that return !result;
// the editor cannot be reverted and instead do a soft revert that just } catch (error) {
// enables us to close the editor. With this, a user can always close a // if that fails, since we are about to close the editor, we accept that
// dirty editor even when reverting fails. // the editor cannot be reverted and instead do a soft revert that just
return editor.revert({ soft: true }).then(ok => !ok); // enables us to close the editor. With this, a user can always close a
}); // dirty editor even when reverting fails.
const result = await editor.revert({ soft: true });
case ConfirmResult.CANCEL: return !result;
return true; // veto }
} case ConfirmResult.CANCEL:
})); return true; // veto
}
} }
//#endregion //#endregion
//#region closeEditors() //#region closeEditors()
closeEditors(args: EditorInput[] | ICloseEditorsFilter, options?: ICloseEditorOptions): Promise<void> { async closeEditors(args: EditorInput[] | ICloseEditorsFilter, options?: ICloseEditorOptions): Promise<void> {
if (this.isEmpty()) { if (this.isEmpty()) {
return Promise.resolve(); return;
} }
const editors = this.getEditorsToClose(args); const editors = this.getEditorsToClose(args);
// Check for dirty and veto // Check for dirty and veto
return this.handleDirty(editors.slice(0)).then(veto => { const veto = await this.handleDirty(editors.slice(0));
if (veto) { if (veto) {
return; return;
} }
// Do close // Do close
this.doCloseEditors(editors, options); this.doCloseEditors(editors, options);
});
} }
private getEditorsToClose(editors: EditorInput[] | ICloseEditorsFilter): EditorInput[] { private getEditorsToClose(editors: EditorInput[] | ICloseEditorsFilter): EditorInput[] {
@@ -1263,7 +1261,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
//#region closeAllEditors() //#region closeAllEditors()
closeAllEditors(): Promise<void> { async closeAllEditors(): Promise<void> {
if (this.isEmpty()) { if (this.isEmpty()) {
// If the group is empty and the request is to close all editors, we still close // If the group is empty and the request is to close all editors, we still close
@@ -1273,19 +1271,18 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
this.accessor.removeGroup(this); this.accessor.removeGroup(this);
} }
return Promise.resolve(); return;
} }
// Check for dirty and veto // Check for dirty and veto
const editors = this._group.getEditors(true); const editors = this._group.getEditors(true);
return this.handleDirty(editors.slice(0)).then(veto => { const veto = await this.handleDirty(editors.slice(0));
if (veto) { if (veto) {
return; return;
} }
// Do close // Do close
this.doCloseAllEditors(); this.doCloseAllEditors();
});
} }
private doCloseAllEditors(): void { private doCloseAllEditors(): void {
@@ -1308,7 +1305,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
//#region replaceEditors() //#region replaceEditors()
replaceEditors(editors: EditorReplacement[]): Promise<void> { async replaceEditors(editors: EditorReplacement[]): Promise<void> {
// Extract active vs. inactive replacements // Extract active vs. inactive replacements
let activeReplacement: EditorReplacement | undefined; let activeReplacement: EditorReplacement | undefined;
@@ -1366,10 +1363,8 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
this.titleAreaControl.closeEditor(activeReplacement.editor); this.titleAreaControl.closeEditor(activeReplacement.editor);
} }
return openEditorResult.then(() => undefined); await openEditorResult;
} }
return Promise.resolve();
} }
//#endregion //#endregion

View File

@@ -858,8 +858,8 @@ export class ShowLanguageExtensionsAction extends Action {
this.enabled = galleryService.isEnabled(); this.enabled = galleryService.isEnabled();
} }
run(): Promise<void> { async run(): Promise<void> {
return this.commandService.executeCommand('workbench.extensions.action.showExtensionsForLanguage', this.fileExtension).then(() => undefined); await this.commandService.executeCommand('workbench.extensions.action.showExtensionsForLanguage', this.fileExtension);
} }
} }
@@ -883,7 +883,7 @@ export class ChangeModeAction extends Action {
super(actionId, actionLabel); super(actionId, actionLabel);
} }
run(): Promise<any> { async run(): Promise<any> {
const activeTextEditorWidget = getCodeEditor(this.editorService.activeTextEditorWidget); const activeTextEditorWidget = getCodeEditor(this.editorService.activeTextEditorWidget);
if (!activeTextEditorWidget) { if (!activeTextEditorWidget) {
return this.quickInputService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]); return this.quickInputService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
@@ -1038,31 +1038,30 @@ export class ChangeModeAction extends Action {
}; };
}); });
setTimeout(() => { setTimeout(async () => {
this.quickInputService.pick(picks, { placeHolder: nls.localize('pickLanguageToConfigure', "Select Language Mode to Associate with '{0}'", extension || base) }).then(language => { const language = await this.quickInputService.pick(picks, { placeHolder: nls.localize('pickLanguageToConfigure', "Select Language Mode to Associate with '{0}'", extension || base) });
if (language) { if (language) {
const fileAssociationsConfig = this.configurationService.inspect<{}>(FILES_ASSOCIATIONS_CONFIG); const fileAssociationsConfig = this.configurationService.inspect<{}>(FILES_ASSOCIATIONS_CONFIG);
let associationKey: string; let associationKey: string;
if (extension && base[0] !== '.') { if (extension && base[0] !== '.') {
associationKey = `*${extension}`; // only use "*.ext" if the file path is in the form of <name>.<ext> associationKey = `*${extension}`; // only use "*.ext" if the file path is in the form of <name>.<ext>
} else { } else {
associationKey = base; // otherwise use the basename (e.g. .gitignore, Dockerfile) associationKey = base; // otherwise use the basename (e.g. .gitignore, Dockerfile)
}
// If the association is already being made in the workspace, make sure to target workspace settings
let target = ConfigurationTarget.USER;
if (fileAssociationsConfig.workspace && !!fileAssociationsConfig.workspace[associationKey]) {
target = ConfigurationTarget.WORKSPACE;
}
// Make sure to write into the value of the target and not the merged value from USER and WORKSPACE config
const currentAssociations = deepClone((target === ConfigurationTarget.WORKSPACE) ? fileAssociationsConfig.workspace : fileAssociationsConfig.user) || Object.create(null);
currentAssociations[associationKey] = language.id;
this.configurationService.updateValue(FILES_ASSOCIATIONS_CONFIG, currentAssociations, target);
} }
});
// If the association is already being made in the workspace, make sure to target workspace settings
let target = ConfigurationTarget.USER;
if (fileAssociationsConfig.workspace && !!fileAssociationsConfig.workspace[associationKey]) {
target = ConfigurationTarget.WORKSPACE;
}
// Make sure to write into the value of the target and not the merged value from USER and WORKSPACE config
const currentAssociations = deepClone((target === ConfigurationTarget.WORKSPACE) ? fileAssociationsConfig.workspace : fileAssociationsConfig.user) || Object.create(null);
currentAssociations[associationKey] = language.id;
this.configurationService.updateValue(FILES_ASSOCIATIONS_CONFIG, currentAssociations, target);
}
}, 50 /* quick open is sensitive to being opened so soon after another */); }, 50 /* quick open is sensitive to being opened so soon after another */);
} }
} }
@@ -1085,7 +1084,7 @@ class ChangeIndentationAction extends Action {
super(actionId, actionLabel); super(actionId, actionLabel);
} }
run(): Promise<any> { async run(): Promise<any> {
const activeTextEditorWidget = getCodeEditor(this.editorService.activeTextEditorWidget); const activeTextEditorWidget = getCodeEditor(this.editorService.activeTextEditorWidget);
if (!activeTextEditorWidget) { if (!activeTextEditorWidget) {
return this.quickInputService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]); return this.quickInputService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
@@ -1117,7 +1116,8 @@ class ChangeIndentationAction extends Action {
picks.splice(3, 0, { type: 'separator', label: nls.localize('indentConvert', "convert file") }); picks.splice(3, 0, { type: 'separator', label: nls.localize('indentConvert', "convert file") });
picks.unshift({ type: 'separator', label: nls.localize('indentView', "change view") }); picks.unshift({ type: 'separator', label: nls.localize('indentView', "change view") });
return this.quickInputService.pick(picks, { placeHolder: nls.localize('pickAction', "Select Action"), matchOnDetail: true }).then(action => action && action.run()); const action = await this.quickInputService.pick(picks, { placeHolder: nls.localize('pickAction', "Select Action"), matchOnDetail: true });
return action && action.run();
} }
} }
@@ -1135,7 +1135,7 @@ export class ChangeEOLAction extends Action {
super(actionId, actionLabel); super(actionId, actionLabel);
} }
run(): Promise<any> { async run(): Promise<any> {
const activeTextEditorWidget = getCodeEditor(this.editorService.activeTextEditorWidget); const activeTextEditorWidget = getCodeEditor(this.editorService.activeTextEditorWidget);
if (!activeTextEditorWidget) { if (!activeTextEditorWidget) {
return this.quickInputService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]); return this.quickInputService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
@@ -1145,7 +1145,7 @@ export class ChangeEOLAction extends Action {
return this.quickInputService.pick([{ label: nls.localize('noWritableCodeEditor', "The active code editor is read-only.") }]); return this.quickInputService.pick([{ label: nls.localize('noWritableCodeEditor', "The active code editor is read-only.") }]);
} }
const textModel = activeTextEditorWidget.getModel(); let textModel = activeTextEditorWidget.getModel();
const EOLOptions: IChangeEOLEntry[] = [ const EOLOptions: IChangeEOLEntry[] = [
{ label: nlsEOLLF, eol: EndOfLineSequence.LF }, { label: nlsEOLLF, eol: EndOfLineSequence.LF },
@@ -1154,15 +1154,14 @@ export class ChangeEOLAction extends Action {
const selectedIndex = (textModel && textModel.getEOL() === '\n') ? 0 : 1; const selectedIndex = (textModel && textModel.getEOL() === '\n') ? 0 : 1;
return this.quickInputService.pick(EOLOptions, { placeHolder: nls.localize('pickEndOfLine', "Select End of Line Sequence"), activeItem: EOLOptions[selectedIndex] }).then(eol => { const eol = await this.quickInputService.pick(EOLOptions, { placeHolder: nls.localize('pickEndOfLine', "Select End of Line Sequence"), activeItem: EOLOptions[selectedIndex] });
if (eol) { if (eol) {
const activeCodeEditor = getCodeEditor(this.editorService.activeTextEditorWidget); const activeCodeEditor = getCodeEditor(this.editorService.activeTextEditorWidget);
if (activeCodeEditor && activeCodeEditor.hasModel() && isWritableCodeEditor(activeCodeEditor)) { if (activeCodeEditor && activeCodeEditor.hasModel() && isWritableCodeEditor(activeCodeEditor)) {
const textModel = activeCodeEditor.getModel(); textModel = activeCodeEditor.getModel();
textModel.pushEOL(eol.eol); textModel.pushEOL(eol.eol);
}
} }
}); }
} }
} }

View File

@@ -567,16 +567,15 @@ class InlineImageView {
return context; return context;
} }
private static imageSrc(descriptor: IResourceDescriptor, textFileService: ITextFileService): Promise<string> { private static async imageSrc(descriptor: IResourceDescriptor, textFileService: ITextFileService): Promise<string> {
if (descriptor.resource.scheme === Schemas.data) { if (descriptor.resource.scheme === Schemas.data) {
return Promise.resolve(descriptor.resource.toString(true /* skip encoding */)); return Promise.resolve(descriptor.resource.toString(true /* skip encoding */));
} }
return textFileService.read(descriptor.resource, { encoding: 'base64' }).then(data => { const data = await textFileService.read(descriptor.resource, { encoding: 'base64' });
const mime = getMime(descriptor); const mime = getMime(descriptor);
return `data:${mime};base64,${data.value}`; return `data:${mime};base64,${data.value}`;
});
} }
} }

View File

@@ -93,10 +93,11 @@ export class SideBySideEditor extends BaseEditor {
this.updateStyles(); this.updateStyles();
} }
setInput(newInput: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> { async setInput(newInput: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
const oldInput = this.input as SideBySideEditorInput; const oldInput = this.input as SideBySideEditorInput;
return super.setInput(newInput, options, token) await super.setInput(newInput, options, token);
.then(() => this.updateInput(oldInput, newInput as SideBySideEditorInput, options, token));
return this.updateInput(oldInput, (newInput as SideBySideEditorInput), options, token);
} }
setOptions(options: EditorOptions): void { setOptions(options: EditorOptions): void {
@@ -158,7 +159,7 @@ export class SideBySideEditor extends BaseEditor {
return this.detailsEditor; return this.detailsEditor;
} }
private updateInput(oldInput: SideBySideEditorInput, newInput: SideBySideEditorInput, options: EditorOptions, token: CancellationToken): Promise<void> { private async updateInput(oldInput: SideBySideEditorInput, newInput: SideBySideEditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
if (!newInput.matches(oldInput)) { if (!newInput.matches(oldInput)) {
if (oldInput) { if (oldInput) {
this.disposeEditors(); this.disposeEditors();
@@ -166,14 +167,15 @@ export class SideBySideEditor extends BaseEditor {
return this.setNewInput(newInput, options, token); return this.setNewInput(newInput, options, token);
} }
if (!this.detailsEditor || !this.masterEditor) { if (!this.detailsEditor || !this.masterEditor) {
return Promise.resolve(); return Promise.resolve();
} }
return Promise.all([ await Promise.all([
this.detailsEditor.setInput(newInput.details, null, token), this.detailsEditor.setInput(newInput.details, null, token),
this.masterEditor.setInput(newInput.master, options, token)] this.masterEditor.setInput(newInput.master, options, token)
).then(() => undefined); ]);
} }
private setNewInput(newInput: SideBySideEditorInput, options: EditorOptions, token: CancellationToken): Promise<void> { private setNewInput(newInput: SideBySideEditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
@@ -196,7 +198,7 @@ export class SideBySideEditor extends BaseEditor {
return editor; return editor;
} }
private onEditorsCreated(details: BaseEditor, master: BaseEditor, detailsInput: EditorInput, masterInput: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> { private async onEditorsCreated(details: BaseEditor, master: BaseEditor, detailsInput: EditorInput, masterInput: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
this.detailsEditor = details; this.detailsEditor = details;
this.masterEditor = master; this.masterEditor = master;
@@ -207,7 +209,12 @@ export class SideBySideEditor extends BaseEditor {
this.onDidCreateEditors.fire(undefined); this.onDidCreateEditors.fire(undefined);
return Promise.all([this.detailsEditor.setInput(detailsInput, null, token), this.masterEditor.setInput(masterInput, options, token)]).then(() => this.focus()); await Promise.all([
this.detailsEditor.setInput(detailsInput, null, token),
this.masterEditor.setInput(masterInput, options, token)]
);
return this.focus();
} }
updateStyles(): void { updateStyles(): void {

View File

@@ -84,7 +84,7 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
return this.instantiationService.createInstance(DiffEditorWidget, parent, configuration); return this.instantiationService.createInstance(DiffEditorWidget, parent, configuration);
} }
setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> { async setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
// Dispose previous diff navigator // Dispose previous diff navigator
this.diffNavigatorDisposables = dispose(this.diffNavigatorDisposables); this.diffNavigatorDisposables = dispose(this.diffNavigatorDisposables);
@@ -93,56 +93,55 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
this.saveTextDiffEditorViewState(this.input); this.saveTextDiffEditorViewState(this.input);
// Set input and resolve // Set input and resolve
return super.setInput(input, options, token).then(() => { await super.setInput(input, options, token);
return input.resolve().then(resolvedModel => {
// Check for cancellation try {
if (token.isCancellationRequested) { const resolvedModel = await input.resolve();
return undefined;
}
// Assert Model Instance // Check for cancellation
if (!(resolvedModel instanceof TextDiffEditorModel) && this.openAsBinary(input, options)) { if (token.isCancellationRequested) {
return undefined;
}
// Set Editor Model
const diffEditor = this.getControl();
const resolvedDiffEditorModel = <TextDiffEditorModel>resolvedModel;
diffEditor.setModel(resolvedDiffEditorModel.textDiffEditorModel);
// Apply Options from TextOptions
let optionsGotApplied = false;
if (options && types.isFunction((<TextEditorOptions>options).apply)) {
optionsGotApplied = (<TextEditorOptions>options).apply(diffEditor, ScrollType.Immediate);
}
// Otherwise restore View State
let hasPreviousViewState = false;
if (!optionsGotApplied) {
hasPreviousViewState = this.restoreTextDiffEditorViewState(input);
}
// Diff navigator
this.diffNavigator = new DiffNavigator(diffEditor, {
alwaysRevealFirst: !optionsGotApplied && !hasPreviousViewState // only reveal first change if we had no options or viewstate
});
this.diffNavigatorDisposables.push(this.diffNavigator);
// Readonly flag
diffEditor.updateOptions({ readOnly: resolvedDiffEditorModel.isReadonly() });
return undefined; return undefined;
}, error => { }
// In case we tried to open a file and the response indicates that this is not a text file, fallback to binary diff. // Assert Model Instance
if (this.isFileBinaryError(error) && this.openAsBinary(input, options)) { if (!(resolvedModel instanceof TextDiffEditorModel) && this.openAsBinary(input, options)) {
return null; return undefined;
} }
// Otherwise make sure the error bubbles up // Set Editor Model
return Promise.reject(error); const diffEditor = this.getControl();
const resolvedDiffEditorModel = <TextDiffEditorModel>resolvedModel;
diffEditor.setModel(resolvedDiffEditorModel.textDiffEditorModel);
// Apply Options from TextOptions
let optionsGotApplied = false;
if (options && types.isFunction((<TextEditorOptions>options).apply)) {
optionsGotApplied = (<TextEditorOptions>options).apply(diffEditor, ScrollType.Immediate);
}
// Otherwise restore View State
let hasPreviousViewState = false;
if (!optionsGotApplied) {
hasPreviousViewState = this.restoreTextDiffEditorViewState(input);
}
// Diff navigator
this.diffNavigator = new DiffNavigator(diffEditor, {
alwaysRevealFirst: !optionsGotApplied && !hasPreviousViewState // only reveal first change if we had no options or viewstate
}); });
}); this.diffNavigatorDisposables.push(this.diffNavigator);
// Readonly flag
diffEditor.updateOptions({ readOnly: resolvedDiffEditorModel.isReadonly() });
} catch (error) {
// In case we tried to open a file and the response indicates that this is not a text file, fallback to binary diff.
if (this.isFileBinaryError(error) && this.openAsBinary(input, options)) {
return;
}
throw error;
}
} }
setOptions(options: EditorOptions): void { setOptions(options: EditorOptions): void {

View File

@@ -191,14 +191,13 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditor {
return this.instantiationService.createInstance(CodeEditorWidget, parent, configuration, {}); return this.instantiationService.createInstance(CodeEditorWidget, parent, configuration, {});
} }
setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> { async setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
return super.setInput(input, options, token).then(() => { await super.setInput(input, options, token);
// Update editor options after having set the input. We do this because there can be // Update editor options after having set the input. We do this because there can be
// editor input specific options (e.g. an ARIA label depending on the input showing) // editor input specific options (e.g. an ARIA label depending on the input showing)
this.updateEditorConfiguration(); this.updateEditorConfiguration();
this._editorContainer.setAttribute('aria-label', this.computeAriaLabel()); this._editorContainer.setAttribute('aria-label', this.computeAriaLabel());
});
} }
protected setEditorVisible(visible: boolean, group: IEditorGroup): void { protected setEditorVisible(visible: boolean, group: IEditorGroup): void {

View File

@@ -7,7 +7,7 @@ import * as nls from 'vs/nls';
import * as types from 'vs/base/common/types'; import * as types from 'vs/base/common/types';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { TextEditorOptions, EditorModel, EditorInput, EditorOptions } from 'vs/workbench/common/editor'; import { TextEditorOptions, EditorInput, EditorOptions } from 'vs/workbench/common/editor';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput'; import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel'; import { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel';
import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput'; import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput';
@@ -54,45 +54,41 @@ export class AbstractTextResourceEditor extends BaseTextEditor {
return nls.localize('textEditor', "Text Editor"); return nls.localize('textEditor', "Text Editor");
} }
setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> { async setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
// Remember view settings if input changes // Remember view settings if input changes
this.saveTextResourceEditorViewState(this.input); this.saveTextResourceEditorViewState(this.input);
// Set input and resolve // Set input and resolve
return super.setInput(input, options, token).then(() => { await super.setInput(input, options, token);
return input.resolve().then((resolvedModel: EditorModel) => { const resolvedModel = await input.resolve();
// Check for cancellation // Check for cancellation
if (token.isCancellationRequested) { if (token.isCancellationRequested) {
return undefined; return undefined;
} }
// Assert Model instance // Assert Model instance
if (!(resolvedModel instanceof BaseTextEditorModel)) { if (!(resolvedModel instanceof BaseTextEditorModel)) {
return Promise.reject(new Error('Unable to open file as text')); return Promise.reject(new Error('Unable to open file as text'));
} }
// Set Editor Model // Set Editor Model
const textEditor = this.getControl(); const textEditor = this.getControl();
const textEditorModel = resolvedModel.textEditorModel; const textEditorModel = resolvedModel.textEditorModel;
textEditor.setModel(textEditorModel); textEditor.setModel(textEditorModel);
// Apply Options from TextOptions // Apply Options from TextOptions
let optionsGotApplied = false; let optionsGotApplied = false;
const textOptions = <TextEditorOptions>options; const textOptions = <TextEditorOptions>options;
if (textOptions && types.isFunction(textOptions.apply)) { if (textOptions && types.isFunction(textOptions.apply)) {
optionsGotApplied = textOptions.apply(textEditor, ScrollType.Immediate); optionsGotApplied = textOptions.apply(textEditor, ScrollType.Immediate);
} }
// Otherwise restore View State // Otherwise restore View State
if (!optionsGotApplied) { if (!optionsGotApplied) {
this.restoreTextResourceEditorViewState(input); this.restoreTextResourceEditorViewState(input);
} }
return undefined;
});
});
} }
private restoreTextResourceEditorViewState(input: EditorInput) { private restoreTextResourceEditorViewState(input: EditorInput) {

View File

@@ -160,7 +160,7 @@ export class NotificationActionRunner extends ActionRunner {
super(); super();
} }
protected runAction(action: IAction, context: INotificationViewItem): Promise<any> { protected async runAction(action: IAction, context: INotificationViewItem): Promise<any> {
/* __GDPR__ /* __GDPR__
"workbenchActionExecuted" : { "workbenchActionExecuted" : {
@@ -171,8 +171,10 @@ export class NotificationActionRunner extends ActionRunner {
this.telemetryService.publicLog('workbenchActionExecuted', { id: action.id, from: 'message' }); this.telemetryService.publicLog('workbenchActionExecuted', { id: action.id, from: 'message' });
// Run and make sure to notify on any error again // Run and make sure to notify on any error again
super.runAction(action, context).then(undefined, error => this.notificationService.error(error)); try {
await super.runAction(action, context);
return Promise.resolve(); } catch (error) {
this.notificationService.error(error);
}
} }
} }

View File

@@ -93,18 +93,17 @@ export class NotificationsToasts extends Themable {
}); });
} }
private onCanShowNotifications(): Promise<void> { private async onCanShowNotifications(): Promise<void> {
// Wait for the running phase to ensure we can draw notifications properly // Wait for the running phase to ensure we can draw notifications properly
return this.lifecycleService.when(LifecyclePhase.Ready).then(() => { await this.lifecycleService.when(LifecyclePhase.Ready);
// Push notificiations out until either workbench is restored // Push notificiations out until either workbench is restored
// or some time has ellapsed to reduce pressure on the startup // or some time has ellapsed to reduce pressure on the startup
return Promise.race([ return Promise.race([
this.lifecycleService.when(LifecyclePhase.Restored), this.lifecycleService.when(LifecyclePhase.Restored),
timeout(2000) timeout(2000)
]); ]);
});
} }
private onDidNotificationChange(e: INotificationChangeEvent): void { private onDidNotificationChange(e: INotificationChangeEvent): void {

View File

@@ -259,8 +259,7 @@ export class QuickOpenController extends Component implements IQuickOpenService
// Pass to handlers // Pass to handlers
for (let prefix in this.mapResolvedHandlersToPrefix) { for (let prefix in this.mapResolvedHandlersToPrefix) {
const promise = this.mapResolvedHandlersToPrefix[prefix]; this.mapResolvedHandlersToPrefix[prefix].then(handler => {
promise.then(handler => {
this.handlerOnOpenCalled[prefix] = false; this.handlerOnOpenCalled[prefix] = false;
handler.onClose(reason === HideReason.CANCELED); // Don't check if onOpen was called to preserve old behaviour for now handler.onClose(reason === HideReason.CANCELED); // Don't check if onOpen was called to preserve old behaviour for now
@@ -429,7 +428,7 @@ export class QuickOpenController extends Component implements IQuickOpenService
}); });
} }
private handleDefaultHandler(handler: QuickOpenHandlerDescriptor, value: string, token: CancellationToken): Promise<void> { private async handleDefaultHandler(handler: QuickOpenHandlerDescriptor, value: string, token: CancellationToken): Promise<void> {
// Fill in history results if matching and we are configured to search in history // Fill in history results if matching and we are configured to search in history
let matchingHistoryEntries: QuickOpenEntry[]; let matchingHistoryEntries: QuickOpenEntry[];
@@ -444,47 +443,41 @@ export class QuickOpenController extends Component implements IQuickOpenService
} }
// Resolve // Resolve
return this.resolveHandler(handler).then(resolvedHandler => { const resolvedHandler = await this.resolveHandler(handler);
const quickOpenModel = new QuickOpenModel(matchingHistoryEntries, this.actionProvider);
let inputSet = false; const quickOpenModel = new QuickOpenModel(matchingHistoryEntries, this.actionProvider);
// If we have matching entries from history we want to show them directly and not wait for the other results to come in let inputSet = false;
// This also applies when we used to have entries from a previous run and now there are no more history results matching
const previousInput = this.quickOpenWidget.getInput();
const wasShowingHistory = previousInput && previousInput.entries && previousInput.entries.some(e => e instanceof EditorHistoryEntry || e instanceof EditorHistoryEntryGroup);
if (wasShowingHistory || matchingHistoryEntries.length > 0) {
let responseDelay: Promise<void>;
if (resolvedHandler.hasShortResponseTime()) {
responseDelay = timeout(QuickOpenController.MAX_SHORT_RESPONSE_TIME);
} else {
responseDelay = Promise.resolve();
}
responseDelay.then(() => { // If we have matching entries from history we want to show them directly and not wait for the other results to come in
if (!token.isCancellationRequested && !inputSet) { // This also applies when we used to have entries from a previous run and now there are no more history results matching
this.quickOpenWidget.setInput(quickOpenModel, { autoFocusFirstEntry: true }); const previousInput = this.quickOpenWidget.getInput();
inputSet = true; const wasShowingHistory = previousInput && previousInput.entries && previousInput.entries.some(e => e instanceof EditorHistoryEntry || e instanceof EditorHistoryEntryGroup);
} if (wasShowingHistory || matchingHistoryEntries.length > 0) {
}); if (resolvedHandler.hasShortResponseTime()) {
await timeout(QuickOpenController.MAX_SHORT_RESPONSE_TIME);
} }
// Get results if (!token.isCancellationRequested && !inputSet) {
return resolvedHandler.getResults(value, token).then(result => { this.quickOpenWidget.setInput(quickOpenModel, { autoFocusFirstEntry: true });
if (!token.isCancellationRequested) { inputSet = true;
}
}
// now is the time to show the input if we did not have set it before // Get results
if (!inputSet) { const result = await resolvedHandler.getResults(value, token);
this.quickOpenWidget.setInput(quickOpenModel, { autoFocusFirstEntry: true }); if (!token.isCancellationRequested) {
inputSet = true;
}
// merge history and default handler results // now is the time to show the input if we did not have set it before
const handlerResults = (result && result.entries) || []; if (!inputSet) {
this.mergeResults(quickOpenModel, handlerResults, types.withNullAsUndefined(resolvedHandler.getGroupLabel())); this.quickOpenWidget.setInput(quickOpenModel, { autoFocusFirstEntry: true });
} inputSet = true;
}); }
});
// merge history and default handler results
const handlerResults = (result && result.entries) || [];
this.mergeResults(quickOpenModel, handlerResults, types.withNullAsUndefined(resolvedHandler.getGroupLabel()));
}
} }
private mergeResults(quickOpenModel: QuickOpenModel, handlerResults: QuickOpenEntry[], groupLabel: string | undefined): void { private mergeResults(quickOpenModel: QuickOpenModel, handlerResults: QuickOpenEntry[], groupLabel: string | undefined): void {
@@ -516,46 +509,44 @@ export class QuickOpenController extends Component implements IQuickOpenService
} }
} }
private handleSpecificHandler(handlerDescriptor: QuickOpenHandlerDescriptor, value: string, token: CancellationToken): Promise<void> { private async handleSpecificHandler(handlerDescriptor: QuickOpenHandlerDescriptor, value: string, token: CancellationToken): Promise<void> {
return this.resolveHandler(handlerDescriptor).then((resolvedHandler: QuickOpenHandler) => { const resolvedHandler = await this.resolveHandler(handlerDescriptor);
// Remove handler prefix from search value // Remove handler prefix from search value
value = value.substr(handlerDescriptor.prefix.length); value = value.substr(handlerDescriptor.prefix.length);
// Return early if the handler can not run in the current environment and inform the user // Return early if the handler can not run in the current environment and inform the user
const canRun = resolvedHandler.canRun(); const canRun = resolvedHandler.canRun();
if (types.isUndefinedOrNull(canRun) || (typeof canRun === 'boolean' && !canRun) || typeof canRun === 'string') { if (types.isUndefinedOrNull(canRun) || (typeof canRun === 'boolean' && !canRun) || typeof canRun === 'string') {
const placeHolderLabel = (typeof canRun === 'string') ? canRun : nls.localize('canNotRunPlaceholder', "This quick open handler can not be used in the current context"); const placeHolderLabel = (typeof canRun === 'string') ? canRun : nls.localize('canNotRunPlaceholder', "This quick open handler can not be used in the current context");
const model = new QuickOpenModel([new PlaceholderQuickOpenEntry(placeHolderLabel)], this.actionProvider); const model = new QuickOpenModel([new PlaceholderQuickOpenEntry(placeHolderLabel)], this.actionProvider);
this.showModel(model, resolvedHandler.getAutoFocus(value, { model, quickNavigateConfiguration: this.quickOpenWidget.getQuickNavigateConfiguration() }), types.withNullAsUndefined(resolvedHandler.getAriaLabel()));
return Promise.resolve(undefined);
}
// Support extra class from handler
const extraClass = resolvedHandler.getClass();
if (extraClass) {
this.quickOpenWidget.setExtraClass(extraClass);
}
// When handlers change, clear the result list first before loading the new results
if (this.previousActiveHandlerDescriptor !== handlerDescriptor) {
this.clearModel();
}
// Receive Results from Handler and apply
const result = await resolvedHandler.getResults(value, token);
if (!token.isCancellationRequested) {
if (!result || !result.entries.length) {
const model = new QuickOpenModel([new PlaceholderQuickOpenEntry(resolvedHandler.getEmptyLabel(value))]);
this.showModel(model, resolvedHandler.getAutoFocus(value, { model, quickNavigateConfiguration: this.quickOpenWidget.getQuickNavigateConfiguration() }), types.withNullAsUndefined(resolvedHandler.getAriaLabel())); this.showModel(model, resolvedHandler.getAutoFocus(value, { model, quickNavigateConfiguration: this.quickOpenWidget.getQuickNavigateConfiguration() }), types.withNullAsUndefined(resolvedHandler.getAriaLabel()));
} else {
return Promise.resolve(undefined); this.showModel(result, resolvedHandler.getAutoFocus(value, { model: result, quickNavigateConfiguration: this.quickOpenWidget.getQuickNavigateConfiguration() }), types.withNullAsUndefined(resolvedHandler.getAriaLabel()));
} }
}
// Support extra class from handler
const extraClass = resolvedHandler.getClass();
if (extraClass) {
this.quickOpenWidget.setExtraClass(extraClass);
}
// When handlers change, clear the result list first before loading the new results
if (this.previousActiveHandlerDescriptor !== handlerDescriptor) {
this.clearModel();
}
// Receive Results from Handler and apply
return resolvedHandler.getResults(value, token).then(result => {
if (!token.isCancellationRequested) {
if (!result || !result.entries.length) {
const model = new QuickOpenModel([new PlaceholderQuickOpenEntry(resolvedHandler.getEmptyLabel(value))]);
this.showModel(model, resolvedHandler.getAutoFocus(value, { model, quickNavigateConfiguration: this.quickOpenWidget.getQuickNavigateConfiguration() }), types.withNullAsUndefined(resolvedHandler.getAriaLabel()));
} else {
this.showModel(result, resolvedHandler.getAutoFocus(value, { model: result, quickNavigateConfiguration: this.quickOpenWidget.getQuickNavigateConfiguration() }), types.withNullAsUndefined(resolvedHandler.getAriaLabel()));
}
}
});
});
} }
private showModel(model: IModel<any>, autoFocus?: IAutoFocus, ariaLabel?: string): void { private showModel(model: IModel<any>, autoFocus?: IAutoFocus, ariaLabel?: string): void {
@@ -837,7 +828,7 @@ export class RemoveFromEditorHistoryAction extends Action {
super(id, label); super(id, label);
} }
run(): Promise<any> { async run(): Promise<any> {
interface IHistoryPickEntry extends IQuickPickItem { interface IHistoryPickEntry extends IQuickPickItem {
input: IEditorInput | IResourceInput; input: IEditorInput | IResourceInput;
} }
@@ -854,11 +845,10 @@ export class RemoveFromEditorHistoryAction extends Action {
}; };
}); });
return this.quickInputService.pick(picks, { placeHolder: nls.localize('pickHistory', "Select an editor entry to remove from history"), matchOnDescription: true }).then(pick => { const pick = await this.quickInputService.pick(picks, { placeHolder: nls.localize('pickHistory', "Select an editor entry to remove from history"), matchOnDescription: true });
if (pick) { if (pick) {
this.historyService.remove(pick.input); this.historyService.remove(pick.input);
} }
});
} }
} }

View File

@@ -23,12 +23,10 @@ export const QUICKOPEN_ACION_LABEL = nls.localize('quickOpen', "Go to File...");
CommandsRegistry.registerCommand({ CommandsRegistry.registerCommand({
id: QUICKOPEN_ACTION_ID, id: QUICKOPEN_ACTION_ID,
handler: function (accessor: ServicesAccessor, prefix: string | null = null) { handler: async function (accessor: ServicesAccessor, prefix: string | null = null) {
const quickOpenService = accessor.get(IQuickOpenService); const quickOpenService = accessor.get(IQuickOpenService);
return quickOpenService.show(typeof prefix === 'string' ? prefix : undefined).then(() => { await quickOpenService.show(typeof prefix === 'string' ? prefix : undefined);
return undefined;
});
}, },
description: { description: {
description: `Quick open`, description: `Quick open`,
@@ -42,12 +40,10 @@ CommandsRegistry.registerCommand({
}); });
export const QUICKOPEN_FOCUS_SECONDARY_ACTION_ID = 'workbench.action.quickOpenPreviousEditor'; export const QUICKOPEN_FOCUS_SECONDARY_ACTION_ID = 'workbench.action.quickOpenPreviousEditor';
CommandsRegistry.registerCommand(QUICKOPEN_FOCUS_SECONDARY_ACTION_ID, function (accessor: ServicesAccessor, prefix: string | null = null) { CommandsRegistry.registerCommand(QUICKOPEN_FOCUS_SECONDARY_ACTION_ID, async function (accessor: ServicesAccessor, prefix: string | null = null) {
const quickOpenService = accessor.get(IQuickOpenService); const quickOpenService = accessor.get(IQuickOpenService);
return quickOpenService.show(undefined, { autoFocus: { autoFocusSecondEntry: true } }).then(() => { await quickOpenService.show(undefined, { autoFocus: { autoFocusSecondEntry: true } });
return undefined;
});
}); });
export class BaseQuickOpenNavigateAction extends Action { export class BaseQuickOpenNavigateAction extends Action {

View File

@@ -189,19 +189,18 @@ export class SidebarPart extends CompositePart<Viewlet> implements IViewletServi
this.hideActiveComposite(); this.hideActiveComposite();
} }
openViewlet(id: string | undefined, focus?: boolean): Promise<IViewlet | null> { async openViewlet(id: string | undefined, focus?: boolean): Promise<IViewlet | null> {
if (typeof id === 'string' && this.getViewlet(id)) { if (typeof id === 'string' && this.getViewlet(id)) {
return Promise.resolve(this.doOpenViewlet(id, focus)); return Promise.resolve(this.doOpenViewlet(id, focus));
} }
return this.extensionService.whenInstalledExtensionsRegistered() await this.extensionService.whenInstalledExtensionsRegistered();
.then(() => {
if (typeof id === 'string' && this.getViewlet(id)) {
return this.doOpenViewlet(id, focus);
}
return null; if (typeof id === 'string' && this.getViewlet(id)) {
}); return this.doOpenViewlet(id, focus);
}
return null;
} }
getViewlets(): ViewletDescriptor[] { getViewlets(): ViewletDescriptor[] {

View File

@@ -382,7 +382,7 @@ class StatusBarEntryItem extends Disposable {
} }
} }
private executeCommand(id: string, args?: unknown[]) { private async executeCommand(id: string, args?: unknown[]): Promise<void> {
args = args || []; args = args || [];
// Maintain old behaviour of always focusing the editor here // Maintain old behaviour of always focusing the editor here
@@ -398,7 +398,11 @@ class StatusBarEntryItem extends Disposable {
} }
*/ */
this.telemetryService.publicLog('workbenchActionExecuted', { id, from: 'status bar' }); this.telemetryService.publicLog('workbenchActionExecuted', { id, from: 'status bar' });
this.commandService.executeCommand(id, ...args).then(undefined, err => this.notificationService.error(toErrorMessage(err))); try {
await this.commandService.executeCommand(id, ...args);
} catch (error) {
this.notificationService.error(toErrorMessage(error));
}
} }
dispose(): void { dispose(): void {

View File

@@ -391,14 +391,13 @@ export class TitlebarPart extends Part implements ITitleService {
const restoreIconContainer = append(this.windowControls, $('div.window-icon-bg')); const restoreIconContainer = append(this.windowControls, $('div.window-icon-bg'));
this.maxRestoreControl = append(restoreIconContainer, $('div.window-icon')); this.maxRestoreControl = append(restoreIconContainer, $('div.window-icon'));
addClass(this.maxRestoreControl, 'window-max-restore'); addClass(this.maxRestoreControl, 'window-max-restore');
this._register(addDisposableListener(this.maxRestoreControl, EventType.CLICK, e => { this._register(addDisposableListener(this.maxRestoreControl, EventType.CLICK, async e => {
this.windowService.isMaximized().then((maximized) => { const maximized = await this.windowService.isMaximized();
if (maximized) { if (maximized) {
return this.windowService.unmaximizeWindow(); return this.windowService.unmaximizeWindow();
} }
return this.windowService.maximizeWindow(); return this.windowService.maximizeWindow();
});
})); }));
// Close // Close

View File

@@ -251,15 +251,13 @@ export class CustomTreeView extends Disposable implements ITreeView {
set dataProvider(dataProvider: ITreeViewDataProvider | null) { set dataProvider(dataProvider: ITreeViewDataProvider | null) {
if (dataProvider) { if (dataProvider) {
this._dataProvider = new class implements ITreeViewDataProvider { this._dataProvider = new class implements ITreeViewDataProvider {
getChildren(node: ITreeItem): Promise<ITreeItem[]> { async getChildren(node: ITreeItem): Promise<ITreeItem[]> {
if (node && node.children) { if (node && node.children) {
return Promise.resolve(node.children); return Promise.resolve(node.children);
} }
const promise = node instanceof Root ? dataProvider.getChildren() : dataProvider.getChildren(node); const children = await (node instanceof Root ? dataProvider.getChildren() : dataProvider.getChildren(node));
return promise.then(children => { node.children = children;
node.children = children; return children;
return children;
});
} }
}; };
this.updateMessage(); this.updateMessage();
@@ -524,19 +522,16 @@ export class CustomTreeView extends Disposable implements ITreeView {
} }
private refreshing: boolean = false; private refreshing: boolean = false;
private doRefresh(elements: ITreeItem[]): Promise<void> { private async doRefresh(elements: ITreeItem[]): Promise<void> {
if (this.tree) { if (this.tree) {
this.refreshing = true; this.refreshing = true;
return Promise.all(elements.map(e => this.tree.refresh(e))) await Promise.all(elements.map(e => this.tree.refresh(e)));
.then(() => { this.refreshing = false;
this.refreshing = false; this.updateContentAreas();
this.updateContentAreas(); if (this.focused) {
if (this.focused) { this.focus();
this.focus(); }
}
});
} }
return Promise.resolve(undefined);
} }
private updateContentAreas(): void { private updateContentAreas(): void {

View File

@@ -618,21 +618,19 @@ export class ViewsService extends Disposable implements IViewsService {
return viewDescriptorCollectionItem ? viewDescriptorCollectionItem.viewDescriptorCollection : null; return viewDescriptorCollectionItem ? viewDescriptorCollectionItem.viewDescriptorCollection : null;
} }
openView(id: string, focus: boolean): Promise<IView | null> { async openView(id: string, focus: boolean): Promise<IView | null> {
const viewContainer = Registry.as<IViewsRegistry>(ViewExtensions.ViewsRegistry).getViewContainer(id); const viewContainer = Registry.as<IViewsRegistry>(ViewExtensions.ViewsRegistry).getViewContainer(id);
if (viewContainer) { if (viewContainer) {
const viewletDescriptor = this.viewletService.getViewlet(viewContainer.id); const viewletDescriptor = this.viewletService.getViewlet(viewContainer.id);
if (viewletDescriptor) { if (viewletDescriptor) {
return this.viewletService.openViewlet(viewletDescriptor.id, focus) const viewlet = await this.viewletService.openViewlet(viewletDescriptor.id, focus) as IViewsViewlet | null;
.then((viewlet: IViewsViewlet) => { if (viewlet && viewlet.openView) {
if (viewlet && viewlet.openView) { return viewlet.openView(id, focus);
return viewlet.openView(id, focus); }
}
return null;
});
} }
} }
return Promise.resolve(null);
return null;
} }
private onDidRegisterViewContainer(viewContainer: ViewContainer): void { private onDidRegisterViewContainer(viewContainer: ViewContainer): void {
@@ -669,7 +667,7 @@ export class ViewsService extends Disposable implements IViewsService {
}; };
const when = ContextKeyExpr.has(`${viewDescriptor.id}.active`); const when = ContextKeyExpr.has(`${viewDescriptor.id}.active`);
disposables.push(CommandsRegistry.registerCommand(command.id, () => this.openView(viewDescriptor.id, true).then(() => null))); disposables.push(CommandsRegistry.registerCommand(command.id, () => this.openView(viewDescriptor.id, true)));
disposables.push(MenuRegistry.appendMenuItem(MenuId.CommandPalette, { disposables.push(MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command, command,

View File

@@ -26,28 +26,27 @@ class CodeRendererMain extends Disposable {
private workbench: Workbench; private workbench: Workbench;
open(): Promise<void> { async open(): Promise<void> {
const services = this.initServices(); const services = this.initServices();
return domContentLoaded().then(() => { await domContentLoaded();
mark('willStartWorkbench'); mark('willStartWorkbench');
// Create Workbench // Create Workbench
this.workbench = new Workbench( this.workbench = new Workbench(
document.body, document.body,
services.serviceCollection, services.serviceCollection,
services.logService services.logService
); );
// Layout // Layout
this._register(addDisposableListener(window, EventType.RESIZE, () => this.workbench.layout())); this._register(addDisposableListener(window, EventType.RESIZE, () => this.workbench.layout()));
// Workbench Lifecycle // Workbench Lifecycle
this._register(this.workbench.onShutdown(() => this.dispose())); this._register(this.workbench.onShutdown(() => this.dispose()));
// Startup // Startup
this.workbench.startup(); this.workbench.startup();
});
} }
private initServices(): { serviceCollection: ServiceCollection, logService: ILogService } { private initServices(): { serviceCollection: ServiceCollection, logService: ILogService } {

View File

@@ -131,7 +131,7 @@ export class Workbench extends Layout {
// Services // Services
const instantiationService = this.initServices(this.serviceCollection); const instantiationService = this.initServices(this.serviceCollection);
instantiationService.invokeFunction(accessor => { instantiationService.invokeFunction(async accessor => {
const lifecycleService = accessor.get(ILifecycleService); const lifecycleService = accessor.get(ILifecycleService);
const storageService = accessor.get(IStorageService); const storageService = accessor.get(IStorageService);
const configurationService = accessor.get(IConfigurationService); const configurationService = accessor.get(IConfigurationService);
@@ -158,7 +158,11 @@ export class Workbench extends Layout {
this.layout(); this.layout();
// Restore // Restore
this.restoreWorkbench(accessor.get(IEditorService), accessor.get(IEditorGroupsService), accessor.get(IViewletService), accessor.get(IPanelService), accessor.get(ILogService), lifecycleService).then(undefined, error => onUnexpectedError(error)); try {
await this.restoreWorkbench(accessor.get(IEditorService), accessor.get(IEditorGroupsService), accessor.get(IViewletService), accessor.get(IPanelService), accessor.get(ILogService), lifecycleService);
} catch (error) {
onUnexpectedError(error);
}
}); });
return instantiationService; return instantiationService;
@@ -338,7 +342,7 @@ export class Workbench extends Layout {
registerNotificationCommands(notificationsCenter, notificationsToasts); registerNotificationCommands(notificationsCenter, notificationsToasts);
} }
private restoreWorkbench( private async restoreWorkbench(
editorService: IEditorService, editorService: IEditorService,
editorGroupService: IEditorGroupsService, editorGroupService: IEditorGroupsService,
viewletService: IViewletService, viewletService: IViewletService,
@@ -349,36 +353,39 @@ export class Workbench extends Layout {
const restorePromises: Promise<void>[] = []; const restorePromises: Promise<void>[] = [];
// Restore editors // Restore editors
mark('willRestoreEditors'); restorePromises.push((async () => {
restorePromises.push(editorGroupService.whenRestored.then(() => { mark('willRestoreEditors');
function openEditors(editors: IResourceEditor[], editorService: IEditorService) { // first ensure the editor part is restored
if (editors.length) { await editorGroupService.whenRestored;
return editorService.openEditors(editors);
}
return Promise.resolve(undefined);
}
// then see for editors to open as instructed
let editors: IResourceEditor[];
if (Array.isArray(this.state.editor.editorsToOpen)) { if (Array.isArray(this.state.editor.editorsToOpen)) {
return openEditors(this.state.editor.editorsToOpen, editorService); editors = this.state.editor.editorsToOpen;
} else {
editors = await this.state.editor.editorsToOpen;
} }
return this.state.editor.editorsToOpen.then(editors => openEditors(editors, editorService)); if (editors.length) {
}).then(() => mark('didRestoreEditors'))); await editorService.openEditors(editors);
}
mark('didRestoreEditors');
})());
// Restore Sidebar // Restore Sidebar
if (this.state.sideBar.viewletToRestore) { if (this.state.sideBar.viewletToRestore) {
mark('willRestoreViewlet'); restorePromises.push((async () => {
restorePromises.push(viewletService.openViewlet(this.state.sideBar.viewletToRestore) mark('willRestoreViewlet');
.then(viewlet => {
if (!viewlet) {
return viewletService.openViewlet(viewletService.getDefaultViewletId()); // fallback to default viewlet as needed
}
return viewlet; const viewlet = await viewletService.openViewlet(this.state.sideBar.viewletToRestore);
}) if (!viewlet) {
.then(() => mark('didRestoreViewlet'))); await viewletService.openViewlet(viewletService.getDefaultViewletId()); // fallback to default viewlet as needed
}
mark('didRestoreViewlet');
})());
} }
// Restore Panel // Restore Panel
@@ -401,23 +408,24 @@ export class Workbench extends Layout {
// Emit a warning after 10s if restore does not complete // Emit a warning after 10s if restore does not complete
const restoreTimeoutHandle = setTimeout(() => logService.warn('Workbench did not finish loading in 10 seconds, that might be a problem that should be reported.'), 10000); const restoreTimeoutHandle = setTimeout(() => logService.warn('Workbench did not finish loading in 10 seconds, that might be a problem that should be reported.'), 10000);
return Promise.all(restorePromises) try {
.then(() => clearTimeout(restoreTimeoutHandle)) await Promise.all(restorePromises);
.catch(error => onUnexpectedError(error))
.finally(() => {
// Set lifecycle phase to `Restored` clearTimeout(restoreTimeoutHandle);
lifecycleService.phase = LifecyclePhase.Restored; } catch (error) {
onUnexpectedError(error);
} finally {
// Set lifecycle phase to `Eventually` after a short delay and when idle (min 2.5sec, max 5sec) // Set lifecycle phase to `Restored`
setTimeout(() => { lifecycleService.phase = LifecyclePhase.Restored;
this._register(runWhenIdle(() => {
lifecycleService.phase = LifecyclePhase.Eventually;
}, 2500));
}, 2500);
// Telemetry: startup metrics // Set lifecycle phase to `Eventually` after a short delay and when idle (min 2.5sec, max 5sec)
mark('didStartWorkbench'); setTimeout(() => {
}); this._register(runWhenIdle(() => lifecycleService.phase = LifecyclePhase.Eventually, 2500));
}, 2500);
// Telemetry: startup metrics
mark('didStartWorkbench');
}
} }
} }

View File

@@ -82,46 +82,40 @@ Registry.add(Extensions.WorkbenchActions, new class implements IWorkbenchActionR
} }
private createCommandHandler(descriptor: SyncActionDescriptor): ICommandHandler { private createCommandHandler(descriptor: SyncActionDescriptor): ICommandHandler {
return (accessor, args) => { return async (accessor, args) => {
const notificationService = accessor.get(INotificationService); const notificationService = accessor.get(INotificationService);
const instantiationService = accessor.get(IInstantiationService); const instantiationService = accessor.get(IInstantiationService);
const lifecycleService = accessor.get(ILifecycleService); const lifecycleService = accessor.get(ILifecycleService);
Promise.resolve(this.triggerAndDisposeAction(instantiationService, lifecycleService, descriptor, args)).then(undefined, err => { try {
notificationService.error(err); await this.triggerAndDisposeAction(instantiationService, lifecycleService, descriptor, args);
}); } catch (error) {
notificationService.error(error);
}
}; };
} }
private triggerAndDisposeAction(instantiationService: IInstantiationService, lifecycleService: ILifecycleService, descriptor: SyncActionDescriptor, args: any): Promise<void> { private async triggerAndDisposeAction(instantiationService: IInstantiationService, lifecycleService: ILifecycleService, descriptor: SyncActionDescriptor, args: any): Promise<void> {
// run action when workbench is created // run action when workbench is created
return lifecycleService.when(LifecyclePhase.Ready).then(() => { await lifecycleService.when(LifecyclePhase.Ready);
const actionInstance = instantiationService.createInstance(descriptor.syncDescriptor);
try {
actionInstance.label = descriptor.label || actionInstance.label;
// don't run the action when not enabled const actionInstance = instantiationService.createInstance(descriptor.syncDescriptor);
if (!actionInstance.enabled) { actionInstance.label = descriptor.label || actionInstance.label;
actionInstance.dispose();
return undefined; // don't run the action when not enabled
} if (!actionInstance.enabled) {
actionInstance.dispose();
const from = args && args.from || 'keybinding'; return;
}
return Promise.resolve(actionInstance.run(undefined, { from })).then(() => { // otherwise run and dispose
actionInstance.dispose(); try {
}, err => { const from = args && args.from || 'keybinding';
actionInstance.dispose(); await actionInstance.run(undefined, { from });
} finally {
return Promise.reject(err); actionInstance.dispose();
}); }
} catch (err) {
actionInstance.dispose();
return Promise.reject(err);
}
});
} }
}); });

View File

@@ -80,9 +80,7 @@ class WorkbenchContributionsRegistry implements IWorkbenchContributionsRegistry
// Otherwise wait for phase to be reached // Otherwise wait for phase to be reached
else { else {
lifecycleService.when(phase).then(() => { lifecycleService.when(phase).then(() => this.doInstantiateByPhase(instantiationService, phase));
this.doInstantiateByPhase(instantiationService, phase);
});
} }
} }

View File

@@ -72,20 +72,17 @@ export class BinaryEditorModel extends EditorModel {
return this.etag; return this.etag;
} }
load(): Promise<BinaryEditorModel> { async load(): Promise<BinaryEditorModel> {
// Make sure to resolve up to date stat for file resources // Make sure to resolve up to date stat for file resources
if (this.fileService.canHandleResource(this.resource)) { if (this.fileService.canHandleResource(this.resource)) {
return this.fileService.resolve(this.resource, { resolveMetadata: true }).then(stat => { const stat = await this.fileService.resolve(this.resource, { resolveMetadata: true });
this.etag = stat.etag; this.etag = stat.etag;
if (typeof stat.size === 'number') { if (typeof stat.size === 'number') {
this.size = stat.size; this.size = stat.size;
} }
return this;
});
} }
return Promise.resolve(this); return this;
} }
} }

View File

@@ -34,45 +34,44 @@ export class DiffEditorInput extends SideBySideEditorInput {
return this.master; return this.master;
} }
resolve(): Promise<EditorModel> { async resolve(): Promise<EditorModel> {
// Create Model - we never reuse our cached model if refresh is true because we cannot // Create Model - we never reuse our cached model if refresh is true because we cannot
// decide for the inputs within if the cached model can be reused or not. There may be // decide for the inputs within if the cached model can be reused or not. There may be
// inputs that need to be loaded again and thus we always recreate the model and dispose // inputs that need to be loaded again and thus we always recreate the model and dispose
// the previous one - if any. // the previous one - if any.
return this.createModel().then(resolvedModel => { const resolvedModel = await this.createModel();
if (this.cachedModel) { if (this.cachedModel) {
this.cachedModel.dispose(); this.cachedModel.dispose();
} }
this.cachedModel = resolvedModel; this.cachedModel = resolvedModel;
return this.cachedModel; return this.cachedModel;
});
} }
getPreferredEditorId(candidates: string[]): string { getPreferredEditorId(candidates: string[]): string {
return this.forceOpenAsBinary ? BINARY_DIFF_EDITOR_ID : TEXT_DIFF_EDITOR_ID; return this.forceOpenAsBinary ? BINARY_DIFF_EDITOR_ID : TEXT_DIFF_EDITOR_ID;
} }
private createModel(): Promise<DiffEditorModel> { private async createModel(): Promise<DiffEditorModel> {
// Join resolve call over two inputs and build diff editor model // Join resolve call over two inputs and build diff editor model
return Promise.all([ const models = await Promise.all([
this.originalInput.resolve(), this.originalInput.resolve(),
this.modifiedInput.resolve() this.modifiedInput.resolve()
]).then(models => { ]);
const originalEditorModel = models[0];
const modifiedEditorModel = models[1];
// If both are text models, return textdiffeditor model const originalEditorModel = models[0];
if (modifiedEditorModel instanceof BaseTextEditorModel && originalEditorModel instanceof BaseTextEditorModel) { const modifiedEditorModel = models[1];
return new TextDiffEditorModel(originalEditorModel, modifiedEditorModel);
}
// Otherwise return normal diff model // If both are text models, return textdiffeditor model
return new DiffEditorModel(originalEditorModel, modifiedEditorModel); if (modifiedEditorModel instanceof BaseTextEditorModel && originalEditorModel instanceof BaseTextEditorModel) {
}); return new TextDiffEditorModel(originalEditorModel, modifiedEditorModel);
}
// Otherwise return normal diff model
return new DiffEditorModel(originalEditorModel, modifiedEditorModel);
} }
dispose(): void { dispose(): void {

View File

@@ -37,11 +37,13 @@ export class DiffEditorModel extends EditorModel {
return this._modifiedModel; return this._modifiedModel;
} }
load(): Promise<EditorModel> { async load(): Promise<EditorModel> {
return Promise.all([ await Promise.all([
this._originalModel ? this._originalModel.load() : Promise.resolve(undefined), this._originalModel ? this._originalModel.load() : Promise.resolve(undefined),
this._modifiedModel ? this._modifiedModel.load() : Promise.resolve(undefined), this._modifiedModel ? this._modifiedModel.load() : Promise.resolve(undefined),
]).then(() => this); ]);
return this;
} }
isResolved(): boolean { isResolved(): boolean {

View File

@@ -76,31 +76,31 @@ export class ResourceEditorInput extends EditorInput implements IModeSupport {
this.preferredMode = mode; this.preferredMode = mode;
} }
resolve(): Promise<ITextEditorModel> { async resolve(): Promise<ITextEditorModel> {
if (!this.modelReference) { if (!this.modelReference) {
this.modelReference = this.textModelResolverService.createModelReference(this.resource); this.modelReference = this.textModelResolverService.createModelReference(this.resource);
} }
return this.modelReference.then(ref => { const ref = await this.modelReference;
const model = ref.object;
// Ensure the resolved model is of expected type const model = ref.object;
if (!(model instanceof ResourceEditorModel)) {
ref.dispose();
this.modelReference = null;
return Promise.reject(new Error(`Unexpected model for ResourceInput: ${this.resource}`)); // Ensure the resolved model is of expected type
} if (!(model instanceof ResourceEditorModel)) {
ref.dispose();
this.modelReference = null;
this.cachedModel = model; return Promise.reject(new Error(`Unexpected model for ResourceInput: ${this.resource}`));
}
// Set mode if we have a preferred mode configured this.cachedModel = model;
if (this.preferredMode) {
model.setMode(this.preferredMode);
}
return model; // Set mode if we have a preferred mode configured
}); if (this.preferredMode) {
model.setMode(this.preferredMode);
}
return model;
} }
matches(otherInput: unknown): boolean { matches(otherInput: unknown): boolean {

View File

@@ -26,6 +26,7 @@ export class ResourceEditorModel extends BaseTextEditorModel {
} }
dispose(): void { dispose(): void {
// TODO@Joao: force this class to dispose the underlying model // TODO@Joao: force this class to dispose the underlying model
if (this.textEditorModelHandle) { if (this.textEditorModelHandle) {
this.modelService.destroyModel(this.textEditorModelHandle); this.modelService.destroyModel(this.textEditorModelHandle);

View File

@@ -33,12 +33,12 @@ export class TextDiffEditorModel extends DiffEditorModel {
return this._modifiedModel; return this._modifiedModel;
} }
load(): Promise<EditorModel> { async load(): Promise<EditorModel> {
return super.load().then(() => { await super.load();
this.updateTextDiffEditorModel();
return this; this.updateTextDiffEditorModel();
});
return this;
} }
private updateTextDiffEditorModel(): void { private updateTextDiffEditorModel(): void {

View File

@@ -11,7 +11,7 @@ import { IModeService } from 'vs/editor/common/services/modeService';
import { IModelService } from 'vs/editor/common/services/modelService'; import { IModelService } from 'vs/editor/common/services/modelService';
import { Event, Emitter } from 'vs/base/common/event'; import { Event, Emitter } from 'vs/base/common/event';
import { RunOnceScheduler } from 'vs/base/common/async'; import { RunOnceScheduler } from 'vs/base/common/async';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup'; import { IBackupFileService, IResolvedBackup } from 'vs/workbench/services/backup/common/backup';
import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration'; import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration';
import { ITextBufferFactory } from 'vs/editor/common/model'; import { ITextBufferFactory } from 'vs/editor/common/model';
import { createTextBufferFactory } from 'vs/editor/common/model/textModel'; import { createTextBufferFactory } from 'vs/editor/common/model/textModel';
@@ -135,52 +135,48 @@ export class UntitledEditorModel extends BaseTextEditorModel implements IEncodin
return Promise.resolve(); return Promise.resolve();
} }
load(): Promise<UntitledEditorModel & IResolvedTextEditorModel> { async load(): Promise<UntitledEditorModel & IResolvedTextEditorModel> {
// Check for backups first // Check for backups first
return this.backupFileService.loadBackupResource(this.resource).then(backupResource => { let backup: IResolvedBackup<object> | undefined = undefined;
if (backupResource) { const backupResource = await this.backupFileService.loadBackupResource(this.resource);
return this.backupFileService.resolveBackupContent(backupResource); if (backupResource) {
} backup = await this.backupFileService.resolveBackupContent(backupResource);
}
return Promise.resolve(undefined); // untitled associated to file path are dirty right away as well as untitled with content
}).then(backup => { this.setDirty(this._hasAssociatedFilePath || !!backup || !!this.initialValue);
const hasBackup = !!backup;
// untitled associated to file path are dirty right away as well as untitled with content let untitledContents: ITextBufferFactory;
this.setDirty(this._hasAssociatedFilePath || hasBackup || !!this.initialValue); if (backup) {
untitledContents = backup.value;
} else {
untitledContents = createTextBufferFactory(this.initialValue || '');
}
let untitledContents: ITextBufferFactory; // Create text editor model if not yet done
if (backup) { if (!this.textEditorModel) {
untitledContents = backup.value; this.createTextEditorModel(untitledContents, this.resource, this.preferredMode);
} else { }
untitledContents = createTextBufferFactory(this.initialValue || '');
}
// Create text editor model if not yet done // Otherwise update
if (!this.textEditorModel) { else {
this.createTextEditorModel(untitledContents, this.resource, this.preferredMode); this.updateTextEditorModel(untitledContents, this.preferredMode);
} }
// Otherwise update // Encoding
else { this.configuredEncoding = this.configurationService.getValue<string>(this.resource, 'files.encoding');
this.updateTextEditorModel(untitledContents, this.preferredMode);
}
// Encoding // We know for a fact there is a text editor model here
this.configuredEncoding = this.configurationService.getValue<string>(this.resource, 'files.encoding'); const textEditorModel = this.textEditorModel!;
// We know for a fact there is a text editor model here // Listen to content changes
const textEditorModel = this.textEditorModel!; this._register(textEditorModel.onDidChangeContent(() => this.onModelContentChanged()));
// Listen to content changes // Listen to mode changes
this._register(textEditorModel.onDidChangeContent(() => this.onModelContentChanged())); this._register(textEditorModel.onDidChangeLanguage(() => this.onConfigurationChange())); // mode change can have impact on config
// Listen to mode changes return this as UntitledEditorModel & IResolvedTextEditorModel;
this._register(textEditorModel.onDidChangeLanguage(() => this.onConfigurationChange())); // mode change can have impact on config
return this as UntitledEditorModel & IResolvedTextEditorModel;
});
} }
private onModelContentChanged(): void { private onModelContentChanged(): void {

View File

@@ -33,46 +33,47 @@ export class BackupRestorer implements IWorkbenchContribution {
this.lifecycleService.when(LifecyclePhase.Restored).then(() => this.doRestoreBackups()); this.lifecycleService.when(LifecyclePhase.Restored).then(() => this.doRestoreBackups());
} }
private doRestoreBackups(): Promise<URI[] | undefined> { private async doRestoreBackups(): Promise<URI[] | undefined> {
// Find all files and untitled with backups // Find all files and untitled with backups
return this.backupFileService.getWorkspaceFileBackups().then(backups => { const backups = await this.backupFileService.getWorkspaceFileBackups();
const unresolvedBackups = await this.doResolveOpenedBackups(backups);
// Resolve backups that are opened // Some failed to restore or were not opened at all so we open and resolve them manually
return this.doResolveOpenedBackups(backups).then((unresolved): Promise<URI[] | undefined> | undefined => { if (unresolvedBackups.length > 0) {
await this.doOpenEditors(unresolvedBackups);
// Some failed to restore or were not opened at all so we open and resolve them manually return this.doResolveOpenedBackups(unresolvedBackups);
if (unresolved.length > 0) { }
return this.doOpenEditors(unresolved).then(() => this.doResolveOpenedBackups(unresolved));
}
return undefined; return undefined;
});
});
} }
private doResolveOpenedBackups(backups: URI[]): Promise<URI[]> { private async doResolveOpenedBackups(backups: URI[]): Promise<URI[]> {
const restorePromises: Promise<unknown>[] = []; const unresolvedBackups: URI[] = [];
const unresolved: URI[] = [];
backups.forEach(backup => { await Promise.all(backups.map(async backup => {
const openedEditor = this.editorService.getOpened({ resource: backup }); const openedEditor = this.editorService.getOpened({ resource: backup });
if (openedEditor) { if (openedEditor) {
restorePromises.push(openedEditor.resolve().then(undefined, () => unresolved.push(backup))); try {
await openedEditor.resolve(); // trigger load
} catch (error) {
unresolvedBackups.push(backup); // ignore error and remember as unresolved
}
} else { } else {
unresolved.push(backup); unresolvedBackups.push(backup);
} }
}); }));
return Promise.all(restorePromises).then(() => unresolved, () => unresolved); return unresolvedBackups;
} }
private doOpenEditors(resources: URI[]): Promise<void> { private async doOpenEditors(resources: URI[]): Promise<void> {
const hasOpenedEditors = this.editorService.visibleEditors.length > 0; const hasOpenedEditors = this.editorService.visibleEditors.length > 0;
const inputs = resources.map((resource, index) => this.resolveInput(resource, index, hasOpenedEditors)); const inputs = resources.map((resource, index) => this.resolveInput(resource, index, hasOpenedEditors));
// Open all remaining backups as editors and resolve them to load their backups // Open all remaining backups as editors and resolve them to load their backups
return this.editorService.openEditors(inputs).then(() => undefined); await this.editorService.openEditors(inputs);
} }
private resolveInput(resource: URI, index: number, hasOpenedEditors: boolean): IResourceInput | IUntitledResourceInput { private resolveInput(resource: URI, index: number, hasOpenedEditors: boolean): IResourceInput | IUntitledResourceInput {

View File

@@ -7,6 +7,7 @@ import * as nls from 'vs/nls';
import * as path from 'vs/base/common/path'; import * as path from 'vs/base/common/path';
import * as cp from 'child_process'; import * as cp from 'child_process';
import * as pfs from 'vs/base/node/pfs'; import * as pfs from 'vs/base/node/pfs';
import * as extpath from 'vs/base/node/extpath';
import * as platform from 'vs/base/common/platform'; import * as platform from 'vs/base/common/platform';
import { promisify } from 'util'; import { promisify } from 'util';
import { Action } from 'vs/base/common/actions'; import { Action } from 'vs/base/common/actions';
@@ -91,7 +92,7 @@ class InstallAction extends Action {
private isInstalled(): Promise<boolean> { private isInstalled(): Promise<boolean> {
return pfs.lstat(this.target) return pfs.lstat(this.target)
.then(stat => stat.isSymbolicLink()) .then(stat => stat.isSymbolicLink())
.then(() => pfs.readlink(this.target)) .then(() => extpath.realpath(this.target))
.then(link => link === getSource()) .then(link => link === getSource())
.then(undefined, ignore('ENOENT', false)); .then(undefined, ignore('ENOENT', false));
} }

View File

@@ -0,0 +1,46 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as DOM from 'vs/base/browser/dom';
import { Button } from 'vs/base/browser/ui/button/button';
import { IAction } from 'vs/base/common/actions';
import { Disposable, dispose } from 'vs/base/common/lifecycle';
import { IMenu } from 'vs/platform/actions/common/actions';
import { attachButtonStyler } from 'vs/platform/theme/common/styler';
import { IThemeService } from 'vs/platform/theme/common/themeService';
export class CommentFormActions extends Disposable {
private _buttonElements: HTMLElement[] = [];
constructor(
private container: HTMLElement,
private actionHandler: (action: IAction) => void,
private themeService: IThemeService
) {
super();
}
setActions(menu: IMenu) {
dispose(this._toDispose);
this._buttonElements.forEach(b => DOM.removeNode(b));
const groups = menu.getActions({ shouldForwardArgs: true });
for (const group of groups) {
const [, actions] = group;
actions.forEach(action => {
const button = new Button(this.container);
this._buttonElements.push(button.element);
this._toDispose.push(button);
this._toDispose.push(attachButtonStyler(button, this.themeService));
this._toDispose.push(button.onDidClick(() => this.actionHandler(action)));
button.enabled = action.enabled;
button.label = action.label;
});
}
}
}

View File

@@ -0,0 +1,58 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IDisposable } from 'vs/base/common/lifecycle';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions';
import { IAction } from 'vs/base/common/actions';
import { MainThreadCommentController } from 'vs/workbench/api/browser/mainThreadComments';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { Comment, CommentThread2 } from 'vs/editor/common/modes';
import { fillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
export class CommentMenus implements IDisposable {
constructor(
controller: MainThreadCommentController,
@IContextKeyService private contextKeyService: IContextKeyService,
@IMenuService private readonly menuService: IMenuService,
@IContextMenuService private readonly contextMenuService: IContextMenuService
) {
const commentControllerKey = this.contextKeyService.createKey<string | undefined>('commentController', undefined);
commentControllerKey.set(controller.contextValue);
}
getCommentThreadTitleActions(commentThread: CommentThread2, contextKeyService: IContextKeyService): IMenu {
return this.getMenu(MenuId.CommentThreadTitle, contextKeyService);
}
getCommentThreadActions(commentThread: CommentThread2, contextKeyService: IContextKeyService): IMenu {
return this.getMenu(MenuId.CommentThreadActions, contextKeyService);
}
getCommentTitleActions(comment: Comment, contextKeyService: IContextKeyService): IMenu {
return this.getMenu(MenuId.CommentTitle, contextKeyService);
}
getCommentActions(comment: Comment, contextKeyService: IContextKeyService): IMenu {
return this.getMenu(MenuId.CommentActions, contextKeyService);
}
private getMenu(menuId: MenuId, contextKeyService: IContextKeyService): IMenu {
const menu = this.menuService.createMenu(menuId, contextKeyService);
const primary: IAction[] = [];
const secondary: IAction[] = [];
const result = { primary, secondary };
fillInContextMenuActions(menu, { shouldForwardArgs: true }, result, this.contextMenuService, g => true);
return menu;
}
dispose(): void {
}
}

View File

@@ -8,7 +8,7 @@ import * as dom from 'vs/base/browser/dom';
import * as modes from 'vs/editor/common/modes'; import * as modes from 'vs/editor/common/modes';
import { ActionsOrientation, ActionViewItem, ActionBar } from 'vs/base/browser/ui/actionbar/actionbar'; import { ActionsOrientation, ActionViewItem, ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
import { Button } from 'vs/base/browser/ui/button/button'; import { Button } from 'vs/base/browser/ui/button/button';
import { Action, IActionRunner } from 'vs/base/common/actions'; import { Action, IActionRunner, IAction } from 'vs/base/common/actions';
import { Disposable, IDisposable } from 'vs/base/common/lifecycle'; import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
import { ITextModel } from 'vs/editor/common/model'; import { ITextModel } from 'vs/editor/common/model';
@@ -35,6 +35,11 @@ import { ToggleReactionsAction, ReactionAction, ReactionActionViewItem } from '.
import { ICommandService } from 'vs/platform/commands/common/commands'; import { ICommandService } from 'vs/platform/commands/common/commands';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { ICommentThreadWidget } from 'vs/workbench/contrib/comments/common/commentThreadWidget'; import { ICommentThreadWidget } from 'vs/workbench/contrib/comments/common/commentThreadWidget';
import { MenuItemAction } from 'vs/platform/actions/common/actions';
import { ContextAwareMenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { CommentFormActions } from 'vs/workbench/contrib/comments/browser/commentFormActions';
const UPDATE_COMMENT_LABEL = nls.localize('label.updateComment', "Update comment"); const UPDATE_COMMENT_LABEL = nls.localize('label.updateComment', "Update comment");
const UPDATE_IN_PROGRESS_LABEL = nls.localize('label.updatingComment', "Updating comment..."); const UPDATE_IN_PROGRESS_LABEL = nls.localize('label.updatingComment', "Updating comment...");
@@ -57,10 +62,13 @@ export class CommentNode extends Disposable {
private _updateCommentButton: Button; private _updateCommentButton: Button;
private _errorEditingContainer: HTMLElement; private _errorEditingContainer: HTMLElement;
private _isPendingLabel: HTMLElement; private _isPendingLabel: HTMLElement;
private _contextKeyService: IContextKeyService;
private _commentContextValue: IContextKey<string>;
private _deleteAction: Action; private _deleteAction: Action;
protected actionRunner?: IActionRunner; protected actionRunner?: IActionRunner;
protected toolbar: ToolBar; protected toolbar: ToolBar;
private _commentFormActions: CommentFormActions;
private _onDidDelete = new Emitter<CommentNode>(); private _onDidDelete = new Emitter<CommentNode>();
@@ -85,12 +93,17 @@ export class CommentNode extends Disposable {
@IModelService private modelService: IModelService, @IModelService private modelService: IModelService,
@IModeService private modeService: IModeService, @IModeService private modeService: IModeService,
@IDialogService private dialogService: IDialogService, @IDialogService private dialogService: IDialogService,
@IKeybindingService private keybindingService: IKeybindingService,
@INotificationService private notificationService: INotificationService, @INotificationService private notificationService: INotificationService,
@IContextMenuService private contextMenuService: IContextMenuService @IContextMenuService private contextMenuService: IContextMenuService,
@IContextKeyService contextKeyService: IContextKeyService
) { ) {
super(); super();
this._domNode = dom.$('div.review-comment'); this._domNode = dom.$('div.review-comment');
this._contextKeyService = contextKeyService.createScoped(this._domNode);
this._commentContextValue = this._contextKeyService.createKey('comment', comment.contextValue);
this._domNode.tabIndex = 0; this._domNode.tabIndex = 0;
const avatar = dom.append(this._domNode, dom.$('div.avatar-container')); const avatar = dom.append(this._domNode, dom.$('div.avatar-container'));
if (comment.userIconPath) { if (comment.userIconPath) {
@@ -139,7 +152,7 @@ export class CommentNode extends Disposable {
} }
private createActionsToolbar() { private createActionsToolbar() {
const actions: Action[] = []; const actions: IAction[] = [];
let reactionGroup = this.commentService.getReactionGroup(this.owner); let reactionGroup = this.commentService.getReactionGroup(this.owner);
if (reactionGroup && reactionGroup.length) { if (reactionGroup && reactionGroup.length) {
@@ -163,6 +176,17 @@ export class CommentNode extends Disposable {
actions.push(this._deleteAction); actions.push(this._deleteAction);
} }
let commentMenus = this.commentService.getCommentMenus(this.owner);
const menu = commentMenus.getCommentTitleActions(this.comment, this._contextKeyService);
this._toDispose.push(menu);
this._toDispose.push(menu.onDidChange(e => {
const contributedActions = menu.getActions({ shouldForwardArgs: true }).reduce((r, [, actions]) => [...r, ...actions], <MenuItemAction[]>[]);
this.toolbar.setActions(contributedActions);
}));
const contributedActions = menu.getActions({ shouldForwardArgs: true }).reduce((r, [, actions]) => [...r, ...actions], <MenuItemAction[]>[]);
actions.push(...contributedActions);
if (actions.length) { if (actions.length) {
this.toolbar = new ToolBar(this._actionsToolbarContainer, this.contextMenuService, { this.toolbar = new ToolBar(this._actionsToolbarContainer, this.contextMenuService, {
actionViewItemProvider: action => { actionViewItemProvider: action => {
@@ -185,6 +209,12 @@ export class CommentNode extends Disposable {
orientation: ActionsOrientation.HORIZONTAL orientation: ActionsOrientation.HORIZONTAL
}); });
this.toolbar.context = {
thread: this.commentThread,
commentUniqueId: this.comment.uniqueIdInThread,
$mid: 9
};
this.registerActionBarListeners(this._actionsToolbarContainer); this.registerActionBarListeners(this._actionsToolbarContainer);
this.toolbar.setActions(actions, [])(); this.toolbar.setActions(actions, [])();
this._toDispose.push(this.toolbar); this._toDispose.push(this.toolbar);
@@ -196,12 +226,15 @@ export class CommentNode extends Disposable {
if (action.id === 'comment.delete' || action.id === 'comment.edit' || action.id === ToggleReactionsAction.ID) { if (action.id === 'comment.delete' || action.id === 'comment.edit' || action.id === ToggleReactionsAction.ID) {
options = { label: false, icon: true }; options = { label: false, icon: true };
} else { } else {
options = { label: true, icon: true }; options = { label: false, icon: true };
} }
if (action.id === ReactionAction.ID) { if (action.id === ReactionAction.ID) {
let item = new ReactionActionViewItem(action); let item = new ReactionActionViewItem(action);
return item; return item;
} else if (action instanceof MenuItemAction) {
let item = new ContextAwareMenuEntryActionViewItem(action, this.keybindingService, this.notificationService, this.contextMenuService);
return item;
} else { } else {
let item = new ActionViewItem({}, action, options); let item = new ActionViewItem({}, action, options);
return item; return item;
@@ -391,14 +424,12 @@ export class CommentNode extends Disposable {
uri: this._commentEditor.getModel()!.uri, uri: this._commentEditor.getModel()!.uri,
value: this.comment.body.value value: this.comment.body.value
}; };
this.commentService.setActiveCommentThread(commentThread);
this._commentEditorDisposables.push(this._commentEditor.onDidFocusEditorWidget(() => { this._commentEditorDisposables.push(this._commentEditor.onDidFocusEditorWidget(() => {
commentThread.input = { commentThread.input = {
uri: this._commentEditor!.getModel()!.uri, uri: this._commentEditor!.getModel()!.uri,
value: this.comment.body.value value: this.comment.body.value
}; };
this.commentService.setActiveCommentThread(commentThread);
})); }));
this._commentEditorDisposables.push(this._commentEditor.onDidChangeModelContent(e => { this._commentEditorDisposables.push(this._commentEditor.onDidChangeModelContent(e => {
@@ -419,10 +450,15 @@ export class CommentNode extends Disposable {
private removeCommentEditor() { private removeCommentEditor() {
this.isEditing = false; this.isEditing = false;
this._editAction.enabled = true; if (this._editAction) {
this._editAction.enabled = true;
}
this._body.classList.remove('hidden'); this._body.classList.remove('hidden');
this._commentEditorModel.dispose(); if (this._commentEditorModel) {
this._commentEditorModel.dispose();
}
this._commentEditorDisposables.forEach(dispose => dispose.dispose()); this._commentEditorDisposables.forEach(dispose => dispose.dispose());
this._commentEditorDisposables = []; this._commentEditorDisposables = [];
if (this._commentEditor) { if (this._commentEditor) {
@@ -450,7 +486,6 @@ export class CommentNode extends Disposable {
uri: this._commentEditor.getModel()!.uri, uri: this._commentEditor.getModel()!.uri,
value: newBody value: newBody
}; };
this.commentService.setActiveCommentThread(commentThread);
let commandId = this.comment.editCommand.id; let commandId = this.comment.editCommand.id;
let args = this.comment.editCommand.arguments || []; let args = this.comment.editCommand.arguments || [];
@@ -488,7 +523,6 @@ export class CommentNode extends Disposable {
if (result.confirmed) { if (result.confirmed) {
try { try {
if (this.comment.deleteCommand) { if (this.comment.deleteCommand) {
this.commentService.setActiveCommentThread(this.commentThread as modes.CommentThread2);
let commandId = this.comment.deleteCommand.id; let commandId = this.comment.deleteCommand.id;
let args = this.comment.deleteCommand.arguments || []; let args = this.comment.deleteCommand.arguments || [];
@@ -512,41 +546,81 @@ export class CommentNode extends Disposable {
}); });
} }
public switchToEditMode() {
if (this.isEditing) {
return;
}
this.isEditing = true;
this._body.classList.add('hidden');
this._commentEditContainer = dom.append(this._commentDetailsContainer, dom.$('.edit-container'));
this.createCommentEditor();
this._errorEditingContainer = dom.append(this._commentEditContainer, dom.$('.validation-error.hidden'));
const formActions = dom.append(this._commentEditContainer, dom.$('.form-actions'));
const menus = this.commentService.getCommentMenus(this.owner);
const menu = menus.getCommentActions(this.comment, this._contextKeyService);
this._toDispose.push(menu);
this._toDispose.push(menu.onDidChange(() => {
this._commentFormActions.setActions(menu);
}));
this._commentFormActions = new CommentFormActions(formActions, (action: IAction): void => {
let text = this._commentEditor!.getValue();
action.run({
thread: this.commentThread,
commentUniqueId: this.comment.uniqueIdInThread,
text: text,
$mid: 10
});
this.removeCommentEditor();
}, this.themeService);
this._commentFormActions.setActions(menu);
}
private createEditAction(commentDetailsContainer: HTMLElement): Action { private createEditAction(commentDetailsContainer: HTMLElement): Action {
return new Action('comment.edit', nls.localize('label.edit', "Edit"), 'octicon octicon-pencil', true, () => { return new Action('comment.edit', nls.localize('label.edit', "Edit"), 'octicon octicon-pencil', true, () => {
this.isEditing = true; return this.editCommentAction(commentDetailsContainer);
this._body.classList.add('hidden');
this._commentEditContainer = dom.append(commentDetailsContainer, dom.$('.edit-container'));
this.createCommentEditor();
this._errorEditingContainer = dom.append(this._commentEditContainer, dom.$('.validation-error.hidden'));
const formActions = dom.append(this._commentEditContainer, dom.$('.form-actions'));
const cancelEditButton = new Button(formActions);
cancelEditButton.label = nls.localize('label.cancel', "Cancel");
this._toDispose.push(attachButtonStyler(cancelEditButton, this.themeService));
this._toDispose.push(cancelEditButton.onDidClick(_ => {
this.removeCommentEditor();
}));
this._updateCommentButton = new Button(formActions);
this._updateCommentButton.label = UPDATE_COMMENT_LABEL;
this._toDispose.push(attachButtonStyler(this._updateCommentButton, this.themeService));
this._toDispose.push(this._updateCommentButton.onDidClick(_ => {
this.editComment();
}));
this._commentEditorDisposables.push(this._commentEditor!.onDidChangeModelContent(_ => {
this._updateCommentButton.enabled = !!this._commentEditor!.getValue();
}));
this._editAction.enabled = false;
return Promise.resolve();
}); });
} }
private editCommentAction(commentDetailsContainer: HTMLElement) {
this.isEditing = true;
this._body.classList.add('hidden');
this._commentEditContainer = dom.append(commentDetailsContainer, dom.$('.edit-container'));
this.createCommentEditor();
this._errorEditingContainer = dom.append(this._commentEditContainer, dom.$('.validation-error.hidden'));
const formActions = dom.append(this._commentEditContainer, dom.$('.form-actions'));
const cancelEditButton = new Button(formActions);
cancelEditButton.label = nls.localize('label.cancel', "Cancel");
this._toDispose.push(attachButtonStyler(cancelEditButton, this.themeService));
this._toDispose.push(cancelEditButton.onDidClick(_ => {
this.removeCommentEditor();
}));
this._updateCommentButton = new Button(formActions);
this._updateCommentButton.label = UPDATE_COMMENT_LABEL;
this._toDispose.push(attachButtonStyler(this._updateCommentButton, this.themeService));
this._toDispose.push(this._updateCommentButton.onDidClick(_ => {
this.editComment();
}));
this._commentEditorDisposables.push(this._commentEditor!.onDidChangeModelContent(_ => {
this._updateCommentButton.enabled = !!this._commentEditor!.getValue();
}));
this._editAction.enabled = false;
return Promise.resolve();
}
private registerActionBarListeners(actionsContainer: HTMLElement): void { private registerActionBarListeners(actionsContainer: HTMLElement): void {
this._toDispose.push(dom.addDisposableListener(this._domNode, 'mouseenter', () => { this._toDispose.push(dom.addDisposableListener(this._domNode, 'mouseenter', () => {
actionsContainer.classList.remove('hidden'); actionsContainer.classList.remove('hidden');
@@ -581,6 +655,14 @@ export class CommentNode extends Disposable {
this._body.appendChild(this._md); this._body.appendChild(this._md);
} }
if (newComment.mode !== undefined && newComment.mode !== this.comment.mode) {
if (newComment.mode === modes.CommentMode.Editing) {
this.switchToEditMode();
} else {
this.removeCommentEditor();
}
}
const shouldUpdateActions = newComment.editCommand !== this.comment.editCommand || newComment.deleteCommand !== this.comment.deleteCommand; const shouldUpdateActions = newComment.editCommand !== this.comment.editCommand || newComment.deleteCommand !== this.comment.deleteCommand;
this.comment = newComment; this.comment = newComment;
@@ -610,6 +692,12 @@ export class CommentNode extends Disposable {
if (this.comment.commentReactions && this.comment.commentReactions.length) { if (this.comment.commentReactions && this.comment.commentReactions.length) {
this.createReactionsContainer(this._commentDetailsContainer); this.createReactionsContainer(this._commentDetailsContainer);
} }
if (this.comment.contextValue) {
this._commentContextValue.set(this.comment.contextValue);
} else {
this._commentContextValue.reset();
}
} }
focus() { focus() {

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { CommentThread, DocumentCommentProvider, CommentThreadChangedEvent, CommentInfo, Comment, CommentReaction, CommentingRanges, CommentThread2 } from 'vs/editor/common/modes'; import { CommentThread, DocumentCommentProvider, CommentThreadChangedEvent, CommentInfo, Comment, CommentReaction, CommentingRanges, CommentThread2 } from 'vs/editor/common/modes';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Event, Emitter } from 'vs/base/common/event'; import { Event, Emitter } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle'; import { Disposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
@@ -14,6 +14,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import { assign } from 'vs/base/common/objects'; import { assign } from 'vs/base/common/objects';
import { ICommentThreadChangedEvent } from 'vs/workbench/contrib/comments/common/commentModel'; import { ICommentThreadChangedEvent } from 'vs/workbench/contrib/comments/common/commentModel';
import { MainThreadCommentController } from 'vs/workbench/api/browser/mainThreadComments'; import { MainThreadCommentController } from 'vs/workbench/api/browser/mainThreadComments';
import { CommentMenus } from 'vs/workbench/contrib/comments/browser/commentMenus';
export const ICommentService = createDecorator<ICommentService>('commentService'); export const ICommentService = createDecorator<ICommentService>('commentService');
@@ -37,9 +38,7 @@ export interface ICommentService {
readonly onDidSetResourceCommentInfos: Event<IResourceCommentThreadEvent>; readonly onDidSetResourceCommentInfos: Event<IResourceCommentThreadEvent>;
readonly onDidSetAllCommentThreads: Event<IWorkspaceCommentThreadsEvent>; readonly onDidSetAllCommentThreads: Event<IWorkspaceCommentThreadsEvent>;
readonly onDidUpdateCommentThreads: Event<ICommentThreadChangedEvent>; readonly onDidUpdateCommentThreads: Event<ICommentThreadChangedEvent>;
readonly onDidChangeActiveCommentThread: Event<CommentThread | null>;
readonly onDidChangeActiveCommentingRange: Event<{ range: Range, commentingRangesInfo: CommentingRanges }>; readonly onDidChangeActiveCommentingRange: Event<{ range: Range, commentingRangesInfo: CommentingRanges }>;
readonly onDidChangeInput: Event<string>;
readonly onDidSetDataProvider: Event<void>; readonly onDidSetDataProvider: Event<void>;
readonly onDidDeleteDataProvider: Event<string>; readonly onDidDeleteDataProvider: Event<string>;
setDocumentComments(resource: URI, commentInfos: ICommentInfo[]): void; setDocumentComments(resource: URI, commentInfos: ICommentInfo[]): void;
@@ -47,9 +46,13 @@ export interface ICommentService {
removeWorkspaceComments(owner: string): void; removeWorkspaceComments(owner: string): void;
registerCommentController(owner: string, commentControl: MainThreadCommentController): void; registerCommentController(owner: string, commentControl: MainThreadCommentController): void;
unregisterCommentController(owner: string): void; unregisterCommentController(owner: string): void;
getCommentController(owner: string): MainThreadCommentController | undefined;
createCommentThreadTemplate(owner: string, resource: URI, range: Range): void;
getCommentMenus(owner: string): CommentMenus;
registerDataProvider(owner: string, commentProvider: DocumentCommentProvider): void; registerDataProvider(owner: string, commentProvider: DocumentCommentProvider): void;
unregisterDataProvider(owner: string): void; unregisterDataProvider(owner: string): void;
updateComments(ownerId: string, event: CommentThreadChangedEvent): void; updateComments(ownerId: string, event: CommentThreadChangedEvent): void;
disposeCommentThread(ownerId: string, threadId: string): void;
createNewCommentThread(owner: string, resource: URI, range: Range, text: string): Promise<CommentThread | null>; createNewCommentThread(owner: string, resource: URI, range: Range, text: string): Promise<CommentThread | null>;
replyToCommentThread(owner: string, resource: URI, range: Range, thread: CommentThread, text: string): Promise<CommentThread | null>; replyToCommentThread(owner: string, resource: URI, range: Range, thread: CommentThread, text: string): Promise<CommentThread | null>;
editComment(owner: string, resource: URI, comment: Comment, text: string): Promise<void>; editComment(owner: string, resource: URI, comment: Comment, text: string): Promise<void>;
@@ -66,9 +69,6 @@ export interface ICommentService {
deleteReaction(owner: string, resource: URI, comment: Comment, reaction: CommentReaction): Promise<void>; deleteReaction(owner: string, resource: URI, comment: Comment, reaction: CommentReaction): Promise<void>;
getReactionGroup(owner: string): CommentReaction[] | undefined; getReactionGroup(owner: string): CommentReaction[] | undefined;
toggleReaction(owner: string, resource: URI, thread: CommentThread2, comment: Comment, reaction: CommentReaction): Promise<void>; toggleReaction(owner: string, resource: URI, thread: CommentThread2, comment: Comment, reaction: CommentReaction): Promise<void>;
getCommentThreadFromTemplate(owner: string, resource: URI, range: IRange, ): CommentThread2 | undefined;
setActiveCommentThread(commentThread: CommentThread | null): void;
setInput(input: string): void;
} }
export class CommentService extends Disposable implements ICommentService { export class CommentService extends Disposable implements ICommentService {
@@ -89,11 +89,6 @@ export class CommentService extends Disposable implements ICommentService {
private readonly _onDidUpdateCommentThreads: Emitter<ICommentThreadChangedEvent> = this._register(new Emitter<ICommentThreadChangedEvent>()); private readonly _onDidUpdateCommentThreads: Emitter<ICommentThreadChangedEvent> = this._register(new Emitter<ICommentThreadChangedEvent>());
readonly onDidUpdateCommentThreads: Event<ICommentThreadChangedEvent> = this._onDidUpdateCommentThreads.event; readonly onDidUpdateCommentThreads: Event<ICommentThreadChangedEvent> = this._onDidUpdateCommentThreads.event;
private readonly _onDidChangeActiveCommentThread = this._register(new Emitter<CommentThread | null>());
readonly onDidChangeActiveCommentThread: Event<CommentThread | null> = this._onDidChangeActiveCommentThread.event;
private readonly _onDidChangeInput: Emitter<string> = this._register(new Emitter<string>());
readonly onDidChangeInput: Event<string> = this._onDidChangeInput.event;
private readonly _onDidChangeActiveCommentingRange: Emitter<{ private readonly _onDidChangeActiveCommentingRange: Emitter<{
range: Range, commentingRangesInfo: range: Range, commentingRangesInfo:
CommentingRanges CommentingRanges
@@ -106,19 +101,14 @@ export class CommentService extends Disposable implements ICommentService {
private _commentProviders = new Map<string, DocumentCommentProvider>(); private _commentProviders = new Map<string, DocumentCommentProvider>();
private _commentControls = new Map<string, MainThreadCommentController>(); private _commentControls = new Map<string, MainThreadCommentController>();
private _commentMenus = new Map<string, CommentMenus>();
constructor() { constructor(
@IInstantiationService protected instantiationService: IInstantiationService
) {
super(); super();
} }
setActiveCommentThread(commentThread: CommentThread | null) {
this._onDidChangeActiveCommentThread.fire(commentThread);
}
setInput(input: string) {
this._onDidChangeInput.fire(input);
}
setDocumentComments(resource: URI, commentInfos: ICommentInfo[]): void { setDocumentComments(resource: URI, commentInfos: ICommentInfo[]): void {
this._onDidSetResourceCommentInfos.fire({ resource, commentInfos }); this._onDidSetResourceCommentInfos.fire({ resource, commentInfos });
} }
@@ -141,6 +131,39 @@ export class CommentService extends Disposable implements ICommentService {
this._onDidDeleteDataProvider.fire(owner); this._onDidDeleteDataProvider.fire(owner);
} }
getCommentController(owner: string): MainThreadCommentController | undefined {
return this._commentControls.get(owner);
}
createCommentThreadTemplate(owner: string, resource: URI, range: Range): void {
const commentController = this._commentControls.get(owner);
if (!commentController) {
return;
}
commentController.createCommentThreadTemplate(resource, range);
}
disposeCommentThread(owner: string, threadId: string) {
let controller = this.getCommentController(owner);
if (controller) {
controller.deleteCommentThreadMain(threadId);
}
}
getCommentMenus(owner: string): CommentMenus {
if (this._commentMenus.get(owner)) {
return this._commentMenus.get(owner)!;
}
let controller = this._commentControls.get(owner);
let menu = this.instantiationService.createInstance(CommentMenus, controller!);
this._commentMenus.set(owner, menu);
return menu;
}
registerDataProvider(owner: string, commentProvider: DocumentCommentProvider): void { registerDataProvider(owner: string, commentProvider: DocumentCommentProvider): void {
this._commentProviders.set(owner, commentProvider); this._commentProviders.set(owner, commentProvider);
this._onDidSetDataProvider.fire(); this._onDidSetDataProvider.fire();
@@ -256,16 +279,6 @@ export class CommentService extends Disposable implements ICommentService {
} }
} }
getCommentThreadFromTemplate(owner: string, resource: URI, range: IRange, ): CommentThread2 | undefined {
const commentController = this._commentControls.get(owner);
if (commentController) {
return commentController.getCommentThreadFromTemplate(resource, range);
}
return undefined;
}
getReactionGroup(owner: string): CommentReaction[] | undefined { getReactionGroup(owner: string): CommentReaction[] | undefined {
const commentProvider = this._commentControls.get(owner); const commentProvider = this._commentControls.get(owner);

View File

@@ -5,9 +5,9 @@
import * as nls from 'vs/nls'; import * as nls from 'vs/nls';
import * as dom from 'vs/base/browser/dom'; import * as dom from 'vs/base/browser/dom';
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar'; import { ActionBar, ActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar';
import { Button } from 'vs/base/browser/ui/button/button'; import { Button } from 'vs/base/browser/ui/button/button';
import { Action } from 'vs/base/common/actions'; import { Action, IAction } from 'vs/base/common/actions';
import * as arrays from 'vs/base/common/arrays'; import * as arrays from 'vs/base/common/arrays';
import { Color } from 'vs/base/common/color'; import { Color } from 'vs/base/common/color';
import { Emitter, Event } from 'vs/base/common/event'; import { Emitter, Event } from 'vs/base/common/event';
@@ -38,9 +38,18 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
import { generateUuid } from 'vs/base/common/uuid'; import { generateUuid } from 'vs/base/common/uuid';
import { ICommentThreadWidget } from 'vs/workbench/contrib/comments/common/commentThreadWidget'; import { ICommentThreadWidget } from 'vs/workbench/contrib/comments/common/commentThreadWidget';
import { withNullAsUndefined } from 'vs/base/common/types'; import { withNullAsUndefined } from 'vs/base/common/types';
import { CommentMenus } from 'vs/workbench/contrib/comments/browser/commentMenus';
import { MenuItemAction, IMenu } from 'vs/platform/actions/common/actions';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { ContextAwareMenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { CommentContextKeys } from 'vs/workbench/contrib/comments/common/commentContextKeys';
import { CommentFormActions } from 'vs/workbench/contrib/comments/browser/commentFormActions';
export const COMMENTEDITOR_DECORATION_KEY = 'commenteditordecoration'; export const COMMENTEDITOR_DECORATION_KEY = 'commenteditordecoration';
const COLLAPSE_ACTION_CLASS = 'expand-review-action octicon octicon-x'; const COLLAPSE_ACTION_CLASS = 'expand-review-action octicon octicon-chevron-up';
const COMMENT_SCHEME = 'comment'; const COMMENT_SCHEME = 'comment';
@@ -70,6 +79,11 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
private _styleElement: HTMLStyleElement; private _styleElement: HTMLStyleElement;
private _formActions: HTMLElement | null; private _formActions: HTMLElement | null;
private _error: HTMLElement; private _error: HTMLElement;
private _contextKeyService: IContextKeyService;
private _threadIsEmpty: IContextKey<boolean>;
private _commentThreadContextValue: IContextKey<string>;
private _commentEditorIsEmpty: IContextKey<boolean>;
private _commentFormActions: CommentFormActions;
public get owner(): string { public get owner(): string {
return this._owner; return this._owner;
@@ -86,6 +100,8 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
return this._draftMode; return this._draftMode;
} }
private _commentMenus: CommentMenus;
constructor( constructor(
editor: ICodeEditor, editor: ICodeEditor,
private _owner: string, private _owner: string,
@@ -98,15 +114,25 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
@IModelService private modelService: IModelService, @IModelService private modelService: IModelService,
@IThemeService private themeService: IThemeService, @IThemeService private themeService: IThemeService,
@ICommentService private commentService: ICommentService, @ICommentService private commentService: ICommentService,
@IOpenerService private openerService: IOpenerService @IOpenerService private openerService: IOpenerService,
@IKeybindingService private keybindingService: IKeybindingService,
@INotificationService private notificationService: INotificationService,
@IContextMenuService private contextMenuService: IContextMenuService,
@IContextKeyService contextKeyService: IContextKeyService
) { ) {
super(editor, { keepEditorSelection: true }); super(editor, { keepEditorSelection: true });
this._contextKeyService = contextKeyService.createScoped(this.domNode);
this._threadIsEmpty = CommentContextKeys.commentThreadIsEmpty.bindTo(this._contextKeyService);
this._threadIsEmpty.set(!_commentThread.comments || !_commentThread.comments.length);
this._commentThreadContextValue = contextKeyService.createKey('commentThread', _commentThread.contextValue);
this._resizeObserver = null; this._resizeObserver = null;
this._isExpanded = _commentThread.collapsibleState ? _commentThread.collapsibleState === modes.CommentThreadCollapsibleState.Expanded : undefined; this._isExpanded = _commentThread.collapsibleState ? _commentThread.collapsibleState === modes.CommentThreadCollapsibleState.Expanded : undefined;
this._globalToDispose = []; this._globalToDispose = [];
this._commentThreadDisposables = []; this._commentThreadDisposables = [];
this._submitActionsDisposables = []; this._submitActionsDisposables = [];
this._formActions = null; this._formActions = null;
this._commentMenus = this.commentService.getCommentMenus(this._owner);
this.create(); this.create();
this._styleElement = dom.createStyleSheet(this.domNode); this._styleElement = dom.createStyleSheet(this.domNode);
@@ -185,10 +211,6 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
this._bodyElement = <HTMLDivElement>dom.$('.body'); this._bodyElement = <HTMLDivElement>dom.$('.body');
container.appendChild(this._bodyElement); container.appendChild(this._bodyElement);
dom.addDisposableListener(this._bodyElement, dom.EventType.FOCUS_IN, e => {
this.commentService.setActiveCommentThread(this._commentThread);
});
} }
protected _fillHead(container: HTMLElement): void { protected _fillHead(container: HTMLElement): void {
@@ -198,12 +220,41 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
this.createThreadLabel(); this.createThreadLabel();
const actionsContainer = dom.append(this._headElement, dom.$('.review-actions')); const actionsContainer = dom.append(this._headElement, dom.$('.review-actions'));
this._actionbarWidget = new ActionBar(actionsContainer, {}); this._actionbarWidget = new ActionBar(actionsContainer, {
actionViewItemProvider: (action: IAction) => {
if (action instanceof MenuItemAction) {
let item = new ContextAwareMenuEntryActionViewItem(action, this.keybindingService, this.notificationService, this.contextMenuService);
return item;
} else {
let item = new ActionViewItem({}, action, { label: false, icon: true });
return item;
}
}
});
this._disposables.push(this._actionbarWidget); this._disposables.push(this._actionbarWidget);
this._collapseAction = new Action('review.expand', nls.localize('label.collapse', "Collapse"), COLLAPSE_ACTION_CLASS, true, () => this.collapse()); this._collapseAction = new Action('review.expand', nls.localize('label.collapse', "Collapse"), COLLAPSE_ACTION_CLASS, true, () => this.collapse());
this._actionbarWidget.push(this._collapseAction, { label: false, icon: true }); if ((this._commentThread as modes.CommentThread2).commentThreadHandle !== undefined) {
const menu = this._commentMenus.getCommentThreadTitleActions(this._commentThread as modes.CommentThread2, this._contextKeyService);
this.setActionBarActions(menu);
this._disposables.push(menu);
this._disposables.push(menu.onDidChange(e => {
this.setActionBarActions(menu);
}));
} else {
this._actionbarWidget.push([this._collapseAction], { label: false, icon: true });
}
this._actionbarWidget.context = this._commentThread;
}
private setActionBarActions(menu: IMenu): void {
const groups = menu.getActions({ shouldForwardArgs: true }).reduce((r, [, actions]) => [...r, ...actions], <MenuItemAction[]>[]);
this._actionbarWidget.clear();
this._actionbarWidget.push([...groups, this._collapseAction], { label: false, icon: true });
} }
public collapse(): Promise<void> { public collapse(): Promise<void> {
@@ -214,9 +265,9 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
} else { } else {
const deleteCommand = (this._commentThread as modes.CommentThread2).deleteCommand; const deleteCommand = (this._commentThread as modes.CommentThread2).deleteCommand;
if (deleteCommand) { if (deleteCommand) {
this.commentService.setActiveCommentThread(this._commentThread);
return this.commandService.executeCommand(deleteCommand.id, ...(deleteCommand.arguments || [])); return this.commandService.executeCommand(deleteCommand.id, ...(deleteCommand.arguments || []));
} else if (this._commentEditor.getValue() === '') { } else if (this._commentEditor.getValue() === '') {
this.commentService.disposeCommentThread(this._owner, this._commentThread.threadId!);
this.dispose(); this.dispose();
return Promise.resolve(); return Promise.resolve();
} }
@@ -245,9 +296,10 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
} }
} }
async update(commentThread: modes.CommentThread | modes.CommentThread2, replaceTemplate: boolean = false) { async update(commentThread: modes.CommentThread | modes.CommentThread2) {
const oldCommentsLen = this._commentElements.length; const oldCommentsLen = this._commentElements.length;
const newCommentsLen = commentThread.comments ? commentThread.comments.length : 0; const newCommentsLen = commentThread.comments ? commentThread.comments.length : 0;
this._threadIsEmpty.set(!newCommentsLen);
let commentElementsToDel: CommentNode[] = []; let commentElementsToDel: CommentNode[] = [];
let commentElementsToDelIndex: number[] = []; let commentElementsToDelIndex: number[] = [];
@@ -294,26 +346,12 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
this._commentThread = commentThread; this._commentThread = commentThread;
this._commentElements = newCommentNodeList; this._commentElements = newCommentNodeList;
this.createThreadLabel(replaceTemplate); this.createThreadLabel();
if (replaceTemplate) {
// since we are replacing the old comment thread, we need to rebind the listeners.
this._commentThreadDisposables.forEach(global => global.dispose());
this._commentThreadDisposables = [];
}
if (replaceTemplate) {
this.createTextModelListener();
}
if (this._formActions && this._commentEditor.hasModel()) { if (this._formActions && this._commentEditor.hasModel()) {
dom.clearNode(this._formActions); dom.clearNode(this._formActions);
const model = this._commentEditor.getModel(); const model = this._commentEditor.getModel();
this.createCommentWidgetActions2(this._formActions, model); this.createCommentWidgetActions2(this._formActions, model);
if (replaceTemplate) {
this.createCommentWidgetActionsListener(this._formActions, model);
}
} }
// Move comment glyph widget and show position if the line has changed. // Move comment glyph widget and show position if the line has changed.
@@ -346,6 +384,12 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
this.hide(); this.hide();
} }
} }
if (this._commentThread.contextValue) {
this._commentThreadContextValue.set(this._commentThread.contextValue);
} else {
this._commentThreadContextValue.reset();
}
} }
updateDraftMode(draftMode: modes.DraftMode | undefined) { updateDraftMode(draftMode: modes.DraftMode | undefined) {
@@ -368,7 +412,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
this._commentEditor.layout({ height: 5 * 18, width: widthInPixel - 54 /* margin 20px * 10 + scrollbar 14px*/ }); this._commentEditor.layout({ height: 5 * 18, width: widthInPixel - 54 /* margin 20px * 10 + scrollbar 14px*/ });
} }
display(lineNumber: number, fromTemplate: boolean = false) { display(lineNumber: number) {
this._commentGlyph = new CommentGlyphWidget(this.editor, lineNumber); this._commentGlyph = new CommentGlyphWidget(this.editor, lineNumber);
this._disposables.push(this.editor.onMouseDown(e => this.onEditorMouseDown(e))); this._disposables.push(this.editor.onMouseDown(e => this.onEditorMouseDown(e)));
@@ -394,18 +438,30 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
const hasExistingComments = this._commentThread.comments && this._commentThread.comments.length > 0; const hasExistingComments = this._commentThread.comments && this._commentThread.comments.length > 0;
this._commentForm = dom.append(this._bodyElement, dom.$('.comment-form')); this._commentForm = dom.append(this._bodyElement, dom.$('.comment-form'));
this._commentEditor = this.instantiationService.createInstance(SimpleCommentEditor, this._commentForm, SimpleCommentEditor.getEditorOptions(), this._parentEditor, this); this._commentEditor = this.instantiationService.createInstance(SimpleCommentEditor, this._commentForm, SimpleCommentEditor.getEditorOptions(), this._parentEditor, this);
this._commentEditorIsEmpty = CommentContextKeys.commentIsEmpty.bindTo(this._contextKeyService);
this._commentEditorIsEmpty.set(!this._pendingComment);
const modeId = generateUuid() + '-' + (hasExistingComments ? this._commentThread.threadId : ++INMEM_MODEL_ID); const modeId = generateUuid() + '-' + (hasExistingComments ? this._commentThread.threadId : ++INMEM_MODEL_ID);
const params = JSON.stringify({ const params = JSON.stringify({
extensionId: this.extensionId, extensionId: this.extensionId,
commentThreadId: this.commentThread.threadId commentThreadId: this.commentThread.threadId
}); });
const resource = URI.parse(`${COMMENT_SCHEME}:commentinput-${modeId}.md?${params}`);
let resource = URI.parse(`${COMMENT_SCHEME}://${this.extensionId}/commentinput-${modeId}.md?${params}`); // TODO. Remove params once extensions adopt authority.
let commentController = this.commentService.getCommentController(this.owner);
if (commentController) {
resource = resource.with({ authority: commentController.id });
}
const model = this.modelService.createModel(this._pendingComment || '', this.modeService.createByFilepathOrFirstLine(resource.path), resource, false); const model = this.modelService.createModel(this._pendingComment || '', this.modeService.createByFilepathOrFirstLine(resource.path), resource, false);
this._disposables.push(model); this._disposables.push(model);
this._commentEditor.setModel(model); this._commentEditor.setModel(model);
this._disposables.push(this._commentEditor); this._disposables.push(this._commentEditor);
this._disposables.push(this._commentEditor.getModel()!.onDidChangeContent(() => this.setCommentEditorDecorations())); this._disposables.push(this._commentEditor.getModel()!.onDidChangeContent(() => {
this.setCommentEditorDecorations();
this._commentEditorIsEmpty.set(!this._commentEditor.getValue());
}));
if ((this._commentThread as modes.CommentThread2).commentThreadHandle !== undefined) { if ((this._commentThread as modes.CommentThread2).commentThreadHandle !== undefined) {
this.createTextModelListener(); this.createTextModelListener();
} }
@@ -426,9 +482,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
this._formActions = dom.append(this._commentForm, dom.$('.form-actions')); this._formActions = dom.append(this._commentForm, dom.$('.form-actions'));
if ((this._commentThread as modes.CommentThread2).commentThreadHandle !== undefined) { if ((this._commentThread as modes.CommentThread2).commentThreadHandle !== undefined) {
this.createCommentWidgetActions2(this._formActions, model); this.createCommentWidgetActions2(this._formActions, model);
if (!fromTemplate) { this.createCommentWidgetActionsListener(this._formActions, model);
this.createCommentWidgetActionsListener(this._formActions, model);
}
} else { } else {
this.createCommentWidgetActions(this._formActions, model); this.createCommentWidgetActions(this._formActions, model);
} }
@@ -462,7 +516,6 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
uri: this._commentEditor.getModel()!.uri, uri: this._commentEditor.getModel()!.uri,
value: this._commentEditor.getValue() value: this._commentEditor.getValue()
}; };
this.commentService.setActiveCommentThread(this._commentThread);
})); }));
this._commentThreadDisposables.push(this._commentEditor.getModel()!.onDidChangeContent(() => { this._commentThreadDisposables.push(this._commentEditor.getModel()!.onDidChangeContent(() => {
@@ -674,7 +727,6 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
uri: this._commentEditor.getModel()!.uri, uri: this._commentEditor.getModel()!.uri,
value: this._commentEditor.getValue() value: this._commentEditor.getValue()
}; };
this.commentService.setActiveCommentThread(this._commentThread);
await this.commandService.executeCommand(acceptInputCommand.id, ...(acceptInputCommand.arguments || [])); await this.commandService.executeCommand(acceptInputCommand.id, ...(acceptInputCommand.arguments || []));
})); }));
@@ -699,11 +751,29 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
uri: this._commentEditor.getModel()!.uri, uri: this._commentEditor.getModel()!.uri,
value: this._commentEditor.getValue() value: this._commentEditor.getValue()
}; };
this.commentService.setActiveCommentThread(this._commentThread);
await this.commandService.executeCommand(command.id, ...(command.arguments || [])); await this.commandService.executeCommand(command.id, ...(command.arguments || []));
})); }));
}); });
} }
const menu = this._commentMenus.getCommentThreadActions(commentThread, this._contextKeyService);
this._disposables.push(menu);
this._disposables.push(menu.onDidChange(() => {
this._commentFormActions.setActions(menu);
}));
this._commentFormActions = new CommentFormActions(container, (action: IAction) => {
action.run({
thread: this._commentThread,
text: this._commentEditor.getValue(),
$mid: 8
});
this.hideReplyArea();
}, this.themeService);
this._commentFormActions.setActions(menu);
} }
private createNewCommentNode(comment: modes.Comment): CommentNode { private createNewCommentNode(comment: modes.Comment): CommentNode {
@@ -751,7 +821,6 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
uri: this._commentEditor.getModel()!.uri, uri: this._commentEditor.getModel()!.uri,
value: this._commentEditor.getValue() value: this._commentEditor.getValue()
}; };
this.commentService.setActiveCommentThread(this._commentThread);
let commandId = commentThread.acceptInputCommand.id; let commandId = commentThread.acceptInputCommand.id;
let args = commentThread.acceptInputCommand.arguments || []; let args = commentThread.acceptInputCommand.arguments || [];
@@ -827,14 +896,13 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
} }
} }
private createThreadLabel(replaceTemplate: boolean = false) { private createThreadLabel() {
let label: string | undefined; let label: string | undefined;
if ((this._commentThread as modes.CommentThread2).commentThreadHandle !== undefined) { if ((this._commentThread as modes.CommentThread2).commentThreadHandle !== undefined) {
label = (this._commentThread as modes.CommentThread2).label; label = (this._commentThread as modes.CommentThread2).label;
} }
if (label === undefined && !replaceTemplate) { if (label === undefined) {
// if it's for replacing the comment thread template, the comment thread widget title can be undefined as extensions may set it later
if (this._commentThread.comments && this._commentThread.comments.length) { if (this._commentThread.comments && this._commentThread.comments.length) {
const participantsList = this._commentThread.comments.filter(arrays.uniqueFilter(comment => comment.userName)).map(comment => `@${comment.userName}`).join(', '); const participantsList = this._commentThread.comments.filter(arrays.uniqueFilter(comment => comment.userName)).map(comment => `@${comment.userName}`).join(', ');
label = nls.localize('commentThreadParticipants', "Participants: {0}", participantsList); label = nls.localize('commentThreadParticipants', "Participants: {0}", participantsList);
@@ -847,7 +915,6 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
this._headingLabel.innerHTML = strings.escape(label); this._headingLabel.innerHTML = strings.escape(label);
this._headingLabel.setAttribute('aria-label', label); this._headingLabel.setAttribute('aria-label', label);
} }
} }
private expandReplyArea() { private expandReplyArea() {
@@ -857,6 +924,17 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
} }
} }
private hideReplyArea() {
this._commentEditor.setValue('');
this._pendingComment = '';
if (dom.hasClass(this._commentForm, 'expand')) {
dom.removeClass(this._commentForm, 'expand');
}
this._commentEditor.getDomNode()!.style.outline = '';
this._error.textContent = '';
dom.addClass(this._error, 'hidden');
}
private createReplyButton() { private createReplyButton() {
this._reviewThreadReplyButton = <HTMLButtonElement>dom.append(this._commentForm, dom.$('button.review-thread-reply-button')); this._reviewThreadReplyButton = <HTMLButtonElement>dom.append(this._commentForm, dom.$('button.review-thread-reply-button'));
if ((this._commentThread as modes.CommentThread2).commentThreadHandle !== undefined) { if ((this._commentThread as modes.CommentThread2).commentThreadHandle !== undefined) {

View File

@@ -64,7 +64,7 @@ class CommentingRangeDecoration {
return this._decorationId; return this._decorationId;
} }
constructor(private _editor: ICodeEditor, private _ownerId: string, private _extensionId: string | undefined, private _label: string | undefined, private _range: IRange, private _reply: modes.Command | undefined, commentingOptions: ModelDecorationOptions, private _template: modes.CommentThreadTemplate | undefined, private commentingRangesInfo?: modes.CommentingRanges) { constructor(private _editor: ICodeEditor, private _ownerId: string, private _extensionId: string | undefined, private _label: string | undefined, private _range: IRange, private _reply: modes.Command | undefined, commentingOptions: ModelDecorationOptions, private commentingRangesInfo?: modes.CommentingRanges) {
const startLineNumber = _range.startLineNumber; const startLineNumber = _range.startLineNumber;
const endLineNumber = _range.endLineNumber; const endLineNumber = _range.endLineNumber;
let commentingRangeDecorations = [{ let commentingRangeDecorations = [{
@@ -81,14 +81,13 @@ class CommentingRangeDecoration {
} }
} }
public getCommentAction(): { replyCommand: modes.Command | undefined, ownerId: string, extensionId: string | undefined, label: string | undefined, commentingRangesInfo: modes.CommentingRanges | undefined, template: modes.CommentThreadTemplate | undefined } { public getCommentAction(): { replyCommand: modes.Command | undefined, ownerId: string, extensionId: string | undefined, label: string | undefined, commentingRangesInfo: modes.CommentingRanges | undefined } {
return { return {
extensionId: this._extensionId, extensionId: this._extensionId,
label: this._label, label: this._label,
replyCommand: this._reply, replyCommand: this._reply,
ownerId: this._ownerId, ownerId: this._ownerId,
commentingRangesInfo: this.commentingRangesInfo, commentingRangesInfo: this.commentingRangesInfo
template: this._template
}; };
} }
@@ -125,11 +124,11 @@ class CommentingRangeDecorator {
for (const info of commentInfos) { for (const info of commentInfos) {
if (Array.isArray(info.commentingRanges)) { if (Array.isArray(info.commentingRanges)) {
info.commentingRanges.forEach(range => { info.commentingRanges.forEach(range => {
commentingRangeDecorations.push(new CommentingRangeDecoration(editor, info.owner, info.extensionId, info.label, range, info.reply, this.decorationOptions, info.template)); commentingRangeDecorations.push(new CommentingRangeDecoration(editor, info.owner, info.extensionId, info.label, range, info.reply, this.decorationOptions));
}); });
} else { } else {
(info.commentingRanges ? info.commentingRanges.ranges : []).forEach(range => { (info.commentingRanges ? info.commentingRanges.ranges : []).forEach(range => {
commentingRangeDecorations.push(new CommentingRangeDecoration(editor, info.owner, info.extensionId, info.label, range, undefined, this.decorationOptions, info.template, info.commentingRanges as modes.CommentingRanges)); commentingRangeDecorations.push(new CommentingRangeDecoration(editor, info.owner, info.extensionId, info.label, range, undefined, this.decorationOptions, info.commentingRanges as modes.CommentingRanges));
}); });
} }
} }
@@ -424,7 +423,7 @@ export class ReviewController implements IEditorContribution {
} }
removed.forEach(thread => { removed.forEach(thread => {
let matchedZones = this._commentWidgets.filter(zoneWidget => zoneWidget.owner === e.owner && zoneWidget.commentThread.threadId === thread.threadId); let matchedZones = this._commentWidgets.filter(zoneWidget => zoneWidget.owner === e.owner && zoneWidget.commentThread.threadId === thread.threadId && zoneWidget.commentThread.threadId !== '');
if (matchedZones.length) { if (matchedZones.length) {
let matchedZone = matchedZones[0]; let matchedZone = matchedZones[0];
let index = this._commentWidgets.indexOf(matchedZone); let index = this._commentWidgets.indexOf(matchedZone);
@@ -449,7 +448,7 @@ export class ReviewController implements IEditorContribution {
let matchedNewCommentThreadZones = this._commentWidgets.filter(zoneWidget => zoneWidget.owner === e.owner && (zoneWidget.commentThread as any).commentThreadHandle === -1 && Range.equalsRange(zoneWidget.commentThread.range, thread.range)); let matchedNewCommentThreadZones = this._commentWidgets.filter(zoneWidget => zoneWidget.owner === e.owner && (zoneWidget.commentThread as any).commentThreadHandle === -1 && Range.equalsRange(zoneWidget.commentThread.range, thread.range));
if (matchedNewCommentThreadZones.length) { if (matchedNewCommentThreadZones.length) {
matchedNewCommentThreadZones[0].update(thread, true); matchedNewCommentThreadZones[0].update(thread);
return; return;
} }
@@ -469,22 +468,6 @@ export class ReviewController implements IEditorContribution {
this._commentWidgets.push(zoneWidget); this._commentWidgets.push(zoneWidget);
} }
private addCommentThreadFromTemplate(lineNumber: number, ownerId: string): ReviewZoneWidget {
let templateCommentThread = this.commentService.getCommentThreadFromTemplate(ownerId, this.editor.getModel()!.uri, {
startLineNumber: lineNumber,
startColumn: 1,
endLineNumber: lineNumber,
endColumn: 1
})!;
templateCommentThread.collapsibleState = modes.CommentThreadCollapsibleState.Expanded;
templateCommentThread.comments = [];
let templateReviewZoneWidget = this.instantiationService.createInstance(ReviewZoneWidget, this.editor, ownerId, templateCommentThread, '', modes.DraftMode.NotSupported);
return templateReviewZoneWidget;
}
private addComment(lineNumber: number, replyCommand: modes.Command | undefined, ownerId: string, extensionId: string | undefined, draftMode: modes.DraftMode | undefined, pendingComment: string | null) { private addComment(lineNumber: number, replyCommand: modes.Command | undefined, ownerId: string, extensionId: string | undefined, draftMode: modes.DraftMode | undefined, pendingComment: string | null) {
if (this._newCommentWidget) { if (this._newCommentWidget) {
this.notificationService.warn(`Please submit the comment at line ${this._newCommentWidget.position ? this._newCommentWidget.position.lineNumber : -1} before creating a new one.`); this.notificationService.warn(`Please submit the comment at line ${this._newCommentWidget.position ? this._newCommentWidget.position.lineNumber : -1} before creating a new one.`);
@@ -640,16 +623,16 @@ export class ReviewController implements IEditorContribution {
const commentInfos = newCommentInfos.filter(info => info.ownerId === pick.id); const commentInfos = newCommentInfos.filter(info => info.ownerId === pick.id);
if (commentInfos.length) { if (commentInfos.length) {
const { replyCommand, ownerId, extensionId, commentingRangesInfo, template } = commentInfos[0]; const { replyCommand, ownerId, extensionId, commentingRangesInfo } = commentInfos[0];
this.addCommentAtLine2(lineNumber, replyCommand, ownerId, extensionId, commentingRangesInfo, template); this.addCommentAtLine2(lineNumber, replyCommand, ownerId, extensionId, commentingRangesInfo);
} }
}).then(() => { }).then(() => {
this._addInProgress = false; this._addInProgress = false;
}); });
} }
} else { } else {
const { replyCommand, ownerId, extensionId, commentingRangesInfo, template } = newCommentInfos[0]!; const { replyCommand, ownerId, extensionId, commentingRangesInfo } = newCommentInfos[0]!;
this.addCommentAtLine2(lineNumber, replyCommand, ownerId, extensionId, commentingRangesInfo, template); this.addCommentAtLine2(lineNumber, replyCommand, ownerId, extensionId, commentingRangesInfo);
} }
return Promise.resolve(); return Promise.resolve();
@@ -668,11 +651,11 @@ export class ReviewController implements IEditorContribution {
return picks; return picks;
} }
private getContextMenuActions(commentInfos: { replyCommand: modes.Command | undefined, ownerId: string, extensionId: string | undefined, label: string | undefined, commentingRangesInfo: modes.CommentingRanges | undefined, template: modes.CommentThreadTemplate | undefined }[], lineNumber: number): (IAction | ContextSubMenu)[] { private getContextMenuActions(commentInfos: { replyCommand: modes.Command | undefined, ownerId: string, extensionId: string | undefined, label: string | undefined, commentingRangesInfo: modes.CommentingRanges | undefined }[], lineNumber: number): (IAction | ContextSubMenu)[] {
const actions: (IAction | ContextSubMenu)[] = []; const actions: (IAction | ContextSubMenu)[] = [];
commentInfos.forEach(commentInfo => { commentInfos.forEach(commentInfo => {
const { replyCommand, ownerId, extensionId, label, commentingRangesInfo, template } = commentInfo; const { replyCommand, ownerId, extensionId, label, commentingRangesInfo } = commentInfo;
actions.push(new Action( actions.push(new Action(
'addCommentThread', 'addCommentThread',
@@ -680,7 +663,7 @@ export class ReviewController implements IEditorContribution {
undefined, undefined,
true, true,
() => { () => {
this.addCommentAtLine2(lineNumber, replyCommand, ownerId, extensionId, commentingRangesInfo, template); this.addCommentAtLine2(lineNumber, replyCommand, ownerId, extensionId, commentingRangesInfo);
return Promise.resolve(); return Promise.resolve();
} }
)); ));
@@ -688,23 +671,10 @@ export class ReviewController implements IEditorContribution {
return actions; return actions;
} }
public addCommentAtLine2(lineNumber: number, replyCommand: modes.Command | undefined, ownerId: string, extensionId: string | undefined, commentingRangesInfo: modes.CommentingRanges | undefined, template: modes.CommentThreadTemplate | undefined) { public addCommentAtLine2(lineNumber: number, replyCommand: modes.Command | undefined, ownerId: string, extensionId: string | undefined, commentingRangesInfo: modes.CommentingRanges | undefined) {
if (commentingRangesInfo) { if (commentingRangesInfo) {
let range = new Range(lineNumber, 1, lineNumber, 1); let range = new Range(lineNumber, 1, lineNumber, 1);
if (template) { if (commentingRangesInfo.newCommentThreadCallback) {
// create comment widget through template
let commentThreadWidget = this.addCommentThreadFromTemplate(lineNumber, ownerId);
commentThreadWidget.display(lineNumber, true);
this._commentWidgets.push(commentThreadWidget);
commentThreadWidget.onDidClose(() => {
this._commentWidgets = this._commentWidgets.filter(zoneWidget => !(
zoneWidget.owner === commentThreadWidget.owner &&
(zoneWidget.commentThread as any).commentThreadHandle === -1 &&
Range.equalsRange(zoneWidget.commentThread.range, commentThreadWidget.commentThread.range)
));
});
this.processNextThreadToAdd();
} else if (commentingRangesInfo.newCommentThreadCallback) {
return commentingRangesInfo.newCommentThreadCallback(this.editor.getModel()!.uri, range) return commentingRangesInfo.newCommentThreadCallback(this.editor.getModel()!.uri, range)
.then(_ => { .then(_ => {
this.processNextThreadToAdd(); this.processNextThreadToAdd();
@@ -713,6 +683,11 @@ export class ReviewController implements IEditorContribution {
this.notificationService.error(nls.localize('commentThreadAddFailure', "Adding a new comment thread failed: {0}.", e.message)); this.notificationService.error(nls.localize('commentThreadAddFailure', "Adding a new comment thread failed: {0}.", e.message));
this.processNextThreadToAdd(); this.processNextThreadToAdd();
}); });
} else {
// latest api, no comments creation callback
this.commentService.createCommentThreadTemplate(ownerId, this.editor.getModel()!.uri, range);
this.processNextThreadToAdd();
return undefined; // {{SQL CARBON EDIT}} @anthonydresser strict-null-check
} }
} else { } else {
const commentInfo = this._commentInfos.filter(info => info.owner === ownerId); const commentInfo = this._commentInfos.filter(info => info.owner === ownerId);

View File

@@ -19,11 +19,12 @@ import { ReviewController } from 'vs/workbench/contrib/comments/browser/comments
import { CommentsDataFilter, CommentsDataSource, CommentsModelRenderer } from 'vs/workbench/contrib/comments/browser/commentsTreeViewer'; import { CommentsDataFilter, CommentsDataSource, CommentsModelRenderer } from 'vs/workbench/contrib/comments/browser/commentsTreeViewer';
import { ICommentService, IWorkspaceCommentThreadsEvent } from 'vs/workbench/contrib/comments/browser/commentService'; import { ICommentService, IWorkspaceCommentThreadsEvent } from 'vs/workbench/contrib/comments/browser/commentService';
import { IEditorService, ACTIVE_GROUP, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService'; import { IEditorService, ACTIVE_GROUP, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { ICommandService } from 'vs/platform/commands/common/commands'; import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/commands';
import { textLinkForeground, textLinkActiveForeground, focusBorder, textPreformatForeground } from 'vs/platform/theme/common/colorRegistry'; import { textLinkForeground, textLinkActiveForeground, focusBorder, textPreformatForeground } from 'vs/platform/theme/common/colorRegistry';
import { IOpenerService } from 'vs/platform/opener/common/opener'; import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IStorageService } from 'vs/platform/storage/common/storage'; import { IStorageService } from 'vs/platform/storage/common/storage';
import { ResourceLabels } from 'vs/workbench/browser/labels'; import { ResourceLabels } from 'vs/workbench/browser/labels';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
export const COMMENTS_PANEL_ID = 'workbench.panel.comments'; export const COMMENTS_PANEL_ID = 'workbench.panel.comments';
export const COMMENTS_PANEL_TITLE = 'Comments'; export const COMMENTS_PANEL_TITLE = 'Comments';
@@ -266,3 +267,14 @@ export class CommentsPanel extends Panel {
} }
} }
} }
CommandsRegistry.registerCommand({
id: 'workbench.action.focusCommentsPanel',
handler: (accessor) => {
const panelService = accessor.get(IPanelService);
const panels = panelService.getPanels();
if (panels.some(panelIdentifier => panelIdentifier.id === COMMENTS_PANEL_ID)) {
panelService.openPanel(COMMENTS_PANEL_ID, true);
}
}
});

View File

@@ -198,6 +198,16 @@
background-image: url(./reaction-hc.svg); background-image: url(./reaction-hc.svg);
} }
.monaco-editor .review-widget .body .review-comment .comment-title .action-label {
display: block;
height: 18px;
line-height: 18px;
min-width: 28px;
background-size: 16px;
background-position: center center;
background-repeat: no-repeat;
}
.monaco-editor .review-widget .body .review-comment .comment-title .action-label.toolbar-toggle-pickReactions { .monaco-editor .review-widget .body .review-comment .comment-title .action-label.toolbar-toggle-pickReactions {
background-image: url(./reaction.svg); background-image: url(./reaction.svg);
width: 18px; width: 18px;

View File

@@ -22,6 +22,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility'; import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { ICommentThreadWidget } from 'vs/workbench/contrib/comments/common/commentThreadWidget'; import { ICommentThreadWidget } from 'vs/workbench/contrib/comments/common/commentThreadWidget';
import { CommentContextKeys } from 'vs/workbench/contrib/comments/common/commentContextKeys';
export const ctxCommentEditorFocused = new RawContextKey<boolean>('commentEditorFocused', false); export const ctxCommentEditorFocused = new RawContextKey<boolean>('commentEditorFocused', false);
@@ -30,6 +31,7 @@ export class SimpleCommentEditor extends CodeEditorWidget {
private _parentEditor: ICodeEditor; private _parentEditor: ICodeEditor;
private _parentThread: ICommentThreadWidget; private _parentThread: ICommentThreadWidget;
private _commentEditorFocused: IContextKey<boolean>; private _commentEditorFocused: IContextKey<boolean>;
private _commentEditorEmpty: IContextKey<boolean>;
constructor( constructor(
domElement: HTMLElement, domElement: HTMLElement,
@@ -56,11 +58,15 @@ export class SimpleCommentEditor extends CodeEditorWidget {
super(domElement, options, codeEditorWidgetOptions, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService, accessibilityService); super(domElement, options, codeEditorWidgetOptions, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService, accessibilityService);
this._commentEditorFocused = ctxCommentEditorFocused.bindTo(this._contextKeyService); this._commentEditorFocused = ctxCommentEditorFocused.bindTo(contextKeyService);
this._commentEditorEmpty = CommentContextKeys.commentIsEmpty.bindTo(contextKeyService);
this._commentEditorEmpty.set(!this.getValue());
this._parentEditor = parentEditor; this._parentEditor = parentEditor;
this._parentThread = parentThread; this._parentThread = parentThread;
this._register(this.onDidFocusEditorWidget(_ => this._commentEditorFocused.set(true))); this._register(this.onDidFocusEditorWidget(_ => this._commentEditorFocused.set(true)));
this._register(this.onDidChangeModelContent(e => this._commentEditorEmpty.set(!this.getValue())));
this._register(this.onDidBlurEditorWidget(_ => this._commentEditorFocused.reset())); this._register(this.onDidBlurEditorWidget(_ => this._commentEditorFocused.reset()));
} }

View File

@@ -0,0 +1,17 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
export namespace CommentContextKeys {
/**
* A context key that is set when the comment thread has no comments.
*/
export const commentThreadIsEmpty = new RawContextKey<boolean>('commentThreadIsEmpty', false);
/**
* A context key that is set when the comment has no input.
*/
export const commentIsEmpty = new RawContextKey<boolean>('commentIsEmpty', false);
}

View File

@@ -161,7 +161,7 @@ export abstract class AbstractExpressionsRenderer implements ITreeRenderer<IExpr
}); });
const styler = attachInputBoxStyler(inputBox, this.themeService); const styler = attachInputBoxStyler(inputBox, this.themeService);
inputBox.value = options.initialValue; inputBox.value = replaceWhitespace(options.initialValue);
inputBox.focus(); inputBox.focus();
inputBox.select(); inputBox.select();

View File

@@ -47,24 +47,19 @@ export class BinaryFileEditor extends BaseBinaryResourceEditor {
); );
} }
private openInternal(input: EditorInput, options: EditorOptions): Promise<void> { private async openInternal(input: EditorInput, options: EditorOptions): Promise<void> {
if (input instanceof FileEditorInput) { if (input instanceof FileEditorInput) {
input.setForceOpenAsText(); input.setForceOpenAsText();
return this.editorService.openEditor(input, options, this.group).then(() => undefined); await this.editorService.openEditor(input, options, this.group);
} }
return Promise.resolve();
} }
private openExternal(resource: URI): void { private async openExternal(resource: URI): Promise<void> {
this.windowsService.openExternal(resource.toString()).then(didOpen => { const didOpen = await this.windowsService.openExternal(resource.toString());
if (!didOpen) { if (!didOpen) {
return this.windowsService.showItemInFolder(resource); return this.windowsService.showItemInFolder(resource);
} }
return undefined;
});
} }
getTitle(): string | null { getTitle(): string | null {

View File

@@ -135,7 +135,7 @@ export class FileEditorTracker extends Disposable implements IWorkbenchContribut
private handleDeletes(arg1: URI | FileChangesEvent, isExternal: boolean, movedTo?: URI): void { private handleDeletes(arg1: URI | FileChangesEvent, isExternal: boolean, movedTo?: URI): void {
const nonDirtyFileEditors = this.getOpenedFileEditors(false /* non-dirty only */); const nonDirtyFileEditors = this.getOpenedFileEditors(false /* non-dirty only */);
nonDirtyFileEditors.forEach(editor => { nonDirtyFileEditors.forEach(async editor => {
const resource = editor.getResource(); const resource = editor.getResource();
// Handle deletes in opened editors depending on: // Handle deletes in opened editors depending on:
@@ -170,20 +170,17 @@ export class FileEditorTracker extends Disposable implements IWorkbenchContribut
// file is really gone and not just a faulty file event. // file is really gone and not just a faulty file event.
// This only applies to external file events, so we need to check for the isExternal // This only applies to external file events, so we need to check for the isExternal
// flag. // flag.
let checkExists: Promise<boolean>; let exists = false;
if (isExternal) { if (isExternal) {
checkExists = timeout(100).then(() => this.fileService.exists(resource)); await timeout(100);
} else { exists = await this.fileService.exists(resource);
checkExists = Promise.resolve(false);
} }
checkExists.then(exists => { if (!exists && !editor.isDisposed()) {
if (!exists && !editor.isDisposed()) { editor.dispose();
editor.dispose(); } else if (this.environmentService.verbose) {
} else if (this.environmentService.verbose) { console.warn(`File exists even though we received a delete event: ${resource.toString()}`);
console.warn(`File exists even though we received a delete event: ${resource.toString()}`); }
}
});
} }
}); });
} }

View File

@@ -125,101 +125,103 @@ export class TextFileEditor extends BaseTextEditor {
} }
} }
setInput(input: FileEditorInput, options: EditorOptions, token: CancellationToken): Promise<void> { async setInput(input: FileEditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
// Update/clear view settings if input changes // Update/clear view settings if input changes
this.doSaveOrClearTextEditorViewState(this.input); this.doSaveOrClearTextEditorViewState(this.input);
// Set input and resolve // Set input and resolve
return super.setInput(input, options, token).then(() => { await super.setInput(input, options, token);
return input.resolve().then(resolvedModel => { try {
const resolvedModel = await input.resolve();
// Check for cancellation // Check for cancellation
if (token.isCancellationRequested) { if (token.isCancellationRequested) {
return undefined; return;
} }
// There is a special case where the text editor has to handle binary file editor input: if a binary file // There is a special case where the text editor has to handle binary file editor input: if a binary file
// has been resolved and cached before, it maybe an actual instance of BinaryEditorModel. In this case our text // has been resolved and cached before, it maybe an actual instance of BinaryEditorModel. In this case our text
// editor has to open this model using the binary editor. We return early in this case. // editor has to open this model using the binary editor. We return early in this case.
if (resolvedModel instanceof BinaryEditorModel) { if (resolvedModel instanceof BinaryEditorModel) {
return this.openAsBinary(input, options); return this.openAsBinary(input, options);
} }
const textFileModel = <ITextFileEditorModel>resolvedModel; const textFileModel = <ITextFileEditorModel>resolvedModel;
// Editor // Editor
const textEditor = this.getControl(); const textEditor = this.getControl();
textEditor.setModel(textFileModel.textEditorModel); textEditor.setModel(textFileModel.textEditorModel);
// Always restore View State if any associated // Always restore View State if any associated
const editorViewState = this.loadTextEditorViewState(this.input.getResource()); const editorViewState = this.loadTextEditorViewState(this.input.getResource());
if (editorViewState) { if (editorViewState) {
textEditor.restoreViewState(editorViewState); textEditor.restoreViewState(editorViewState);
} }
// TextOptions (avoiding instanceof here for a reason, do not change!) // TextOptions (avoiding instanceof here for a reason, do not change!)
if (options && types.isFunction((<TextEditorOptions>options).apply)) { if (options && types.isFunction((<TextEditorOptions>options).apply)) {
(<TextEditorOptions>options).apply(textEditor, ScrollType.Immediate); (<TextEditorOptions>options).apply(textEditor, ScrollType.Immediate);
} }
// Readonly flag // Readonly flag
textEditor.updateOptions({ readOnly: textFileModel.isReadonly() }); textEditor.updateOptions({ readOnly: textFileModel.isReadonly() });
}, error => { } catch (error) {
// In case we tried to open a file inside the text editor and the response // In case we tried to open a file inside the text editor and the response
// indicates that this is not a text file, reopen the file through the binary // indicates that this is not a text file, reopen the file through the binary
// editor. // editor.
if ((<TextFileOperationError>error).textFileOperationResult === TextFileOperationResult.FILE_IS_BINARY) { if ((<TextFileOperationError>error).textFileOperationResult === TextFileOperationResult.FILE_IS_BINARY) {
return this.openAsBinary(input, options); return this.openAsBinary(input, options);
} }
// Similar, handle case where we were asked to open a folder in the text editor. // Similar, handle case where we were asked to open a folder in the text editor.
if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_IS_DIRECTORY) { if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_IS_DIRECTORY) {
this.openAsFolder(input); this.openAsFolder(input);
return Promise.reject(new Error(nls.localize('openFolderError', "File is a directory"))); throw new Error(nls.localize('openFolderError', "File is a directory"));
} }
// Offer to create a file from the error if we have a file not found and the name is valid // Offer to create a file from the error if we have a file not found and the name is valid
if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_NOT_FOUND && isValidBasename(basename(input.getResource()))) { if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_NOT_FOUND && isValidBasename(basename(input.getResource()))) {
return Promise.reject(createErrorWithActions(toErrorMessage(error), { throw createErrorWithActions(toErrorMessage(error), {
actions: [ actions: [
new Action('workbench.files.action.createMissingFile', nls.localize('createFile', "Create File"), undefined, true, () => { new Action('workbench.files.action.createMissingFile', nls.localize('createFile', "Create File"), undefined, true, async () => {
return this.textFileService.create(input.getResource()).then(() => this.editorService.openEditor({ await this.textFileService.create(input.getResource());
resource: input.getResource(),
options: {
pinned: true // new file gets pinned by default
}
}));
})
]
}));
}
if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_EXCEED_MEMORY_LIMIT) { return this.editorService.openEditor({
const memoryLimit = Math.max(MIN_MAX_MEMORY_SIZE_MB, +this.configurationService.getValue<number>(undefined, 'files.maxMemoryForLargeFilesMB') || FALLBACK_MAX_MEMORY_SIZE_MB); resource: input.getResource(),
options: {
pinned: true // new file gets pinned by default
}
});
})
]
});
}
return Promise.reject(createErrorWithActions(toErrorMessage(error), { if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_EXCEED_MEMORY_LIMIT) {
actions: [ const memoryLimit = Math.max(MIN_MAX_MEMORY_SIZE_MB, +this.configurationService.getValue<number>(undefined, 'files.maxMemoryForLargeFilesMB') || FALLBACK_MAX_MEMORY_SIZE_MB);
new Action('workbench.window.action.relaunchWithIncreasedMemoryLimit', nls.localize('relaunchWithIncreasedMemoryLimit', "Restart with {0} MB", memoryLimit), undefined, true, () => {
return this.windowsService.relaunch({
addArgs: [
`--max-memory=${memoryLimit}`
]
});
}),
new Action('workbench.window.action.configureMemoryLimit', nls.localize('configureMemoryLimit', 'Configure Memory Limit'), undefined, true, () => {
return this.preferencesService.openGlobalSettings(undefined, { query: 'files.maxMemoryForLargeFilesMB' });
})
]
}));
}
// Otherwise make sure the error bubbles up throw createErrorWithActions(toErrorMessage(error), {
return Promise.reject(error); actions: [
}); new Action('workbench.window.action.relaunchWithIncreasedMemoryLimit', nls.localize('relaunchWithIncreasedMemoryLimit', "Restart with {0} MB", memoryLimit), undefined, true, () => {
}); return this.windowsService.relaunch({
addArgs: [
`--max-memory=${memoryLimit}`
]
});
}),
new Action('workbench.window.action.configureMemoryLimit', nls.localize('configureMemoryLimit', 'Configure Memory Limit'), undefined, true, () => {
return this.preferencesService.openGlobalSettings(undefined, { query: 'files.maxMemoryForLargeFilesMB' });
})
]
});
}
// Otherwise make sure the error bubbles up
throw error;
}
} }
private openAsBinary(input: FileEditorInput, options: EditorOptions): void { private openAsBinary(input: FileEditorInput, options: EditorOptions): void {
@@ -227,21 +229,20 @@ export class TextFileEditor extends BaseTextEditor {
this.editorService.openEditor(input, options, this.group); this.editorService.openEditor(input, options, this.group);
} }
private openAsFolder(input: FileEditorInput): void { private async openAsFolder(input: FileEditorInput): Promise<void> {
if (!this.group) { if (!this.group) {
return; return;
} }
// Since we cannot open a folder, we have to restore the previous input if any and close the editor // Since we cannot open a folder, we have to restore the previous input if any and close the editor
this.group.closeEditor(this.input).then(() => { await this.group.closeEditor(this.input);
// Best we can do is to reveal the folder in the explorer // Best we can do is to reveal the folder in the explorer
if (this.contextService.isInsideWorkspace(input.getResource())) { if (this.contextService.isInsideWorkspace(input.getResource())) {
this.viewletService.openViewlet(VIEWLET_ID).then(() => { await this.viewletService.openViewlet(VIEWLET_ID);
this.explorerService.select(input.getResource(), true);
}); this.explorerService.select(input.getResource(), true);
} }
});
} }
protected getAriaLabel(): string { protected getAriaLabel(): string {

View File

@@ -240,26 +240,26 @@ class ResolveSaveConflictAction extends Action {
super('workbench.files.action.resolveConflict', nls.localize('compareChanges', "Compare")); super('workbench.files.action.resolveConflict', nls.localize('compareChanges', "Compare"));
} }
run(): Promise<any> { async run(): Promise<any> {
if (!this.model.isDisposed()) { if (!this.model.isDisposed()) {
const resource = this.model.getResource(); const resource = this.model.getResource();
const name = basename(resource); const name = basename(resource);
const editorLabel = nls.localize('saveConflictDiffLabel', "{0} (in file) ↔ {1} (in {2}) - Resolve save conflict", name, name, this.environmentService.appNameLong); const editorLabel = nls.localize('saveConflictDiffLabel', "{0} (in file) ↔ {1} (in {2}) - Resolve save conflict", name, name, this.environmentService.appNameLong);
return TextFileContentProvider.open(resource, CONFLICT_RESOLUTION_SCHEME, editorLabel, this.editorService, { pinned: true }).then(() => { await TextFileContentProvider.open(resource, CONFLICT_RESOLUTION_SCHEME, editorLabel, this.editorService, { pinned: true });
if (this.storageService.getBoolean(LEARN_MORE_DIRTY_WRITE_IGNORE_KEY, StorageScope.GLOBAL)) {
return; // return if this message is ignored
}
// Show additional help how to resolve the save conflict if (this.storageService.getBoolean(LEARN_MORE_DIRTY_WRITE_IGNORE_KEY, StorageScope.GLOBAL)) {
const actions: INotificationActions = { primary: [], secondary: [] }; return; // return if this message is ignored
actions.primary!.push(this.instantiationService.createInstance(ResolveConflictLearnMoreAction)); }
actions.secondary!.push(this.instantiationService.createInstance(DoNotShowResolveConflictLearnMoreAction));
const handle = this.notificationService.notify({ severity: Severity.Info, message: conflictEditorHelp, actions }); // Show additional help how to resolve the save conflict
Event.once(handle.onDidClose)(() => dispose(...actions.primary!, ...actions.secondary!)); const actions: INotificationActions = { primary: [], secondary: [] };
pendingResolveSaveConflictMessages.push(handle); actions.primary!.push(this.instantiationService.createInstance(ResolveConflictLearnMoreAction));
}); actions.secondary!.push(this.instantiationService.createInstance(DoNotShowResolveConflictLearnMoreAction));
const handle = this.notificationService.notify({ severity: Severity.Info, message: conflictEditorHelp, actions });
Event.once(handle.onDidClose)(() => dispose(...actions.primary!, ...actions.secondary!));
pendingResolveSaveConflictMessages.push(handle);
} }
return Promise.resolve(true); return Promise.resolve(true);
@@ -316,31 +316,28 @@ export const acceptLocalChangesCommand = (accessor: ServicesAccessor, resource:
const editor = control.input; const editor = control.input;
const group = control.group; const group = control.group;
resolverService.createModelReference(resource).then(reference => { resolverService.createModelReference(resource).then(async reference => {
const model = reference.object as IResolvedTextFileEditorModel; const model = reference.object as IResolvedTextFileEditorModel;
const localModelSnapshot = model.createSnapshot(); const localModelSnapshot = model.createSnapshot();
clearPendingResolveSaveConflictMessages(); // hide any previously shown message about how to use these actions clearPendingResolveSaveConflictMessages(); // hide any previously shown message about how to use these actions
// Revert to be able to save // Revert to be able to save
return model.revert().then(() => { await model.revert();
// Restore user value (without loosing undo stack) // Restore user value (without loosing undo stack)
modelService.updateModel(model.textEditorModel, createTextBufferFactoryFromSnapshot(localModelSnapshot)); modelService.updateModel(model.textEditorModel, createTextBufferFactoryFromSnapshot(localModelSnapshot));
// Trigger save // Trigger save
return model.save().then(() => { await model.save();
// Reopen file input // Reopen file input
return editorService.openEditor({ resource: model.getResource() }, group).then(() => { await editorService.openEditor({ resource: model.getResource() }, group);
// Clean up // Clean up
group.closeEditor(editor); group.closeEditor(editor);
editor.dispose(); editor.dispose();
reference.dispose(); reference.dispose();
});
});
});
}); });
}; };
@@ -355,22 +352,20 @@ export const revertLocalChangesCommand = (accessor: ServicesAccessor, resource:
const editor = control.input; const editor = control.input;
const group = control.group; const group = control.group;
resolverService.createModelReference(resource).then(reference => { resolverService.createModelReference(resource).then(async reference => {
const model = reference.object as ITextFileEditorModel; const model = reference.object as ITextFileEditorModel;
clearPendingResolveSaveConflictMessages(); // hide any previously shown message about how to use these actions clearPendingResolveSaveConflictMessages(); // hide any previously shown message about how to use these actions
// Revert on model // Revert on model
return model.revert().then(() => { await model.revert();
// Reopen file input // Reopen file input
return editorService.openEditor({ resource: model.getResource() }, group).then(() => { await editorService.openEditor({ resource: model.getResource() }, group);
// Clean up // Clean up
group.closeEditor(editor); group.closeEditor(editor);
editor.dispose(); editor.dispose();
reference.dispose(); reference.dispose();
});
});
}); });
}; };

Some files were not shown because too many files have changed in this diff Show More