mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Merge from master
This commit is contained in:
@@ -2,33 +2,33 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { IPosition } from 'vs/base/browser/ui/contextview/contextview';
|
||||
import { always } from 'vs/base/common/async';
|
||||
import { illegalArgument } from 'vs/base/common/errors';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { ServicesAccessor, IConstructorSignature1 } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { IEditorContribution } from 'vs/editor/common/editorCommon';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
import { ITextModelService } from 'vs/editor/common/services/resolverService';
|
||||
import { MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
|
||||
import { CommandsRegistry, ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
|
||||
import { KeybindingsRegistry, IKeybindings } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IConstructorSignature1, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IKeybindings, KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
import { MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
|
||||
import { IContextKeyService, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { IPosition } from 'vs/base/browser/ui/contextview/contextview';
|
||||
|
||||
export type ServicesAccessor = ServicesAccessor;
|
||||
export type IEditorContributionCtor = IConstructorSignature1<ICodeEditor, editorCommon.IEditorContribution>;
|
||||
export type IEditorContributionCtor = IConstructorSignature1<ICodeEditor, IEditorContribution>;
|
||||
|
||||
//#region Command
|
||||
|
||||
export interface ICommandKeybindingsOptions extends IKeybindings {
|
||||
kbExpr?: ContextKeyExpr;
|
||||
kbExpr?: ContextKeyExpr | null;
|
||||
weight: number;
|
||||
}
|
||||
export interface ICommandMenubarOptions {
|
||||
@@ -40,17 +40,17 @@ export interface ICommandMenubarOptions {
|
||||
}
|
||||
export interface ICommandOptions {
|
||||
id: string;
|
||||
precondition: ContextKeyExpr;
|
||||
kbOpts?: ICommandKeybindingsOptions;
|
||||
precondition: ContextKeyExpr | null;
|
||||
kbOpts?: ICommandKeybindingsOptions | null;
|
||||
description?: ICommandHandlerDescription;
|
||||
menubarOpts?: ICommandMenubarOptions;
|
||||
}
|
||||
export abstract class Command {
|
||||
public readonly id: string;
|
||||
public readonly precondition: ContextKeyExpr;
|
||||
private readonly _kbOpts: ICommandKeybindingsOptions;
|
||||
private readonly _menubarOpts: ICommandMenubarOptions;
|
||||
private readonly _description: ICommandHandlerDescription;
|
||||
public readonly precondition: ContextKeyExpr | null;
|
||||
private readonly _kbOpts: ICommandKeybindingsOptions | null | undefined;
|
||||
private readonly _menubarOpts: ICommandMenubarOptions | null | undefined;
|
||||
private readonly _description: ICommandHandlerDescription | null | undefined;
|
||||
|
||||
constructor(opts: ICommandOptions) {
|
||||
this.id = opts.id;
|
||||
@@ -89,7 +89,7 @@ export abstract class Command {
|
||||
id: this.id,
|
||||
handler: (accessor, args) => this.runCommand(accessor, args),
|
||||
weight: this._kbOpts.weight,
|
||||
when: kbWhen,
|
||||
when: kbWhen || null,
|
||||
primary: this._kbOpts.primary,
|
||||
secondary: this._kbOpts.secondary,
|
||||
win: this._kbOpts.win,
|
||||
@@ -108,7 +108,7 @@ export abstract class Command {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract runCommand(accessor: ServicesAccessor, args: any): void | TPromise<void>;
|
||||
public abstract runCommand(accessor: ServicesAccessor, args: any): void | Thenable<void>;
|
||||
}
|
||||
|
||||
//#endregion Command
|
||||
@@ -118,7 +118,7 @@ export abstract class Command {
|
||||
export interface IContributionCommandOptions<T> extends ICommandOptions {
|
||||
handler: (controller: T) => void;
|
||||
}
|
||||
export interface EditorControllerCommand<T extends editorCommon.IEditorContribution> {
|
||||
export interface EditorControllerCommand<T extends IEditorContribution> {
|
||||
new(opts: IContributionCommandOptions<T>): EditorCommand;
|
||||
}
|
||||
export abstract class EditorCommand extends Command {
|
||||
@@ -126,7 +126,7 @@ export abstract class EditorCommand extends Command {
|
||||
/**
|
||||
* Create a command class that is bound to a certain editor contribution.
|
||||
*/
|
||||
public static bindToContribution<T extends editorCommon.IEditorContribution>(controllerGetter: (editor: ICodeEditor) => T): EditorControllerCommand<T> {
|
||||
public static bindToContribution<T extends IEditorContribution>(controllerGetter: (editor: ICodeEditor) => T): EditorControllerCommand<T> {
|
||||
return class EditorControllerCommandImpl extends EditorCommand {
|
||||
private _callback: (controller: T) => void;
|
||||
|
||||
@@ -145,7 +145,7 @@ export abstract class EditorCommand extends Command {
|
||||
};
|
||||
}
|
||||
|
||||
public runCommand(accessor: ServicesAccessor, args: any): void | TPromise<void> {
|
||||
public runCommand(accessor: ServicesAccessor, args: any): void | Thenable<void> {
|
||||
const codeEditorService = accessor.get(ICodeEditorService);
|
||||
|
||||
// Find the editor with text focus or active
|
||||
@@ -162,11 +162,11 @@ export abstract class EditorCommand extends Command {
|
||||
return;
|
||||
}
|
||||
|
||||
return this.runEditorCommand(editorAccessor, editor, args);
|
||||
return this.runEditorCommand(editorAccessor, editor!, args);
|
||||
});
|
||||
}
|
||||
|
||||
public abstract runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | TPromise<void>;
|
||||
public abstract runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | Thenable<void>;
|
||||
}
|
||||
|
||||
//#endregion EditorCommand
|
||||
@@ -187,7 +187,7 @@ export abstract class EditorAction extends EditorCommand {
|
||||
|
||||
public label: string;
|
||||
public alias: string;
|
||||
private menuOpts: IEditorCommandMenuOptions;
|
||||
private menuOpts: IEditorCommandMenuOptions | undefined;
|
||||
|
||||
constructor(opts: IActionOptions) {
|
||||
super(opts);
|
||||
@@ -213,7 +213,7 @@ export abstract class EditorAction extends EditorCommand {
|
||||
super.register();
|
||||
}
|
||||
|
||||
public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | TPromise<void> {
|
||||
public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | Thenable<void> {
|
||||
this.reportTelemetry(accessor, editor);
|
||||
return this.run(accessor, editor, args || {});
|
||||
}
|
||||
@@ -231,7 +231,7 @@ export abstract class EditorAction extends EditorCommand {
|
||||
accessor.get(ITelemetryService).publicLog('editorActionInvoked', { name: this.label, id: this.id, ...editor.getTelemetryData() });
|
||||
}
|
||||
|
||||
public abstract run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | TPromise<void>;
|
||||
public abstract run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | Thenable<void>;
|
||||
}
|
||||
|
||||
//#endregion EditorAction
|
||||
@@ -260,13 +260,23 @@ export function registerDefaultLanguageCommand(id: string, handler: (model: ITex
|
||||
}
|
||||
|
||||
const model = accessor.get(IModelService).getModel(resource);
|
||||
if (!model) {
|
||||
throw illegalArgument('Can not find open model for ' + resource);
|
||||
if (model) {
|
||||
const editorPosition = Position.lift(position);
|
||||
return handler(model, editorPosition, args);
|
||||
}
|
||||
|
||||
const editorPosition = Position.lift(position);
|
||||
|
||||
return handler(model, editorPosition, args);
|
||||
return accessor.get(ITextModelService).createModelReference(resource).then(reference => {
|
||||
return always(new Promise((resolve, reject) => {
|
||||
try {
|
||||
let result = handler(reference.object.textEditorModel, Position.lift(position), args);
|
||||
resolve(result);
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
}), () => {
|
||||
reference.dispose();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user