mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-08 17:24:01 -05:00
Merge from vscode 5b9869eb02fa4c96205a74d05cad9164dfd06d60 (#5607)
This commit is contained in:
@@ -106,6 +106,16 @@ export class MainThreadCommentThread implements modes.CommentThread2 {
|
||||
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>();
|
||||
get onDidChangeLabel(): Event<string> { return this._onDidChangeLabel.event; }
|
||||
|
||||
@@ -204,6 +214,7 @@ export class MainThreadCommentThread implements modes.CommentThread2 {
|
||||
batchUpdate(
|
||||
range: IRange,
|
||||
label: string,
|
||||
contextValue: string | undefined,
|
||||
comments: modes.Comment[],
|
||||
acceptInputCommand: modes.Command | undefined,
|
||||
additionalCommands: modes.Command[],
|
||||
@@ -211,6 +222,7 @@ export class MainThreadCommentThread implements modes.CommentThread2 {
|
||||
collapsibleState: modes.CommentThreadCollapsibleState) {
|
||||
this._range = range;
|
||||
this._label = label;
|
||||
this._contextValue = contextValue;
|
||||
this._comments = comments;
|
||||
this._acceptInputCommand = acceptInputCommand;
|
||||
this._additionalCommands = additionalCommands;
|
||||
@@ -247,6 +259,10 @@ export class MainThreadCommentController {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
get contextValue(): string {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
get proxy(): ExtHostCommentsShape {
|
||||
return this._proxy;
|
||||
}
|
||||
@@ -319,13 +335,14 @@ export class MainThreadCommentController {
|
||||
resource: UriComponents,
|
||||
range: IRange,
|
||||
label: string,
|
||||
contextValue: string | undefined,
|
||||
comments: modes.Comment[],
|
||||
acceptInputCommand: modes.Command | undefined,
|
||||
additionalCommands: modes.Command[],
|
||||
deleteCommand: modes.Command | undefined,
|
||||
collapsibleState: modes.CommentThreadCollapsibleState): void {
|
||||
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, {
|
||||
added: [],
|
||||
@@ -349,6 +366,14 @@ export class MainThreadCommentController {
|
||||
thread.dispose();
|
||||
}
|
||||
|
||||
deleteCommentThreadMain(commentThreadId: string) {
|
||||
this._threads.forEach(thread => {
|
||||
if (thread.threadId === commentThreadId) {
|
||||
this._proxy.$deleteCommentThread(this._handle, thread.commentThreadHandle);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
updateInput(input: string) {
|
||||
let thread = this.activeCommentThread;
|
||||
|
||||
@@ -377,31 +402,26 @@ export class MainThreadCommentController {
|
||||
}
|
||||
|
||||
let commentingRanges = await this._proxy.$provideCommentingRanges(this.handle, resource, token);
|
||||
let staticContribution = await this._proxy.$checkStaticContribution(this.handle);
|
||||
|
||||
return <ICommentInfo>{
|
||||
owner: this._uniqueId,
|
||||
label: this.label,
|
||||
threads: ret,
|
||||
commentingRanges: commentingRanges ?
|
||||
{
|
||||
resource: resource, ranges: commentingRanges, newCommentThreadCallback: async (uri: UriComponents, range: IRange) => {
|
||||
let threadHandle = await this._proxy.$createNewCommentWidgetCallback(this.handle, uri, range, token);
|
||||
commentingRanges: commentingRanges ? {
|
||||
resource: resource,
|
||||
ranges: commentingRanges,
|
||||
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
|
||||
// return this.getKnownThread(threadHandle);
|
||||
// }
|
||||
// if (threadHandle !== undefined) { {{SQL CARBON EDIT}} @anthonydresser this never happens but throws error because of strict null checks
|
||||
// return this.getKnownThread(threadHandle);
|
||||
// }
|
||||
|
||||
return undefined; // {{SQL CARBON EDIT}} @anthonydresser revert back after strict-null-check
|
||||
}
|
||||
} : [],
|
||||
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
|
||||
return undefined; // {{SQL CARBON EDIT}} @anthonydresser revert back after strict-null-check
|
||||
}
|
||||
} : [],
|
||||
draftMode: modes.DraftMode.NotSupported
|
||||
};
|
||||
}
|
||||
|
||||
@@ -427,26 +447,8 @@ export class MainThreadCommentController {
|
||||
return ret;
|
||||
}
|
||||
|
||||
getCommentThreadFromTemplate(resource: UriComponents, range: IRange): MainThreadCommentThread {
|
||||
let thread = new MainThreadCommentThread(
|
||||
-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;
|
||||
createCommentThreadTemplate(resource: UriComponents, range: IRange): void {
|
||||
this._proxy.$createCommentThreadTemplate(this.handle, resource, range);
|
||||
}
|
||||
|
||||
toJSON(): any {
|
||||
@@ -467,8 +469,6 @@ export class MainThreadComments extends Disposable implements MainThreadComments
|
||||
private _handlers = new Map<number, string>();
|
||||
private _commentControllers = new Map<number, MainThreadCommentController>();
|
||||
|
||||
private _activeCommentThread?: MainThreadCommentThread;
|
||||
private _input?: modes.CommentInput;
|
||||
private _openPanelListener: IDisposable | null;
|
||||
|
||||
constructor(
|
||||
@@ -477,32 +477,12 @@ export class MainThreadComments extends Disposable implements MainThreadComments
|
||||
@ICommentService private readonly _commentService: ICommentService,
|
||||
@IPanelService private readonly _panelService: IPanelService,
|
||||
@ITelemetryService private readonly _telemetryService: ITelemetryService,
|
||||
@IConfigurationService private readonly _configurationService: IConfigurationService
|
||||
@IConfigurationService private readonly _configurationService: IConfigurationService,
|
||||
) {
|
||||
super();
|
||||
this._disposables = [];
|
||||
this._activeCommentThreadDisposables = [];
|
||||
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 {
|
||||
@@ -562,6 +542,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments
|
||||
resource: UriComponents,
|
||||
range: IRange,
|
||||
label: string,
|
||||
contextValue: string | undefined,
|
||||
comments: modes.Comment[],
|
||||
acceptInputCommand: modes.Command | undefined,
|
||||
additionalCommands: modes.Command[],
|
||||
@@ -573,7 +554,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments
|
||||
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) {
|
||||
|
||||
@@ -141,7 +141,7 @@ export interface MainThreadCommentsShape extends IDisposable {
|
||||
$unregisterCommentController(handle: number): void;
|
||||
$updateCommentControllerFeatures(handle: number, features: CommentProviderFeatures): void;
|
||||
$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;
|
||||
$setInputValue(handle: number, input: string): void;
|
||||
$registerDocumentCommentProvider(handle: number, features: CommentProviderFeatures): void;
|
||||
@@ -1211,9 +1211,11 @@ export interface ExtHostProgressShape {
|
||||
export interface ExtHostCommentsShape {
|
||||
$provideDocumentComments(handle: number, document: UriComponents): Promise<modes.CommentInfo | 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>;
|
||||
$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>;
|
||||
$checkStaticContribution(commentControllerHandle: number): Promise<boolean>;
|
||||
$provideReactionGroup(commentControllerHandle: number): Promise<modes.CommentReaction[] | undefined>;
|
||||
$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>;
|
||||
|
||||
@@ -69,6 +69,70 @@ export class ExtHostComments implements ExtHostCommentsShape {
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -88,6 +152,16 @@ export class ExtHostComments implements ExtHostCommentsShape {
|
||||
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> {
|
||||
const commentController = this._commentControllers.get(commentControllerHandle);
|
||||
|
||||
@@ -99,15 +173,12 @@ export class ExtHostComments implements ExtHostCommentsShape {
|
||||
return Promise.resolve(commentControllerHandle);
|
||||
}
|
||||
|
||||
$onActiveCommentThreadChange(commentControllerHandle: number, threadHandle: number): Promise<number | undefined> {
|
||||
$deleteCommentThread(commentControllerHandle: number, commentThreadHandle: number) {
|
||||
const commentController = this._commentControllers.get(commentControllerHandle);
|
||||
|
||||
if (!commentController) {
|
||||
return Promise.resolve(undefined);
|
||||
if (commentController) {
|
||||
commentController.$deleteCommentThread(commentThreadHandle);
|
||||
}
|
||||
|
||||
commentController.$onActiveCommentThreadChange(threadHandle);
|
||||
return Promise.resolve(threadHandle);
|
||||
}
|
||||
|
||||
$provideCommentingRanges(commentControllerHandle: number, uriComponents: UriComponents, token: CancellationToken): Promise<IRange[] | undefined> {
|
||||
@@ -164,7 +235,7 @@ export class ExtHostComments implements ExtHostCommentsShape {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
if (!(commentController as any).emptyCommentThreadFactory && !(commentController.commentingRangeProvider && commentController.commentingRangeProvider.createEmptyCommentThread)) {
|
||||
if (!(commentController as any).emptyCommentThreadFactory) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
@@ -173,13 +244,23 @@ export class ExtHostComments implements ExtHostCommentsShape {
|
||||
if ((commentController as any).emptyCommentThreadFactory) {
|
||||
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());
|
||||
}
|
||||
|
||||
$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(
|
||||
extensionId: ExtensionIdentifier,
|
||||
provider: vscode.WorkspaceCommentProvider
|
||||
@@ -376,12 +457,18 @@ export class ExtHostComments implements ExtHostCommentsShape {
|
||||
export class ExtHostCommentThread implements vscode.CommentThread {
|
||||
private static _handlePool: number = 0;
|
||||
readonly handle = ExtHostCommentThread._handlePool++;
|
||||
public commentHandle: number = 0;
|
||||
|
||||
set threadId(id: string) {
|
||||
this._id = id;
|
||||
}
|
||||
|
||||
get threadId(): string {
|
||||
return this._id;
|
||||
return this._id!;
|
||||
}
|
||||
|
||||
get id(): string {
|
||||
return this._id;
|
||||
return this._id!;
|
||||
}
|
||||
|
||||
get resource(): vscode.Uri {
|
||||
@@ -417,6 +504,17 @@ export class ExtHostCommentThread implements vscode.CommentThread {
|
||||
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[] {
|
||||
return this._comments;
|
||||
}
|
||||
@@ -475,15 +573,21 @@ export class ExtHostCommentThread implements vscode.CommentThread {
|
||||
return this._isDiposed;
|
||||
}
|
||||
|
||||
private _commentsMap: Map<vscode.Comment, number> = new Map<vscode.Comment, number>();
|
||||
|
||||
constructor(
|
||||
private _proxy: MainThreadCommentsShape,
|
||||
private readonly _commandsConverter: CommandsConverter,
|
||||
private _commentController: ExtHostCommentController,
|
||||
private _id: string,
|
||||
private _id: string | undefined,
|
||||
private _uri: vscode.Uri,
|
||||
private _range: vscode.Range,
|
||||
private _comments: vscode.Comment[]
|
||||
) {
|
||||
if (this._id === undefined) {
|
||||
this._id = `${_commentController.id}.${this.handle}`;
|
||||
}
|
||||
|
||||
this._proxy.$createCommentThread(
|
||||
this._commentController.handle,
|
||||
this.handle,
|
||||
@@ -507,7 +611,8 @@ export class ExtHostCommentThread implements vscode.CommentThread {
|
||||
eventuallyUpdateCommentThread(): void {
|
||||
const commentThreadRange = extHostTypeConverter.Range.from(this._range);
|
||||
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 additionalCommands = this._additionalCommands ? this._additionalCommands.map(x => this._commandsConverter.toInternal(x)) : [];
|
||||
const deleteCommand = this._deleteCommand ? this._commandsConverter.toInternal(this._deleteCommand) : undefined;
|
||||
@@ -516,10 +621,11 @@ export class ExtHostCommentThread implements vscode.CommentThread {
|
||||
this._proxy.$updateCommentThread(
|
||||
this._commentController.handle,
|
||||
this.handle,
|
||||
this._id,
|
||||
this._id!,
|
||||
this._uri,
|
||||
commentThreadRange,
|
||||
label,
|
||||
contextValue,
|
||||
comments,
|
||||
acceptInputCommand,
|
||||
additionalCommands,
|
||||
@@ -538,6 +644,18 @@ export class ExtHostCommentThread implements vscode.CommentThread {
|
||||
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() {
|
||||
this._localDisposables.forEach(disposable => disposable.dispose());
|
||||
this._proxy.$deleteCommentThread(
|
||||
@@ -599,15 +717,6 @@ class ExtHostCommentController implements vscode.CommentController {
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -618,30 +727,6 @@ class ExtHostCommentController implements vscode.CommentController {
|
||||
private _threads: Map<number, ExtHostCommentThread> = new Map<number, ExtHostCommentThread>();
|
||||
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;
|
||||
|
||||
get reactionProvider(): vscode.CommentReactionProvider | undefined {
|
||||
@@ -666,12 +751,37 @@ class ExtHostCommentController implements vscode.CommentController {
|
||||
this._proxy.$registerCommentController(this.handle, _id, _label);
|
||||
}
|
||||
|
||||
createCommentThread(id: string, 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(resource: vscode.Uri, range: vscode.Range, comments: vscode.Comment[]): vscode.CommentThread;
|
||||
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);
|
||||
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) {
|
||||
if (!this.inputBox) {
|
||||
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) {
|
||||
return this._threads.get(handle);
|
||||
}
|
||||
@@ -759,16 +865,25 @@ function convertFromComment(comment: modes.Comment): vscode.Comment {
|
||||
count: reaction.count,
|
||||
hasReacted: reaction.hasReacted
|
||||
};
|
||||
}) : undefined
|
||||
}) : undefined,
|
||||
mode: comment.mode ? comment.mode : modes.CommentMode.Preview
|
||||
};
|
||||
}
|
||||
|
||||
function convertToModeComment(commentController: ExtHostCommentController, vscodeComment: vscode.Comment, commandsConverter: CommandsConverter): modes.Comment {
|
||||
const iconPath = vscodeComment.author && vscodeComment.author.iconPath ? vscodeComment.author.iconPath.toString() :
|
||||
(vscodeComment.userIconPath ? vscodeComment.userIconPath.toString() : vscodeComment.gravatar);
|
||||
function convertToModeComment2(thread: ExtHostCommentThread, commentController: ExtHostCommentController, vscodeComment: vscode.Comment, commandsConverter: CommandsConverter, commentsMap: Map<vscode.Comment, number>): modes.Comment {
|
||||
let commentUniqueId = commentsMap.get(vscodeComment)!;
|
||||
if (!commentUniqueId) {
|
||||
commentUniqueId = ++thread.commentHandle;
|
||||
commentsMap.set(vscodeComment, commentUniqueId);
|
||||
}
|
||||
|
||||
const iconPath = vscodeComment.author && vscodeComment.author.iconPath ? vscodeComment.author.iconPath.toString() : undefined;
|
||||
|
||||
return {
|
||||
commentId: vscodeComment.id || vscodeComment.commentId,
|
||||
mode: vscodeComment.mode,
|
||||
contextValue: vscodeComment.contextValue,
|
||||
uniqueIdInThread: commentUniqueId,
|
||||
body: extHostTypeConverter.MarkdownString.from(vscodeComment.body),
|
||||
userName: vscodeComment.author ? vscodeComment.author.name : vscodeComment.userName,
|
||||
userIconPath: iconPath,
|
||||
|
||||
@@ -2297,6 +2297,12 @@ export enum CommentThreadCollapsibleState {
|
||||
*/
|
||||
Expanded = 1
|
||||
}
|
||||
|
||||
export enum CommentMode {
|
||||
Editing = 0,
|
||||
Preview = 1
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
@es5ClassCompat
|
||||
|
||||
@@ -51,6 +51,10 @@ namespace schema {
|
||||
case 'notebook/toolbar': return MenuId.NotebookToolbar;
|
||||
case 'dataExplorer/context': return MenuId.DataExplorerContext;
|
||||
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;
|
||||
@@ -196,7 +200,27 @@ namespace schema {
|
||||
description: localize('view.itemContext', "The contributed view item context menu"),
|
||||
type: 'array',
|
||||
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
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -681,6 +681,8 @@ export function createApiFactory(
|
||||
}
|
||||
};
|
||||
|
||||
const comments = comment;
|
||||
|
||||
// {{SQL CARBON EDIT}} -- no-op debug extensibility API
|
||||
// namespace: debug
|
||||
const debug: typeof vscode.debug = {
|
||||
@@ -766,6 +768,7 @@ export function createApiFactory(
|
||||
languages,
|
||||
scm,
|
||||
comment,
|
||||
comments,
|
||||
tasks,
|
||||
window,
|
||||
workspace,
|
||||
@@ -781,6 +784,7 @@ export function createApiFactory(
|
||||
ColorInformation: extHostTypes.ColorInformation,
|
||||
ColorPresentation: extHostTypes.ColorPresentation,
|
||||
CommentThreadCollapsibleState: extHostTypes.CommentThreadCollapsibleState,
|
||||
CommentMode: extHostTypes.CommentMode,
|
||||
CompletionItem: extHostTypes.CompletionItem,
|
||||
CompletionItemKind: extHostTypes.CompletionItemKind,
|
||||
CompletionList: extHostTypes.CompletionList,
|
||||
|
||||
@@ -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({
|
||||
id: 'list.expand',
|
||||
weight: KeybindingWeight.WorkbenchContrib,
|
||||
|
||||
@@ -73,7 +73,7 @@ abstract class BaseNavigationAction extends Action {
|
||||
return this.panelService.openPanel(activePanelId, true)!;
|
||||
}
|
||||
|
||||
protected navigateToSidebar(): Promise<IViewlet | boolean> {
|
||||
protected async navigateToSidebar(): Promise<IViewlet | boolean> {
|
||||
if (!this.layoutService.isVisible(Parts.SIDEBAR_PART)) {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
@@ -84,8 +84,8 @@ abstract class BaseNavigationAction extends Action {
|
||||
}
|
||||
const activeViewletId = activeViewlet.getId();
|
||||
|
||||
return this.viewletService.openViewlet(activeViewletId, true)
|
||||
.then(value => value === null ? false : value);
|
||||
const value = await this.viewletService.openViewlet(activeViewletId, true);
|
||||
return value === null ? false : value;
|
||||
}
|
||||
|
||||
protected navigateAcrossEditorGroup(direction: GroupDirection): boolean {
|
||||
|
||||
@@ -160,21 +160,18 @@ export class GlobalRemoveRootFolderAction extends Action {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
run(): Promise<any> {
|
||||
async run(): Promise<any> {
|
||||
const state = this.contextService.getWorkbenchState();
|
||||
|
||||
// Workspace / Folder
|
||||
if (state === WorkbenchState.WORKSPACE || state === WorkbenchState.FOLDER) {
|
||||
return this.commandService.executeCommand<IWorkspaceFolder>(PICK_WORKSPACE_FOLDER_COMMAND_ID).then(folder => {
|
||||
if (folder) {
|
||||
return this.workspaceEditingService.removeFolders([folder.uri]).then(() => true);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
const folder = await this.commandService.executeCommand<IWorkspaceFolder>(PICK_WORKSPACE_FOLDER_COMMAND_ID);
|
||||
if (folder) {
|
||||
await this.workspaceEditingService.removeFolders([folder.uri]);
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.resolve(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,20 +190,18 @@ export class SaveWorkspaceAsAction extends Action {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
run(): Promise<any> {
|
||||
return this.workspaceEditingService.pickNewWorkspacePath().then((configPathUri): Promise<void> | void => {
|
||||
if (configPathUri) {
|
||||
switch (this.contextService.getWorkbenchState()) {
|
||||
case WorkbenchState.EMPTY:
|
||||
case WorkbenchState.FOLDER:
|
||||
const folders = this.contextService.getWorkspace().folders.map(folder => ({ uri: folder.uri }));
|
||||
return this.workspaceEditingService.createAndEnterWorkspace(folders, configPathUri);
|
||||
|
||||
case WorkbenchState.WORKSPACE:
|
||||
return this.workspaceEditingService.saveAndEnterWorkspace(configPathUri);
|
||||
}
|
||||
async run(): Promise<any> {
|
||||
const configPathUri = await this.workspaceEditingService.pickNewWorkspacePath();
|
||||
if (configPathUri) {
|
||||
switch (this.contextService.getWorkbenchState()) {
|
||||
case WorkbenchState.EMPTY:
|
||||
case WorkbenchState.FOLDER:
|
||||
const folders = this.contextService.getWorkspace().folders.map(folder => ({ uri: folder.uri }));
|
||||
return this.workspaceEditingService.createAndEnterWorkspace(folders, configPathUri);
|
||||
case WorkbenchState.WORKSPACE:
|
||||
return this.workspaceEditingService.saveAndEnterWorkspace(configPathUri);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,14 +291,13 @@ export class DuplicateWorkspaceInNewWindowAction extends Action {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
run(): Promise<any> {
|
||||
async run(): Promise<any> {
|
||||
const folders = this.workspaceContextService.getWorkspace().folders;
|
||||
const remoteAuthority = this.environmentService.configuration.remoteAuthority;
|
||||
|
||||
return this.workspacesService.createUntitledWorkspace(folders, remoteAuthority).then(newWorkspace => {
|
||||
return this.workspaceEditingService.copyWorkspaceSettings(newWorkspace).then(() => {
|
||||
return this.windowService.openWindow([{ workspaceUri: newWorkspace.configPath }], { forceNewWindow: true });
|
||||
});
|
||||
});
|
||||
const newWorkspace = await this.workspacesService.createUntitledWorkspace(folders, remoteAuthority);
|
||||
await this.workspaceEditingService.copyWorkspaceSettings(newWorkspace);
|
||||
|
||||
return this.windowService.openWindow([{ workspaceUri: newWorkspace.configPath }], { forceNewWindow: true });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,30 +54,28 @@ CommandsRegistry.registerCommand({
|
||||
|
||||
CommandsRegistry.registerCommand({
|
||||
id: ADD_ROOT_FOLDER_COMMAND_ID,
|
||||
handler: (accessor) => {
|
||||
handler: async (accessor) => {
|
||||
const viewletService = accessor.get(IViewletService);
|
||||
const workspaceEditingService = accessor.get(IWorkspaceEditingService);
|
||||
const dialogsService = accessor.get(IFileDialogService);
|
||||
return dialogsService.showOpenDialog({
|
||||
const folders = await dialogsService.showOpenDialog({
|
||||
openLabel: mnemonicButtonLabel(nls.localize({ key: 'add', comment: ['&& denotes a mnemonic'] }, "&&Add")),
|
||||
title: nls.localize('addFolderToWorkspaceTitle', "Add Folder to Workspace"),
|
||||
canSelectFolders: true,
|
||||
canSelectMany: true,
|
||||
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 labelService = accessor.get(ILabelService);
|
||||
const contextService = accessor.get(IWorkspaceContextService);
|
||||
@@ -86,7 +84,7 @@ CommandsRegistry.registerCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, function (acc
|
||||
|
||||
const folders = contextService.getWorkspace().folders;
|
||||
if (!folders.length) {
|
||||
return undefined;
|
||||
return undefined; // {{SQL CARBON EDIT}} @anthonydresser strict-null-check
|
||||
}
|
||||
|
||||
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 pick = await quickInputService.pick(folderPicks, options, token);
|
||||
|
||||
return quickInputService.pick(folderPicks, options, token).then(pick => {
|
||||
if (!pick) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (pick) {
|
||||
return folders[folderPicks.indexOf(pick)];
|
||||
});
|
||||
}
|
||||
|
||||
return undefined; // {{SQL CARBON EDIT}} @anthonydresser strict-null-check
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
if (!untitledOrFileResources.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make the window active to handle the drop properly within
|
||||
this.windowService.focusWindow().then(() => {
|
||||
await this.windowService.focusWindow();
|
||||
|
||||
// Check for special things being dropped
|
||||
return this.doHandleDrop(untitledOrFileResources).then(isWorkspaceOpening => {
|
||||
if (isWorkspaceOpening) {
|
||||
return undefined; // return early if the drop operation resulted in this window changing to a workspace
|
||||
}
|
||||
// Check for special things being dropped
|
||||
const isWorkspaceOpening = await this.doHandleDrop(untitledOrFileResources);
|
||||
|
||||
// Add external ones to recently open list unless dropped resource is a workspace
|
||||
const recents: IRecentFile[] = untitledOrFileResources.filter(d => d.isExternal && d.resource.scheme === Schemas.file).map(d => ({ fileUri: d.resource }));
|
||||
if (recents.length) {
|
||||
this.windowsService.addRecentlyOpened(recents);
|
||||
}
|
||||
if (isWorkspaceOpening) {
|
||||
return; // return early if the drop operation resulted in this window changing to a workspace
|
||||
}
|
||||
|
||||
const editors: IResourceEditor[] = untitledOrFileResources.map(untitledOrFileResource => ({
|
||||
resource: untitledOrFileResource.resource,
|
||||
options: {
|
||||
pinned: true,
|
||||
index: targetIndex,
|
||||
viewState: (untitledOrFileResource as IDraggedEditor).viewState
|
||||
}
|
||||
}));
|
||||
// Add external ones to recently open list unless dropped resource is a workspace
|
||||
const recents: IRecentFile[] = untitledOrFileResources.filter(d => d.isExternal && d.resource.scheme === Schemas.file).map(d => ({ fileUri: d.resource }));
|
||||
if (recents.length) {
|
||||
this.windowsService.addRecentlyOpened(recents);
|
||||
}
|
||||
|
||||
// Open in Editor
|
||||
const targetGroup = resolveTargetGroup();
|
||||
return this.editorService.openEditors(editors, targetGroup).then(() => {
|
||||
const editors: IResourceEditor[] = untitledOrFileResources.map(untitledOrFileResource => ({
|
||||
resource: untitledOrFileResource.resource,
|
||||
options: {
|
||||
pinned: true,
|
||||
index: targetIndex,
|
||||
viewState: (untitledOrFileResource as IDraggedEditor).viewState
|
||||
}
|
||||
}));
|
||||
|
||||
// Finish with provided function
|
||||
afterDrop(targetGroup);
|
||||
});
|
||||
});
|
||||
});
|
||||
// Open in Editor
|
||||
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
|
||||
const resourcesWithBackups: IDraggedEditor[] = untitledOrFileResources.filter(resource => !resource.isExternal && !!(resource as IDraggedEditor).backupResource);
|
||||
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
|
||||
@@ -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
|
||||
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
|
||||
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
|
||||
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 this.backupFileService.backupResource(droppedDirtyEditor.resource, content.value.create(this.getDefaultEOL()).createSnapshot(true));
|
||||
}).then(() => false, () => false /* ignore any error */);
|
||||
return false;
|
||||
}
|
||||
|
||||
private getDefaultEOL(): DefaultEndOfLine {
|
||||
@@ -259,44 +261,50 @@ export class ResourcesDropHandler {
|
||||
return DefaultEndOfLine.LF;
|
||||
}
|
||||
|
||||
private handleWorkspaceFileDrop(fileOnDiskResources: URI[]): Promise<boolean> {
|
||||
private async handleWorkspaceFileDrop(fileOnDiskResources: URI[]): Promise<boolean> {
|
||||
const urisToOpen: IURIToOpen[] = [];
|
||||
const folderURIs: IWorkspaceFolderCreationData[] = [];
|
||||
|
||||
return Promise.all(fileOnDiskResources.map(fileOnDiskResource => {
|
||||
await Promise.all(fileOnDiskResources.map(async fileOnDiskResource => {
|
||||
|
||||
// Check for Workspace
|
||||
if (hasWorkspaceFileExtension(fileOnDiskResource)) {
|
||||
urisToOpen.push({ workspaceUri: fileOnDiskResource });
|
||||
|
||||
return undefined;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for Folder
|
||||
return this.fileService.resolve(fileOnDiskResource).then(stat => {
|
||||
try {
|
||||
const stat = await this.fileService.resolve(fileOnDiskResource);
|
||||
if (stat.isDirectory) {
|
||||
urisToOpen.push({ folderUri: stat.resource });
|
||||
folderURIs.push({ uri: stat.resource });
|
||||
}
|
||||
}, error => undefined);
|
||||
})).then(_ => {
|
||||
|
||||
// Return early if no external resource is a folder or workspace
|
||||
if (urisToOpen.length === 0) {
|
||||
return false;
|
||||
} catch (error) {
|
||||
// Ignore error
|
||||
}
|
||||
}));
|
||||
|
||||
// Pass focus to window
|
||||
this.windowService.focusWindow();
|
||||
// Return early if no external resource is a folder or workspace
|
||||
if (urisToOpen.length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open in separate windows if we drop workspaces or just one folder
|
||||
if (urisToOpen.length > folderURIs.length || folderURIs.length === 1) {
|
||||
return this.windowService.openWindow(urisToOpen, { forceReuseWindow: true }).then(_ => true);
|
||||
}
|
||||
// Pass focus to window
|
||||
this.windowService.focusWindow();
|
||||
|
||||
// folders.length > 1: Multiple folders: Create new workspace with folders and open
|
||||
return this.workspaceEditingService.createAndEnterWorkspace(folderURIs).then(_ => true);
|
||||
});
|
||||
// Open in separate windows if we drop workspaces or just one folder
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,15 +42,15 @@ export class ViewletActivityAction extends ActivityAction {
|
||||
super(activity);
|
||||
}
|
||||
|
||||
run(event: any): Promise<any> {
|
||||
async run(event: any): Promise<any> {
|
||||
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)
|
||||
const now = Date.now();
|
||||
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;
|
||||
|
||||
@@ -61,11 +61,12 @@ export class ViewletActivityAction extends ActivityAction {
|
||||
if (sideBarVisible && activeViewlet && activeViewlet.getId() === this.activity.id) {
|
||||
this.logAction('hide');
|
||||
this.layoutService.setSideBarHidden(true);
|
||||
return Promise.resolve();
|
||||
return true;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -204,12 +204,13 @@ export class CompositeBar extends Widget implements ICompositeBar {
|
||||
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)) {
|
||||
this.updateCompositeSwitcher();
|
||||
|
||||
if (open) {
|
||||
this.options.openComposite(compositeId).then(() => this.activateComposite(compositeId)); // Activate after opening
|
||||
await this.options.openComposite(compositeId);
|
||||
this.activateComposite(compositeId); // Activate after opening
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,44 +74,33 @@ export abstract class BaseBinaryResourceEditor extends BaseEditor {
|
||||
parent.appendChild(this.scrollbar.getDomNode());
|
||||
}
|
||||
|
||||
setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
|
||||
return super.setInput(input, options, token).then(() => {
|
||||
return input.resolve().then(model => {
|
||||
async setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
|
||||
await super.setInput(input, options, token);
|
||||
const model = await input.resolve();
|
||||
|
||||
// Check for cancellation
|
||||
if (token.isCancellationRequested) {
|
||||
return undefined;
|
||||
}
|
||||
// Check for cancellation
|
||||
if (token.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Assert Model instance
|
||||
if (!(model instanceof BinaryEditorModel)) {
|
||||
return Promise.reject(new Error('Unable to open file as binary'));
|
||||
}
|
||||
// Assert Model instance
|
||||
if (!(model instanceof BinaryEditorModel)) {
|
||||
throw new Error('Unable to open file as binary');
|
||||
}
|
||||
|
||||
// Render Input
|
||||
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,
|
||||
{
|
||||
openInternalClb: _ => this.handleOpenInternalCallback(input, options),
|
||||
openExternalClb: this.environmentService.configuration.remoteAuthority ? undefined : resource => this.callbacks.openExternal(resource),
|
||||
metadataClb: meta => this.handleMetadataChanged(meta)
|
||||
}
|
||||
);
|
||||
|
||||
return undefined;
|
||||
});
|
||||
// Render Input
|
||||
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, {
|
||||
openInternalClb: () => this.handleOpenInternalCallback(input, options),
|
||||
openExternalClb: this.environmentService.configuration.remoteAuthority ? undefined : resource => this.callbacks.openExternal(resource),
|
||||
metadataClb: meta => this.handleMetadataChanged(meta)
|
||||
});
|
||||
}
|
||||
|
||||
private handleOpenInternalCallback(input: EditorInput, options: EditorOptions) {
|
||||
this.callbacks.openInternal(input, options).then(() => {
|
||||
private async handleOpenInternalCallback(input: EditorInput, options: EditorOptions): Promise<void> {
|
||||
await this.callbacks.openInternal(input, options);
|
||||
|
||||
// Signal to listeners that the binary editor has been opened in-place
|
||||
this._onDidOpenInPlace.fire();
|
||||
});
|
||||
// Signal to listeners that the binary editor has been opened in-place
|
||||
this._onDidOpenInPlace.fire();
|
||||
}
|
||||
|
||||
private handleMetadataChanged(meta: string | undefined): void {
|
||||
|
||||
@@ -539,23 +539,27 @@ export class RevertAndCloseEditorAction extends Action {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
run(): Promise<any> {
|
||||
async run(): Promise<any> {
|
||||
const activeControl = this.editorService.activeControl;
|
||||
if (activeControl) {
|
||||
const editor = activeControl.input;
|
||||
const group = activeControl.group;
|
||||
|
||||
// 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
|
||||
// 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
|
||||
// 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;
|
||||
}
|
||||
|
||||
run(): Promise<any> {
|
||||
async run(): Promise<any> {
|
||||
|
||||
// Just close all if there are no or one dirty editor
|
||||
if (this.textFileService.getDirty().length < 2) {
|
||||
@@ -626,26 +630,23 @@ export abstract class BaseCloseAllAction extends Action {
|
||||
}
|
||||
|
||||
// Otherwise ask for combined confirmation
|
||||
return this.textFileService.confirmSave().then(confirm => {
|
||||
if (confirm === ConfirmResult.CANCEL) {
|
||||
return undefined;
|
||||
}
|
||||
const confirm = await this.textFileService.confirmSave();
|
||||
if (confirm === ConfirmResult.CANCEL) {
|
||||
return;
|
||||
}
|
||||
|
||||
let saveOrRevertPromise: Promise<boolean>;
|
||||
if (confirm === ConfirmResult.DONT_SAVE) {
|
||||
saveOrRevertPromise = this.textFileService.revertAll(undefined, { soft: true }).then(() => true);
|
||||
} else {
|
||||
saveOrRevertPromise = this.textFileService.saveAll(true).then(res => res.results.every(r => !!r.success));
|
||||
}
|
||||
let saveOrRevert: boolean;
|
||||
if (confirm === ConfirmResult.DONT_SAVE) {
|
||||
await this.textFileService.revertAll(undefined, { soft: true });
|
||||
saveOrRevert = true;
|
||||
} else {
|
||||
const res = await this.textFileService.saveAll(true);
|
||||
saveOrRevert = res.results.every(r => !!r.success);
|
||||
}
|
||||
|
||||
return saveOrRevertPromise.then(success => {
|
||||
if (success) {
|
||||
return this.doCloseAll();
|
||||
}
|
||||
|
||||
return undefined;
|
||||
});
|
||||
});
|
||||
if (saveOrRevert) {
|
||||
return this.doCloseAll();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract doCloseAll(): Promise<any>;
|
||||
@@ -684,10 +685,10 @@ export class CloseAllEditorGroupsAction extends BaseCloseAllAction {
|
||||
super(id, label, undefined, textFileService, editorGroupService);
|
||||
}
|
||||
|
||||
protected doCloseAll(): Promise<any> {
|
||||
return Promise.all(this.groupsToClose.map(g => g.closeAllEditors())).then(() => {
|
||||
this.groupsToClose.forEach(group => this.editorGroupService.removeGroup(group));
|
||||
});
|
||||
protected async doCloseAll(): Promise<any> {
|
||||
await Promise.all(this.groupsToClose.map(group => group.closeAllEditors()));
|
||||
|
||||
this.groupsToClose.forEach(group => this.editorGroupService.removeGroup(group));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 { group } = resolveCommandsContext(editorGroupService, getCommandsContext(resourceOrContext, context));
|
||||
if (group) {
|
||||
return group.closeAllEditors().then(() => {
|
||||
if (group.count === 0 && editorGroupService.getGroup(group.id) /* could be gone by now */) {
|
||||
editorGroupService.removeGroup(group); // only remove group if it is now empty
|
||||
}
|
||||
});
|
||||
}
|
||||
await group.closeAllEditors();
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ export class EditorControl extends Disposable {
|
||||
return this._activeControl as IVisibleEditor | null;
|
||||
}
|
||||
|
||||
openEditor(editor: EditorInput, options?: EditorOptions): Promise<IOpenEditorResult> {
|
||||
async openEditor(editor: EditorInput, options?: EditorOptions): Promise<IOpenEditorResult> {
|
||||
|
||||
// Editor control
|
||||
const descriptor = Registry.as<IEditorRegistry>(EditorExtensions.Editors).getEditor(editor);
|
||||
@@ -68,7 +68,8 @@ export class EditorControl extends Disposable {
|
||||
const control = this.doShowEditorControl(descriptor);
|
||||
|
||||
// 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 {
|
||||
@@ -150,7 +151,7 @@ export class EditorControl extends Disposable {
|
||||
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
|
||||
// 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();
|
||||
}
|
||||
|
||||
return Promise.resolve(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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
|
||||
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)
|
||||
if (operation.isCurrent()) {
|
||||
@@ -186,17 +188,10 @@ export class EditorControl extends Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
// Operation done
|
||||
operation.stop();
|
||||
|
||||
return editorWillChange;
|
||||
}, e => {
|
||||
|
||||
// Operation done
|
||||
} finally {
|
||||
operation.stop();
|
||||
|
||||
return Promise.reject(e);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private doHideActiveEditorControl(): void {
|
||||
|
||||
@@ -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) {
|
||||
return Promise.resolve(); // nothing to show
|
||||
}
|
||||
@@ -430,16 +430,15 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
|
||||
const activeElement = document.activeElement;
|
||||
|
||||
// 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
|
||||
// not changed meanwhile. This prevents focus from being
|
||||
// stolen accidentally on startup when the user already
|
||||
// clicked somewhere.
|
||||
if (this.accessor.activeGroup === this && activeElement === document.activeElement) {
|
||||
this.focus();
|
||||
}
|
||||
});
|
||||
// Set focused now if this is the active group and focus has
|
||||
// not changed meanwhile. This prevents focus from being
|
||||
// stolen accidentally on startup when the user already
|
||||
// clicked somewhere.
|
||||
if (this.accessor.activeGroup === this && activeElement === document.activeElement) {
|
||||
this.focus();
|
||||
}
|
||||
}
|
||||
|
||||
//#region event handling
|
||||
@@ -821,34 +820,33 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
|
||||
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
|
||||
let openEditorPromise: Promise<IEditor | null>;
|
||||
let openEditor: IEditor | null = null;
|
||||
if (active) {
|
||||
openEditorPromise = this.editorControl.openEditor(editor, options).then(result => {
|
||||
try {
|
||||
const result = await this.editorControl.openEditor(editor, options);
|
||||
|
||||
// Editor change event
|
||||
if (result.editorChanged) {
|
||||
this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_ACTIVE, editor });
|
||||
}
|
||||
|
||||
return result.control;
|
||||
}, error => {
|
||||
openEditor = result.control;
|
||||
} catch (error) {
|
||||
|
||||
// Handle errors but do not bubble them up
|
||||
this.doHandleOpenEditorError(error, editor, options);
|
||||
|
||||
return null; // error: return NULL as result to signal this
|
||||
});
|
||||
}
|
||||
} 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
|
||||
this.titleAreaControl.openEditor(editor);
|
||||
|
||||
return openEditorPromise;
|
||||
return openEditor;
|
||||
}
|
||||
|
||||
private doHandleOpenEditorError(error: Error, editor: EditorInput, options?: EditorOptions): void {
|
||||
@@ -884,37 +882,33 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
|
||||
|
||||
//#region openEditors()
|
||||
|
||||
openEditors(editors: { editor: EditorInput, options?: EditorOptions }[]): Promise<IEditor | null> {
|
||||
async openEditors(editors: { editor: EditorInput, options?: EditorOptions }[]): Promise<IEditor | null> {
|
||||
if (!editors.length) {
|
||||
return Promise.resolve(null);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Do not modify original array
|
||||
editors = editors.slice(0);
|
||||
|
||||
let result: IEditor | null;
|
||||
|
||||
// Use the first editor as active editor
|
||||
const { editor, options } = editors.shift()!;
|
||||
return this.openEditor(editor, options).then(activeEditor => {
|
||||
result = activeEditor; // this can be NULL if the opening failed
|
||||
let firstEditor = await this.openEditor(editor, options);
|
||||
|
||||
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
|
||||
return Promise.all(editors.map(({ editor, options }, index) => {
|
||||
const adjustedEditorOptions = options || new EditorOptions();
|
||||
adjustedEditorOptions.inactive = true;
|
||||
adjustedEditorOptions.pinned = true;
|
||||
adjustedEditorOptions.index = startingIndex + index;
|
||||
const openedEditor = await this.openEditor(editor, adjustedEditorOptions);
|
||||
if (!firstEditor) {
|
||||
firstEditor = openedEditor; // only take if the first editor opening failed
|
||||
}
|
||||
}));
|
||||
|
||||
return this.openEditor(editor, adjustedEditorOptions).then(activeEditor => {
|
||||
if (!result) {
|
||||
result = activeEditor; // only take if the first editor opening failed
|
||||
}
|
||||
});
|
||||
})).then(() => result);
|
||||
});
|
||||
return firstEditor;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
@@ -995,20 +989,19 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
|
||||
|
||||
//#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) {
|
||||
return Promise.resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for dirty and veto
|
||||
return this.handleDirty([editor]).then(veto => {
|
||||
if (veto) {
|
||||
return;
|
||||
}
|
||||
const veto = await this.handleDirty([editor]);
|
||||
if (veto) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Do close
|
||||
this.doCloseEditor(editor, options && options.preserveFocus ? false : undefined);
|
||||
});
|
||||
// Do close
|
||||
this.doCloseEditor(editor, options && options.preserveFocus ? false : undefined);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private handleDirty(editors: EditorInput[]): Promise<boolean /* veto */> {
|
||||
private async handleDirty(editors: EditorInput[]): Promise<boolean /* veto */> {
|
||||
if (!editors.length) {
|
||||
return Promise.resolve(false); // no veto
|
||||
}
|
||||
@@ -1128,22 +1121,21 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
|
||||
this.mapEditorToPendingConfirmation.set(editor, handleDirtyPromise);
|
||||
}
|
||||
|
||||
return handleDirtyPromise.then(veto => {
|
||||
const veto = await handleDirtyPromise;
|
||||
|
||||
// Make sure to remove from our map of cached pending confirmations
|
||||
this.mapEditorToPendingConfirmation.delete(editor);
|
||||
// Make sure to remove from our map of cached pending confirmations
|
||||
this.mapEditorToPendingConfirmation.delete(editor);
|
||||
|
||||
// Return for the first veto we got
|
||||
if (veto) {
|
||||
return veto;
|
||||
}
|
||||
// Return for the first veto we got
|
||||
if (veto) {
|
||||
return veto;
|
||||
}
|
||||
|
||||
// Otherwise continue with the remainders
|
||||
return this.handleDirty(editors);
|
||||
});
|
||||
// Otherwise continue with the remainders
|
||||
return this.handleDirty(editors);
|
||||
}
|
||||
|
||||
private doHandleDirty(editor: EditorInput): Promise<boolean /* veto */> {
|
||||
private async doHandleDirty(editor: EditorInput): Promise<boolean /* veto */> {
|
||||
if (
|
||||
!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
|
||||
@@ -1153,59 +1145,65 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
|
||||
}
|
||||
|
||||
// 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
|
||||
// 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;
|
||||
}
|
||||
const res = await editor.confirmSave();
|
||||
|
||||
// Otherwise, handle accordingly
|
||||
switch (res) {
|
||||
case ConfirmResult.SAVE:
|
||||
return editor.save().then(ok => !ok);
|
||||
// It could be that the editor saved meanwhile, so we check again
|
||||
// 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;
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
// 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
|
||||
// dirty editor even when reverting fails.
|
||||
return editor.revert({ soft: true }).then(ok => !ok);
|
||||
});
|
||||
return !result;
|
||||
} catch (error) {
|
||||
// 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
|
||||
// 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 true; // veto
|
||||
}
|
||||
}));
|
||||
return !result;
|
||||
}
|
||||
case ConfirmResult.CANCEL:
|
||||
return true; // veto
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region closeEditors()
|
||||
|
||||
closeEditors(args: EditorInput[] | ICloseEditorsFilter, options?: ICloseEditorOptions): Promise<void> {
|
||||
async closeEditors(args: EditorInput[] | ICloseEditorsFilter, options?: ICloseEditorOptions): Promise<void> {
|
||||
if (this.isEmpty()) {
|
||||
return Promise.resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
const editors = this.getEditorsToClose(args);
|
||||
|
||||
// Check for dirty and veto
|
||||
return this.handleDirty(editors.slice(0)).then(veto => {
|
||||
if (veto) {
|
||||
return;
|
||||
}
|
||||
const veto = await this.handleDirty(editors.slice(0));
|
||||
if (veto) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Do close
|
||||
this.doCloseEditors(editors, options);
|
||||
});
|
||||
// Do close
|
||||
this.doCloseEditors(editors, options);
|
||||
}
|
||||
|
||||
private getEditorsToClose(editors: EditorInput[] | ICloseEditorsFilter): EditorInput[] {
|
||||
@@ -1263,7 +1261,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
|
||||
|
||||
//#region closeAllEditors()
|
||||
|
||||
closeAllEditors(): Promise<void> {
|
||||
async closeAllEditors(): Promise<void> {
|
||||
if (this.isEmpty()) {
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for dirty and veto
|
||||
const editors = this._group.getEditors(true);
|
||||
return this.handleDirty(editors.slice(0)).then(veto => {
|
||||
if (veto) {
|
||||
return;
|
||||
}
|
||||
const veto = await this.handleDirty(editors.slice(0));
|
||||
if (veto) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Do close
|
||||
this.doCloseAllEditors();
|
||||
});
|
||||
// Do close
|
||||
this.doCloseAllEditors();
|
||||
}
|
||||
|
||||
private doCloseAllEditors(): void {
|
||||
@@ -1308,7 +1305,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
|
||||
|
||||
//#region replaceEditors()
|
||||
|
||||
replaceEditors(editors: EditorReplacement[]): Promise<void> {
|
||||
async replaceEditors(editors: EditorReplacement[]): Promise<void> {
|
||||
|
||||
// Extract active vs. inactive replacements
|
||||
let activeReplacement: EditorReplacement | undefined;
|
||||
@@ -1366,10 +1363,8 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
|
||||
this.titleAreaControl.closeEditor(activeReplacement.editor);
|
||||
}
|
||||
|
||||
return openEditorResult.then(() => undefined);
|
||||
await openEditorResult;
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
@@ -858,8 +858,8 @@ export class ShowLanguageExtensionsAction extends Action {
|
||||
this.enabled = galleryService.isEnabled();
|
||||
}
|
||||
|
||||
run(): Promise<void> {
|
||||
return this.commandService.executeCommand('workbench.extensions.action.showExtensionsForLanguage', this.fileExtension).then(() => undefined);
|
||||
async run(): Promise<void> {
|
||||
await this.commandService.executeCommand('workbench.extensions.action.showExtensionsForLanguage', this.fileExtension);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -883,7 +883,7 @@ export class ChangeModeAction extends Action {
|
||||
super(actionId, actionLabel);
|
||||
}
|
||||
|
||||
run(): Promise<any> {
|
||||
async run(): Promise<any> {
|
||||
const activeTextEditorWidget = getCodeEditor(this.editorService.activeTextEditorWidget);
|
||||
if (!activeTextEditorWidget) {
|
||||
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(() => {
|
||||
this.quickInputService.pick(picks, { placeHolder: nls.localize('pickLanguageToConfigure', "Select Language Mode to Associate with '{0}'", extension || base) }).then(language => {
|
||||
if (language) {
|
||||
const fileAssociationsConfig = this.configurationService.inspect<{}>(FILES_ASSOCIATIONS_CONFIG);
|
||||
setTimeout(async () => {
|
||||
const language = await this.quickInputService.pick(picks, { placeHolder: nls.localize('pickLanguageToConfigure', "Select Language Mode to Associate with '{0}'", extension || base) });
|
||||
if (language) {
|
||||
const fileAssociationsConfig = this.configurationService.inspect<{}>(FILES_ASSOCIATIONS_CONFIG);
|
||||
|
||||
let associationKey: string;
|
||||
if (extension && base[0] !== '.') {
|
||||
associationKey = `*${extension}`; // only use "*.ext" if the file path is in the form of <name>.<ext>
|
||||
} else {
|
||||
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);
|
||||
let associationKey: string;
|
||||
if (extension && base[0] !== '.') {
|
||||
associationKey = `*${extension}`; // only use "*.ext" if the file path is in the form of <name>.<ext>
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}, 50 /* quick open is sensitive to being opened so soon after another */);
|
||||
}
|
||||
}
|
||||
@@ -1085,7 +1084,7 @@ class ChangeIndentationAction extends Action {
|
||||
super(actionId, actionLabel);
|
||||
}
|
||||
|
||||
run(): Promise<any> {
|
||||
async run(): Promise<any> {
|
||||
const activeTextEditorWidget = getCodeEditor(this.editorService.activeTextEditorWidget);
|
||||
if (!activeTextEditorWidget) {
|
||||
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.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);
|
||||
}
|
||||
|
||||
run(): Promise<any> {
|
||||
async run(): Promise<any> {
|
||||
const activeTextEditorWidget = getCodeEditor(this.editorService.activeTextEditorWidget);
|
||||
if (!activeTextEditorWidget) {
|
||||
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.") }]);
|
||||
}
|
||||
|
||||
const textModel = activeTextEditorWidget.getModel();
|
||||
let textModel = activeTextEditorWidget.getModel();
|
||||
|
||||
const EOLOptions: IChangeEOLEntry[] = [
|
||||
{ label: nlsEOLLF, eol: EndOfLineSequence.LF },
|
||||
@@ -1154,15 +1154,14 @@ export class ChangeEOLAction extends Action {
|
||||
|
||||
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 => {
|
||||
if (eol) {
|
||||
const activeCodeEditor = getCodeEditor(this.editorService.activeTextEditorWidget);
|
||||
if (activeCodeEditor && activeCodeEditor.hasModel() && isWritableCodeEditor(activeCodeEditor)) {
|
||||
const textModel = activeCodeEditor.getModel();
|
||||
textModel.pushEOL(eol.eol);
|
||||
}
|
||||
const eol = await this.quickInputService.pick(EOLOptions, { placeHolder: nls.localize('pickEndOfLine', "Select End of Line Sequence"), activeItem: EOLOptions[selectedIndex] });
|
||||
if (eol) {
|
||||
const activeCodeEditor = getCodeEditor(this.editorService.activeTextEditorWidget);
|
||||
if (activeCodeEditor && activeCodeEditor.hasModel() && isWritableCodeEditor(activeCodeEditor)) {
|
||||
textModel = activeCodeEditor.getModel();
|
||||
textModel.pushEOL(eol.eol);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -567,16 +567,15 @@ class InlineImageView {
|
||||
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) {
|
||||
return Promise.resolve(descriptor.resource.toString(true /* skip encoding */));
|
||||
}
|
||||
|
||||
return textFileService.read(descriptor.resource, { encoding: 'base64' }).then(data => {
|
||||
const mime = getMime(descriptor);
|
||||
const data = await textFileService.read(descriptor.resource, { encoding: 'base64' });
|
||||
const mime = getMime(descriptor);
|
||||
|
||||
return `data:${mime};base64,${data.value}`;
|
||||
});
|
||||
return `data:${mime};base64,${data.value}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -93,10 +93,11 @@ export class SideBySideEditor extends BaseEditor {
|
||||
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;
|
||||
return super.setInput(newInput, options, token)
|
||||
.then(() => this.updateInput(oldInput, newInput as SideBySideEditorInput, options, token));
|
||||
await super.setInput(newInput, options, token);
|
||||
|
||||
return this.updateInput(oldInput, (newInput as SideBySideEditorInput), options, token);
|
||||
}
|
||||
|
||||
setOptions(options: EditorOptions): void {
|
||||
@@ -158,7 +159,7 @@ export class SideBySideEditor extends BaseEditor {
|
||||
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 (oldInput) {
|
||||
this.disposeEditors();
|
||||
@@ -166,14 +167,15 @@ export class SideBySideEditor extends BaseEditor {
|
||||
|
||||
return this.setNewInput(newInput, options, token);
|
||||
}
|
||||
|
||||
if (!this.detailsEditor || !this.masterEditor) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return Promise.all([
|
||||
await Promise.all([
|
||||
this.detailsEditor.setInput(newInput.details, null, token),
|
||||
this.masterEditor.setInput(newInput.master, options, token)]
|
||||
).then(() => undefined);
|
||||
this.masterEditor.setInput(newInput.master, options, token)
|
||||
]);
|
||||
}
|
||||
|
||||
private setNewInput(newInput: SideBySideEditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
|
||||
@@ -196,7 +198,7 @@ export class SideBySideEditor extends BaseEditor {
|
||||
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.masterEditor = master;
|
||||
|
||||
@@ -207,7 +209,12 @@ export class SideBySideEditor extends BaseEditor {
|
||||
|
||||
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 {
|
||||
|
||||
@@ -84,7 +84,7 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
|
||||
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
|
||||
this.diffNavigatorDisposables = dispose(this.diffNavigatorDisposables);
|
||||
@@ -93,56 +93,55 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
|
||||
this.saveTextDiffEditorViewState(this.input);
|
||||
|
||||
// Set input and resolve
|
||||
return super.setInput(input, options, token).then(() => {
|
||||
return input.resolve().then(resolvedModel => {
|
||||
await super.setInput(input, options, token);
|
||||
|
||||
// Check for cancellation
|
||||
if (token.isCancellationRequested) {
|
||||
return undefined;
|
||||
}
|
||||
try {
|
||||
const resolvedModel = await input.resolve();
|
||||
|
||||
// Assert Model Instance
|
||||
if (!(resolvedModel instanceof TextDiffEditorModel) && this.openAsBinary(input, options)) {
|
||||
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() });
|
||||
// Check for cancellation
|
||||
if (token.isCancellationRequested) {
|
||||
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.
|
||||
if (this.isFileBinaryError(error) && this.openAsBinary(input, options)) {
|
||||
return null;
|
||||
}
|
||||
// Assert Model Instance
|
||||
if (!(resolvedModel instanceof TextDiffEditorModel) && this.openAsBinary(input, options)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Otherwise make sure the error bubbles up
|
||||
return Promise.reject(error);
|
||||
// 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() });
|
||||
} 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 {
|
||||
|
||||
@@ -191,14 +191,13 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditor {
|
||||
return this.instantiationService.createInstance(CodeEditorWidget, parent, configuration, {});
|
||||
}
|
||||
|
||||
setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
|
||||
return super.setInput(input, options, token).then(() => {
|
||||
async setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
|
||||
await super.setInput(input, options, token);
|
||||
|
||||
// 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)
|
||||
this.updateEditorConfiguration();
|
||||
this._editorContainer.setAttribute('aria-label', this.computeAriaLabel());
|
||||
});
|
||||
// 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)
|
||||
this.updateEditorConfiguration();
|
||||
this._editorContainer.setAttribute('aria-label', this.computeAriaLabel());
|
||||
}
|
||||
|
||||
protected setEditorVisible(visible: boolean, group: IEditorGroup): void {
|
||||
|
||||
@@ -7,7 +7,7 @@ import * as nls from 'vs/nls';
|
||||
import * as types from 'vs/base/common/types';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
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 { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel';
|
||||
import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput';
|
||||
@@ -54,45 +54,41 @@ export class AbstractTextResourceEditor extends BaseTextEditor {
|
||||
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
|
||||
this.saveTextResourceEditorViewState(this.input);
|
||||
|
||||
// Set input and resolve
|
||||
return super.setInput(input, options, token).then(() => {
|
||||
return input.resolve().then((resolvedModel: EditorModel) => {
|
||||
await super.setInput(input, options, token);
|
||||
const resolvedModel = await input.resolve();
|
||||
|
||||
// Check for cancellation
|
||||
if (token.isCancellationRequested) {
|
||||
return undefined;
|
||||
}
|
||||
// Check for cancellation
|
||||
if (token.isCancellationRequested) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Assert Model instance
|
||||
if (!(resolvedModel instanceof BaseTextEditorModel)) {
|
||||
return Promise.reject(new Error('Unable to open file as text'));
|
||||
}
|
||||
// Assert Model instance
|
||||
if (!(resolvedModel instanceof BaseTextEditorModel)) {
|
||||
return Promise.reject(new Error('Unable to open file as text'));
|
||||
}
|
||||
|
||||
// Set Editor Model
|
||||
const textEditor = this.getControl();
|
||||
const textEditorModel = resolvedModel.textEditorModel;
|
||||
textEditor.setModel(textEditorModel);
|
||||
// Set Editor Model
|
||||
const textEditor = this.getControl();
|
||||
const textEditorModel = resolvedModel.textEditorModel;
|
||||
textEditor.setModel(textEditorModel);
|
||||
|
||||
// Apply Options from TextOptions
|
||||
let optionsGotApplied = false;
|
||||
const textOptions = <TextEditorOptions>options;
|
||||
if (textOptions && types.isFunction(textOptions.apply)) {
|
||||
optionsGotApplied = textOptions.apply(textEditor, ScrollType.Immediate);
|
||||
}
|
||||
// Apply Options from TextOptions
|
||||
let optionsGotApplied = false;
|
||||
const textOptions = <TextEditorOptions>options;
|
||||
if (textOptions && types.isFunction(textOptions.apply)) {
|
||||
optionsGotApplied = textOptions.apply(textEditor, ScrollType.Immediate);
|
||||
}
|
||||
|
||||
// Otherwise restore View State
|
||||
if (!optionsGotApplied) {
|
||||
this.restoreTextResourceEditorViewState(input);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
});
|
||||
});
|
||||
// Otherwise restore View State
|
||||
if (!optionsGotApplied) {
|
||||
this.restoreTextResourceEditorViewState(input);
|
||||
}
|
||||
}
|
||||
|
||||
private restoreTextResourceEditorViewState(input: EditorInput) {
|
||||
|
||||
@@ -160,7 +160,7 @@ export class NotificationActionRunner extends ActionRunner {
|
||||
super();
|
||||
}
|
||||
|
||||
protected runAction(action: IAction, context: INotificationViewItem): Promise<any> {
|
||||
protected async runAction(action: IAction, context: INotificationViewItem): Promise<any> {
|
||||
|
||||
/* __GDPR__
|
||||
"workbenchActionExecuted" : {
|
||||
@@ -171,8 +171,10 @@ export class NotificationActionRunner extends ActionRunner {
|
||||
this.telemetryService.publicLog('workbenchActionExecuted', { id: action.id, from: 'message' });
|
||||
|
||||
// Run and make sure to notify on any error again
|
||||
super.runAction(action, context).then(undefined, error => this.notificationService.error(error));
|
||||
|
||||
return Promise.resolve();
|
||||
try {
|
||||
await super.runAction(action, context);
|
||||
} catch (error) {
|
||||
this.notificationService.error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
return this.lifecycleService.when(LifecyclePhase.Ready).then(() => {
|
||||
await this.lifecycleService.when(LifecyclePhase.Ready);
|
||||
|
||||
// Push notificiations out until either workbench is restored
|
||||
// or some time has ellapsed to reduce pressure on the startup
|
||||
return Promise.race([
|
||||
this.lifecycleService.when(LifecyclePhase.Restored),
|
||||
timeout(2000)
|
||||
]);
|
||||
});
|
||||
// Push notificiations out until either workbench is restored
|
||||
// or some time has ellapsed to reduce pressure on the startup
|
||||
return Promise.race([
|
||||
this.lifecycleService.when(LifecyclePhase.Restored),
|
||||
timeout(2000)
|
||||
]);
|
||||
}
|
||||
|
||||
private onDidNotificationChange(e: INotificationChangeEvent): void {
|
||||
|
||||
@@ -259,8 +259,7 @@ export class QuickOpenController extends Component implements IQuickOpenService
|
||||
|
||||
// Pass to handlers
|
||||
for (let prefix in this.mapResolvedHandlersToPrefix) {
|
||||
const promise = this.mapResolvedHandlersToPrefix[prefix];
|
||||
promise.then(handler => {
|
||||
this.mapResolvedHandlersToPrefix[prefix].then(handler => {
|
||||
this.handlerOnOpenCalled[prefix] = false;
|
||||
|
||||
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
|
||||
let matchingHistoryEntries: QuickOpenEntry[];
|
||||
@@ -444,47 +443,41 @@ export class QuickOpenController extends Component implements IQuickOpenService
|
||||
}
|
||||
|
||||
// Resolve
|
||||
return this.resolveHandler(handler).then(resolvedHandler => {
|
||||
const quickOpenModel = new QuickOpenModel(matchingHistoryEntries, this.actionProvider);
|
||||
const resolvedHandler = await this.resolveHandler(handler);
|
||||
|
||||
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
|
||||
// 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();
|
||||
}
|
||||
let inputSet = false;
|
||||
|
||||
responseDelay.then(() => {
|
||||
if (!token.isCancellationRequested && !inputSet) {
|
||||
this.quickOpenWidget.setInput(quickOpenModel, { autoFocusFirstEntry: true });
|
||||
inputSet = true;
|
||||
}
|
||||
});
|
||||
// If we have matching entries from history we want to show them directly and not wait for the other results to come in
|
||||
// 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) {
|
||||
if (resolvedHandler.hasShortResponseTime()) {
|
||||
await timeout(QuickOpenController.MAX_SHORT_RESPONSE_TIME);
|
||||
}
|
||||
|
||||
// Get results
|
||||
return resolvedHandler.getResults(value, token).then(result => {
|
||||
if (!token.isCancellationRequested) {
|
||||
if (!token.isCancellationRequested && !inputSet) {
|
||||
this.quickOpenWidget.setInput(quickOpenModel, { autoFocusFirstEntry: true });
|
||||
inputSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
// now is the time to show the input if we did not have set it before
|
||||
if (!inputSet) {
|
||||
this.quickOpenWidget.setInput(quickOpenModel, { autoFocusFirstEntry: true });
|
||||
inputSet = true;
|
||||
}
|
||||
// Get results
|
||||
const result = await resolvedHandler.getResults(value, token);
|
||||
if (!token.isCancellationRequested) {
|
||||
|
||||
// merge history and default handler results
|
||||
const handlerResults = (result && result.entries) || [];
|
||||
this.mergeResults(quickOpenModel, handlerResults, types.withNullAsUndefined(resolvedHandler.getGroupLabel()));
|
||||
}
|
||||
});
|
||||
});
|
||||
// now is the time to show the input if we did not have set it before
|
||||
if (!inputSet) {
|
||||
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 {
|
||||
@@ -516,46 +509,44 @@ export class QuickOpenController extends Component implements IQuickOpenService
|
||||
}
|
||||
}
|
||||
|
||||
private handleSpecificHandler(handlerDescriptor: QuickOpenHandlerDescriptor, value: string, token: CancellationToken): Promise<void> {
|
||||
return this.resolveHandler(handlerDescriptor).then((resolvedHandler: QuickOpenHandler) => {
|
||||
private async handleSpecificHandler(handlerDescriptor: QuickOpenHandlerDescriptor, value: string, token: CancellationToken): Promise<void> {
|
||||
const resolvedHandler = await this.resolveHandler(handlerDescriptor);
|
||||
|
||||
// Remove handler prefix from search value
|
||||
value = value.substr(handlerDescriptor.prefix.length);
|
||||
// Remove handler prefix from search value
|
||||
value = value.substr(handlerDescriptor.prefix.length);
|
||||
|
||||
// Return early if the handler can not run in the current environment and inform the user
|
||||
const canRun = resolvedHandler.canRun();
|
||||
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");
|
||||
// Return early if the handler can not run in the current environment and inform the user
|
||||
const canRun = resolvedHandler.canRun();
|
||||
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 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()));
|
||||
|
||||
return Promise.resolve(undefined);
|
||||
} else {
|
||||
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 {
|
||||
@@ -837,7 +828,7 @@ export class RemoveFromEditorHistoryAction extends Action {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
run(): Promise<any> {
|
||||
async run(): Promise<any> {
|
||||
interface IHistoryPickEntry extends IQuickPickItem {
|
||||
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 => {
|
||||
if (pick) {
|
||||
this.historyService.remove(pick.input);
|
||||
}
|
||||
});
|
||||
const pick = await this.quickInputService.pick(picks, { placeHolder: nls.localize('pickHistory', "Select an editor entry to remove from history"), matchOnDescription: true });
|
||||
if (pick) {
|
||||
this.historyService.remove(pick.input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,12 +23,10 @@ export const QUICKOPEN_ACION_LABEL = nls.localize('quickOpen', "Go to File...");
|
||||
|
||||
CommandsRegistry.registerCommand({
|
||||
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);
|
||||
|
||||
return quickOpenService.show(typeof prefix === 'string' ? prefix : undefined).then(() => {
|
||||
return undefined;
|
||||
});
|
||||
await quickOpenService.show(typeof prefix === 'string' ? prefix : undefined);
|
||||
},
|
||||
description: {
|
||||
description: `Quick open`,
|
||||
@@ -42,12 +40,10 @@ CommandsRegistry.registerCommand({
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
return quickOpenService.show(undefined, { autoFocus: { autoFocusSecondEntry: true } }).then(() => {
|
||||
return undefined;
|
||||
});
|
||||
await quickOpenService.show(undefined, { autoFocus: { autoFocusSecondEntry: true } });
|
||||
});
|
||||
|
||||
export class BaseQuickOpenNavigateAction extends Action {
|
||||
|
||||
@@ -189,19 +189,18 @@ export class SidebarPart extends CompositePart<Viewlet> implements IViewletServi
|
||||
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)) {
|
||||
return Promise.resolve(this.doOpenViewlet(id, focus));
|
||||
}
|
||||
|
||||
return this.extensionService.whenInstalledExtensionsRegistered()
|
||||
.then(() => {
|
||||
if (typeof id === 'string' && this.getViewlet(id)) {
|
||||
return this.doOpenViewlet(id, focus);
|
||||
}
|
||||
await this.extensionService.whenInstalledExtensionsRegistered();
|
||||
|
||||
return null;
|
||||
});
|
||||
if (typeof id === 'string' && this.getViewlet(id)) {
|
||||
return this.doOpenViewlet(id, focus);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
getViewlets(): ViewletDescriptor[] {
|
||||
|
||||
@@ -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 || [];
|
||||
|
||||
// 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.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 {
|
||||
|
||||
@@ -391,14 +391,13 @@ export class TitlebarPart extends Part implements ITitleService {
|
||||
const restoreIconContainer = append(this.windowControls, $('div.window-icon-bg'));
|
||||
this.maxRestoreControl = append(restoreIconContainer, $('div.window-icon'));
|
||||
addClass(this.maxRestoreControl, 'window-max-restore');
|
||||
this._register(addDisposableListener(this.maxRestoreControl, EventType.CLICK, e => {
|
||||
this.windowService.isMaximized().then((maximized) => {
|
||||
if (maximized) {
|
||||
return this.windowService.unmaximizeWindow();
|
||||
}
|
||||
this._register(addDisposableListener(this.maxRestoreControl, EventType.CLICK, async e => {
|
||||
const maximized = await this.windowService.isMaximized();
|
||||
if (maximized) {
|
||||
return this.windowService.unmaximizeWindow();
|
||||
}
|
||||
|
||||
return this.windowService.maximizeWindow();
|
||||
});
|
||||
return this.windowService.maximizeWindow();
|
||||
}));
|
||||
|
||||
// Close
|
||||
|
||||
@@ -251,15 +251,13 @@ export class CustomTreeView extends Disposable implements ITreeView {
|
||||
set dataProvider(dataProvider: ITreeViewDataProvider | null) {
|
||||
if (dataProvider) {
|
||||
this._dataProvider = new class implements ITreeViewDataProvider {
|
||||
getChildren(node: ITreeItem): Promise<ITreeItem[]> {
|
||||
async getChildren(node: ITreeItem): Promise<ITreeItem[]> {
|
||||
if (node && node.children) {
|
||||
return Promise.resolve(node.children);
|
||||
}
|
||||
const promise = node instanceof Root ? dataProvider.getChildren() : dataProvider.getChildren(node);
|
||||
return promise.then(children => {
|
||||
node.children = children;
|
||||
return children;
|
||||
});
|
||||
const children = await (node instanceof Root ? dataProvider.getChildren() : dataProvider.getChildren(node));
|
||||
node.children = children;
|
||||
return children;
|
||||
}
|
||||
};
|
||||
this.updateMessage();
|
||||
@@ -524,19 +522,16 @@ export class CustomTreeView extends Disposable implements ITreeView {
|
||||
}
|
||||
|
||||
private refreshing: boolean = false;
|
||||
private doRefresh(elements: ITreeItem[]): Promise<void> {
|
||||
private async doRefresh(elements: ITreeItem[]): Promise<void> {
|
||||
if (this.tree) {
|
||||
this.refreshing = true;
|
||||
return Promise.all(elements.map(e => this.tree.refresh(e)))
|
||||
.then(() => {
|
||||
this.refreshing = false;
|
||||
this.updateContentAreas();
|
||||
if (this.focused) {
|
||||
this.focus();
|
||||
}
|
||||
});
|
||||
await Promise.all(elements.map(e => this.tree.refresh(e)));
|
||||
this.refreshing = false;
|
||||
this.updateContentAreas();
|
||||
if (this.focused) {
|
||||
this.focus();
|
||||
}
|
||||
}
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
private updateContentAreas(): void {
|
||||
|
||||
@@ -618,21 +618,19 @@ export class ViewsService extends Disposable implements IViewsService {
|
||||
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);
|
||||
if (viewContainer) {
|
||||
const viewletDescriptor = this.viewletService.getViewlet(viewContainer.id);
|
||||
if (viewletDescriptor) {
|
||||
return this.viewletService.openViewlet(viewletDescriptor.id, focus)
|
||||
.then((viewlet: IViewsViewlet) => {
|
||||
if (viewlet && viewlet.openView) {
|
||||
return viewlet.openView(id, focus);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
const viewlet = await this.viewletService.openViewlet(viewletDescriptor.id, focus) as IViewsViewlet | null;
|
||||
if (viewlet && viewlet.openView) {
|
||||
return viewlet.openView(id, focus);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private onDidRegisterViewContainer(viewContainer: ViewContainer): void {
|
||||
@@ -669,7 +667,7 @@ export class ViewsService extends Disposable implements IViewsService {
|
||||
};
|
||||
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, {
|
||||
command,
|
||||
|
||||
@@ -26,28 +26,27 @@ class CodeRendererMain extends Disposable {
|
||||
|
||||
private workbench: Workbench;
|
||||
|
||||
open(): Promise<void> {
|
||||
async open(): Promise<void> {
|
||||
const services = this.initServices();
|
||||
|
||||
return domContentLoaded().then(() => {
|
||||
mark('willStartWorkbench');
|
||||
await domContentLoaded();
|
||||
mark('willStartWorkbench');
|
||||
|
||||
// Create Workbench
|
||||
this.workbench = new Workbench(
|
||||
document.body,
|
||||
services.serviceCollection,
|
||||
services.logService
|
||||
);
|
||||
// Create Workbench
|
||||
this.workbench = new Workbench(
|
||||
document.body,
|
||||
services.serviceCollection,
|
||||
services.logService
|
||||
);
|
||||
|
||||
// Layout
|
||||
this._register(addDisposableListener(window, EventType.RESIZE, () => this.workbench.layout()));
|
||||
// Layout
|
||||
this._register(addDisposableListener(window, EventType.RESIZE, () => this.workbench.layout()));
|
||||
|
||||
// Workbench Lifecycle
|
||||
this._register(this.workbench.onShutdown(() => this.dispose()));
|
||||
// Workbench Lifecycle
|
||||
this._register(this.workbench.onShutdown(() => this.dispose()));
|
||||
|
||||
// Startup
|
||||
this.workbench.startup();
|
||||
});
|
||||
// Startup
|
||||
this.workbench.startup();
|
||||
}
|
||||
|
||||
private initServices(): { serviceCollection: ServiceCollection, logService: ILogService } {
|
||||
|
||||
@@ -131,7 +131,7 @@ export class Workbench extends Layout {
|
||||
// Services
|
||||
const instantiationService = this.initServices(this.serviceCollection);
|
||||
|
||||
instantiationService.invokeFunction(accessor => {
|
||||
instantiationService.invokeFunction(async accessor => {
|
||||
const lifecycleService = accessor.get(ILifecycleService);
|
||||
const storageService = accessor.get(IStorageService);
|
||||
const configurationService = accessor.get(IConfigurationService);
|
||||
@@ -158,7 +158,11 @@ export class Workbench extends Layout {
|
||||
this.layout();
|
||||
|
||||
// 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;
|
||||
@@ -338,7 +342,7 @@ export class Workbench extends Layout {
|
||||
registerNotificationCommands(notificationsCenter, notificationsToasts);
|
||||
}
|
||||
|
||||
private restoreWorkbench(
|
||||
private async restoreWorkbench(
|
||||
editorService: IEditorService,
|
||||
editorGroupService: IEditorGroupsService,
|
||||
viewletService: IViewletService,
|
||||
@@ -349,36 +353,39 @@ export class Workbench extends Layout {
|
||||
const restorePromises: Promise<void>[] = [];
|
||||
|
||||
// Restore editors
|
||||
mark('willRestoreEditors');
|
||||
restorePromises.push(editorGroupService.whenRestored.then(() => {
|
||||
restorePromises.push((async () => {
|
||||
mark('willRestoreEditors');
|
||||
|
||||
function openEditors(editors: IResourceEditor[], editorService: IEditorService) {
|
||||
if (editors.length) {
|
||||
return editorService.openEditors(editors);
|
||||
}
|
||||
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
// first ensure the editor part is restored
|
||||
await editorGroupService.whenRestored;
|
||||
|
||||
// then see for editors to open as instructed
|
||||
let editors: IResourceEditor[];
|
||||
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));
|
||||
}).then(() => mark('didRestoreEditors')));
|
||||
if (editors.length) {
|
||||
await editorService.openEditors(editors);
|
||||
}
|
||||
|
||||
mark('didRestoreEditors');
|
||||
})());
|
||||
|
||||
// Restore Sidebar
|
||||
if (this.state.sideBar.viewletToRestore) {
|
||||
mark('willRestoreViewlet');
|
||||
restorePromises.push(viewletService.openViewlet(this.state.sideBar.viewletToRestore)
|
||||
.then(viewlet => {
|
||||
if (!viewlet) {
|
||||
return viewletService.openViewlet(viewletService.getDefaultViewletId()); // fallback to default viewlet as needed
|
||||
}
|
||||
restorePromises.push((async () => {
|
||||
mark('willRestoreViewlet');
|
||||
|
||||
return viewlet;
|
||||
})
|
||||
.then(() => mark('didRestoreViewlet')));
|
||||
const viewlet = await viewletService.openViewlet(this.state.sideBar.viewletToRestore);
|
||||
if (!viewlet) {
|
||||
await viewletService.openViewlet(viewletService.getDefaultViewletId()); // fallback to default viewlet as needed
|
||||
}
|
||||
|
||||
mark('didRestoreViewlet');
|
||||
})());
|
||||
}
|
||||
|
||||
// Restore Panel
|
||||
@@ -401,23 +408,24 @@ export class Workbench extends Layout {
|
||||
// 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);
|
||||
|
||||
return Promise.all(restorePromises)
|
||||
.then(() => clearTimeout(restoreTimeoutHandle))
|
||||
.catch(error => onUnexpectedError(error))
|
||||
.finally(() => {
|
||||
try {
|
||||
await Promise.all(restorePromises);
|
||||
|
||||
// Set lifecycle phase to `Restored`
|
||||
lifecycleService.phase = LifecyclePhase.Restored;
|
||||
clearTimeout(restoreTimeoutHandle);
|
||||
} catch (error) {
|
||||
onUnexpectedError(error);
|
||||
} finally {
|
||||
|
||||
// Set lifecycle phase to `Eventually` after a short delay and when idle (min 2.5sec, max 5sec)
|
||||
setTimeout(() => {
|
||||
this._register(runWhenIdle(() => {
|
||||
lifecycleService.phase = LifecyclePhase.Eventually;
|
||||
}, 2500));
|
||||
}, 2500);
|
||||
// Set lifecycle phase to `Restored`
|
||||
lifecycleService.phase = LifecyclePhase.Restored;
|
||||
|
||||
// Telemetry: startup metrics
|
||||
mark('didStartWorkbench');
|
||||
});
|
||||
// Set lifecycle phase to `Eventually` after a short delay and when idle (min 2.5sec, max 5sec)
|
||||
setTimeout(() => {
|
||||
this._register(runWhenIdle(() => lifecycleService.phase = LifecyclePhase.Eventually, 2500));
|
||||
}, 2500);
|
||||
|
||||
// Telemetry: startup metrics
|
||||
mark('didStartWorkbench');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,46 +82,40 @@ Registry.add(Extensions.WorkbenchActions, new class implements IWorkbenchActionR
|
||||
}
|
||||
|
||||
private createCommandHandler(descriptor: SyncActionDescriptor): ICommandHandler {
|
||||
return (accessor, args) => {
|
||||
return async (accessor, args) => {
|
||||
const notificationService = accessor.get(INotificationService);
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
const lifecycleService = accessor.get(ILifecycleService);
|
||||
|
||||
Promise.resolve(this.triggerAndDisposeAction(instantiationService, lifecycleService, descriptor, args)).then(undefined, err => {
|
||||
notificationService.error(err);
|
||||
});
|
||||
try {
|
||||
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
|
||||
return lifecycleService.when(LifecyclePhase.Ready).then(() => {
|
||||
const actionInstance = instantiationService.createInstance(descriptor.syncDescriptor);
|
||||
try {
|
||||
actionInstance.label = descriptor.label || actionInstance.label;
|
||||
await lifecycleService.when(LifecyclePhase.Ready);
|
||||
|
||||
// don't run the action when not enabled
|
||||
if (!actionInstance.enabled) {
|
||||
actionInstance.dispose();
|
||||
const actionInstance = instantiationService.createInstance(descriptor.syncDescriptor);
|
||||
actionInstance.label = descriptor.label || actionInstance.label;
|
||||
|
||||
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(() => {
|
||||
actionInstance.dispose();
|
||||
}, err => {
|
||||
actionInstance.dispose();
|
||||
|
||||
return Promise.reject(err);
|
||||
});
|
||||
} catch (err) {
|
||||
actionInstance.dispose();
|
||||
|
||||
return Promise.reject(err);
|
||||
}
|
||||
});
|
||||
// otherwise run and dispose
|
||||
try {
|
||||
const from = args && args.from || 'keybinding';
|
||||
await actionInstance.run(undefined, { from });
|
||||
} finally {
|
||||
actionInstance.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -80,9 +80,7 @@ class WorkbenchContributionsRegistry implements IWorkbenchContributionsRegistry
|
||||
|
||||
// Otherwise wait for phase to be reached
|
||||
else {
|
||||
lifecycleService.when(phase).then(() => {
|
||||
this.doInstantiateByPhase(instantiationService, phase);
|
||||
});
|
||||
lifecycleService.when(phase).then(() => this.doInstantiateByPhase(instantiationService, phase));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,20 +72,17 @@ export class BinaryEditorModel extends EditorModel {
|
||||
return this.etag;
|
||||
}
|
||||
|
||||
load(): Promise<BinaryEditorModel> {
|
||||
async load(): Promise<BinaryEditorModel> {
|
||||
|
||||
// Make sure to resolve up to date stat for file resources
|
||||
if (this.fileService.canHandleResource(this.resource)) {
|
||||
return this.fileService.resolve(this.resource, { resolveMetadata: true }).then(stat => {
|
||||
this.etag = stat.etag;
|
||||
if (typeof stat.size === 'number') {
|
||||
this.size = stat.size;
|
||||
}
|
||||
|
||||
return this;
|
||||
});
|
||||
const stat = await this.fileService.resolve(this.resource, { resolveMetadata: true });
|
||||
this.etag = stat.etag;
|
||||
if (typeof stat.size === 'number') {
|
||||
this.size = stat.size;
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.resolve(this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,45 +34,44 @@ export class DiffEditorInput extends SideBySideEditorInput {
|
||||
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
|
||||
// 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
|
||||
// the previous one - if any.
|
||||
return this.createModel().then(resolvedModel => {
|
||||
if (this.cachedModel) {
|
||||
this.cachedModel.dispose();
|
||||
}
|
||||
const resolvedModel = await this.createModel();
|
||||
if (this.cachedModel) {
|
||||
this.cachedModel.dispose();
|
||||
}
|
||||
|
||||
this.cachedModel = resolvedModel;
|
||||
this.cachedModel = resolvedModel;
|
||||
|
||||
return this.cachedModel;
|
||||
});
|
||||
return this.cachedModel;
|
||||
}
|
||||
|
||||
getPreferredEditorId(candidates: string[]): string {
|
||||
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
|
||||
return Promise.all([
|
||||
const models = await Promise.all([
|
||||
this.originalInput.resolve(),
|
||||
this.modifiedInput.resolve()
|
||||
]).then(models => {
|
||||
const originalEditorModel = models[0];
|
||||
const modifiedEditorModel = models[1];
|
||||
]);
|
||||
|
||||
// If both are text models, return textdiffeditor model
|
||||
if (modifiedEditorModel instanceof BaseTextEditorModel && originalEditorModel instanceof BaseTextEditorModel) {
|
||||
return new TextDiffEditorModel(originalEditorModel, modifiedEditorModel);
|
||||
}
|
||||
const originalEditorModel = models[0];
|
||||
const modifiedEditorModel = models[1];
|
||||
|
||||
// Otherwise return normal diff model
|
||||
return new DiffEditorModel(originalEditorModel, modifiedEditorModel);
|
||||
});
|
||||
// If both are text models, return textdiffeditor model
|
||||
if (modifiedEditorModel instanceof BaseTextEditorModel && originalEditorModel instanceof BaseTextEditorModel) {
|
||||
return new TextDiffEditorModel(originalEditorModel, modifiedEditorModel);
|
||||
}
|
||||
|
||||
// Otherwise return normal diff model
|
||||
return new DiffEditorModel(originalEditorModel, modifiedEditorModel);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
|
||||
@@ -37,11 +37,13 @@ export class DiffEditorModel extends EditorModel {
|
||||
return this._modifiedModel;
|
||||
}
|
||||
|
||||
load(): Promise<EditorModel> {
|
||||
return Promise.all([
|
||||
async load(): Promise<EditorModel> {
|
||||
await Promise.all([
|
||||
this._originalModel ? this._originalModel.load() : Promise.resolve(undefined),
|
||||
this._modifiedModel ? this._modifiedModel.load() : Promise.resolve(undefined),
|
||||
]).then(() => this);
|
||||
]);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
isResolved(): boolean {
|
||||
|
||||
@@ -76,31 +76,31 @@ export class ResourceEditorInput extends EditorInput implements IModeSupport {
|
||||
this.preferredMode = mode;
|
||||
}
|
||||
|
||||
resolve(): Promise<ITextEditorModel> {
|
||||
async resolve(): Promise<ITextEditorModel> {
|
||||
if (!this.modelReference) {
|
||||
this.modelReference = this.textModelResolverService.createModelReference(this.resource);
|
||||
}
|
||||
|
||||
return this.modelReference.then(ref => {
|
||||
const model = ref.object;
|
||||
const ref = await this.modelReference;
|
||||
|
||||
// Ensure the resolved model is of expected type
|
||||
if (!(model instanceof ResourceEditorModel)) {
|
||||
ref.dispose();
|
||||
this.modelReference = null;
|
||||
const model = ref.object;
|
||||
|
||||
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
|
||||
if (this.preferredMode) {
|
||||
model.setMode(this.preferredMode);
|
||||
}
|
||||
this.cachedModel = model;
|
||||
|
||||
return model;
|
||||
});
|
||||
// Set mode if we have a preferred mode configured
|
||||
if (this.preferredMode) {
|
||||
model.setMode(this.preferredMode);
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
matches(otherInput: unknown): boolean {
|
||||
|
||||
@@ -26,6 +26,7 @@ export class ResourceEditorModel extends BaseTextEditorModel {
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
|
||||
// TODO@Joao: force this class to dispose the underlying model
|
||||
if (this.textEditorModelHandle) {
|
||||
this.modelService.destroyModel(this.textEditorModelHandle);
|
||||
|
||||
@@ -33,12 +33,12 @@ export class TextDiffEditorModel extends DiffEditorModel {
|
||||
return this._modifiedModel;
|
||||
}
|
||||
|
||||
load(): Promise<EditorModel> {
|
||||
return super.load().then(() => {
|
||||
this.updateTextDiffEditorModel();
|
||||
async load(): Promise<EditorModel> {
|
||||
await super.load();
|
||||
|
||||
return this;
|
||||
});
|
||||
this.updateTextDiffEditorModel();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private updateTextDiffEditorModel(): void {
|
||||
|
||||
@@ -11,7 +11,7 @@ import { IModeService } from 'vs/editor/common/services/modeService';
|
||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
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 { ITextBufferFactory } from 'vs/editor/common/model';
|
||||
import { createTextBufferFactory } from 'vs/editor/common/model/textModel';
|
||||
@@ -135,52 +135,48 @@ export class UntitledEditorModel extends BaseTextEditorModel implements IEncodin
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
load(): Promise<UntitledEditorModel & IResolvedTextEditorModel> {
|
||||
async load(): Promise<UntitledEditorModel & IResolvedTextEditorModel> {
|
||||
|
||||
// Check for backups first
|
||||
return this.backupFileService.loadBackupResource(this.resource).then(backupResource => {
|
||||
if (backupResource) {
|
||||
return this.backupFileService.resolveBackupContent(backupResource);
|
||||
}
|
||||
let backup: IResolvedBackup<object> | undefined = undefined;
|
||||
const backupResource = await this.backupFileService.loadBackupResource(this.resource);
|
||||
if (backupResource) {
|
||||
backup = await this.backupFileService.resolveBackupContent(backupResource);
|
||||
}
|
||||
|
||||
return Promise.resolve(undefined);
|
||||
}).then(backup => {
|
||||
const hasBackup = !!backup;
|
||||
// untitled associated to file path are dirty right away as well as untitled with content
|
||||
this.setDirty(this._hasAssociatedFilePath || !!backup || !!this.initialValue);
|
||||
|
||||
// untitled associated to file path are dirty right away as well as untitled with content
|
||||
this.setDirty(this._hasAssociatedFilePath || hasBackup || !!this.initialValue);
|
||||
let untitledContents: ITextBufferFactory;
|
||||
if (backup) {
|
||||
untitledContents = backup.value;
|
||||
} else {
|
||||
untitledContents = createTextBufferFactory(this.initialValue || '');
|
||||
}
|
||||
|
||||
let untitledContents: ITextBufferFactory;
|
||||
if (backup) {
|
||||
untitledContents = backup.value;
|
||||
} else {
|
||||
untitledContents = createTextBufferFactory(this.initialValue || '');
|
||||
}
|
||||
// Create text editor model if not yet done
|
||||
if (!this.textEditorModel) {
|
||||
this.createTextEditorModel(untitledContents, this.resource, this.preferredMode);
|
||||
}
|
||||
|
||||
// Create text editor model if not yet done
|
||||
if (!this.textEditorModel) {
|
||||
this.createTextEditorModel(untitledContents, this.resource, this.preferredMode);
|
||||
}
|
||||
// Otherwise update
|
||||
else {
|
||||
this.updateTextEditorModel(untitledContents, this.preferredMode);
|
||||
}
|
||||
|
||||
// Otherwise update
|
||||
else {
|
||||
this.updateTextEditorModel(untitledContents, this.preferredMode);
|
||||
}
|
||||
// Encoding
|
||||
this.configuredEncoding = this.configurationService.getValue<string>(this.resource, 'files.encoding');
|
||||
|
||||
// Encoding
|
||||
this.configuredEncoding = this.configurationService.getValue<string>(this.resource, 'files.encoding');
|
||||
// We know for a fact there is a text editor model here
|
||||
const textEditorModel = this.textEditorModel!;
|
||||
|
||||
// We know for a fact there is a text editor model here
|
||||
const textEditorModel = this.textEditorModel!;
|
||||
// Listen to content changes
|
||||
this._register(textEditorModel.onDidChangeContent(() => this.onModelContentChanged()));
|
||||
|
||||
// Listen to content changes
|
||||
this._register(textEditorModel.onDidChangeContent(() => this.onModelContentChanged()));
|
||||
// Listen to mode changes
|
||||
this._register(textEditorModel.onDidChangeLanguage(() => this.onConfigurationChange())); // mode change can have impact on config
|
||||
|
||||
// Listen to mode changes
|
||||
this._register(textEditorModel.onDidChangeLanguage(() => this.onConfigurationChange())); // mode change can have impact on config
|
||||
|
||||
return this as UntitledEditorModel & IResolvedTextEditorModel;
|
||||
});
|
||||
return this as UntitledEditorModel & IResolvedTextEditorModel;
|
||||
}
|
||||
|
||||
private onModelContentChanged(): void {
|
||||
|
||||
@@ -33,46 +33,47 @@ export class BackupRestorer implements IWorkbenchContribution {
|
||||
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
|
||||
return this.backupFileService.getWorkspaceFileBackups().then(backups => {
|
||||
const backups = await this.backupFileService.getWorkspaceFileBackups();
|
||||
const unresolvedBackups = await this.doResolveOpenedBackups(backups);
|
||||
|
||||
// Resolve backups that are opened
|
||||
return this.doResolveOpenedBackups(backups).then((unresolved): Promise<URI[] | undefined> | undefined => {
|
||||
// Some failed to restore or were not opened at all so we open and resolve them manually
|
||||
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
|
||||
if (unresolved.length > 0) {
|
||||
return this.doOpenEditors(unresolved).then(() => this.doResolveOpenedBackups(unresolved));
|
||||
}
|
||||
return this.doResolveOpenedBackups(unresolvedBackups);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
});
|
||||
});
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private doResolveOpenedBackups(backups: URI[]): Promise<URI[]> {
|
||||
const restorePromises: Promise<unknown>[] = [];
|
||||
const unresolved: URI[] = [];
|
||||
private async doResolveOpenedBackups(backups: URI[]): Promise<URI[]> {
|
||||
const unresolvedBackups: URI[] = [];
|
||||
|
||||
backups.forEach(backup => {
|
||||
await Promise.all(backups.map(async backup => {
|
||||
const openedEditor = this.editorService.getOpened({ resource: backup });
|
||||
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 {
|
||||
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 inputs = resources.map((resource, index) => this.resolveInput(resource, index, hasOpenedEditors));
|
||||
|
||||
// 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 {
|
||||
|
||||
@@ -7,6 +7,7 @@ import * as nls from 'vs/nls';
|
||||
import * as path from 'vs/base/common/path';
|
||||
import * as cp from 'child_process';
|
||||
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 { promisify } from 'util';
|
||||
import { Action } from 'vs/base/common/actions';
|
||||
@@ -91,7 +92,7 @@ class InstallAction extends Action {
|
||||
private isInstalled(): Promise<boolean> {
|
||||
return pfs.lstat(this.target)
|
||||
.then(stat => stat.isSymbolicLink())
|
||||
.then(() => pfs.readlink(this.target))
|
||||
.then(() => extpath.realpath(this.target))
|
||||
.then(link => link === getSource())
|
||||
.then(undefined, ignore('ENOENT', false));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
58
src/vs/workbench/contrib/comments/browser/commentMenus.ts
Normal file
58
src/vs/workbench/contrib/comments/browser/commentMenus.ts
Normal 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 {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import * as dom from 'vs/base/browser/dom';
|
||||
import * as modes from 'vs/editor/common/modes';
|
||||
import { ActionsOrientation, ActionViewItem, ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
|
||||
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 { URI } from 'vs/base/common/uri';
|
||||
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 { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
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_IN_PROGRESS_LABEL = nls.localize('label.updatingComment', "Updating comment...");
|
||||
@@ -57,10 +62,13 @@ export class CommentNode extends Disposable {
|
||||
private _updateCommentButton: Button;
|
||||
private _errorEditingContainer: HTMLElement;
|
||||
private _isPendingLabel: HTMLElement;
|
||||
private _contextKeyService: IContextKeyService;
|
||||
private _commentContextValue: IContextKey<string>;
|
||||
|
||||
private _deleteAction: Action;
|
||||
protected actionRunner?: IActionRunner;
|
||||
protected toolbar: ToolBar;
|
||||
private _commentFormActions: CommentFormActions;
|
||||
|
||||
private _onDidDelete = new Emitter<CommentNode>();
|
||||
|
||||
@@ -85,12 +93,17 @@ export class CommentNode extends Disposable {
|
||||
@IModelService private modelService: IModelService,
|
||||
@IModeService private modeService: IModeService,
|
||||
@IDialogService private dialogService: IDialogService,
|
||||
@IKeybindingService private keybindingService: IKeybindingService,
|
||||
@INotificationService private notificationService: INotificationService,
|
||||
@IContextMenuService private contextMenuService: IContextMenuService
|
||||
@IContextMenuService private contextMenuService: IContextMenuService,
|
||||
@IContextKeyService contextKeyService: IContextKeyService
|
||||
) {
|
||||
super();
|
||||
|
||||
this._domNode = dom.$('div.review-comment');
|
||||
this._contextKeyService = contextKeyService.createScoped(this._domNode);
|
||||
this._commentContextValue = this._contextKeyService.createKey('comment', comment.contextValue);
|
||||
|
||||
this._domNode.tabIndex = 0;
|
||||
const avatar = dom.append(this._domNode, dom.$('div.avatar-container'));
|
||||
if (comment.userIconPath) {
|
||||
@@ -139,7 +152,7 @@ export class CommentNode extends Disposable {
|
||||
}
|
||||
|
||||
private createActionsToolbar() {
|
||||
const actions: Action[] = [];
|
||||
const actions: IAction[] = [];
|
||||
|
||||
let reactionGroup = this.commentService.getReactionGroup(this.owner);
|
||||
if (reactionGroup && reactionGroup.length) {
|
||||
@@ -163,6 +176,17 @@ export class CommentNode extends Disposable {
|
||||
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) {
|
||||
this.toolbar = new ToolBar(this._actionsToolbarContainer, this.contextMenuService, {
|
||||
actionViewItemProvider: action => {
|
||||
@@ -185,6 +209,12 @@ export class CommentNode extends Disposable {
|
||||
orientation: ActionsOrientation.HORIZONTAL
|
||||
});
|
||||
|
||||
this.toolbar.context = {
|
||||
thread: this.commentThread,
|
||||
commentUniqueId: this.comment.uniqueIdInThread,
|
||||
$mid: 9
|
||||
};
|
||||
|
||||
this.registerActionBarListeners(this._actionsToolbarContainer);
|
||||
this.toolbar.setActions(actions, [])();
|
||||
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) {
|
||||
options = { label: false, icon: true };
|
||||
} else {
|
||||
options = { label: true, icon: true };
|
||||
options = { label: false, icon: true };
|
||||
}
|
||||
|
||||
if (action.id === ReactionAction.ID) {
|
||||
let item = new ReactionActionViewItem(action);
|
||||
return item;
|
||||
} else if (action instanceof MenuItemAction) {
|
||||
let item = new ContextAwareMenuEntryActionViewItem(action, this.keybindingService, this.notificationService, this.contextMenuService);
|
||||
return item;
|
||||
} else {
|
||||
let item = new ActionViewItem({}, action, options);
|
||||
return item;
|
||||
@@ -391,14 +424,12 @@ export class CommentNode extends Disposable {
|
||||
uri: this._commentEditor.getModel()!.uri,
|
||||
value: this.comment.body.value
|
||||
};
|
||||
this.commentService.setActiveCommentThread(commentThread);
|
||||
|
||||
this._commentEditorDisposables.push(this._commentEditor.onDidFocusEditorWidget(() => {
|
||||
commentThread.input = {
|
||||
uri: this._commentEditor!.getModel()!.uri,
|
||||
value: this.comment.body.value
|
||||
};
|
||||
this.commentService.setActiveCommentThread(commentThread);
|
||||
}));
|
||||
|
||||
this._commentEditorDisposables.push(this._commentEditor.onDidChangeModelContent(e => {
|
||||
@@ -419,10 +450,15 @@ export class CommentNode extends Disposable {
|
||||
|
||||
private removeCommentEditor() {
|
||||
this.isEditing = false;
|
||||
this._editAction.enabled = true;
|
||||
if (this._editAction) {
|
||||
this._editAction.enabled = true;
|
||||
}
|
||||
this._body.classList.remove('hidden');
|
||||
|
||||
this._commentEditorModel.dispose();
|
||||
if (this._commentEditorModel) {
|
||||
this._commentEditorModel.dispose();
|
||||
}
|
||||
|
||||
this._commentEditorDisposables.forEach(dispose => dispose.dispose());
|
||||
this._commentEditorDisposables = [];
|
||||
if (this._commentEditor) {
|
||||
@@ -450,7 +486,6 @@ export class CommentNode extends Disposable {
|
||||
uri: this._commentEditor.getModel()!.uri,
|
||||
value: newBody
|
||||
};
|
||||
this.commentService.setActiveCommentThread(commentThread);
|
||||
let commandId = this.comment.editCommand.id;
|
||||
let args = this.comment.editCommand.arguments || [];
|
||||
|
||||
@@ -488,7 +523,6 @@ export class CommentNode extends Disposable {
|
||||
if (result.confirmed) {
|
||||
try {
|
||||
if (this.comment.deleteCommand) {
|
||||
this.commentService.setActiveCommentThread(this.commentThread as modes.CommentThread2);
|
||||
let commandId = this.comment.deleteCommand.id;
|
||||
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 {
|
||||
return new Action('comment.edit', nls.localize('label.edit', "Edit"), 'octicon octicon-pencil', true, () => {
|
||||
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();
|
||||
return this.editCommentAction(commentDetailsContainer);
|
||||
});
|
||||
}
|
||||
|
||||
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 {
|
||||
this._toDispose.push(dom.addDisposableListener(this._domNode, 'mouseenter', () => {
|
||||
actionsContainer.classList.remove('hidden');
|
||||
@@ -581,6 +655,14 @@ export class CommentNode extends Disposable {
|
||||
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;
|
||||
this.comment = newComment;
|
||||
|
||||
@@ -610,6 +692,12 @@ export class CommentNode extends Disposable {
|
||||
if (this.comment.commentReactions && this.comment.commentReactions.length) {
|
||||
this.createReactionsContainer(this._commentDetailsContainer);
|
||||
}
|
||||
|
||||
if (this.comment.contextValue) {
|
||||
this._commentContextValue.set(this.comment.contextValue);
|
||||
} else {
|
||||
this._commentContextValue.reset();
|
||||
}
|
||||
}
|
||||
|
||||
focus() {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
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 { Disposable } from 'vs/base/common/lifecycle';
|
||||
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 { ICommentThreadChangedEvent } from 'vs/workbench/contrib/comments/common/commentModel';
|
||||
import { MainThreadCommentController } from 'vs/workbench/api/browser/mainThreadComments';
|
||||
import { CommentMenus } from 'vs/workbench/contrib/comments/browser/commentMenus';
|
||||
|
||||
export const ICommentService = createDecorator<ICommentService>('commentService');
|
||||
|
||||
@@ -37,9 +38,7 @@ export interface ICommentService {
|
||||
readonly onDidSetResourceCommentInfos: Event<IResourceCommentThreadEvent>;
|
||||
readonly onDidSetAllCommentThreads: Event<IWorkspaceCommentThreadsEvent>;
|
||||
readonly onDidUpdateCommentThreads: Event<ICommentThreadChangedEvent>;
|
||||
readonly onDidChangeActiveCommentThread: Event<CommentThread | null>;
|
||||
readonly onDidChangeActiveCommentingRange: Event<{ range: Range, commentingRangesInfo: CommentingRanges }>;
|
||||
readonly onDidChangeInput: Event<string>;
|
||||
readonly onDidSetDataProvider: Event<void>;
|
||||
readonly onDidDeleteDataProvider: Event<string>;
|
||||
setDocumentComments(resource: URI, commentInfos: ICommentInfo[]): void;
|
||||
@@ -47,9 +46,13 @@ export interface ICommentService {
|
||||
removeWorkspaceComments(owner: string): void;
|
||||
registerCommentController(owner: string, commentControl: MainThreadCommentController): 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;
|
||||
unregisterDataProvider(owner: string): 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>;
|
||||
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>;
|
||||
@@ -66,9 +69,6 @@ export interface ICommentService {
|
||||
deleteReaction(owner: string, resource: URI, comment: Comment, reaction: CommentReaction): Promise<void>;
|
||||
getReactionGroup(owner: string): CommentReaction[] | undefined;
|
||||
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 {
|
||||
@@ -89,11 +89,6 @@ export class CommentService extends Disposable implements ICommentService {
|
||||
private readonly _onDidUpdateCommentThreads: Emitter<ICommentThreadChangedEvent> = this._register(new Emitter<ICommentThreadChangedEvent>());
|
||||
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<{
|
||||
range: Range, commentingRangesInfo:
|
||||
CommentingRanges
|
||||
@@ -106,19 +101,14 @@ export class CommentService extends Disposable implements ICommentService {
|
||||
private _commentProviders = new Map<string, DocumentCommentProvider>();
|
||||
|
||||
private _commentControls = new Map<string, MainThreadCommentController>();
|
||||
private _commentMenus = new Map<string, CommentMenus>();
|
||||
|
||||
constructor() {
|
||||
constructor(
|
||||
@IInstantiationService protected instantiationService: IInstantiationService
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
setActiveCommentThread(commentThread: CommentThread | null) {
|
||||
this._onDidChangeActiveCommentThread.fire(commentThread);
|
||||
}
|
||||
|
||||
setInput(input: string) {
|
||||
this._onDidChangeInput.fire(input);
|
||||
}
|
||||
|
||||
setDocumentComments(resource: URI, commentInfos: ICommentInfo[]): void {
|
||||
this._onDidSetResourceCommentInfos.fire({ resource, commentInfos });
|
||||
}
|
||||
@@ -141,6 +131,39 @@ export class CommentService extends Disposable implements ICommentService {
|
||||
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 {
|
||||
this._commentProviders.set(owner, commentProvider);
|
||||
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 {
|
||||
const commentProvider = this._commentControls.get(owner);
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
|
||||
import * as nls from 'vs/nls';
|
||||
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 { Action } from 'vs/base/common/actions';
|
||||
import { Action, IAction } from 'vs/base/common/actions';
|
||||
import * as arrays from 'vs/base/common/arrays';
|
||||
import { Color } from 'vs/base/common/color';
|
||||
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 { ICommentThreadWidget } from 'vs/workbench/contrib/comments/common/commentThreadWidget';
|
||||
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';
|
||||
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';
|
||||
|
||||
|
||||
@@ -70,6 +79,11 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
|
||||
private _styleElement: HTMLStyleElement;
|
||||
private _formActions: HTMLElement | null;
|
||||
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 {
|
||||
return this._owner;
|
||||
@@ -86,6 +100,8 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
|
||||
return this._draftMode;
|
||||
}
|
||||
|
||||
private _commentMenus: CommentMenus;
|
||||
|
||||
constructor(
|
||||
editor: ICodeEditor,
|
||||
private _owner: string,
|
||||
@@ -98,15 +114,25 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
|
||||
@IModelService private modelService: IModelService,
|
||||
@IThemeService private themeService: IThemeService,
|
||||
@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 });
|
||||
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._isExpanded = _commentThread.collapsibleState ? _commentThread.collapsibleState === modes.CommentThreadCollapsibleState.Expanded : undefined;
|
||||
this._globalToDispose = [];
|
||||
this._commentThreadDisposables = [];
|
||||
this._submitActionsDisposables = [];
|
||||
this._formActions = null;
|
||||
this._commentMenus = this.commentService.getCommentMenus(this._owner);
|
||||
this.create();
|
||||
|
||||
this._styleElement = dom.createStyleSheet(this.domNode);
|
||||
@@ -185,10 +211,6 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
|
||||
|
||||
this._bodyElement = <HTMLDivElement>dom.$('.body');
|
||||
container.appendChild(this._bodyElement);
|
||||
|
||||
dom.addDisposableListener(this._bodyElement, dom.EventType.FOCUS_IN, e => {
|
||||
this.commentService.setActiveCommentThread(this._commentThread);
|
||||
});
|
||||
}
|
||||
|
||||
protected _fillHead(container: HTMLElement): void {
|
||||
@@ -198,12 +220,41 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
|
||||
this.createThreadLabel();
|
||||
|
||||
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._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> {
|
||||
@@ -214,9 +265,9 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
|
||||
} else {
|
||||
const deleteCommand = (this._commentThread as modes.CommentThread2).deleteCommand;
|
||||
if (deleteCommand) {
|
||||
this.commentService.setActiveCommentThread(this._commentThread);
|
||||
return this.commandService.executeCommand(deleteCommand.id, ...(deleteCommand.arguments || []));
|
||||
} else if (this._commentEditor.getValue() === '') {
|
||||
this.commentService.disposeCommentThread(this._owner, this._commentThread.threadId!);
|
||||
this.dispose();
|
||||
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 newCommentsLen = commentThread.comments ? commentThread.comments.length : 0;
|
||||
this._threadIsEmpty.set(!newCommentsLen);
|
||||
|
||||
let commentElementsToDel: CommentNode[] = [];
|
||||
let commentElementsToDelIndex: number[] = [];
|
||||
@@ -294,26 +346,12 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
|
||||
|
||||
this._commentThread = commentThread;
|
||||
this._commentElements = newCommentNodeList;
|
||||
this.createThreadLabel(replaceTemplate);
|
||||
|
||||
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();
|
||||
}
|
||||
this.createThreadLabel();
|
||||
|
||||
if (this._formActions && this._commentEditor.hasModel()) {
|
||||
dom.clearNode(this._formActions);
|
||||
const model = this._commentEditor.getModel();
|
||||
this.createCommentWidgetActions2(this._formActions, model);
|
||||
|
||||
if (replaceTemplate) {
|
||||
this.createCommentWidgetActionsListener(this._formActions, model);
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
if (this._commentThread.contextValue) {
|
||||
this._commentThreadContextValue.set(this._commentThread.contextValue);
|
||||
} else {
|
||||
this._commentThreadContextValue.reset();
|
||||
}
|
||||
}
|
||||
|
||||
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*/ });
|
||||
}
|
||||
|
||||
display(lineNumber: number, fromTemplate: boolean = false) {
|
||||
display(lineNumber: number) {
|
||||
this._commentGlyph = new CommentGlyphWidget(this.editor, lineNumber);
|
||||
|
||||
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;
|
||||
this._commentForm = dom.append(this._bodyElement, dom.$('.comment-form'));
|
||||
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 params = JSON.stringify({
|
||||
extensionId: this.extensionId,
|
||||
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);
|
||||
this._disposables.push(model);
|
||||
this._commentEditor.setModel(model);
|
||||
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) {
|
||||
this.createTextModelListener();
|
||||
}
|
||||
@@ -426,9 +482,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
|
||||
this._formActions = dom.append(this._commentForm, dom.$('.form-actions'));
|
||||
if ((this._commentThread as modes.CommentThread2).commentThreadHandle !== undefined) {
|
||||
this.createCommentWidgetActions2(this._formActions, model);
|
||||
if (!fromTemplate) {
|
||||
this.createCommentWidgetActionsListener(this._formActions, model);
|
||||
}
|
||||
this.createCommentWidgetActionsListener(this._formActions, model);
|
||||
} else {
|
||||
this.createCommentWidgetActions(this._formActions, model);
|
||||
}
|
||||
@@ -462,7 +516,6 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
|
||||
uri: this._commentEditor.getModel()!.uri,
|
||||
value: this._commentEditor.getValue()
|
||||
};
|
||||
this.commentService.setActiveCommentThread(this._commentThread);
|
||||
}));
|
||||
|
||||
this._commentThreadDisposables.push(this._commentEditor.getModel()!.onDidChangeContent(() => {
|
||||
@@ -674,7 +727,6 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
|
||||
uri: this._commentEditor.getModel()!.uri,
|
||||
value: this._commentEditor.getValue()
|
||||
};
|
||||
this.commentService.setActiveCommentThread(this._commentThread);
|
||||
await this.commandService.executeCommand(acceptInputCommand.id, ...(acceptInputCommand.arguments || []));
|
||||
}));
|
||||
|
||||
@@ -699,11 +751,29 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
|
||||
uri: this._commentEditor.getModel()!.uri,
|
||||
value: this._commentEditor.getValue()
|
||||
};
|
||||
this.commentService.setActiveCommentThread(this._commentThread);
|
||||
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 {
|
||||
@@ -751,7 +821,6 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
|
||||
uri: this._commentEditor.getModel()!.uri,
|
||||
value: this._commentEditor.getValue()
|
||||
};
|
||||
this.commentService.setActiveCommentThread(this._commentThread);
|
||||
let commandId = commentThread.acceptInputCommand.id;
|
||||
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;
|
||||
if ((this._commentThread as modes.CommentThread2).commentThreadHandle !== undefined) {
|
||||
label = (this._commentThread as modes.CommentThread2).label;
|
||||
}
|
||||
|
||||
if (label === undefined && !replaceTemplate) {
|
||||
// if it's for replacing the comment thread template, the comment thread widget title can be undefined as extensions may set it later
|
||||
if (label === undefined) {
|
||||
if (this._commentThread.comments && this._commentThread.comments.length) {
|
||||
const participantsList = this._commentThread.comments.filter(arrays.uniqueFilter(comment => comment.userName)).map(comment => `@${comment.userName}`).join(', ');
|
||||
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.setAttribute('aria-label', label);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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() {
|
||||
this._reviewThreadReplyButton = <HTMLButtonElement>dom.append(this._commentForm, dom.$('button.review-thread-reply-button'));
|
||||
if ((this._commentThread as modes.CommentThread2).commentThreadHandle !== undefined) {
|
||||
|
||||
@@ -64,7 +64,7 @@ class CommentingRangeDecoration {
|
||||
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 endLineNumber = _range.endLineNumber;
|
||||
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 {
|
||||
extensionId: this._extensionId,
|
||||
label: this._label,
|
||||
replyCommand: this._reply,
|
||||
ownerId: this._ownerId,
|
||||
commentingRangesInfo: this.commentingRangesInfo,
|
||||
template: this._template
|
||||
commentingRangesInfo: this.commentingRangesInfo
|
||||
};
|
||||
}
|
||||
|
||||
@@ -125,11 +124,11 @@ class CommentingRangeDecorator {
|
||||
for (const info of commentInfos) {
|
||||
if (Array.isArray(info.commentingRanges)) {
|
||||
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 {
|
||||
(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 => {
|
||||
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) {
|
||||
let matchedZone = matchedZones[0];
|
||||
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));
|
||||
|
||||
if (matchedNewCommentThreadZones.length) {
|
||||
matchedNewCommentThreadZones[0].update(thread, true);
|
||||
matchedNewCommentThreadZones[0].update(thread);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -469,22 +468,6 @@ export class ReviewController implements IEditorContribution {
|
||||
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) {
|
||||
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.`);
|
||||
@@ -640,16 +623,16 @@ export class ReviewController implements IEditorContribution {
|
||||
const commentInfos = newCommentInfos.filter(info => info.ownerId === pick.id);
|
||||
|
||||
if (commentInfos.length) {
|
||||
const { replyCommand, ownerId, extensionId, commentingRangesInfo, template } = commentInfos[0];
|
||||
this.addCommentAtLine2(lineNumber, replyCommand, ownerId, extensionId, commentingRangesInfo, template);
|
||||
const { replyCommand, ownerId, extensionId, commentingRangesInfo } = commentInfos[0];
|
||||
this.addCommentAtLine2(lineNumber, replyCommand, ownerId, extensionId, commentingRangesInfo);
|
||||
}
|
||||
}).then(() => {
|
||||
this._addInProgress = false;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const { replyCommand, ownerId, extensionId, commentingRangesInfo, template } = newCommentInfos[0]!;
|
||||
this.addCommentAtLine2(lineNumber, replyCommand, ownerId, extensionId, commentingRangesInfo, template);
|
||||
const { replyCommand, ownerId, extensionId, commentingRangesInfo } = newCommentInfos[0]!;
|
||||
this.addCommentAtLine2(lineNumber, replyCommand, ownerId, extensionId, commentingRangesInfo);
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
@@ -668,11 +651,11 @@ export class ReviewController implements IEditorContribution {
|
||||
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)[] = [];
|
||||
|
||||
commentInfos.forEach(commentInfo => {
|
||||
const { replyCommand, ownerId, extensionId, label, commentingRangesInfo, template } = commentInfo;
|
||||
const { replyCommand, ownerId, extensionId, label, commentingRangesInfo } = commentInfo;
|
||||
|
||||
actions.push(new Action(
|
||||
'addCommentThread',
|
||||
@@ -680,7 +663,7 @@ export class ReviewController implements IEditorContribution {
|
||||
undefined,
|
||||
true,
|
||||
() => {
|
||||
this.addCommentAtLine2(lineNumber, replyCommand, ownerId, extensionId, commentingRangesInfo, template);
|
||||
this.addCommentAtLine2(lineNumber, replyCommand, ownerId, extensionId, commentingRangesInfo);
|
||||
return Promise.resolve();
|
||||
}
|
||||
));
|
||||
@@ -688,23 +671,10 @@ export class ReviewController implements IEditorContribution {
|
||||
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) {
|
||||
let range = new Range(lineNumber, 1, lineNumber, 1);
|
||||
if (template) {
|
||||
// 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) {
|
||||
if (commentingRangesInfo.newCommentThreadCallback) {
|
||||
return commentingRangesInfo.newCommentThreadCallback(this.editor.getModel()!.uri, range)
|
||||
.then(_ => {
|
||||
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.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 {
|
||||
const commentInfo = this._commentInfos.filter(info => info.owner === ownerId);
|
||||
|
||||
@@ -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 { ICommentService, IWorkspaceCommentThreadsEvent } from 'vs/workbench/contrib/comments/browser/commentService';
|
||||
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 { IOpenerService } from 'vs/platform/opener/common/opener';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
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_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);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -198,6 +198,16 @@
|
||||
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 {
|
||||
background-image: url(./reaction.svg);
|
||||
width: 18px;
|
||||
|
||||
@@ -22,6 +22,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
|
||||
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
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);
|
||||
|
||||
@@ -30,6 +31,7 @@ export class SimpleCommentEditor extends CodeEditorWidget {
|
||||
private _parentEditor: ICodeEditor;
|
||||
private _parentThread: ICommentThreadWidget;
|
||||
private _commentEditorFocused: IContextKey<boolean>;
|
||||
private _commentEditorEmpty: IContextKey<boolean>;
|
||||
|
||||
constructor(
|
||||
domElement: HTMLElement,
|
||||
@@ -56,11 +58,15 @@ export class SimpleCommentEditor extends CodeEditorWidget {
|
||||
|
||||
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._parentThread = parentThread;
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -161,7 +161,7 @@ export abstract class AbstractExpressionsRenderer implements ITreeRenderer<IExpr
|
||||
});
|
||||
const styler = attachInputBoxStyler(inputBox, this.themeService);
|
||||
|
||||
inputBox.value = options.initialValue;
|
||||
inputBox.value = replaceWhitespace(options.initialValue);
|
||||
inputBox.focus();
|
||||
inputBox.select();
|
||||
|
||||
|
||||
@@ -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) {
|
||||
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 {
|
||||
this.windowsService.openExternal(resource.toString()).then(didOpen => {
|
||||
if (!didOpen) {
|
||||
return this.windowsService.showItemInFolder(resource);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
});
|
||||
private async openExternal(resource: URI): Promise<void> {
|
||||
const didOpen = await this.windowsService.openExternal(resource.toString());
|
||||
if (!didOpen) {
|
||||
return this.windowsService.showItemInFolder(resource);
|
||||
}
|
||||
}
|
||||
|
||||
getTitle(): string | null {
|
||||
|
||||
@@ -135,7 +135,7 @@ export class FileEditorTracker extends Disposable implements IWorkbenchContribut
|
||||
|
||||
private handleDeletes(arg1: URI | FileChangesEvent, isExternal: boolean, movedTo?: URI): void {
|
||||
const nonDirtyFileEditors = this.getOpenedFileEditors(false /* non-dirty only */);
|
||||
nonDirtyFileEditors.forEach(editor => {
|
||||
nonDirtyFileEditors.forEach(async editor => {
|
||||
const resource = editor.getResource();
|
||||
|
||||
// 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.
|
||||
// This only applies to external file events, so we need to check for the isExternal
|
||||
// flag.
|
||||
let checkExists: Promise<boolean>;
|
||||
let exists = false;
|
||||
if (isExternal) {
|
||||
checkExists = timeout(100).then(() => this.fileService.exists(resource));
|
||||
} else {
|
||||
checkExists = Promise.resolve(false);
|
||||
await timeout(100);
|
||||
exists = await this.fileService.exists(resource);
|
||||
}
|
||||
|
||||
checkExists.then(exists => {
|
||||
if (!exists && !editor.isDisposed()) {
|
||||
editor.dispose();
|
||||
} else if (this.environmentService.verbose) {
|
||||
console.warn(`File exists even though we received a delete event: ${resource.toString()}`);
|
||||
}
|
||||
});
|
||||
if (!exists && !editor.isDisposed()) {
|
||||
editor.dispose();
|
||||
} else if (this.environmentService.verbose) {
|
||||
console.warn(`File exists even though we received a delete event: ${resource.toString()}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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
|
||||
this.doSaveOrClearTextEditorViewState(this.input);
|
||||
|
||||
// Set input and resolve
|
||||
return super.setInput(input, options, token).then(() => {
|
||||
return input.resolve().then(resolvedModel => {
|
||||
await super.setInput(input, options, token);
|
||||
try {
|
||||
const resolvedModel = await input.resolve();
|
||||
|
||||
// Check for cancellation
|
||||
if (token.isCancellationRequested) {
|
||||
return undefined;
|
||||
}
|
||||
// Check for cancellation
|
||||
if (token.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 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
|
||||
// editor has to open this model using the binary editor. We return early in this case.
|
||||
if (resolvedModel instanceof BinaryEditorModel) {
|
||||
return this.openAsBinary(input, options);
|
||||
}
|
||||
// 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
|
||||
// editor has to open this model using the binary editor. We return early in this case.
|
||||
if (resolvedModel instanceof BinaryEditorModel) {
|
||||
return this.openAsBinary(input, options);
|
||||
}
|
||||
|
||||
const textFileModel = <ITextFileEditorModel>resolvedModel;
|
||||
const textFileModel = <ITextFileEditorModel>resolvedModel;
|
||||
|
||||
// Editor
|
||||
const textEditor = this.getControl();
|
||||
textEditor.setModel(textFileModel.textEditorModel);
|
||||
// Editor
|
||||
const textEditor = this.getControl();
|
||||
textEditor.setModel(textFileModel.textEditorModel);
|
||||
|
||||
// Always restore View State if any associated
|
||||
const editorViewState = this.loadTextEditorViewState(this.input.getResource());
|
||||
if (editorViewState) {
|
||||
textEditor.restoreViewState(editorViewState);
|
||||
}
|
||||
// Always restore View State if any associated
|
||||
const editorViewState = this.loadTextEditorViewState(this.input.getResource());
|
||||
if (editorViewState) {
|
||||
textEditor.restoreViewState(editorViewState);
|
||||
}
|
||||
|
||||
// TextOptions (avoiding instanceof here for a reason, do not change!)
|
||||
if (options && types.isFunction((<TextEditorOptions>options).apply)) {
|
||||
(<TextEditorOptions>options).apply(textEditor, ScrollType.Immediate);
|
||||
}
|
||||
// TextOptions (avoiding instanceof here for a reason, do not change!)
|
||||
if (options && types.isFunction((<TextEditorOptions>options).apply)) {
|
||||
(<TextEditorOptions>options).apply(textEditor, ScrollType.Immediate);
|
||||
}
|
||||
|
||||
// Readonly flag
|
||||
textEditor.updateOptions({ readOnly: textFileModel.isReadonly() });
|
||||
}, error => {
|
||||
// Readonly flag
|
||||
textEditor.updateOptions({ readOnly: textFileModel.isReadonly() });
|
||||
} catch (error) {
|
||||
|
||||
// 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
|
||||
// editor.
|
||||
if ((<TextFileOperationError>error).textFileOperationResult === TextFileOperationResult.FILE_IS_BINARY) {
|
||||
return this.openAsBinary(input, options);
|
||||
}
|
||||
// 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
|
||||
// editor.
|
||||
if ((<TextFileOperationError>error).textFileOperationResult === TextFileOperationResult.FILE_IS_BINARY) {
|
||||
return this.openAsBinary(input, options);
|
||||
}
|
||||
|
||||
// Similar, handle case where we were asked to open a folder in the text editor.
|
||||
if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_IS_DIRECTORY) {
|
||||
this.openAsFolder(input);
|
||||
// Similar, handle case where we were asked to open a folder in the text editor.
|
||||
if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_IS_DIRECTORY) {
|
||||
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
|
||||
if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_NOT_FOUND && isValidBasename(basename(input.getResource()))) {
|
||||
return Promise.reject(createErrorWithActions(toErrorMessage(error), {
|
||||
actions: [
|
||||
new Action('workbench.files.action.createMissingFile', nls.localize('createFile', "Create File"), undefined, true, () => {
|
||||
return this.textFileService.create(input.getResource()).then(() => this.editorService.openEditor({
|
||||
resource: input.getResource(),
|
||||
options: {
|
||||
pinned: true // new file gets pinned by default
|
||||
}
|
||||
}));
|
||||
})
|
||||
]
|
||||
}));
|
||||
}
|
||||
// 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()))) {
|
||||
throw createErrorWithActions(toErrorMessage(error), {
|
||||
actions: [
|
||||
new Action('workbench.files.action.createMissingFile', nls.localize('createFile', "Create File"), undefined, true, async () => {
|
||||
await this.textFileService.create(input.getResource());
|
||||
|
||||
if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_EXCEED_MEMORY_LIMIT) {
|
||||
const memoryLimit = Math.max(MIN_MAX_MEMORY_SIZE_MB, +this.configurationService.getValue<number>(undefined, 'files.maxMemoryForLargeFilesMB') || FALLBACK_MAX_MEMORY_SIZE_MB);
|
||||
return this.editorService.openEditor({
|
||||
resource: input.getResource(),
|
||||
options: {
|
||||
pinned: true // new file gets pinned by default
|
||||
}
|
||||
});
|
||||
})
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
return Promise.reject(createErrorWithActions(toErrorMessage(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' });
|
||||
})
|
||||
]
|
||||
}));
|
||||
}
|
||||
if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_EXCEED_MEMORY_LIMIT) {
|
||||
const memoryLimit = Math.max(MIN_MAX_MEMORY_SIZE_MB, +this.configurationService.getValue<number>(undefined, 'files.maxMemoryForLargeFilesMB') || FALLBACK_MAX_MEMORY_SIZE_MB);
|
||||
|
||||
// Otherwise make sure the error bubbles up
|
||||
return Promise.reject(error);
|
||||
});
|
||||
});
|
||||
throw createErrorWithActions(toErrorMessage(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 {
|
||||
@@ -227,21 +229,20 @@ export class TextFileEditor extends BaseTextEditor {
|
||||
this.editorService.openEditor(input, options, this.group);
|
||||
}
|
||||
|
||||
private openAsFolder(input: FileEditorInput): void {
|
||||
private async openAsFolder(input: FileEditorInput): Promise<void> {
|
||||
if (!this.group) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 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
|
||||
if (this.contextService.isInsideWorkspace(input.getResource())) {
|
||||
this.viewletService.openViewlet(VIEWLET_ID).then(() => {
|
||||
this.explorerService.select(input.getResource(), true);
|
||||
});
|
||||
}
|
||||
});
|
||||
// Best we can do is to reveal the folder in the explorer
|
||||
if (this.contextService.isInsideWorkspace(input.getResource())) {
|
||||
await this.viewletService.openViewlet(VIEWLET_ID);
|
||||
|
||||
this.explorerService.select(input.getResource(), true);
|
||||
}
|
||||
}
|
||||
|
||||
protected getAriaLabel(): string {
|
||||
|
||||
@@ -240,26 +240,26 @@ class ResolveSaveConflictAction extends Action {
|
||||
super('workbench.files.action.resolveConflict', nls.localize('compareChanges', "Compare"));
|
||||
}
|
||||
|
||||
run(): Promise<any> {
|
||||
async run(): Promise<any> {
|
||||
if (!this.model.isDisposed()) {
|
||||
const resource = this.model.getResource();
|
||||
const name = basename(resource);
|
||||
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(() => {
|
||||
if (this.storageService.getBoolean(LEARN_MORE_DIRTY_WRITE_IGNORE_KEY, StorageScope.GLOBAL)) {
|
||||
return; // return if this message is ignored
|
||||
}
|
||||
await TextFileContentProvider.open(resource, CONFLICT_RESOLUTION_SCHEME, editorLabel, this.editorService, { pinned: true });
|
||||
|
||||
// Show additional help how to resolve the save conflict
|
||||
const actions: INotificationActions = { primary: [], secondary: [] };
|
||||
actions.primary!.push(this.instantiationService.createInstance(ResolveConflictLearnMoreAction));
|
||||
actions.secondary!.push(this.instantiationService.createInstance(DoNotShowResolveConflictLearnMoreAction));
|
||||
if (this.storageService.getBoolean(LEARN_MORE_DIRTY_WRITE_IGNORE_KEY, StorageScope.GLOBAL)) {
|
||||
return; // return if this message is ignored
|
||||
}
|
||||
|
||||
const handle = this.notificationService.notify({ severity: Severity.Info, message: conflictEditorHelp, actions });
|
||||
Event.once(handle.onDidClose)(() => dispose(...actions.primary!, ...actions.secondary!));
|
||||
pendingResolveSaveConflictMessages.push(handle);
|
||||
});
|
||||
// Show additional help how to resolve the save conflict
|
||||
const actions: INotificationActions = { primary: [], secondary: [] };
|
||||
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);
|
||||
@@ -316,31 +316,28 @@ export const acceptLocalChangesCommand = (accessor: ServicesAccessor, resource:
|
||||
const editor = control.input;
|
||||
const group = control.group;
|
||||
|
||||
resolverService.createModelReference(resource).then(reference => {
|
||||
resolverService.createModelReference(resource).then(async reference => {
|
||||
const model = reference.object as IResolvedTextFileEditorModel;
|
||||
const localModelSnapshot = model.createSnapshot();
|
||||
|
||||
clearPendingResolveSaveConflictMessages(); // hide any previously shown message about how to use these actions
|
||||
|
||||
// Revert to be able to save
|
||||
return model.revert().then(() => {
|
||||
await model.revert();
|
||||
|
||||
// Restore user value (without loosing undo stack)
|
||||
modelService.updateModel(model.textEditorModel, createTextBufferFactoryFromSnapshot(localModelSnapshot));
|
||||
// Restore user value (without loosing undo stack)
|
||||
modelService.updateModel(model.textEditorModel, createTextBufferFactoryFromSnapshot(localModelSnapshot));
|
||||
|
||||
// Trigger save
|
||||
return model.save().then(() => {
|
||||
// Trigger save
|
||||
await model.save();
|
||||
|
||||
// Reopen file input
|
||||
return editorService.openEditor({ resource: model.getResource() }, group).then(() => {
|
||||
// Reopen file input
|
||||
await editorService.openEditor({ resource: model.getResource() }, group);
|
||||
|
||||
// Clean up
|
||||
group.closeEditor(editor);
|
||||
editor.dispose();
|
||||
reference.dispose();
|
||||
});
|
||||
});
|
||||
});
|
||||
// Clean up
|
||||
group.closeEditor(editor);
|
||||
editor.dispose();
|
||||
reference.dispose();
|
||||
});
|
||||
};
|
||||
|
||||
@@ -355,22 +352,20 @@ export const revertLocalChangesCommand = (accessor: ServicesAccessor, resource:
|
||||
const editor = control.input;
|
||||
const group = control.group;
|
||||
|
||||
resolverService.createModelReference(resource).then(reference => {
|
||||
resolverService.createModelReference(resource).then(async reference => {
|
||||
const model = reference.object as ITextFileEditorModel;
|
||||
|
||||
clearPendingResolveSaveConflictMessages(); // hide any previously shown message about how to use these actions
|
||||
|
||||
// Revert on model
|
||||
return model.revert().then(() => {
|
||||
await model.revert();
|
||||
|
||||
// Reopen file input
|
||||
return editorService.openEditor({ resource: model.getResource() }, group).then(() => {
|
||||
// Reopen file input
|
||||
await editorService.openEditor({ resource: model.getResource() }, group);
|
||||
|
||||
// Clean up
|
||||
group.closeEditor(editor);
|
||||
editor.dispose();
|
||||
reference.dispose();
|
||||
});
|
||||
});
|
||||
// Clean up
|
||||
group.closeEditor(editor);
|
||||
editor.dispose();
|
||||
reference.dispose();
|
||||
});
|
||||
};
|
||||
|
||||
@@ -273,16 +273,17 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
|
||||
return this.doResolveAsText();
|
||||
}
|
||||
|
||||
private doResolveAsText(): Promise<TextFileEditorModel | BinaryEditorModel> {
|
||||
private async doResolveAsText(): Promise<TextFileEditorModel | BinaryEditorModel> {
|
||||
|
||||
// Resolve as text
|
||||
return this.textFileService.models.loadOrCreate(this.resource, {
|
||||
mode: this.preferredMode,
|
||||
encoding: this.preferredEncoding,
|
||||
reload: { async: true }, // trigger a reload of the model if it exists already but do not wait to show the model
|
||||
allowBinary: this.forceOpenAsText,
|
||||
reason: LoadReason.EDITOR
|
||||
}).then(model => {
|
||||
try {
|
||||
await this.textFileService.models.loadOrCreate(this.resource, {
|
||||
mode: this.preferredMode,
|
||||
encoding: this.preferredEncoding,
|
||||
reload: { async: true }, // trigger a reload of the model if it exists already but do not wait to show the model
|
||||
allowBinary: this.forceOpenAsText,
|
||||
reason: LoadReason.EDITOR
|
||||
});
|
||||
|
||||
// This is a bit ugly, because we first resolve the model and then resolve a model reference. the reason being that binary
|
||||
// or very large files do not resolve to a text file model but should be opened as binary files without text. First calling into
|
||||
@@ -292,8 +293,10 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
|
||||
this.textModelReference = this.textModelResolverService.createModelReference(this.resource);
|
||||
}
|
||||
|
||||
return this.textModelReference.then(ref => ref.object as TextFileEditorModel);
|
||||
}, error => {
|
||||
const ref = await this.textModelReference;
|
||||
|
||||
return ref.object as TextFileEditorModel;
|
||||
} catch (error) {
|
||||
|
||||
// In case of an error that indicates that the file is binary or too large, just return with the binary editor model
|
||||
if (
|
||||
@@ -304,12 +307,12 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
|
||||
}
|
||||
|
||||
// Bubble any other error up
|
||||
return Promise.reject(error);
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
private doResolveAsBinary(): Promise<BinaryEditorModel> {
|
||||
return this.instantiationService.createInstance(BinaryEditorModel, this.resource, this.getName()).load().then(m => m as BinaryEditorModel);
|
||||
private async doResolveAsBinary(): Promise<BinaryEditorModel> {
|
||||
return this.instantiationService.createInstance(BinaryEditorModel, this.resource, this.getName()).load();
|
||||
}
|
||||
|
||||
isResolved(): boolean {
|
||||
|
||||
@@ -143,15 +143,13 @@ export class TextFileContentProvider implements ITextModelContentProvider {
|
||||
@IModelService private readonly modelService: IModelService
|
||||
) { }
|
||||
|
||||
static open(resource: URI, scheme: string, label: string, editorService: IEditorService, options?: ITextEditorOptions): Promise<void> {
|
||||
return editorService.openEditor(
|
||||
{
|
||||
leftResource: TextFileContentProvider.resourceToTextFile(scheme, resource),
|
||||
rightResource: resource,
|
||||
label,
|
||||
options
|
||||
}
|
||||
).then();
|
||||
static async open(resource: URI, scheme: string, label: string, editorService: IEditorService, options?: ITextEditorOptions): Promise<void> {
|
||||
await editorService.openEditor({
|
||||
leftResource: TextFileContentProvider.resourceToTextFile(scheme, resource),
|
||||
rightResource: resource,
|
||||
label,
|
||||
options
|
||||
});
|
||||
}
|
||||
|
||||
private static resourceToTextFile(scheme: string, resource: URI): URI {
|
||||
@@ -162,56 +160,55 @@ export class TextFileContentProvider implements ITextModelContentProvider {
|
||||
return resource.with({ scheme: JSON.parse(resource.query)['scheme'], query: null });
|
||||
}
|
||||
|
||||
provideTextContent(resource: URI): Promise<ITextModel> {
|
||||
async provideTextContent(resource: URI): Promise<ITextModel> {
|
||||
const savedFileResource = TextFileContentProvider.textFileToResource(resource);
|
||||
|
||||
// Make sure our text file is resolved up to date
|
||||
return this.resolveEditorModel(resource).then(codeEditorModel => {
|
||||
const codeEditorModel = await this.resolveEditorModel(resource);
|
||||
|
||||
// Make sure to keep contents up to date when it changes
|
||||
if (!this.fileWatcherDisposable) {
|
||||
this.fileWatcherDisposable = this.fileService.onFileChanges(changes => {
|
||||
if (changes.contains(savedFileResource, FileChangeType.UPDATED)) {
|
||||
this.resolveEditorModel(resource, false /* do not create if missing */); // update model when resource changes
|
||||
}
|
||||
});
|
||||
|
||||
if (codeEditorModel) {
|
||||
once(codeEditorModel.onWillDispose)(() => {
|
||||
dispose(this.fileWatcherDisposable);
|
||||
this.fileWatcherDisposable = undefined;
|
||||
});
|
||||
// Make sure to keep contents up to date when it changes
|
||||
if (!this.fileWatcherDisposable) {
|
||||
this.fileWatcherDisposable = this.fileService.onFileChanges(changes => {
|
||||
if (changes.contains(savedFileResource, FileChangeType.UPDATED)) {
|
||||
this.resolveEditorModel(resource, false /* do not create if missing */); // update model when resource changes
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return codeEditorModel;
|
||||
});
|
||||
if (codeEditorModel) {
|
||||
once(codeEditorModel.onWillDispose)(() => {
|
||||
dispose(this.fileWatcherDisposable);
|
||||
this.fileWatcherDisposable = undefined;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return codeEditorModel;
|
||||
}
|
||||
|
||||
private resolveEditorModel(resource: URI, createAsNeeded?: true): Promise<ITextModel>;
|
||||
private resolveEditorModel(resource: URI, createAsNeeded?: boolean): Promise<ITextModel | null>;
|
||||
private resolveEditorModel(resource: URI, createAsNeeded: boolean = true): Promise<ITextModel | null> {
|
||||
private async resolveEditorModel(resource: URI, createAsNeeded: boolean = true): Promise<ITextModel | null> {
|
||||
const savedFileResource = TextFileContentProvider.textFileToResource(resource);
|
||||
|
||||
return this.textFileService.readStream(savedFileResource).then(content => {
|
||||
let codeEditorModel = this.modelService.getModel(resource);
|
||||
if (codeEditorModel) {
|
||||
this.modelService.updateModel(codeEditorModel, content.value);
|
||||
} else if (createAsNeeded) {
|
||||
const textFileModel = this.modelService.getModel(savedFileResource);
|
||||
const content = await this.textFileService.readStream(savedFileResource);
|
||||
|
||||
let languageSelector: ILanguageSelection;
|
||||
if (textFileModel) {
|
||||
languageSelector = this.modeService.create(textFileModel.getModeId());
|
||||
} else {
|
||||
languageSelector = this.modeService.createByFilepathOrFirstLine(savedFileResource.path);
|
||||
}
|
||||
let codeEditorModel = this.modelService.getModel(resource);
|
||||
if (codeEditorModel) {
|
||||
this.modelService.updateModel(codeEditorModel, content.value);
|
||||
} else if (createAsNeeded) {
|
||||
const textFileModel = this.modelService.getModel(savedFileResource);
|
||||
|
||||
codeEditorModel = this.modelService.createModel(content.value, languageSelector, resource);
|
||||
let languageSelector: ILanguageSelection;
|
||||
if (textFileModel) {
|
||||
languageSelector = this.modeService.create(textFileModel.getModeId());
|
||||
} else {
|
||||
languageSelector = this.modeService.createByFilepathOrFirstLine(savedFileResource.path);
|
||||
}
|
||||
|
||||
return codeEditorModel;
|
||||
});
|
||||
codeEditorModel = this.modelService.createModel(content.value, languageSelector, resource);
|
||||
}
|
||||
|
||||
return codeEditorModel;
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
|
||||
@@ -34,26 +34,25 @@ suite('Files - FileEditorTracker', () => {
|
||||
accessor = instantiationService.createInstance(ServiceAccessor);
|
||||
});
|
||||
|
||||
test('file change event updates model', function () {
|
||||
test('file change event updates model', async function () {
|
||||
const tracker = instantiationService.createInstance(FileEditorTracker);
|
||||
|
||||
const resource = toResource.call(this, '/path/index.txt');
|
||||
|
||||
return accessor.textFileService.models.loadOrCreate(resource).then((model: IResolvedTextFileEditorModel) => {
|
||||
model.textEditorModel.setValue('Super Good');
|
||||
assert.equal(snapshotToString(model.createSnapshot()!), 'Super Good');
|
||||
const model = await accessor.textFileService.models.loadOrCreate(resource) as IResolvedTextFileEditorModel;
|
||||
|
||||
return model.save().then(() => {
|
||||
model.textEditorModel.setValue('Super Good');
|
||||
assert.equal(snapshotToString(model.createSnapshot()!), 'Super Good');
|
||||
|
||||
// change event (watcher)
|
||||
accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource, type: FileChangeType.UPDATED }]));
|
||||
await model.save();
|
||||
|
||||
return timeout(0).then(() => { // due to event updating model async
|
||||
assert.equal(snapshotToString(model.createSnapshot()!), 'Hello Html');
|
||||
// change event (watcher)
|
||||
accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource, type: FileChangeType.UPDATED }]));
|
||||
|
||||
tracker.dispose();
|
||||
});
|
||||
});
|
||||
});
|
||||
await timeout(0); // due to event updating model async
|
||||
|
||||
assert.equal(snapshotToString(model.createSnapshot()!), 'Hello Html');
|
||||
|
||||
tracker.dispose();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -390,7 +390,7 @@ export class GotoSymbolHandler extends QuickOpenHandler {
|
||||
this.rangeHighlightDecorationId = undefined;
|
||||
}
|
||||
|
||||
getResults(searchValue: string, token: CancellationToken): Promise<QuickOpenModel | null> {
|
||||
async getResults(searchValue: string, token: CancellationToken): Promise<QuickOpenModel | null> {
|
||||
searchValue = searchValue.trim();
|
||||
|
||||
// Support to cancel pending outline requests
|
||||
@@ -407,20 +407,19 @@ export class GotoSymbolHandler extends QuickOpenHandler {
|
||||
}
|
||||
|
||||
// Resolve Outline Model
|
||||
return this.getOutline().then(outline => {
|
||||
if (!outline) {
|
||||
return outline;
|
||||
}
|
||||
|
||||
if (token.isCancellationRequested) {
|
||||
return outline;
|
||||
}
|
||||
|
||||
// Filter by search
|
||||
outline.applyFilter(searchValue);
|
||||
|
||||
const outline = await this.getOutline();
|
||||
if (!outline) {
|
||||
return outline;
|
||||
});
|
||||
}
|
||||
|
||||
if (token.isCancellationRequested) {
|
||||
return outline;
|
||||
}
|
||||
|
||||
// Filter by search
|
||||
outline.applyFilter(searchValue);
|
||||
|
||||
return outline;
|
||||
}
|
||||
|
||||
getEmptyLabel(searchString: string): string {
|
||||
|
||||
@@ -147,43 +147,45 @@ export class OpenFileHandler extends QuickOpenHandler {
|
||||
return this.doFindResults(query, token, this.cacheState.cacheKey, maxSortedResults);
|
||||
}
|
||||
|
||||
private doFindResults(query: IPreparedQuery, token: CancellationToken, cacheKey?: string, maxSortedResults?: number): Promise<FileQuickOpenModel> {
|
||||
private async doFindResults(query: IPreparedQuery, token: CancellationToken, cacheKey?: string, maxSortedResults?: number): Promise<FileQuickOpenModel> {
|
||||
const queryOptions = this.doResolveQueryOptions(query, cacheKey, maxSortedResults);
|
||||
|
||||
let iconClass: string;
|
||||
let iconClass: string | undefined = undefined;
|
||||
if (this.options && this.options.forceUseIcons && !this.themeService.getFileIconTheme()) {
|
||||
iconClass = 'file'; // only use a generic file icon if we are forced to use an icon and have no icon theme set otherwise
|
||||
}
|
||||
|
||||
return this.getAbsolutePathResult(query).then(result => {
|
||||
if (token.isCancellationRequested) {
|
||||
return Promise.resolve(<ISearchComplete>{ results: [] });
|
||||
let complete: ISearchComplete | undefined = undefined;
|
||||
|
||||
const result = await this.getAbsolutePathResult(query);
|
||||
if (token.isCancellationRequested) {
|
||||
complete = <ISearchComplete>{ results: [] };
|
||||
}
|
||||
|
||||
// If the original search value is an existing file on disk, return it immediately and bypass the search service
|
||||
else if (result) {
|
||||
complete = <ISearchComplete>{ results: [{ resource: result }] };
|
||||
}
|
||||
|
||||
else {
|
||||
complete = await this.searchService.fileSearch(this.queryBuilder.file(this.contextService.getWorkspace().folders.map(folder => folder.uri), queryOptions), token);
|
||||
}
|
||||
|
||||
const results: QuickOpenEntry[] = [];
|
||||
|
||||
if (!token.isCancellationRequested) {
|
||||
for (const fileMatch of complete.results) {
|
||||
const label = basename(fileMatch.resource);
|
||||
const description = this.labelService.getUriLabel(dirname(fileMatch.resource), { relative: true });
|
||||
|
||||
results.push(this.instantiationService.createInstance(FileEntry, fileMatch.resource, label, description, iconClass));
|
||||
}
|
||||
}
|
||||
|
||||
// If the original search value is an existing file on disk, return it immediately and bypass the search service
|
||||
if (result) {
|
||||
return Promise.resolve(<ISearchComplete>{ results: [{ resource: result }] });
|
||||
}
|
||||
|
||||
return this.searchService.fileSearch(this.queryBuilder.file(this.contextService.getWorkspace().folders.map(folder => folder.uri), queryOptions), token);
|
||||
}).then(complete => {
|
||||
const results: QuickOpenEntry[] = [];
|
||||
|
||||
if (!token.isCancellationRequested) {
|
||||
for (const fileMatch of complete.results) {
|
||||
|
||||
const label = basename(fileMatch.resource);
|
||||
const description = this.labelService.getUriLabel(dirname(fileMatch.resource), { relative: true });
|
||||
|
||||
results.push(this.instantiationService.createInstance(FileEntry, fileMatch.resource, label, description, iconClass));
|
||||
}
|
||||
}
|
||||
|
||||
return new FileQuickOpenModel(results, <IFileSearchStats>complete.stats);
|
||||
});
|
||||
return new FileQuickOpenModel(results, <IFileSearchStats>complete.stats);
|
||||
}
|
||||
|
||||
private getAbsolutePathResult(query: IPreparedQuery): Promise<URI | undefined> {
|
||||
private async getAbsolutePathResult(query: IPreparedQuery): Promise<URI | undefined> {
|
||||
const detildifiedQuery = untildify(query.original, this.environmentService.userHome);
|
||||
if (isAbsolute(detildifiedQuery)) {
|
||||
const workspaceFolders = this.contextService.getWorkspace().folders;
|
||||
@@ -191,12 +193,16 @@ export class OpenFileHandler extends QuickOpenHandler {
|
||||
workspaceFolders[0].uri.with({ path: detildifiedQuery }) :
|
||||
URI.file(detildifiedQuery);
|
||||
|
||||
return this.fileService.resolve(resource).then(
|
||||
stat => stat.isDirectory ? undefined : resource,
|
||||
error => undefined);
|
||||
try {
|
||||
const stat = await this.fileService.resolve(resource);
|
||||
|
||||
return stat.isDirectory ? undefined : resource;
|
||||
} catch (error) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.resolve(undefined);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private doResolveQueryOptions(query: IPreparedQuery, cacheKey?: string, maxSortedResults?: number): IFileQueryBuilderOptions {
|
||||
|
||||
@@ -53,6 +53,7 @@ const ModulesToLookFor = [
|
||||
// JS frameworks
|
||||
'react',
|
||||
'react-native',
|
||||
'rnpm-plugin-windows',
|
||||
'@angular/core',
|
||||
'@ionic',
|
||||
'vue',
|
||||
@@ -268,6 +269,7 @@ export class WorkspaceStats implements IWorkbenchContribution {
|
||||
"workspace.npm.hapi" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
|
||||
"workspace.npm.socket.io" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
|
||||
"workspace.npm.restify" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
|
||||
"workspace.npm.rnpm-plugin-windows" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
|
||||
"workspace.npm.react" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
|
||||
"workspace.npm.@angular/core" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
|
||||
"workspace.npm.vue" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
|
||||
@@ -288,6 +290,7 @@ export class WorkspaceStats implements IWorkbenchContribution {
|
||||
"workspace.reactNative" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
|
||||
"workspace.ionic" : { "classification" : "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": "true" },
|
||||
"workspace.nativeScript" : { "classification" : "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": "true" },
|
||||
"workspace.java.pom" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
|
||||
"workspace.py.requirements" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
|
||||
"workspace.py.requirements.star" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
|
||||
"workspace.py.Pipfile" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
|
||||
@@ -387,6 +390,8 @@ export class WorkspaceStats implements IWorkbenchContribution {
|
||||
tags['workspace.npm'] = nameSet.has('package.json') || nameSet.has('node_modules');
|
||||
tags['workspace.bower'] = nameSet.has('bower.json') || nameSet.has('bower_components');
|
||||
|
||||
tags['workspace.java.pom'] = nameSet.has('pom.xml');
|
||||
|
||||
tags['workspace.yeoman.code.ext'] = nameSet.has('vsc-extension-quickstart.md');
|
||||
|
||||
tags['workspace.py.requirements'] = nameSet.has('requirements.txt');
|
||||
@@ -502,23 +507,24 @@ export class WorkspaceStats implements IWorkbenchContribution {
|
||||
const packageJsonPromises = getFilePromises('package.json', this.fileService, this.textFileService, content => {
|
||||
try {
|
||||
const packageJsonContents = JSON.parse(content.value);
|
||||
if (packageJsonContents['dependencies']) {
|
||||
for (let module of ModulesToLookFor) {
|
||||
if ('react-native' === module) {
|
||||
if (packageJsonContents['dependencies'][module]) {
|
||||
tags['workspace.reactNative'] = true;
|
||||
}
|
||||
} else if ('tns-core-modules' === module) {
|
||||
if (packageJsonContents['dependencies'][module]) {
|
||||
tags['workspace.nativescript'] = true;
|
||||
}
|
||||
} else {
|
||||
if (packageJsonContents['dependencies'][module]) {
|
||||
tags['workspace.npm.' + module] = true;
|
||||
}
|
||||
let dependencies = packageJsonContents['dependencies'];
|
||||
let devDependencies = packageJsonContents['devDependencies'];
|
||||
for (let module of ModulesToLookFor) {
|
||||
if ('react-native' === module) {
|
||||
if ((dependencies && dependencies[module]) || (devDependencies && devDependencies[module])) {
|
||||
tags['workspace.reactNative'] = true;
|
||||
}
|
||||
} else if ('tns-core-modules' === module) {
|
||||
if ((dependencies && dependencies[module]) || (devDependencies && devDependencies[module])) {
|
||||
tags['workspace.nativescript'] = true;
|
||||
}
|
||||
} else {
|
||||
if ((dependencies && dependencies[module]) || (devDependencies && devDependencies[module])) {
|
||||
tags['workspace.npm.' + module] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (e) {
|
||||
// Ignore errors when resolving file or parsing file contents
|
||||
|
||||
@@ -165,8 +165,7 @@ class WebviewPortMappingProvider extends Disposable {
|
||||
|
||||
session.onBeforeRequest(async (details) => {
|
||||
const uri = URI.parse(details.url);
|
||||
const allowedSchemes = ['http', 'https', 'ws', 'wss'];
|
||||
if (allowedSchemes.indexOf(uri.scheme) === -1) {
|
||||
if (uri.scheme !== 'http' && uri.scheme !== 'https') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -113,11 +113,10 @@ export class OpenNewsletterSignupUrlAction extends Action {
|
||||
this.telemetryService = telemetryService;
|
||||
}
|
||||
|
||||
run(): Promise<void> {
|
||||
this.telemetryService.getTelemetryInfo().then(info => {
|
||||
window.open(`${OpenNewsletterSignupUrlAction.URL}?machineId=${encodeURIComponent(info.machineId)}`);
|
||||
});
|
||||
return Promise.resolve();
|
||||
async run(): Promise<void> {
|
||||
const info = await this.telemetryService.getTelemetryInfo();
|
||||
|
||||
window.open(`${OpenNewsletterSignupUrlAction.URL}?machineId=${encodeURIComponent(info.machineId)}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ export abstract class BaseZoomAction extends Action {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
protected setConfiguredZoomLevel(level: number): void {
|
||||
protected async setConfiguredZoomLevel(level: number): Promise<void> {
|
||||
level = Math.round(level); // when reaching smallest zoom, prevent fractional zoom levels
|
||||
|
||||
const applyZoom = () => {
|
||||
@@ -98,7 +98,9 @@ export abstract class BaseZoomAction extends Action {
|
||||
browser.setZoomLevel(webFrame.getZoomLevel(), /*isTrusted*/false);
|
||||
};
|
||||
|
||||
this.configurationService.updateValue(BaseZoomAction.SETTING_KEY, level).then(() => applyZoom());
|
||||
await this.configurationService.updateValue(BaseZoomAction.SETTING_KEY, level);
|
||||
|
||||
applyZoom();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,8 +177,10 @@ export class ReloadWindowAction extends Action {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
run(): Promise<boolean> {
|
||||
return this.windowService.reloadWindow().then(() => true);
|
||||
async run(): Promise<boolean> {
|
||||
await this.windowService.reloadWindow();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,8 +197,10 @@ export class ReloadWindowWithExtensionsDisabledAction extends Action {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
run(): Promise<boolean> {
|
||||
return this.windowService.reloadWindow({ _: [], 'disable-extensions': true }).then(() => true);
|
||||
async run(): Promise<boolean> {
|
||||
await this.windowService.reloadWindow({ _: [], 'disable-extensions': true });
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,41 +227,38 @@ export abstract class BaseSwitchWindow extends Action {
|
||||
|
||||
protected abstract isQuickNavigate(): boolean;
|
||||
|
||||
run(): Promise<void> {
|
||||
async run(): Promise<void> {
|
||||
const currentWindowId = this.windowService.windowId;
|
||||
|
||||
return this.windowsService.getWindows().then(windows => {
|
||||
const placeHolder = nls.localize('switchWindowPlaceHolder', "Select a window to switch to");
|
||||
const picks = windows.map(win => {
|
||||
const resource = win.filename ? URI.file(win.filename) : win.folderUri ? win.folderUri : win.workspace ? win.workspace.configPath : undefined;
|
||||
const fileKind = win.filename ? FileKind.FILE : win.workspace ? FileKind.ROOT_FOLDER : win.folderUri ? FileKind.FOLDER : FileKind.FILE;
|
||||
return {
|
||||
payload: win.id,
|
||||
label: win.title,
|
||||
iconClasses: getIconClasses(this.modelService, this.modeService, resource, fileKind),
|
||||
description: (currentWindowId === win.id) ? nls.localize('current', "Current Window") : undefined,
|
||||
buttons: (!this.isQuickNavigate() && currentWindowId !== win.id) ? [this.closeWindowAction] : undefined
|
||||
};
|
||||
});
|
||||
const windows = await this.windowsService.getWindows();
|
||||
const placeHolder = nls.localize('switchWindowPlaceHolder', "Select a window to switch to");
|
||||
const picks = windows.map(win => {
|
||||
const resource = win.filename ? URI.file(win.filename) : win.folderUri ? win.folderUri : win.workspace ? win.workspace.configPath : undefined;
|
||||
const fileKind = win.filename ? FileKind.FILE : win.workspace ? FileKind.ROOT_FOLDER : win.folderUri ? FileKind.FOLDER : FileKind.FILE;
|
||||
return {
|
||||
payload: win.id,
|
||||
label: win.title,
|
||||
iconClasses: getIconClasses(this.modelService, this.modeService, resource, fileKind),
|
||||
description: (currentWindowId === win.id) ? nls.localize('current', "Current Window") : undefined,
|
||||
buttons: (!this.isQuickNavigate() && currentWindowId !== win.id) ? [this.closeWindowAction] : undefined
|
||||
};
|
||||
});
|
||||
const autoFocusIndex = (picks.indexOf(picks.filter(pick => pick.payload === currentWindowId)[0]) + 1) % picks.length;
|
||||
|
||||
const autoFocusIndex = (picks.indexOf(picks.filter(pick => pick.payload === currentWindowId)[0]) + 1) % picks.length;
|
||||
|
||||
return this.quickInputService.pick(picks, {
|
||||
contextKey: 'inWindowsPicker',
|
||||
activeItem: picks[autoFocusIndex],
|
||||
placeHolder,
|
||||
quickNavigate: this.isQuickNavigate() ? { keybindings: this.keybindingService.lookupKeybindings(this.id) } : undefined,
|
||||
onDidTriggerItemButton: context => {
|
||||
this.windowsService.closeWindow(context.item.payload).then(() => {
|
||||
context.removeItem();
|
||||
});
|
||||
}
|
||||
});
|
||||
}).then(pick => {
|
||||
if (pick) {
|
||||
this.windowsService.focusWindow(pick.payload);
|
||||
const pick = await this.quickInputService.pick(picks, {
|
||||
contextKey: 'inWindowsPicker',
|
||||
activeItem: picks[autoFocusIndex],
|
||||
placeHolder,
|
||||
quickNavigate: this.isQuickNavigate() ? { keybindings: this.keybindingService.lookupKeybindings(this.id) } : undefined,
|
||||
onDidTriggerItemButton: async context => {
|
||||
await this.windowsService.closeWindow(context.item.payload);
|
||||
context.removeItem();
|
||||
}
|
||||
});
|
||||
|
||||
if (pick) {
|
||||
this.windowsService.focusWindow(pick.payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,12 +334,13 @@ export abstract class BaseOpenRecentAction extends Action {
|
||||
|
||||
protected abstract isQuickNavigate(): boolean;
|
||||
|
||||
run(): Promise<void> {
|
||||
return this.windowService.getRecentlyOpened()
|
||||
.then(({ workspaces, files }) => this.openRecent(workspaces, files));
|
||||
async run(): Promise<void> {
|
||||
const { workspaces, files } = await this.windowService.getRecentlyOpened();
|
||||
|
||||
this.openRecent(workspaces, files);
|
||||
}
|
||||
|
||||
private openRecent(recentWorkspaces: Array<IRecentWorkspace | IRecentFolder>, recentFiles: IRecentFile[]): void {
|
||||
private async openRecent(recentWorkspaces: Array<IRecentWorkspace | IRecentFolder>, recentFiles: IRecentFile[]): Promise<void> {
|
||||
|
||||
const toPick = (recent: IRecent, labelService: ILabelService, buttons: IQuickInputButton[] | undefined) => {
|
||||
let uriToOpen: IURIToOpen | undefined;
|
||||
@@ -376,26 +380,26 @@ export abstract class BaseOpenRecentAction extends Action {
|
||||
const firstEntry = recentWorkspaces[0];
|
||||
let autoFocusSecondEntry: boolean = firstEntry && this.contextService.isCurrentWorkspace(isRecentWorkspace(firstEntry) ? firstEntry.workspace : firstEntry.folderUri);
|
||||
|
||||
let keyMods: IKeyMods;
|
||||
let keyMods: IKeyMods | undefined;
|
||||
const workspaceSeparator: IQuickPickSeparator = { type: 'separator', label: nls.localize('workspaces', "workspaces") };
|
||||
const fileSeparator: IQuickPickSeparator = { type: 'separator', label: nls.localize('files', "files") };
|
||||
const picks = [workspaceSeparator, ...workspacePicks, fileSeparator, ...filePicks];
|
||||
this.quickInputService.pick(picks, {
|
||||
const pick = await this.quickInputService.pick(picks, {
|
||||
contextKey: inRecentFilesPickerContextKey,
|
||||
activeItem: [...workspacePicks, ...filePicks][autoFocusSecondEntry ? 1 : 0],
|
||||
placeHolder: isMacintosh ? nls.localize('openRecentPlaceHolderMac', "Select to open (hold Cmd-key to open in new window)") : nls.localize('openRecentPlaceHolder', "Select to open (hold Ctrl-key to open in new window)"),
|
||||
matchOnDescription: true,
|
||||
onKeyMods: mods => keyMods = mods,
|
||||
quickNavigate: this.isQuickNavigate() ? { keybindings: this.keybindingService.lookupKeybindings(this.id) } : undefined,
|
||||
onDidTriggerItemButton: context => {
|
||||
this.windowsService.removeFromRecentlyOpened([context.item.resource]).then(() => context.removeItem());
|
||||
}
|
||||
}).then((pick): Promise<void> | void => {
|
||||
if (pick) {
|
||||
const forceNewWindow = keyMods.ctrlCmd;
|
||||
return this.windowService.openWindow([pick.uriToOpen], { forceNewWindow });
|
||||
onDidTriggerItemButton: async context => {
|
||||
await this.windowsService.removeFromRecentlyOpened([context.item.resource]);
|
||||
context.removeItem();
|
||||
}
|
||||
});
|
||||
|
||||
if (pick) {
|
||||
return this.windowService.openWindow([pick.uriToOpen], { forceNewWindow: keyMods && keyMods.ctrlCmd });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,42 +106,39 @@ class CodeRendererMain extends Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
open(): Promise<void> {
|
||||
return this.initServices().then(services => {
|
||||
async open(): Promise<void> {
|
||||
const services = await this.initServices();
|
||||
await domContentLoaded();
|
||||
mark('willStartWorkbench');
|
||||
|
||||
return domContentLoaded().then(() => {
|
||||
mark('willStartWorkbench');
|
||||
// Create Workbench
|
||||
this.workbench = new Workbench(document.body, services.serviceCollection, services.logService);
|
||||
|
||||
// Create Workbench
|
||||
this.workbench = new Workbench(document.body, services.serviceCollection, services.logService);
|
||||
// Layout
|
||||
this._register(addDisposableListener(window, EventType.RESIZE, e => this.onWindowResize(e, true)));
|
||||
|
||||
// Layout
|
||||
this._register(addDisposableListener(window, EventType.RESIZE, e => this.onWindowResize(e, true)));
|
||||
// Workbench Lifecycle
|
||||
this._register(this.workbench.onShutdown(() => this.dispose()));
|
||||
this._register(this.workbench.onWillShutdown(event => event.join(services.storageService.close())));
|
||||
|
||||
// Workbench Lifecycle
|
||||
this._register(this.workbench.onShutdown(() => this.dispose()));
|
||||
this._register(this.workbench.onWillShutdown(event => event.join(services.storageService.close())));
|
||||
// Startup
|
||||
const instantiationService = this.workbench.startup();
|
||||
|
||||
// Startup
|
||||
const instantiationService = this.workbench.startup();
|
||||
// Window
|
||||
this._register(instantiationService.createInstance(ElectronWindow));
|
||||
|
||||
// Window
|
||||
this._register(instantiationService.createInstance(ElectronWindow));
|
||||
// Driver
|
||||
if (this.configuration.driver) {
|
||||
instantiationService.invokeFunction(async accessor => this._register(await registerWindowDriver(accessor)));
|
||||
}
|
||||
|
||||
// Driver
|
||||
if (this.configuration.driver) {
|
||||
instantiationService.invokeFunction(accessor => registerWindowDriver(accessor).then(disposable => this._register(disposable)));
|
||||
}
|
||||
// Config Exporter
|
||||
if (this.configuration['export-default-configuration']) {
|
||||
instantiationService.createInstance(DefaultConfigurationExportHelper);
|
||||
}
|
||||
|
||||
// Config Exporter
|
||||
if (this.configuration['export-default-configuration']) {
|
||||
instantiationService.createInstance(DefaultConfigurationExportHelper);
|
||||
}
|
||||
|
||||
// Logging
|
||||
services.logService.trace('workbench configuration', JSON.stringify(this.configuration));
|
||||
});
|
||||
});
|
||||
// Logging
|
||||
services.logService.trace('workbench configuration', JSON.stringify(this.configuration));
|
||||
}
|
||||
|
||||
private onWindowResize(e: Event, retry: boolean): void {
|
||||
@@ -162,7 +159,7 @@ class CodeRendererMain extends Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
private initServices(): Promise<{ serviceCollection: ServiceCollection, logService: ILogService, storageService: StorageService }> {
|
||||
private async initServices(): Promise<{ serviceCollection: ServiceCollection, logService: ILogService, storageService: StorageService }> {
|
||||
const serviceCollection = new ServiceCollection();
|
||||
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
@@ -203,7 +200,9 @@ class CodeRendererMain extends Disposable {
|
||||
fileService.registerProvider(Schemas.vscodeRemote, remoteFileSystemProvider);
|
||||
}
|
||||
|
||||
return this.resolveWorkspaceInitializationPayload(environmentService).then(payload => Promise.all([
|
||||
const payload = await this.resolveWorkspaceInitializationPayload(environmentService);
|
||||
|
||||
const services = await Promise.all([
|
||||
this.createWorkspaceService(payload, environmentService, fileService, remoteAgentService, logService).then(service => {
|
||||
|
||||
// Workspace
|
||||
@@ -222,10 +221,12 @@ class CodeRendererMain extends Disposable {
|
||||
|
||||
return service;
|
||||
})
|
||||
]).then(services => ({ serviceCollection, logService, storageService: services[1] })));
|
||||
]);
|
||||
|
||||
return { serviceCollection, logService, storageService: services[1] };
|
||||
}
|
||||
|
||||
private resolveWorkspaceInitializationPayload(environmentService: IWorkbenchEnvironmentService): Promise<IWorkspaceInitializationPayload> {
|
||||
private async resolveWorkspaceInitializationPayload(environmentService: IWorkbenchEnvironmentService): Promise<IWorkspaceInitializationPayload> {
|
||||
|
||||
// Multi-root workspace
|
||||
if (this.configuration.workspace) {
|
||||
@@ -233,32 +234,29 @@ class CodeRendererMain extends Disposable {
|
||||
}
|
||||
|
||||
// Single-folder workspace
|
||||
let workspaceInitializationPayload: Promise<IWorkspaceInitializationPayload | undefined> = Promise.resolve(undefined);
|
||||
let workspaceInitializationPayload: IWorkspaceInitializationPayload | undefined;
|
||||
if (this.configuration.folderUri) {
|
||||
workspaceInitializationPayload = this.resolveSingleFolderWorkspaceInitializationPayload(this.configuration.folderUri);
|
||||
workspaceInitializationPayload = await this.resolveSingleFolderWorkspaceInitializationPayload(this.configuration.folderUri);
|
||||
}
|
||||
|
||||
return workspaceInitializationPayload.then(payload => {
|
||||
|
||||
// Fallback to empty workspace if we have no payload yet.
|
||||
if (!payload) {
|
||||
let id: string;
|
||||
if (this.configuration.backupPath) {
|
||||
id = basename(this.configuration.backupPath); // we know the backupPath must be a unique path so we leverage its name as workspace ID
|
||||
} else if (environmentService.isExtensionDevelopment) {
|
||||
id = 'ext-dev'; // extension development window never stores backups and is a singleton
|
||||
} else {
|
||||
return Promise.reject(new Error('Unexpected window configuration without backupPath'));
|
||||
}
|
||||
|
||||
payload = { id };
|
||||
// Fallback to empty workspace if we have no payload yet.
|
||||
if (!workspaceInitializationPayload) {
|
||||
let id: string;
|
||||
if (this.configuration.backupPath) {
|
||||
id = basename(this.configuration.backupPath); // we know the backupPath must be a unique path so we leverage its name as workspace ID
|
||||
} else if (environmentService.isExtensionDevelopment) {
|
||||
id = 'ext-dev'; // extension development window never stores backups and is a singleton
|
||||
} else {
|
||||
throw new Error('Unexpected window configuration without backupPath');
|
||||
}
|
||||
|
||||
return payload;
|
||||
});
|
||||
workspaceInitializationPayload = { id };
|
||||
}
|
||||
|
||||
return workspaceInitializationPayload;
|
||||
}
|
||||
|
||||
private resolveSingleFolderWorkspaceInitializationPayload(folderUri: ISingleFolderWorkspaceIdentifier): Promise<ISingleFolderWorkspaceInitializationPayload | undefined> {
|
||||
private async resolveSingleFolderWorkspaceInitializationPayload(folderUri: ISingleFolderWorkspaceIdentifier): Promise<ISingleFolderWorkspaceInitializationPayload | undefined> {
|
||||
|
||||
// Return early the folder is not local
|
||||
if (folderUri.scheme !== Schemas.file) {
|
||||
@@ -285,40 +283,54 @@ class CodeRendererMain extends Disposable {
|
||||
}
|
||||
|
||||
// For local: ensure path is absolute and exists
|
||||
const sanitizedFolderPath = sanitizeFilePath(folderUri.fsPath, process.env['VSCODE_CWD'] || process.cwd());
|
||||
return stat(sanitizedFolderPath).then(stat => {
|
||||
try {
|
||||
const sanitizedFolderPath = sanitizeFilePath(folderUri.fsPath, process.env['VSCODE_CWD'] || process.cwd());
|
||||
const fileStat = await stat(sanitizedFolderPath);
|
||||
|
||||
const sanitizedFolderUri = URI.file(sanitizedFolderPath);
|
||||
return {
|
||||
id: computeLocalDiskFolderId(sanitizedFolderUri, stat),
|
||||
id: computeLocalDiskFolderId(sanitizedFolderUri, fileStat),
|
||||
folder: sanitizedFolderUri
|
||||
};
|
||||
}, error => onUnexpectedError(error));
|
||||
} catch (error) {
|
||||
onUnexpectedError(error);
|
||||
}
|
||||
|
||||
return undefined; // {{SQL CARBON EDIT}} @anthonydresser strict-null-check
|
||||
}
|
||||
|
||||
private createWorkspaceService(payload: IWorkspaceInitializationPayload, environmentService: IWorkbenchEnvironmentService, fileService: FileService, remoteAgentService: IRemoteAgentService, logService: ILogService): Promise<WorkspaceService> {
|
||||
private async createWorkspaceService(payload: IWorkspaceInitializationPayload, environmentService: IWorkbenchEnvironmentService, fileService: FileService, remoteAgentService: IRemoteAgentService, logService: ILogService): Promise<WorkspaceService> {
|
||||
const configurationFileService = new ConfigurationFileService();
|
||||
configurationFileService.fileService = fileService;
|
||||
|
||||
const workspaceService = new WorkspaceService({ userSettingsResource: URI.file(environmentService.appSettingsPath), remoteAuthority: this.configuration.remoteAuthority, configurationCache: new ConfigurationCache(environmentService) }, configurationFileService, remoteAgentService);
|
||||
|
||||
return workspaceService.initialize(payload).then(() => workspaceService, error => {
|
||||
try {
|
||||
await workspaceService.initialize(payload);
|
||||
|
||||
return workspaceService;
|
||||
} catch (error) {
|
||||
onUnexpectedError(error);
|
||||
logService.error(error);
|
||||
|
||||
return workspaceService;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private createStorageService(payload: IWorkspaceInitializationPayload, environmentService: IWorkbenchEnvironmentService, logService: ILogService, mainProcessService: IMainProcessService): Promise<StorageService> {
|
||||
private async createStorageService(payload: IWorkspaceInitializationPayload, environmentService: IWorkbenchEnvironmentService, logService: ILogService, mainProcessService: IMainProcessService): Promise<StorageService> {
|
||||
const globalStorageDatabase = new GlobalStorageDatabaseChannelClient(mainProcessService.getChannel('storage'));
|
||||
const storageService = new StorageService(globalStorageDatabase, logService, environmentService);
|
||||
|
||||
return storageService.initialize(payload).then(() => storageService, error => {
|
||||
try {
|
||||
await storageService.initialize(payload);
|
||||
|
||||
return storageService;
|
||||
} catch (error) {
|
||||
onUnexpectedError(error);
|
||||
logService.error(error);
|
||||
|
||||
return storageService;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private createLogService(mainProcessService: IMainProcessService, environmentService: IWorkbenchEnvironmentService): ILogService {
|
||||
|
||||
@@ -117,7 +117,7 @@ export class ElectronWindow extends Disposable {
|
||||
});
|
||||
|
||||
// Support runAction event
|
||||
ipc.on('vscode:runAction', (event: Event, request: IRunActionInWindowRequest) => {
|
||||
ipc.on('vscode:runAction', async (event: Event, request: IRunActionInWindowRequest) => {
|
||||
const args: unknown[] = request.args || [];
|
||||
|
||||
// If we run an action from the touchbar, we fill in the currently active resource
|
||||
@@ -134,7 +134,9 @@ export class ElectronWindow extends Disposable {
|
||||
args.push({ from: request.from }); // TODO@telemetry this is a bit weird to send this to every action?
|
||||
}
|
||||
|
||||
this.commandService.executeCommand(request.id, ...args).then(_ => {
|
||||
try {
|
||||
await this.commandService.executeCommand(request.id, ...args);
|
||||
|
||||
/* __GDPR__
|
||||
"commandExecuted" : {
|
||||
"id" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
|
||||
@@ -142,9 +144,9 @@ export class ElectronWindow extends Disposable {
|
||||
}
|
||||
*/
|
||||
this.telemetryService.publicLog('commandExecuted', { id: request.id, from: request.from });
|
||||
}, err => {
|
||||
this.notificationService.error(err);
|
||||
});
|
||||
} catch (error) {
|
||||
this.notificationService.error(error);
|
||||
}
|
||||
});
|
||||
|
||||
// Support runKeybinding event
|
||||
@@ -173,34 +175,30 @@ export class ElectronWindow extends Disposable {
|
||||
});
|
||||
|
||||
// Fullscreen Events
|
||||
ipc.on('vscode:enterFullScreen', () => {
|
||||
this.lifecycleService.when(LifecyclePhase.Ready).then(() => {
|
||||
browser.setFullscreen(true);
|
||||
});
|
||||
ipc.on('vscode:enterFullScreen', async () => {
|
||||
await this.lifecycleService.when(LifecyclePhase.Ready);
|
||||
browser.setFullscreen(true);
|
||||
});
|
||||
|
||||
ipc.on('vscode:leaveFullScreen', () => {
|
||||
this.lifecycleService.when(LifecyclePhase.Ready).then(() => {
|
||||
browser.setFullscreen(false);
|
||||
});
|
||||
ipc.on('vscode:leaveFullScreen', async () => {
|
||||
await this.lifecycleService.when(LifecyclePhase.Ready);
|
||||
browser.setFullscreen(false);
|
||||
});
|
||||
|
||||
// High Contrast Events
|
||||
ipc.on('vscode:enterHighContrast', () => {
|
||||
ipc.on('vscode:enterHighContrast', async () => {
|
||||
const windowConfig = this.configurationService.getValue<IWindowSettings>('window');
|
||||
if (windowConfig && windowConfig.autoDetectHighContrast) {
|
||||
this.lifecycleService.when(LifecyclePhase.Ready).then(() => {
|
||||
this.themeService.setColorTheme(VS_HC_THEME, undefined);
|
||||
});
|
||||
await this.lifecycleService.when(LifecyclePhase.Ready);
|
||||
this.themeService.setColorTheme(VS_HC_THEME, undefined);
|
||||
}
|
||||
});
|
||||
|
||||
ipc.on('vscode:leaveHighContrast', () => {
|
||||
ipc.on('vscode:leaveHighContrast', async () => {
|
||||
const windowConfig = this.configurationService.getValue<IWindowSettings>('window');
|
||||
if (windowConfig && windowConfig.autoDetectHighContrast) {
|
||||
this.lifecycleService.when(LifecyclePhase.Ready).then(() => {
|
||||
this.themeService.restoreColorTheme();
|
||||
});
|
||||
await this.lifecycleService.when(LifecyclePhase.Ready);
|
||||
this.themeService.restoreColorTheme();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -310,32 +308,28 @@ export class ElectronWindow extends Disposable {
|
||||
};
|
||||
|
||||
// Emit event when vscode is ready
|
||||
this.lifecycleService.when(LifecyclePhase.Ready).then(() => {
|
||||
ipc.send('vscode:workbenchReady', this.windowService.windowId);
|
||||
});
|
||||
this.lifecycleService.when(LifecyclePhase.Ready).then(() => ipc.send('vscode:workbenchReady', this.windowService.windowId));
|
||||
|
||||
// Integrity warning
|
||||
this.integrityService.isPure().then(res => this.titleService.updateProperties({ isPure: res.isPure }));
|
||||
|
||||
// Root warning
|
||||
this.lifecycleService.when(LifecyclePhase.Restored).then(() => {
|
||||
let isAdminPromise: Promise<boolean>;
|
||||
this.lifecycleService.when(LifecyclePhase.Restored).then(async () => {
|
||||
let isAdmin: boolean;
|
||||
if (isWindows) {
|
||||
isAdminPromise = import('native-is-elevated').then(isElevated => isElevated());
|
||||
const isElevated = await import('native-is-elevated');
|
||||
isAdmin = isElevated();
|
||||
} else {
|
||||
isAdminPromise = Promise.resolve(isRootUser());
|
||||
isAdmin = isRootUser();
|
||||
}
|
||||
|
||||
return isAdminPromise.then(isAdmin => {
|
||||
// Update title
|
||||
this.titleService.updateProperties({ isAdmin });
|
||||
|
||||
// Update title
|
||||
this.titleService.updateProperties({ isAdmin });
|
||||
|
||||
// Show warning message (unix only)
|
||||
if (isAdmin && !isWindows) {
|
||||
this.notificationService.warn(nls.localize('runningAsRoot', "It is not recommended to run {0} as root user.", product.nameShort));
|
||||
}
|
||||
});
|
||||
// Show warning message (unix only)
|
||||
if (isAdmin && !isWindows) {
|
||||
this.notificationService.warn(nls.localize('runningAsRoot', "It is not recommended to run {0} as root user.", product.nameShort));
|
||||
}
|
||||
});
|
||||
|
||||
// Touchbar menu (if enabled)
|
||||
@@ -408,7 +402,7 @@ export class ElectronWindow extends Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
private setupCrashReporter(): void {
|
||||
private async setupCrashReporter(): Promise<void> {
|
||||
|
||||
// base options with product info
|
||||
const options = {
|
||||
@@ -422,18 +416,14 @@ export class ElectronWindow extends Disposable {
|
||||
};
|
||||
|
||||
// mixin telemetry info
|
||||
this.telemetryService.getTelemetryInfo()
|
||||
.then(info => {
|
||||
assign(options.extra, {
|
||||
vscode_sessionId: info.sessionId
|
||||
});
|
||||
const info = await this.telemetryService.getTelemetryInfo();
|
||||
assign(options.extra, { vscode_sessionId: info.sessionId });
|
||||
|
||||
// start crash reporter right here
|
||||
crashReporter.start(deepClone(options));
|
||||
// start crash reporter right here
|
||||
crashReporter.start(deepClone(options));
|
||||
|
||||
// start crash reporter in the main process
|
||||
return this.windowsService.startCrashReporter(options);
|
||||
});
|
||||
// start crash reporter in the main process
|
||||
return this.windowsService.startCrashReporter(options);
|
||||
}
|
||||
|
||||
private onAddFoldersRequest(request: IAddFoldersRequest): void {
|
||||
@@ -525,22 +515,21 @@ export class ElectronWindow extends Disposable {
|
||||
});
|
||||
}
|
||||
|
||||
private openResources(resources: Array<IResourceInput | IUntitledResourceInput>, diffMode: boolean): void {
|
||||
this.lifecycleService.when(LifecyclePhase.Ready).then((): Promise<unknown> => {
|
||||
private async openResources(resources: Array<IResourceInput | IUntitledResourceInput>, diffMode: boolean): Promise<unknown> {
|
||||
await this.lifecycleService.when(LifecyclePhase.Ready);
|
||||
|
||||
// In diffMode we open 2 resources as diff
|
||||
if (diffMode && resources.length === 2) {
|
||||
return this.editorService.openEditor({ leftResource: resources[0].resource!, rightResource: resources[1].resource!, options: { pinned: true } });
|
||||
}
|
||||
// In diffMode we open 2 resources as diff
|
||||
if (diffMode && resources.length === 2) {
|
||||
return this.editorService.openEditor({ leftResource: resources[0].resource!, rightResource: resources[1].resource!, options: { pinned: true } });
|
||||
}
|
||||
|
||||
// For one file, just put it into the current active editor
|
||||
if (resources.length === 1) {
|
||||
return this.editorService.openEditor(resources[0]);
|
||||
}
|
||||
// For one file, just put it into the current active editor
|
||||
if (resources.length === 1) {
|
||||
return this.editorService.openEditor(resources[0]);
|
||||
}
|
||||
|
||||
// Otherwise open all
|
||||
return this.editorService.openEditors(resources);
|
||||
});
|
||||
// Otherwise open all
|
||||
return this.editorService.openEditors(resources);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
|
||||
@@ -12,7 +12,7 @@ import { RunOnceScheduler } from 'vs/base/common/async';
|
||||
import { FileChangeType, FileChangesEvent } from 'vs/platform/files/common/files';
|
||||
import { ConfigurationModel, ConfigurationModelParser } from 'vs/platform/configuration/common/configurationModels';
|
||||
import { WorkspaceConfigurationModelParser, StandaloneConfigurationModelParser } from 'vs/workbench/services/configuration/common/configurationModels';
|
||||
import { FOLDER_SETTINGS_PATH, TASKS_CONFIGURATION_KEY, FOLDER_SETTINGS_NAME, LAUNCH_CONFIGURATION_KEY, IConfigurationCache, ConfigurationKey, IConfigurationFileService, MACHINE_SCOPES, FOLDER_SCOPES, WORKSPACE_SCOPES } from 'vs/workbench/services/configuration/common/configuration';
|
||||
import { FOLDER_SETTINGS_PATH, TASKS_CONFIGURATION_KEY, FOLDER_SETTINGS_NAME, LAUNCH_CONFIGURATION_KEY, IConfigurationCache, ConfigurationKey, IConfigurationFileService, REMOTE_MACHINE_SCOPES, FOLDER_SCOPES, WORKSPACE_SCOPES } from 'vs/workbench/services/configuration/common/configuration';
|
||||
import { IStoredWorkspaceFolder, IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { JSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditingService';
|
||||
import { WorkbenchState, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
|
||||
@@ -45,7 +45,7 @@ export class RemoteUserConfiguration extends Disposable {
|
||||
this._userConfiguration = this._cachedConfiguration = new CachedUserConfiguration(remoteAuthority, configurationCache);
|
||||
remoteAgentService.getEnvironment().then(async environment => {
|
||||
if (environment) {
|
||||
const userConfiguration = this._register(new UserConfiguration(environment.settingsPath, MACHINE_SCOPES, this._configurationFileService));
|
||||
const userConfiguration = this._register(new UserConfiguration(environment.settingsPath, REMOTE_MACHINE_SCOPES, this._configurationFileService));
|
||||
this._register(userConfiguration.onDidChangeConfiguration(configurationModel => this.onDidUserConfigurationChange(configurationModel)));
|
||||
this._userConfigurationInitializationPromise = userConfiguration.initialize();
|
||||
const configurationModel = await this._userConfigurationInitializationPromise;
|
||||
|
||||
@@ -15,7 +15,7 @@ import { isLinux } from 'vs/base/common/platform';
|
||||
import { ConfigurationChangeEvent, ConfigurationModel, DefaultConfigurationModel } from 'vs/platform/configuration/common/configurationModels';
|
||||
import { IConfigurationChangeEvent, ConfigurationTarget, IConfigurationOverrides, keyFromOverrideIdentifier, isConfigurationOverrides, IConfigurationData, IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { Configuration, WorkspaceConfigurationChangeEvent, AllKeysConfigurationChangeEvent } from 'vs/workbench/services/configuration/common/configurationModels';
|
||||
import { FOLDER_CONFIG_FOLDER_NAME, defaultSettingsSchemaId, userSettingsSchemaId, workspaceSettingsSchemaId, folderSettingsSchemaId, IConfigurationCache, IConfigurationFileService, machineSettingsSchemaId } from 'vs/workbench/services/configuration/common/configuration';
|
||||
import { FOLDER_CONFIG_FOLDER_NAME, defaultSettingsSchemaId, userSettingsSchemaId, workspaceSettingsSchemaId, folderSettingsSchemaId, IConfigurationCache, IConfigurationFileService, machineSettingsSchemaId, LOCAL_MACHINE_SCOPES } from 'vs/workbench/services/configuration/common/configuration';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { IConfigurationRegistry, Extensions, allSettings, windowSettings, resourceSettings, applicationSettings, machineSettings } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { IWorkspaceIdentifier, isWorkspaceIdentifier, IStoredWorkspaceFolder, isStoredWorkspaceFolder, IWorkspaceFolderCreationData, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, IWorkspaceInitializationPayload, isSingleFolderWorkspaceInitializationPayload, ISingleFolderWorkspaceInitializationPayload, IEmptyWorkspaceInitializationPayload, useSlashForPath, getStoredWorkspaceFolder } from 'vs/platform/workspaces/common/workspaces';
|
||||
@@ -74,7 +74,7 @@ export class WorkspaceService extends Disposable implements IConfigurationServic
|
||||
this.defaultConfiguration = new DefaultConfigurationModel();
|
||||
this.configurationCache = configurationCache;
|
||||
if (userSettingsResource) {
|
||||
this.localUserConfiguration = this._register(new UserConfiguration(userSettingsResource, undefined, configurationFileService));
|
||||
this.localUserConfiguration = this._register(new UserConfiguration(userSettingsResource, remoteAuthority ? LOCAL_MACHINE_SCOPES : undefined, configurationFileService));
|
||||
this._register(this.localUserConfiguration.onDidChangeConfiguration(userConfiguration => this.onLocalUserConfigurationChanged(userConfiguration)));
|
||||
}
|
||||
if (remoteAuthority) {
|
||||
@@ -515,14 +515,16 @@ export class WorkspaceService extends Disposable implements IConfigurationServic
|
||||
}, {});
|
||||
};
|
||||
|
||||
const unsupportedApplicationSettings = convertToNotSuggestedProperties(applicationSettings.properties, localize('unsupportedApplicationSetting', "This setting can be applied only in application user settings"));
|
||||
const unsupportedMachineSettings = convertToNotSuggestedProperties(machineSettings.properties, localize('unsupportedMachineSetting', "This setting can be applied only in user settings"));
|
||||
const unsupportedRemoteMachineSettings = convertToNotSuggestedProperties(machineSettings.properties, localize('unsupportedRemoteMachineSetting', "This setting can be applied only in remote machine settings"));
|
||||
const allSettingsSchema: IJSONSchema = { properties: allSettings.properties, patternProperties: allSettings.patternProperties, additionalProperties: false, errorMessage: 'Unknown configuration setting' };
|
||||
const unsupportedApplicationSettings = convertToNotSuggestedProperties(applicationSettings.properties, localize('unsupportedApplicationSetting', "This setting can be applied only in application user Settings"));
|
||||
const unsupportedMachineSettings = convertToNotSuggestedProperties(machineSettings.properties, localize('unsupportedMachineSetting', "This setting can be applied only in user Settings"));
|
||||
const userSettingsSchema: IJSONSchema = this.remoteUserConfiguration ? { properties: { ...applicationSettings.properties, ...unsupportedRemoteMachineSettings, ...windowSettings.properties, ...resourceSettings.properties }, patternProperties: allSettings.patternProperties, additionalProperties: false, errorMessage: 'Unknown configuration setting' } : allSettingsSchema;
|
||||
const machineSettingsSchema: IJSONSchema = { properties: { ...unsupportedApplicationSettings, ...windowSettings.properties, ...resourceSettings.properties }, patternProperties: allSettings.patternProperties, additionalProperties: false, errorMessage: 'Unknown configuration setting' };
|
||||
const workspaceSettingsSchema: IJSONSchema = { properties: { ...unsupportedApplicationSettings, ...unsupportedMachineSettings, ...windowSettings.properties, ...resourceSettings.properties }, patternProperties: allSettings.patternProperties, additionalProperties: false, errorMessage: 'Unknown configuration setting' };
|
||||
|
||||
jsonRegistry.registerSchema(defaultSettingsSchemaId, allSettingsSchema);
|
||||
jsonRegistry.registerSchema(userSettingsSchemaId, allSettingsSchema);
|
||||
jsonRegistry.registerSchema(userSettingsSchemaId, userSettingsSchema);
|
||||
jsonRegistry.registerSchema(machineSettingsSchemaId, machineSettingsSchema);
|
||||
|
||||
if (WorkbenchState.WORKSPACE === this.getWorkbenchState()) {
|
||||
|
||||
@@ -20,7 +20,8 @@ export const workspaceSettingsSchemaId = 'vscode://schemas/settings/workspace';
|
||||
export const folderSettingsSchemaId = 'vscode://schemas/settings/folder';
|
||||
export const launchSchemaId = 'vscode://schemas/launch';
|
||||
|
||||
export const MACHINE_SCOPES = [ConfigurationScope.MACHINE, ConfigurationScope.WINDOW, ConfigurationScope.RESOURCE];
|
||||
export const LOCAL_MACHINE_SCOPES = [ConfigurationScope.APPLICATION, ConfigurationScope.WINDOW, ConfigurationScope.RESOURCE];
|
||||
export const REMOTE_MACHINE_SCOPES = [ConfigurationScope.MACHINE, ConfigurationScope.WINDOW, ConfigurationScope.RESOURCE];
|
||||
export const WORKSPACE_SCOPES = [ConfigurationScope.WINDOW, ConfigurationScope.RESOURCE];
|
||||
export const FOLDER_SCOPES = [ConfigurationScope.RESOURCE];
|
||||
|
||||
|
||||
@@ -268,6 +268,14 @@ suite('WorkspaceConfigurationService - Remote Folder', () => {
|
||||
// return promise;
|
||||
// });
|
||||
|
||||
test('machine settings in local user settings does not override defaults', async () => {
|
||||
fs.writeFileSync(globalSettingsFile, '{ "configurationService.remote.machineSetting": "globalValue" }');
|
||||
registerRemoteFileSystemProvider();
|
||||
resolveRemoteEnvironment();
|
||||
await initialize();
|
||||
assert.equal(testObject.getValue('configurationService.remote.machineSetting'), 'isSet');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
function getWorkspaceId(configPath: URI): string {
|
||||
|
||||
@@ -172,7 +172,7 @@ class NativeContextMenuService extends Disposable implements IContextMenuService
|
||||
}
|
||||
}
|
||||
|
||||
private runAction(actionRunner: IActionRunner, actionToRun: IAction, delegate: IContextMenuDelegate, event: IContextMenuEvent): void {
|
||||
private async runAction(actionRunner: IActionRunner, actionToRun: IAction, delegate: IContextMenuDelegate, event: IContextMenuEvent): Promise<void> {
|
||||
/* __GDPR__
|
||||
"workbenchActionExecuted" : {
|
||||
"id" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
|
||||
@@ -182,9 +182,15 @@ class NativeContextMenuService extends Disposable implements IContextMenuService
|
||||
this.telemetryService.publicLog('workbenchActionExecuted', { id: actionToRun.id, from: 'contextMenu' });
|
||||
|
||||
const context = delegate.getActionsContext ? delegate.getActionsContext(event) : event;
|
||||
const res = actionRunner.run(actionToRun, context) || Promise.resolve(null);
|
||||
|
||||
res.then(undefined, e => this.notificationService.error(e));
|
||||
const runnable = actionRunner.run(actionToRun, context);
|
||||
if (runnable) {
|
||||
try {
|
||||
await runnable;
|
||||
} catch (error) {
|
||||
this.notificationService.error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,17 +78,16 @@ class NativeDialogService implements IDialogService {
|
||||
sharedProcessService.registerChannel('dialog', new DialogChannel(this));
|
||||
}
|
||||
|
||||
confirm(confirmation: IConfirmation): Promise<IConfirmationResult> {
|
||||
async confirm(confirmation: IConfirmation): Promise<IConfirmationResult> {
|
||||
this.logService.trace('DialogService#confirm', confirmation.message);
|
||||
|
||||
const { options, buttonIndexMap } = this.massageMessageBoxOptions(this.getConfirmOptions(confirmation));
|
||||
|
||||
return this.windowService.showMessageBox(options).then(result => {
|
||||
return {
|
||||
confirmed: buttonIndexMap[result.button] === 0 ? true : false,
|
||||
checkboxChecked: result.checkboxChecked
|
||||
};
|
||||
});
|
||||
const result = await this.windowService.showMessageBox(options);
|
||||
return {
|
||||
confirmed: buttonIndexMap[result.button] === 0 ? true : false,
|
||||
checkboxChecked: result.checkboxChecked
|
||||
};
|
||||
}
|
||||
|
||||
private getConfirmOptions(confirmation: IConfirmation): Electron.MessageBoxOptions {
|
||||
@@ -128,7 +127,7 @@ class NativeDialogService implements IDialogService {
|
||||
return opts;
|
||||
}
|
||||
|
||||
show(severity: Severity, message: string, buttons: string[], dialogOptions?: IDialogOptions): Promise<number> {
|
||||
async show(severity: Severity, message: string, buttons: string[], dialogOptions?: IDialogOptions): Promise<number> {
|
||||
this.logService.trace('DialogService#show', message);
|
||||
|
||||
const { options, buttonIndexMap } = this.massageMessageBoxOptions({
|
||||
@@ -139,7 +138,8 @@ class NativeDialogService implements IDialogService {
|
||||
detail: dialogOptions ? dialogOptions.detail : undefined
|
||||
});
|
||||
|
||||
return this.windowService.showMessageBox(options).then(result => buttonIndexMap[result.button]);
|
||||
const result = await this.windowService.showMessageBox(options);
|
||||
return buttonIndexMap[result.button];
|
||||
}
|
||||
|
||||
private massageMessageBoxOptions(options: Electron.MessageBoxOptions): IMassagedMessageBoxOptions {
|
||||
|
||||
@@ -62,17 +62,16 @@ export class CodeEditorService extends CodeEditorServiceImpl {
|
||||
return this.doOpenCodeEditor(input, source, sideBySide);
|
||||
}
|
||||
|
||||
private doOpenCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Promise<ICodeEditor | null> {
|
||||
return this.editorService.openEditor(input, sideBySide ? SIDE_GROUP : ACTIVE_GROUP).then(control => {
|
||||
if (control) {
|
||||
const widget = control.getControl();
|
||||
if (isCodeEditor(widget)) {
|
||||
return widget;
|
||||
}
|
||||
private async doOpenCodeEditor(input: IResourceInput, source: ICodeEditor | null, sideBySide?: boolean): Promise<ICodeEditor | null> {
|
||||
const control = await this.editorService.openEditor(input, sideBySide ? SIDE_GROUP : ACTIVE_GROUP);
|
||||
if (control) {
|
||||
const widget = control.getControl();
|
||||
if (isCodeEditor(widget)) {
|
||||
return widget;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -331,7 +331,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
|
||||
|
||||
openEditors(editors: IEditorInputWithOptions[], group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditor[]>;
|
||||
openEditors(editors: IResourceEditor[], group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditor[]>;
|
||||
openEditors(editors: Array<IEditorInputWithOptions | IResourceEditor>, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditor[]> {
|
||||
async openEditors(editors: Array<IEditorInputWithOptions | IResourceEditor>, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditor[]> {
|
||||
|
||||
// Convert to typed editors and options
|
||||
const typedEditors: IEditorInputWithOptions[] = [];
|
||||
@@ -367,7 +367,9 @@ export class EditorService extends Disposable implements EditorServiceImpl {
|
||||
result.push(group.openEditors(editorsWithOptions));
|
||||
});
|
||||
|
||||
return Promise.all(result).then(editors => coalesce(editors));
|
||||
const openedEditors = await Promise.all(result);
|
||||
|
||||
return coalesce(openedEditors);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
@@ -6,9 +6,48 @@
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { IExtensionManifest } from 'vs/platform/extensions/common/extensions';
|
||||
import { ExtensionsRegistry } from 'vs/workbench/services/extensions/common/extensionsRegistry';
|
||||
import { isUIExtension as _isUIExtension } from 'vs/platform/extensions/node/extensionsUtil';
|
||||
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, configurationService: IConfigurationService): boolean {
|
||||
const uiExtensionPoints = ExtensionsRegistry.getExtensionPoints().filter(e => e.defaultExtensionKind !== 'workspace').map(e => e.name);
|
||||
return _isUIExtension(manifest, uiExtensionPoints, configurationService);
|
||||
const uiContributions = ExtensionsRegistry.getExtensionPoints().filter(e => e.defaultExtensionKind !== 'workspace').map(e => e.name);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
|
||||
import { IDiskFileChange, normalizeFileChanges } from 'vs/workbench/services/files/node/watcher/watcher';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { statLink, readlink } from 'vs/base/node/pfs';
|
||||
import { statLink } from 'vs/base/node/pfs';
|
||||
import { realpath } from 'vs/base/node/extpath';
|
||||
import { watchFolder, watchFile, CHANGE_BUFFER_DELAY } from 'vs/base/node/watcher';
|
||||
import { FileChangeType } from 'vs/platform/files/common/files';
|
||||
import { ThrottledDelayer } from 'vs/base/common/async';
|
||||
@@ -40,7 +41,7 @@ export class FileWatcher extends Disposable {
|
||||
let pathToWatch = this.path;
|
||||
if (isSymbolicLink) {
|
||||
try {
|
||||
pathToWatch = await readlink(pathToWatch);
|
||||
pathToWatch = await realpath(pathToWatch);
|
||||
} catch (error) {
|
||||
this.onError(error);
|
||||
}
|
||||
|
||||
@@ -71,9 +71,9 @@ export class IntegrityServiceImpl implements IIntegrityService {
|
||||
|
||||
this.isPure().then(r => {
|
||||
if (r.isPure) {
|
||||
// all is good
|
||||
return;
|
||||
return; // all is good
|
||||
}
|
||||
|
||||
this._prompt();
|
||||
});
|
||||
}
|
||||
@@ -106,29 +106,25 @@ export class IntegrityServiceImpl implements IIntegrityService {
|
||||
return this._isPurePromise;
|
||||
}
|
||||
|
||||
private _isPure(): Promise<IntegrityTestResult> {
|
||||
private async _isPure(): Promise<IntegrityTestResult> {
|
||||
const expectedChecksums = product.checksums || {};
|
||||
|
||||
return this.lifecycleService.when(LifecyclePhase.Eventually).then(() => {
|
||||
let asyncResults: Promise<ChecksumPair>[] = Object.keys(expectedChecksums).map((filename) => {
|
||||
return this._resolve(filename, expectedChecksums[filename]);
|
||||
});
|
||||
await this.lifecycleService.when(LifecyclePhase.Eventually);
|
||||
|
||||
return Promise.all(asyncResults).then<IntegrityTestResult>((allResults) => {
|
||||
let isPure = true;
|
||||
for (let i = 0, len = allResults.length; i < len; i++) {
|
||||
if (!allResults[i].isPure) {
|
||||
isPure = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const allResults = await Promise.all(Object.keys(expectedChecksums).map(filename => this._resolve(filename, expectedChecksums[filename])));
|
||||
|
||||
return {
|
||||
isPure: isPure,
|
||||
proof: allResults
|
||||
};
|
||||
});
|
||||
});
|
||||
let isPure = true;
|
||||
for (let i = 0, len = allResults.length; i < len; i++) {
|
||||
if (!allResults[i].isPure) {
|
||||
isPure = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
isPure: isPure,
|
||||
proof: allResults
|
||||
};
|
||||
}
|
||||
|
||||
private _resolve(filename: string, expected: string): Promise<ChecksumPair> {
|
||||
|
||||
@@ -208,7 +208,8 @@ export class ScopedProgressService extends ScopedService implements IProgressSer
|
||||
};
|
||||
}
|
||||
|
||||
showWhile(promise: Promise<any>, delay?: number): Promise<void> {
|
||||
async showWhile(promise: Promise<any>, delay?: number): Promise<void> {
|
||||
|
||||
// Join with existing running promise to ensure progress is accurate
|
||||
if (this.progressState.type === ProgressState.Type.While) {
|
||||
promise = Promise.all([promise, this.progressState.whilePromise]);
|
||||
@@ -217,24 +218,25 @@ export class ScopedProgressService extends ScopedService implements IProgressSer
|
||||
// Keep Promise in State
|
||||
this.progressState = new ProgressState.While(promise, delay || 0, Date.now());
|
||||
|
||||
let stop = () => {
|
||||
try {
|
||||
this.doShowWhile(delay);
|
||||
|
||||
// If this is not the last promise in the list of joined promises, return early
|
||||
if (this.progressState.type === ProgressState.Type.While && this.progressState.whilePromise !== promise) {
|
||||
return;
|
||||
await promise;
|
||||
} catch (error) {
|
||||
// ignore
|
||||
} finally {
|
||||
|
||||
// If this is not the last promise in the list of joined promises, skip this
|
||||
if (this.progressState.type !== ProgressState.Type.While || this.progressState.whilePromise === promise) {
|
||||
|
||||
// The while promise is either null or equal the promise we last hooked on
|
||||
this.progressState = ProgressState.None;
|
||||
|
||||
if (this.isActive) {
|
||||
this.progressbar.stop().hide();
|
||||
}
|
||||
}
|
||||
|
||||
// The while promise is either null or equal the promise we last hooked on
|
||||
this.progressState = ProgressState.None;
|
||||
|
||||
if (this.isActive) {
|
||||
this.progressbar.stop().hide();
|
||||
}
|
||||
};
|
||||
|
||||
this.doShowWhile(delay);
|
||||
|
||||
return promise.then(stop, stop);
|
||||
}
|
||||
}
|
||||
|
||||
private doShowWhile(delay?: number): void {
|
||||
@@ -280,13 +282,15 @@ export class ProgressService implements IProgressService {
|
||||
};
|
||||
}
|
||||
|
||||
showWhile(promise: Promise<any>, delay?: number): Promise<void> {
|
||||
const stop = () => {
|
||||
async showWhile(promise: Promise<any>, delay?: number): Promise<void> {
|
||||
try {
|
||||
this.progressbar.infinite().show(delay);
|
||||
|
||||
await promise;
|
||||
} catch (error) {
|
||||
// ignore
|
||||
} finally {
|
||||
this.progressbar.stop().hide();
|
||||
};
|
||||
|
||||
this.progressbar.infinite().show(delay);
|
||||
|
||||
return promise.then(stop, stop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,28 +34,28 @@ export class RemoteExtensionEnvironmentChannelClient {
|
||||
|
||||
constructor(private channel: IChannel) { }
|
||||
|
||||
getEnvironmentData(remoteAuthority: string, extensionDevelopmentPath?: URI[]): Promise<IRemoteAgentEnvironment> {
|
||||
async getEnvironmentData(remoteAuthority: string, extensionDevelopmentPath?: URI[]): Promise<IRemoteAgentEnvironment> {
|
||||
const args: IGetEnvironmentDataArguments = {
|
||||
language: platform.language,
|
||||
remoteAuthority,
|
||||
extensionDevelopmentPath
|
||||
};
|
||||
return this.channel.call<IRemoteAgentEnvironmentDTO>('getEnvironmentData', args)
|
||||
.then((data: IRemoteAgentEnvironmentDTO): IRemoteAgentEnvironment => {
|
||||
return {
|
||||
pid: data.pid,
|
||||
appRoot: URI.revive(data.appRoot),
|
||||
appSettingsHome: URI.revive(data.appSettingsHome),
|
||||
settingsPath: URI.revive(data.settingsPath),
|
||||
logsPath: URI.revive(data.logsPath),
|
||||
extensionsPath: URI.revive(data.extensionsPath),
|
||||
extensionHostLogsPath: URI.revive(data.extensionHostLogsPath),
|
||||
globalStorageHome: URI.revive(data.globalStorageHome),
|
||||
userHome: URI.revive(data.userHome),
|
||||
extensions: data.extensions.map(ext => { (<any>ext).extensionLocation = URI.revive(ext.extensionLocation); return ext; }),
|
||||
os: data.os
|
||||
};
|
||||
});
|
||||
|
||||
const data = await this.channel.call<IRemoteAgentEnvironmentDTO>('getEnvironmentData', args);
|
||||
|
||||
return {
|
||||
pid: data.pid,
|
||||
appRoot: URI.revive(data.appRoot),
|
||||
appSettingsHome: URI.revive(data.appSettingsHome),
|
||||
settingsPath: URI.revive(data.settingsPath),
|
||||
logsPath: URI.revive(data.logsPath),
|
||||
extensionsPath: URI.revive(data.extensionsPath),
|
||||
extensionHostLogsPath: URI.revive(data.extensionHostLogsPath),
|
||||
globalStorageHome: URI.revive(data.globalStorageHome),
|
||||
userHome: URI.revive(data.userHome),
|
||||
extensions: data.extensions.map(ext => { (<any>ext).extensionLocation = URI.revive(ext.extensionLocation); return ext; }),
|
||||
os: data.os
|
||||
};
|
||||
}
|
||||
|
||||
getDiagnosticInfo(options: IDiagnosticInfoOptions): Promise<IDiagnosticInfo> {
|
||||
|
||||
@@ -31,7 +31,7 @@ class ResourceModelCollection extends ReferenceCollection<Promise<ITextEditorMod
|
||||
super();
|
||||
}
|
||||
|
||||
createReferencedObject(key: string, skipActivateProvider?: boolean): Promise<ITextEditorModel> {
|
||||
async createReferencedObject(key: string, skipActivateProvider?: boolean): Promise<ITextEditorModel> {
|
||||
this.modelsToDispose.delete(key);
|
||||
|
||||
const resource = URI.parse(key);
|
||||
@@ -43,15 +43,19 @@ class ResourceModelCollection extends ReferenceCollection<Promise<ITextEditorMod
|
||||
|
||||
// Virtual documents
|
||||
if (this.providers[resource.scheme]) {
|
||||
return this.resolveTextModelContent(key).then(() => this.instantiationService.createInstance(ResourceEditorModel, resource));
|
||||
await this.resolveTextModelContent(key);
|
||||
|
||||
return this.instantiationService.createInstance(ResourceEditorModel, resource);
|
||||
}
|
||||
|
||||
// Either unknown schema, or not yet registered, try to activate
|
||||
if (!skipActivateProvider) {
|
||||
return this.fileService.activateProvider(resource.scheme).then(() => this.createReferencedObject(key, true));
|
||||
await this.fileService.activateProvider(resource.scheme);
|
||||
|
||||
return this.createReferencedObject(key, true);
|
||||
}
|
||||
|
||||
return Promise.reject(new Error('resource is not available'));
|
||||
throw new Error('resource is not available');
|
||||
}
|
||||
|
||||
destroyReferencedObject(key: string, modelPromise: Promise<ITextEditorModel>): void {
|
||||
@@ -101,18 +105,17 @@ class ResourceModelCollection extends ReferenceCollection<Promise<ITextEditorMod
|
||||
return this.providers[scheme] !== undefined;
|
||||
}
|
||||
|
||||
private resolveTextModelContent(key: string): Promise<ITextModel> {
|
||||
private async resolveTextModelContent(key: string): Promise<ITextModel> {
|
||||
const resource = URI.parse(key);
|
||||
const providers = this.providers[resource.scheme] || [];
|
||||
const factories = providers.map(p => () => Promise.resolve(p.provideTextContent(resource)));
|
||||
|
||||
return first(factories).then(model => {
|
||||
if (!model) {
|
||||
return Promise.reject(new Error('resource is not available'));
|
||||
}
|
||||
const model = await first(factories);
|
||||
if (!model) {
|
||||
throw new Error('resource is not available');
|
||||
}
|
||||
|
||||
return model;
|
||||
});
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,14 +134,16 @@ export class TextModelResolverService implements ITextModelService {
|
||||
}
|
||||
|
||||
createModelReference(resource: URI): Promise<IReference<IResolvedTextEditorModel>> {
|
||||
return this._createModelReference(resource);
|
||||
return this.doCreateModelReference(resource);
|
||||
}
|
||||
|
||||
private _createModelReference(resource: URI): Promise<IReference<IResolvedTextEditorModel>> {
|
||||
private async doCreateModelReference(resource: URI): Promise<IReference<IResolvedTextEditorModel>> {
|
||||
|
||||
// Untitled Schema: go through cached input
|
||||
if (resource.scheme === network.Schemas.untitled) {
|
||||
return this.untitledEditorService.loadOrCreate({ resource }).then(model => new ImmortalReference(model as IResolvedTextEditorModel));
|
||||
const model = await this.untitledEditorService.loadOrCreate({ resource });
|
||||
|
||||
return new ImmortalReference(model as IResolvedTextEditorModel);
|
||||
}
|
||||
|
||||
// InMemory Schema: go through model service cache
|
||||
@@ -154,14 +159,15 @@ export class TextModelResolverService implements ITextModelService {
|
||||
|
||||
const ref = this.resourceModelCollection.acquire(resource.toString());
|
||||
|
||||
return ref.object.then(
|
||||
model => ({ object: model, dispose: () => ref.dispose() }),
|
||||
err => {
|
||||
ref.dispose();
|
||||
try {
|
||||
const model = await ref.object;
|
||||
|
||||
return Promise.reject(err);
|
||||
}
|
||||
);
|
||||
return { object: model as IResolvedTextEditorModel, dispose: () => ref.dispose() };
|
||||
} catch (error) {
|
||||
ref.dispose();
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
registerTextModelContentProvider(scheme: string, provider: ITextModelContentProvider): IDisposable {
|
||||
|
||||
@@ -71,6 +71,7 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
|
||||
if (reason !== ShutdownReason.LOAD && reason !== ShutdownReason.CLOSE) {
|
||||
return undefined; // only interested when window is closing or loading
|
||||
}
|
||||
|
||||
const workspaceIdentifier = this.getCurrentWorkspaceIdentifier();
|
||||
if (!workspaceIdentifier || !isEqualOrParent(workspaceIdentifier.configPath, this.environmentService.untitledWorkspacesHome)) {
|
||||
return undefined; // only care about untitled workspaces to ask for saving
|
||||
@@ -190,16 +191,23 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
|
||||
}
|
||||
}
|
||||
|
||||
private doUpdateFolders(foldersToAdd: IWorkspaceFolderCreationData[], foldersToDelete: URI[], index?: number, donotNotifyError: boolean = false): Promise<void> {
|
||||
return this.contextService.updateFolders(foldersToAdd, foldersToDelete, index)
|
||||
.then(() => null, error => donotNotifyError ? Promise.reject(error) : this.handleWorkspaceConfigurationEditingError(error));
|
||||
private async doUpdateFolders(foldersToAdd: IWorkspaceFolderCreationData[], foldersToDelete: URI[], index?: number, donotNotifyError: boolean = false): Promise<void> {
|
||||
try {
|
||||
await this.contextService.updateFolders(foldersToAdd, foldersToDelete, index);
|
||||
} catch (error) {
|
||||
if (donotNotifyError) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
this.handleWorkspaceConfigurationEditingError(error);
|
||||
}
|
||||
}
|
||||
|
||||
addFolders(foldersToAdd: IWorkspaceFolderCreationData[], donotNotifyError: boolean = false): Promise<void> {
|
||||
return this.doAddFolders(foldersToAdd, undefined, donotNotifyError);
|
||||
}
|
||||
|
||||
private doAddFolders(foldersToAdd: IWorkspaceFolderCreationData[], index?: number, donotNotifyError: boolean = false): Promise<void> {
|
||||
private async doAddFolders(foldersToAdd: IWorkspaceFolderCreationData[], index?: number, donotNotifyError: boolean = false): Promise<void> {
|
||||
const state = this.contextService.getWorkbenchState();
|
||||
|
||||
// If we are in no-workspace or single-folder workspace, adding folders has to
|
||||
@@ -217,11 +225,18 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
|
||||
}
|
||||
|
||||
// Delegate addition of folders to workspace service otherwise
|
||||
return this.contextService.addFolders(foldersToAdd, index)
|
||||
.then(() => null, error => donotNotifyError ? Promise.reject(error) : this.handleWorkspaceConfigurationEditingError(error));
|
||||
try {
|
||||
await this.contextService.addFolders(foldersToAdd, index);
|
||||
} catch (error) {
|
||||
if (donotNotifyError) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
this.handleWorkspaceConfigurationEditingError(error);
|
||||
}
|
||||
}
|
||||
|
||||
removeFolders(foldersToRemove: URI[], donotNotifyError: boolean = false): Promise<void> {
|
||||
async removeFolders(foldersToRemove: URI[], donotNotifyError: boolean = false): Promise<void> {
|
||||
|
||||
// If we are in single-folder state and the opened folder is to be removed,
|
||||
// we create an empty workspace and enter it.
|
||||
@@ -230,8 +245,15 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
|
||||
}
|
||||
|
||||
// Delegate removal of folders to workspace service otherwise
|
||||
return this.contextService.removeFolders(foldersToRemove)
|
||||
.then(() => null, error => donotNotifyError ? Promise.reject(error) : this.handleWorkspaceConfigurationEditingError(error));
|
||||
try {
|
||||
await this.contextService.removeFolders(foldersToRemove);
|
||||
} catch (error) {
|
||||
if (donotNotifyError) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
this.handleWorkspaceConfigurationEditingError(error);
|
||||
}
|
||||
}
|
||||
|
||||
private includesSingleFolderWorkspace(folders: URI[]): boolean {
|
||||
@@ -283,10 +305,12 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
|
||||
detail: nls.localize('workspaceOpenedDetail', "The workspace is already opened in another window. Please close that window first and then try again."),
|
||||
noLink: true
|
||||
};
|
||||
return this.windowService.showMessageBox(options).then(() => false);
|
||||
await this.windowService.showMessageBox(options);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return Promise.resolve(true); // OK
|
||||
return true; // OK
|
||||
}
|
||||
|
||||
private async saveWorkspaceAs(workspace: IWorkspaceIdentifier, targetConfigPathURI: URI): Promise<any> {
|
||||
|
||||
Reference in New Issue
Block a user