-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
7989-refactor-preview: Support for Refactor Preview functionality
Signed-off-by: Dan Arad <dan.arad@sap.com>
- Loading branch information
Showing
37 changed files
with
1,240 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** @type {import('eslint').Linter.Config} */ | ||
module.exports = { | ||
extends: [ | ||
'../../configs/build.eslintrc.json' | ||
], | ||
parserOptions: { | ||
tsconfigRootDir: __dirname, | ||
project: 'compile.tsconfig.json' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<div align='center'> | ||
|
||
<br /> | ||
|
||
<img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' /> | ||
|
||
<h2>ECLIPSE THEIA - BULK EDIT EXTENSION</h2> | ||
|
||
<hr /> | ||
|
||
</div> | ||
|
||
## Description | ||
|
||
The `@theia/bulk-edit` extension contributes a `Refactor Preview` widget to the application that displays WorkspaceEdits to end-users. | ||
|
||
## Additional Information | ||
|
||
- [API documentation for `@theia/bulk-edit`](https://eclipse-theia.github.io/theia/docs/next/modules/bulk-edit.html) | ||
- [Theia - GitHub](https://github.com/eclipse-theia/theia) | ||
- [Theia - Website](https://theia-ide.org/) | ||
|
||
## License | ||
|
||
- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/) | ||
- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp) | ||
|
||
## Trademark | ||
"Theia" is a trademark of the Eclipse Foundation | ||
https://www.eclipse.org/theia |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"extends": "../../configs/base.tsconfig", | ||
"compilerOptions": { | ||
"composite": true, | ||
"rootDir": "src", | ||
"outDir": "lib" | ||
}, | ||
"include": [ | ||
"src" | ||
], | ||
"references": [ | ||
{ | ||
"path": "../core/compile.tsconfig.json" | ||
}, | ||
{ | ||
"path": "../editor/compile.tsconfig.json" | ||
}, | ||
{ | ||
"path": "../filesystem/compile.tsconfig.json" | ||
}, | ||
{ | ||
"path": "../monaco/compile.tsconfig.json" | ||
}, | ||
{ | ||
"path": "../workspace/compile.tsconfig.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"name": "@theia/bulk-edit", | ||
"version": "1.10.0", | ||
"description": "Theia - Bulk Edit Extension", | ||
"dependencies": { | ||
"@theia/core": "^1.10.0", | ||
"@theia/editor": "^1.10.0", | ||
"@theia/filesystem": "^1.10.0", | ||
"@theia/monaco": "^1.10.0", | ||
"@theia/workspace": "^1.10.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"theiaExtensions": [ | ||
{ | ||
"frontend": "lib/browser/bulk-edit-frontend-module" | ||
} | ||
], | ||
"keywords": [ | ||
"theia-extension" | ||
], | ||
"license": "EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/eclipse-theia/theia.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/eclipse-theia/theia/issues" | ||
}, | ||
"homepage": "https://github.com/eclipse-theia/theia", | ||
"files": [ | ||
"lib", | ||
"src" | ||
], | ||
"scripts": { | ||
"lint": "theiaext lint", | ||
"build": "theiaext build", | ||
"watch": "theiaext watch", | ||
"clean": "theiaext clean", | ||
"test": "theiaext test" | ||
}, | ||
"devDependencies": { | ||
"@theia/ext-scripts": "^1.10.0" | ||
}, | ||
"nyc": { | ||
"extends": "../../configs/nyc.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021 SAP SE or an SAP affiliate company and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { Command } from '@theia/core/lib/common'; | ||
|
||
export namespace BulkEditCommands { | ||
export const TOGGLE_VIEW: Command = { | ||
id: 'bulk-edit:toggleView' | ||
}; | ||
|
||
export const APPLY: Command = { | ||
id: 'bulk-edit:apply', | ||
iconClass: 'codicon codicon-check' | ||
}; | ||
|
||
export const DISCARD: Command = { | ||
id: 'bulk-edit:discard', | ||
iconClass: 'clear-all' | ||
}; | ||
} |
114 changes: 114 additions & 0 deletions
114
packages/bulk-edit/src/browser/bulk-edit-contribution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021 SAP SE or an SAP affiliate company and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { injectable, inject } from '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'; | ||
|
||
export const BULK_EDIT_WIDGET_NAME = 'Refactor Preview'; | ||
|
||
@injectable() | ||
export class BulkEditContribution extends AbstractViewContribution<BulkEditTreeWidget> implements TabBarToolbarContribution { | ||
private workspaceEdit: monaco.languages.WorkspaceEdit; | ||
|
||
@inject(QuickViewService) | ||
protected readonly quickView: QuickViewService; | ||
|
||
constructor(private readonly bulkEditService: MonacoBulkEditService) { | ||
super({ | ||
widgetId: BULK_EDIT_TREE_WIDGET_ID, | ||
widgetName: BULK_EDIT_WIDGET_NAME, | ||
defaultWidgetOptions: { | ||
area: 'bottom' | ||
} | ||
}); | ||
this.bulkEditService.setPreviewHandler((edits: monaco.languages.WorkspaceEdit) => this.previewEdit(edits)); | ||
} | ||
|
||
registerCommands(registry: CommandRegistry): void { | ||
super.registerCommands(registry); | ||
this.quickView.hideItem(BULK_EDIT_WIDGET_NAME); | ||
|
||
registry.registerCommand(BulkEditCommands.APPLY, { | ||
isEnabled: widget => this.withWidget(widget, () => true), | ||
isVisible: widget => this.withWidget(widget, () => true), | ||
execute: widget => this.withWidget(widget, () => this.apply()) | ||
}); | ||
registry.registerCommand(BulkEditCommands.DISCARD, { | ||
isEnabled: widget => this.withWidget(widget, () => true), | ||
isVisible: widget => this.withWidget(widget, () => true), | ||
execute: widget => this.withWidget(widget, () => this.discard()) | ||
}); | ||
} | ||
|
||
async registerToolbarItems(toolbarRegistry: TabBarToolbarRegistry): Promise<void> { | ||
toolbarRegistry.registerItem({ | ||
id: BulkEditCommands.APPLY.id, | ||
command: BulkEditCommands.APPLY.id, | ||
tooltip: 'Apply Refactoring', | ||
priority: 0, | ||
}); | ||
toolbarRegistry.registerItem({ | ||
id: BulkEditCommands.DISCARD.id, | ||
command: BulkEditCommands.DISCARD.id, | ||
tooltip: 'Discard Refactoring', | ||
priority: 1, | ||
}); | ||
} | ||
|
||
protected withWidget<T>(widget: Widget | undefined = this.tryGetWidget(), cb: (bulkEdit: BulkEditTreeWidget) => T): T | false { | ||
if (widget instanceof BulkEditTreeWidget) { | ||
return cb(widget); | ||
} | ||
return false; | ||
} | ||
|
||
private async previewEdit(workspaceEdit: monaco.languages.WorkspaceEdit): Promise<monaco.languages.WorkspaceEdit> { | ||
const widget = await this.openView({ activate: true }); | ||
|
||
if (widget) { | ||
this.workspaceEdit = workspaceEdit; | ||
await widget.initModel(workspaceEdit); | ||
} | ||
|
||
return workspaceEdit; | ||
} | ||
|
||
private apply(): void { | ||
if (this.workspaceEdit?.edits) { | ||
this.workspaceEdit.edits.forEach(edit => { | ||
if (edit.metadata) { | ||
edit.metadata.needsConfirmation = false; | ||
} | ||
}); | ||
this.bulkEditService.apply(this.workspaceEdit); | ||
} | ||
this.closeView(); | ||
} | ||
|
||
private discard(): void { | ||
if (this.workspaceEdit) { | ||
this.workspaceEdit.edits = []; | ||
} | ||
this.closeView(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/bulk-edit/src/browser/bulk-edit-frontend-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021 SAP SE or an SAP affiliate company and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import { ContainerModule } from 'inversify'; | ||
import { WidgetFactory } from '@theia/core/lib/browser/widget-manager'; | ||
import { BulkEditTreeWidget, BULK_EDIT_TREE_WIDGET_ID, createBulkEditTreeWidget, InMemoryTextResourceResolver } from './bulk-edit-tree'; | ||
import { FrontendApplicationContribution, LabelProviderContribution } from '@theia/core/lib/browser'; | ||
import { bindViewContribution } from '@theia/core/lib/browser'; | ||
import { BulkEditContribution } from './bulk-edit-contribution'; | ||
import { TabBarToolbarContribution } from '@theia/core/lib/browser/shell/tab-bar-toolbar'; | ||
import { BulkEditTreeLabelProvider } from './bulk-edit-tree-label-provider'; | ||
import { ResourceResolver } from '@theia/core/lib/common'; | ||
import '../../src/browser/style/bulk-edit.css'; | ||
|
||
export default new ContainerModule(bind => { | ||
bind(BulkEditTreeWidget).toDynamicValue(ctx => | ||
createBulkEditTreeWidget(ctx.container) | ||
); | ||
bind(WidgetFactory).toDynamicValue(context => ({ | ||
id: BULK_EDIT_TREE_WIDGET_ID, | ||
createWidget: () => context.container.get(BulkEditTreeWidget) | ||
})); | ||
bindViewContribution(bind, BulkEditContribution); | ||
bind(FrontendApplicationContribution).toService(BulkEditContribution); | ||
bind(TabBarToolbarContribution).toService(BulkEditContribution); | ||
|
||
bind(BulkEditTreeLabelProvider).toSelf().inSingletonScope(); | ||
bind(LabelProviderContribution).toService(BulkEditTreeLabelProvider); | ||
|
||
bind(InMemoryTextResourceResolver).toSelf().inSingletonScope(); | ||
bind(ResourceResolver).toService(InMemoryTextResourceResolver); | ||
}); |
Oops, something went wrong.