Skip to content

Commit

Permalink
Align signatures
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
  • Loading branch information
RomanNikitenko committed Mar 1, 2020
1 parent 13bb4ef commit 1a0e2d5
Show file tree
Hide file tree
Showing 9 changed files with 336 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,7 @@ export abstract class QuickOpenBaseAction implements QuickOpenAction {
this.options.checked = value;
}

get radio(): boolean {
return this.options.radio || false;
}

set radio(value: boolean) {
this.options.radio = value;
}

abstract run(item?: QuickOpenItem): PromiseLike<void>;
abstract run(item?: QuickOpenItem): Promise<void>;

dispose(): void { }
}
3 changes: 1 addition & 2 deletions packages/core/src/common/quick-open-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,10 @@ export interface QuickOpenActionOptions {
class?: string | undefined;
enabled?: boolean;
checked?: boolean;
radio?: boolean;
}

export interface QuickOpenAction extends QuickOpenActionOptions, Disposable {
run(item?: QuickOpenItem): PromiseLike<void>;
run(item?: QuickOpenItem): Promise<void>;
}

export enum QuickTitleButtonSide {
Expand Down
2 changes: 1 addition & 1 deletion packages/monaco/src/browser/monaco-command-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class MonacoCommandService implements ICommandService {
async executeCommand(commandId: any, ...args: any[]): Promise<any> {
const handler = this.commandRegistry.getActiveHandler(commandId, ...args);
if (handler) {
this._onWillExecuteCommand.fire({ commandId });
this._onWillExecuteCommand.fire({ commandId, args });
return handler.execute(...args);
}
return this.executeMonacoCommand(commandId, ...args);
Expand Down
24 changes: 16 additions & 8 deletions packages/monaco/src/browser/monaco-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import { MonacoCommandRegistry, MonacoEditorCommandHandler } from './monaco-comm
import MenuRegistry = monaco.actions.MenuRegistry;
import { MonacoCommandService } from './monaco-command-service';

export type MonacoCommand = Command & { delegate?: string };
// vs code doesn't use iconClass anymore, but icon instead, so some adaptation is required to reuse it on theia side
export type MonacoIcon = { dark?: monaco.Uri; light?: monaco.Uri } | monaco.theme.ThemeIcon;
export type MonacoCommand = Command & { icon?: MonacoIcon, delegate?: string };
export namespace MonacoCommands {

export const UNDO = 'undo';
Expand Down Expand Up @@ -68,19 +70,20 @@ export namespace MonacoCommands {
'editor.action.clipboardCopyAction',
'editor.action.clipboardPasteAction'
]);
const iconClasses = new Map<string, string>();
const icons = new Map<string, MonacoIcon>();
for (const menuItem of MenuRegistry.getMenuItems(7)) {
// todo
if (menuItem.command && menuItem.command.iconClass) {
iconClasses.set(menuItem.command.id, menuItem.command.iconClass);

const commandItem = menuItem.command;
if (commandItem && commandItem.icon) {
icons.set(commandItem.id, commandItem.icon);
}
}
for (const command of monaco.editorExtensions.EditorExtensionsRegistry.getEditorActions()) {
const id = command.id;
if (!EXCLUDE_ACTIONS.has(id)) {
const label = command.label;
const iconClass = iconClasses.get(id);
ACTIONS.set(id, { id, label, iconClass });
const icon = icons.get(id);
ACTIONS.set(id, { id, label, icon });
}
}
for (const keybinding of monaco.keybindings.KeybindingsRegistry.getDefaultKeybindings()) {
Expand Down Expand Up @@ -280,7 +283,12 @@ export class MonacoEditorCommandHandlers implements CommandContribution {

protected newKeyboardHandler(action: string): MonacoEditorCommandHandler {
return {
execute: (editor, ...args) => editor.getControl()._modelData.cursor.trigger('keyboard', action, args)
execute: (editor, ...args) => {
const modelData = editor.getControl()._modelData;
if (modelData) {
modelData.cursor.trigger('keyboard', action, args);
}
}
};
}
protected newCommandHandler(action: string): MonacoEditorCommandHandler {
Expand Down
23 changes: 17 additions & 6 deletions packages/monaco/src/browser/monaco-editor-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,13 @@ export class MonacoEditorProvider {
*/
protected suppressMonacoKeybindingListener(editor: MonacoEditor): void {
let keydownListener: monaco.IDisposable | undefined;
for (const listener of editor.getControl()._standaloneKeybindingService._store._toDispose) {
const keybindingService = editor.getControl()._standaloneKeybindingService;
if (!keybindingService) {
console.warn('Cannot suppresses Monaco keydown listener because KeybindingService is not recognized');
return;
}

for (const listener of keybindingService._store._toDispose) {
if ('_type' in listener && listener['_type'] === 'keydown') {
keydownListener = listener;
break;
Expand All @@ -176,6 +182,11 @@ export class MonacoEditorProvider {

protected injectKeybindingResolver(editor: MonacoEditor): void {
const keybindingService = editor.getControl()._standaloneKeybindingService;
if (!keybindingService) {
console.warn('Cannot inject Keybinding Resolver because KeybindingService is not recognized');
return;
}

keybindingService.resolveKeybinding = keybinding => [new MonacoResolvedKeybinding(MonacoResolvedKeybinding.keySequence(keybinding), this.keybindingRegistry)];
keybindingService.resolveKeyboardEvent = keyboardEvent => {
const keybinding = new monaco.keybindings.SimpleKeybinding(
Expand Down Expand Up @@ -353,8 +364,10 @@ export class MonacoEditorProvider {
protected installReferencesController(editor: MonacoEditor): void {
const control = editor.getControl();
const referencesController = control._contributions['editor.contrib.referencesController'];
referencesController._gotoReference = ref => {
referencesController._widget.hide();
referencesController._gotoReference = async ref => {
if (referencesController._widget) {
referencesController._widget.hide();
}

referencesController._ignoreModelChangeEvent = true;
const range = monaco.Range.lift(ref.range).collapseToStart();
Expand Down Expand Up @@ -385,9 +398,7 @@ export class MonacoEditorProvider {

const modelPromise = Promise.resolve(model) as any;
modelPromise.cancel = () => { };
openedEditor._contributions['editor.contrib.referencesController'].toggleWidget(range, modelPromise, {
getMetaTitle: m => m.references.length > 1 ? ` – ${m.references.length} references` : ''
});
openedEditor._contributions['editor.contrib.referencesController'].toggleWidget(range, modelPromise, false);
return;
}

Expand Down
14 changes: 5 additions & 9 deletions packages/monaco/src/browser/monaco-quick-open-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ export class QuickOpenEntry extends monaco.quickOpen.QuickOpenEntry {
return this.item.getLabel();
}

getAriaLabel(): string | undefined {
return this.item.getTooltip();
getAriaLabel(): string {
return this.item.getTooltip() || '';
}

getDetail(): string | undefined {
Expand Down Expand Up @@ -500,7 +500,7 @@ export class QuickOpenEntryGroup extends monaco.quickOpen.QuickOpenEntryGroup {

}

export class MonacoQuickOpenAction implements monaco.quickOpen.IAction {
export class MonacoQuickOpenAction implements monaco.editor.IAction {
constructor(public readonly action: QuickOpenAction) { }

get id(): string {
Expand All @@ -527,12 +527,8 @@ export class MonacoQuickOpenAction implements monaco.quickOpen.IAction {
return this.action.checked || false;
}

get radio(): boolean {
return this.action.radio || false;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
run(entry: QuickOpenEntry | QuickOpenEntryGroup): PromiseLike<any> {
run(entry: QuickOpenEntry | QuickOpenEntryGroup): Promise<any> {
return this.action.run(entry.item);
}

Expand All @@ -550,7 +546,7 @@ export class MonacoQuickOpenActionProvider implements monaco.quickOpen.IActionPr
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
getActions(element: any, entry: QuickOpenEntry | QuickOpenEntryGroup): ReadonlyArray<monaco.quickOpen.IAction> {
getActions(element: any, entry: QuickOpenEntry | QuickOpenEntryGroup): ReadonlyArray<monaco.editor.IAction> {
const actions = this.provider.getActions(entry.item);
return actions.map(action => new MonacoQuickOpenAction(action));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/monaco/src/browser/monaco-resolved-keybinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class MonacoResolvedKeybinding extends monaco.keybindings.ResolvedKeybind
}

public getElectronAccelerator(): string | null {
if (this.isChord) {
if (this.isChord()) {
// Electron cannot handle chords
// eslint-disable-next-line no-null/no-null
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class MonacoSemanticHighlightingService extends SemanticHighlightingServi
// TODO: why for-of? How to pick the right scope? Is it fine to get the first element (with the narrowest scope)?
for (const scope of scopes) {
const tokenTheme = this.tokenTheme();
const metadata = tokenTheme.match(undefined, scope);
const metadata = tokenTheme.match(monaco.services.LanguageId.Null, scope);
// Don't use the inlineClassName from the TokenMetadata, because this
// will conflict with styles used for TM scopes
// (https://github.com/Microsoft/monaco-editor/issues/1070).
Expand Down
Loading

0 comments on commit 1a0e2d5

Please sign in to comment.