Skip to content

Commit

Permalink
8969-upgrade-monaco-editor-core-to-standalone-0.23.x (eclipse-theia#9154
Browse files Browse the repository at this point in the history
)

In preparation for upgrading monaco-editor-core to standalone/0.23.x these changes were implemented:
1) signatures alignment to standalone/0.23.x
2) editor preferences synced with standalone/0.23.x
3) Changes to theme services based on changes in 0.23.x
4) Removal of QuickOpen modules and implementing QuickInput instead

Signed-off-by: Esther Perelman <esther.perelman@sap.com>
Co-authored-by: Esther Perelman <esther.perelman@sap.com>
  • Loading branch information
2 people authored and dna2github committed Aug 25, 2021
1 parent 982eee3 commit e42ef00
Show file tree
Hide file tree
Showing 135 changed files with 4,954 additions and 5,524 deletions.
2 changes: 1 addition & 1 deletion examples/api-tests/src/typescript.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ module.exports = (port, host, argv) => Promise.resolve()

const suggest = editor.getControl()._contributions['editor.contrib.suggestController'];
const getFocusedLabel = () => {
const focusedItem = suggest.widget.getValue().getFocusedItem();
const focusedItem = suggest.widget.getFocusedItem();
return focusedItem && focusedItem.item.completion.label;
};

Expand Down
30 changes: 14 additions & 16 deletions packages/bulk-edit/src/browser/bulk-edit-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable, inject } from '@theia/core/shared/inversify';
import { injectable, inject, optional } from '@theia/core/shared/inversify';
import { Widget } from '@theia/core/lib/browser/widgets/widget';
import { CommandRegistry } from '@theia/core/lib/common';
import { AbstractViewContribution } from '@theia/core/lib/browser/shell/view-contribution';
import { BulkEditCommands } from './bulk-edit-commands';
import { MonacoBulkEditService } from '@theia/monaco/lib/browser/monaco-bulk-edit-service';
import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
import { BulkEditTreeWidget, BULK_EDIT_TREE_WIDGET_ID } from './bulk-edit-tree';
import { QuickViewService } from '@theia/core/lib/browser/quick-view-service';
import { QuickViewService } from '@theia/core/lib/browser';

export const BULK_EDIT_WIDGET_NAME = 'Refactor Preview';

@injectable()
export class BulkEditContribution extends AbstractViewContribution<BulkEditTreeWidget> implements TabBarToolbarContribution {
private workspaceEdit: monaco.languages.WorkspaceEdit;
private edits: monaco.editor.ResourceEdit[];

@inject(QuickViewService)
@inject(QuickViewService) @optional()
protected readonly quickView: QuickViewService;

constructor(private readonly bulkEditService: MonacoBulkEditService) {
Expand All @@ -41,12 +41,12 @@ export class BulkEditContribution extends AbstractViewContribution<BulkEditTreeW
area: 'bottom'
}
});
this.bulkEditService.setPreviewHandler((edits: monaco.languages.WorkspaceEdit) => this.previewEdit(edits));
this.bulkEditService.setPreviewHandler((edits: monaco.editor.ResourceEdit[]) => this.previewEdit(edits));
}

registerCommands(registry: CommandRegistry): void {
super.registerCommands(registry);
this.quickView.hideItem(BULK_EDIT_WIDGET_NAME);
this.quickView?.hideItem(BULK_EDIT_WIDGET_NAME);

registry.registerCommand(BulkEditCommands.APPLY, {
isEnabled: widget => this.withWidget(widget, () => true),
Expand Down Expand Up @@ -82,33 +82,31 @@ export class BulkEditContribution extends AbstractViewContribution<BulkEditTreeW
return false;
}

private async previewEdit(workspaceEdit: monaco.languages.WorkspaceEdit): Promise<monaco.languages.WorkspaceEdit> {
private async previewEdit(edits: monaco.editor.ResourceEdit[]): Promise<monaco.editor.ResourceEdit[]> {
const widget = await this.openView({ activate: true });

if (widget) {
this.workspaceEdit = workspaceEdit;
await widget.initModel(workspaceEdit);
this.edits = edits;
await widget.initModel(edits);
}

return workspaceEdit;
return edits;
}

private apply(): void {
if (this.workspaceEdit?.edits) {
this.workspaceEdit.edits.forEach(edit => {
if (this.edits) {
this.edits.forEach(edit => {
if (edit.metadata) {
edit.metadata.needsConfirmation = false;
}
});
this.bulkEditService.apply(this.workspaceEdit);
this.bulkEditService.apply(this.edits);
}
this.closeView();
}

private discard(): void {
if (this.workspaceEdit) {
this.workspaceEdit.edits = [];
}
this.edits = [];
this.closeView();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { SelectionService } from '@theia/core/lib/common/selection-service';
import { SelectionCommandHandler } from '@theia/core/lib/common/selection-command-handler';

export interface BulkEditNodeSelection {
bulkEdit: monaco.languages.WorkspaceTextEdit | monaco.languages.WorkspaceFileEdit;
bulkEdit: monaco.editor.ResourceFileEdit | monaco.editor.ResourceTextEdit;
}
export namespace BulkEditNodeSelection {
export function is(arg: Object | undefined): arg is BulkEditNodeSelection {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class BulkEditTreeModel extends TreeModelImpl {
this.doOpenNode(node);
}

async initModel(workspaceEdit: monaco.languages.WorkspaceEdit, fileContents: Map<string, string>): Promise<void> {
this.tree.initTree(workspaceEdit, fileContents);
async initModel(edits: monaco.editor.ResourceEdit[], fileContents: Map<string, string>): Promise<void> {
this.tree.initTree(edits, fileContents);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable, inject } from '@theia/core/shared/inversify';
import { injectable, inject, optional } from '@theia/core/shared/inversify';
import {
TreeWidget, TreeProps, ContextMenuRenderer, TreeNode, TreeModel,
CompositeTreeNode, NodeProps
CompositeTreeNode, NodeProps, QuickViewService
} from '@theia/core/lib/browser';
import * as React from '@theia/core/shared/react';
import { BulkEditInfoNode, BulkEditNode } from './bulk-edit-tree';
Expand All @@ -28,7 +28,6 @@ import { EditorWidget, EditorManager, EditorOpenerOptions } from '@theia/editor/
import { DiffUris } from '@theia/core/lib/browser';
import { MEMORY_TEXT } from '@theia/core/lib/common';
import { Disposable } from '@theia/core/lib/common/disposable';
import { QuickViewService } from '@theia/core/lib/browser/quick-view-service';

export const BULK_EDIT_TREE_WIDGET_ID = 'bulkedit';
export const BULK_EDIT_WIDGET_NAME = 'Refactor Preview';
Expand All @@ -43,7 +42,7 @@ export class BulkEditTreeWidget extends TreeWidget {
@inject(EditorManager)
protected readonly editorManager: EditorManager;

@inject(QuickViewService)
@inject(QuickViewService) @optional()
protected readonly quickView: QuickViewService;

constructor(
Expand All @@ -64,9 +63,9 @@ export class BulkEditTreeWidget extends TreeWidget {
}));
}

async initModel(workspaceEdit: monaco.languages.WorkspaceEdit): Promise<void> {
await this.model.initModel(workspaceEdit, await this.getFileContentsMap(workspaceEdit));
this.quickView.showItem(BULK_EDIT_WIDGET_NAME);
async initModel(edits: monaco.editor.ResourceEdit[]): Promise<void> {
await this.model.initModel(edits, await this.getFileContentsMap(edits));
this.quickView?.showItem(BULK_EDIT_WIDGET_NAME);
}

protected handleClickEvent(node: TreeNode | undefined, event: React.MouseEvent<HTMLElement>): void {
Expand Down Expand Up @@ -109,17 +108,17 @@ export class BulkEditTreeWidget extends TreeWidget {
}

protected decorateBulkEditNode(node: BulkEditNode): React.ReactNode {
if (node?.parent && node?.bulkEdit && ('edit' in node?.bulkEdit)) {
if (node?.parent && node?.bulkEdit && ('textEdit' in node?.bulkEdit)) {
const bulkEdit = node.bulkEdit;
const parent = node.parent as BulkEditInfoNode;

if (parent?.fileContents) {
const lines = parent.fileContents.split('\n');
const startLineNum = +bulkEdit.edit.range.startLineNumber;
const startLineNum = +bulkEdit.textEdit?.range?.startLineNumber;

if (lines.length > startLineNum) {
const startColumn = +bulkEdit.edit.range.startColumn;
const endColumn = +bulkEdit.edit.range.endColumn;
const startColumn = +bulkEdit.textEdit.range.startColumn;
const endColumn = +bulkEdit.textEdit.range.endColumn;
const lineText = lines[startLineNum - 1];
const beforeMatch = (startColumn > 26 ? '... ' : '') + lineText.substr(0, startColumn - 1).substr(-25);
const replacedText = lineText.substring(startColumn - 1, endColumn - 1);
Expand All @@ -129,7 +128,7 @@ export class BulkEditTreeWidget extends TreeWidget {
<div className='message'>
{beforeMatch}
<span className="replaced-text">{replacedText}</span>
<span className="inserted-text">{bulkEdit.edit.text}</span>
<span className="inserted-text">{bulkEdit.textEdit.text}</span>
{afterMatch}
</div>
</div>;
Expand All @@ -150,13 +149,14 @@ export class BulkEditTreeWidget extends TreeWidget {
</div>;
}

private async getFileContentsMap(workspaceEdit: monaco.languages.WorkspaceEdit): Promise<Map<string, string>> {
private async getFileContentsMap(edits: monaco.editor.ResourceEdit[]): Promise<Map<string, string>> {
const fileContentMap = new Map<string, string>();

if (workspaceEdit?.edits) {
for (const element of workspaceEdit.edits) {
if (edits) {
for (const element of edits) {
if (element) {
const filePath = (('newUri' in element) && element?.newUri?.path) || (('resource' in element) && element?.resource?.path);
const filePath = (('newResource' in element) && (element as monaco.editor.ResourceFileEdit).newResource?.path) ||
(('resource' in element) && (element as monaco.editor.ResourceTextEdit).resource.path);

if (filePath && !fileContentMap.has(filePath)) {
const fileUri = new URI(filePath).withScheme('file');
Expand Down Expand Up @@ -186,16 +186,16 @@ export class BulkEditTreeWidget extends TreeWidget {
if (bulkEditInfoNode?.fileContents) {
lines = bulkEditInfoNode.fileContents.split('\n');
bulkEditInfoNode.children.map((node: BulkEditNode) => {
if (node.bulkEdit && ('edit' in node.bulkEdit)) {
const startLineNum = node.bulkEdit.edit.range.startLineNumber;
if (node.bulkEdit && ('textEdit' in node.bulkEdit)) {
const startLineNum = node.bulkEdit.textEdit.range.startLineNumber;
if (lines.length > startLineNum) {
const startColumn = node.bulkEdit.edit.range.startColumn;
const endColumn = node.bulkEdit.edit.range.endColumn;
const startColumn = node.bulkEdit.textEdit.range.startColumn;
const endColumn = node.bulkEdit.textEdit.range.endColumn;
const lineText = lines[startLineNum - 1];
const beforeMatch = lineText.substr(0, startColumn - 1);
const replacedText = lineText.substring(startColumn - 1, endColumn - 1);
const afterMatch = lineText.substr(startColumn - 1 + replacedText.length);
lines[startLineNum - 1] = beforeMatch + node.bulkEdit.edit.text + afterMatch;
lines[startLineNum - 1] = beforeMatch + node.bulkEdit.textEdit.text + afterMatch;
}
}
});
Expand All @@ -206,16 +206,16 @@ export class BulkEditTreeWidget extends TreeWidget {

private getEditorOptions(node: BulkEditNode): EditorOpenerOptions {
let options = {};
if (('edit' in node.bulkEdit) && node?.bulkEdit?.edit?.range) {
if (('textEdit' in node.bulkEdit) && node?.bulkEdit?.textEdit?.range) {
options = {
selection: {
start: {
line: node.bulkEdit.edit.range.startLineNumber - 1,
character: node.bulkEdit.edit.range.startColumn - 1
line: node.bulkEdit.textEdit.range.startLineNumber - 1,
character: node.bulkEdit.textEdit.range.startColumn - 1
},
end: {
line: node.bulkEdit.edit.range.endLineNumber - 1,
character: node.bulkEdit.edit.range.endColumn - 1
line: node.bulkEdit.textEdit.range.endLineNumber - 1,
character: node.bulkEdit.textEdit.range.endColumn - 1
}
}
};
Expand All @@ -225,6 +225,6 @@ export class BulkEditTreeWidget extends TreeWidget {

private disposeEditors(): void {
this.editorWidgets.forEach(w => w.dispose());
this.quickView.hideItem(BULK_EDIT_WIDGET_NAME);
this.quickView?.hideItem(BULK_EDIT_WIDGET_NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const expect = chai.expect;
let bulkEditTree: BulkEditTree;
let testContainer: Container;
const fileContextsMap = new Map<string, string>();
let workspaceEdit: monaco.languages.WorkspaceEdit;
let resourceTextEdits: monaco.editor.ResourceTextEdit[];

disableJSDOM();

Expand All @@ -51,15 +51,14 @@ before(() => {
fileContextsMap.set('/c:/test1.ts', 'aaaaaaaaaaaaaaaaaaa');
fileContextsMap.set('/c:/test2.ts', 'bbbbbbbbbbbbbbbbbbb');

workspaceEdit = <monaco.languages.WorkspaceEdit><unknown>{
'edits': [
resourceTextEdits = <monaco.editor.ResourceTextEdit[]><unknown>[
{
'resource': {
'$mid': 1,
'path': '/c:/test1.ts',
'scheme': 'file'
},
'edit': {
'textEdit': {
'text': 'AAAAA', 'range': { 'startLineNumber': 1, 'startColumn': 5, 'endLineNumber': 1, 'endColumn': 10 }
}
},
Expand All @@ -68,12 +67,11 @@ before(() => {
'$mid': 1,
'path': '/c:/test2.ts',
'scheme': 'file'
}, 'edit': {
}, 'textEdit': {
'text': 'BBBBBB', 'range': { 'startLineNumber': 1, 'startColumn': 3, 'endLineNumber': 1, 'endColumn': 8 }
}
}
]
};
];
});

after(() => {
Expand All @@ -82,7 +80,7 @@ after(() => {

describe('bulk-edit-tree', () => {
it('initialize tree', () => {
bulkEditTree.initTree(workspaceEdit, fileContextsMap);
bulkEditTree.initTree(resourceTextEdits, fileContextsMap);
expect((bulkEditTree.root as BulkEditInfoNode).children.length).is.equal(2);
});
});
29 changes: 16 additions & 13 deletions packages/bulk-edit/src/browser/bulk-edit-tree/bulk-edit-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,43 @@ import { TreeNode, CompositeTreeNode, SelectableTreeNode, ExpandableTreeNode, Tr
import { UriSelection } from '@theia/core/lib/common/selection';
import { BulkEditNodeSelection } from './bulk-edit-node-selection';
import URI from '@theia/core/lib/common/uri';
import { WorkspaceFileEdit, WorkspaceTextEdit } from '@theia/monaco/lib/browser/monaco-workspace';
import { ResourceFileEdit, ResourceTextEdit } from '@theia/monaco/lib/browser/monaco-workspace';

@injectable()
export class BulkEditTree extends TreeImpl {
public async initTree(workspaceEdit: monaco.languages.WorkspaceEdit, fileContents: Map<string, string>): Promise<void> {
public async initTree(edits: monaco.editor.ResourceEdit[], fileContents: Map<string, string>): Promise<void> {
this.root = <CompositeTreeNode>{
visible: false,
id: 'theia-bulk-edit-tree-widget',
name: 'BulkEditTree',
children: this.getChildren(workspaceEdit, fileContents),
children: this.getChildren(edits, fileContents),
parent: undefined
};
}

private getChildren(workspaceEdit: monaco.languages.WorkspaceEdit, fileContentsMap: Map<string, string>): BulkEditInfoNode[] {
private getChildren(edits: monaco.editor.ResourceEdit[], fileContentsMap: Map<string, string>): BulkEditInfoNode[] {
let bulkEditInfos: BulkEditInfoNode[] = [];
if (workspaceEdit.edits) {
bulkEditInfos = workspaceEdit.edits
if (edits) {
bulkEditInfos = edits
.map(edit => this.getResourcePath(edit))
.filter((path, index, arr) => path && arr.indexOf(path) === index)
.map((path: string) => this.createBulkEditInfo(path, new URI(path), fileContentsMap.get(path)))
.filter(Boolean);

if (bulkEditInfos.length > 0) {
bulkEditInfos.forEach(editInfo => {
editInfo.children = workspaceEdit.edits.filter(edit => ((('resource' in edit) && edit?.resource?.path === editInfo.id)) ||
(('newUri' in edit) && edit?.newUri?.path === editInfo.id))
.map((edit, index) => this.createBulkEditNode(edit, index, editInfo));
editInfo.children = edits.filter(edit =>
((('resource' in edit) && (edit as monaco.editor.ResourceTextEdit)?.resource?.path === editInfo.id)) ||
(('newResource' in edit) && (edit as monaco.editor.ResourceFileEdit)?.newResource?.path === editInfo.id))
.map((edit, index) => this.createBulkEditNode(('resource' in edit ? edit as monaco.editor.ResourceTextEdit :
edit as monaco.editor.ResourceFileEdit), index, editInfo));
});
}
}
return bulkEditInfos;
}

private createBulkEditNode(bulkEdit: monaco.languages.WorkspaceTextEdit | monaco.languages.WorkspaceFileEdit, index: number, parent: BulkEditInfoNode): BulkEditNode {
private createBulkEditNode(bulkEdit: monaco.editor.ResourceFileEdit | monaco.editor.ResourceTextEdit, index: number, parent: BulkEditInfoNode): BulkEditNode {
const id = parent.id + '_' + index;
const existing = this.getNode(id);
if (BulkEditNode.is(existing)) {
Expand Down Expand Up @@ -82,14 +84,15 @@ export class BulkEditTree extends TreeImpl {
};
}

private getResourcePath(edit: monaco.languages.WorkspaceTextEdit | monaco.languages.WorkspaceFileEdit): string | undefined {
return WorkspaceTextEdit.is(edit) ? edit.resource.path : WorkspaceFileEdit.is(edit) && edit.newUri ? edit.newUri.path : undefined;
private getResourcePath(edit: monaco.editor.ResourceEdit): string | undefined {
return ResourceTextEdit.is(edit) ? edit.resource.path :
ResourceFileEdit.is(edit) && edit.newResource ? edit.newResource.path : undefined;
}
}

export interface BulkEditNode extends UriSelection, SelectableTreeNode {
parent: CompositeTreeNode;
bulkEdit: monaco.languages.WorkspaceTextEdit | monaco.languages.WorkspaceFileEdit;
bulkEdit: monaco.editor.ResourceFileEdit | monaco.editor.ResourceTextEdit;
}
export namespace BulkEditNode {
export function is(node: TreeNode | undefined): node is BulkEditNode {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/browser/color-application-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export class ColorApplicationContribution implements FrontendApplicationContribu
}

this.updateThemeBackground();
ThemeService.get().onThemeChange(() => this.updateThemeBackground());
ThemeService.get().onDidColorThemeChange(() => this.updateThemeBackground());

this.update();
ThemeService.get().onThemeChange(() => this.update());
ThemeService.get().onDidColorThemeChange(() => this.update());
this.colors.onDidChange(() => this.update());
}

Expand Down
Loading

0 comments on commit e42ef00

Please sign in to comment.