Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[plugin] register text decoration key in proper service #4827

Merged
merged 1 commit into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { TextEditorsMainImpl } from './text-editors-main';
import { EditorManager } from '@theia/editor/lib/browser';
import { OpenerService } from '@theia/core/lib/browser/opener-service';
import { MonacoBulkEditService } from '@theia/monaco/lib/browser/monaco-bulk-edit-service';
import { MonacoEditorService } from '@theia/monaco/lib/browser/monaco-editor-service';

export class EditorsAndDocumentsMain {
private toDispose = new DisposableCollection();
Expand Down Expand Up @@ -57,11 +58,12 @@ export class EditorsAndDocumentsMain {
const editorManager = container.get<EditorManager>(EditorManager);
const openerService = container.get<OpenerService>(OpenerService);
const bulkEditService = container.get<MonacoBulkEditService>(MonacoBulkEditService);
const monacoEditorService = container.get(MonacoEditorService);

const documentsMain = new DocumentsMainImpl(this, this.modelService, rpc, editorManager, openerService);
rpc.set(PLUGIN_RPC_CONTEXT.DOCUMENTS_MAIN, documentsMain);

const editorsMain = new TextEditorsMainImpl(this, rpc, bulkEditService);
const editorsMain = new TextEditorsMainImpl(this, rpc, bulkEditService, monacoEditorService);
rpc.set(PLUGIN_RPC_CONTEXT.TEXT_EDITORS_MAIN, editorsMain);

this.stateComputer = new EditorAndDocumentStateComputer(d => this.onDelta(d), editorService, this.modelService);
Expand Down
14 changes: 8 additions & 6 deletions packages/plugin-ext/src/main/browser/text-editors-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { TextEditorMain } from './text-editor-main';
import { disposed } from '../../common/errors';
import { reviveWorkspaceEditDto } from './languages-main';
import { MonacoBulkEditService } from '@theia/monaco/lib/browser/monaco-bulk-edit-service';
import { MonacoEditorService } from '@theia/monaco/lib/browser/monaco-editor-service';

export class TextEditorsMainImpl implements TextEditorsMain {

Expand All @@ -44,8 +45,9 @@ export class TextEditorsMainImpl implements TextEditorsMain {
private editorsToDispose = new Map<string, DisposableCollection>();

constructor(private readonly editorsAndDocuments: EditorsAndDocumentsMain,
rpc: RPCProtocol,
private readonly bulkEditService: MonacoBulkEditService) {
rpc: RPCProtocol,
private readonly bulkEditService: MonacoBulkEditService,
private readonly monacoEditorService: MonacoEditorService) {
this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.TEXT_EDITORS_EXT);
this.toDispose.push(editorsAndDocuments.onTextEditorAdd(editors => editors.forEach(this.onTextEditorAdd, this)));
this.toDispose.push(editorsAndDocuments.onTextEditorRemove(editors => editors.forEach(this.onTextEditorRemove, this)));
Expand Down Expand Up @@ -108,9 +110,9 @@ export class TextEditorsMainImpl implements TextEditorsMain {
}

$tryApplyWorkspaceEdit(dto: WorkspaceEditDto): Promise<boolean> {
const edits = reviveWorkspaceEditDto(dto);
const edits = reviveWorkspaceEditDto(dto);
return new Promise(resolve => {
this.bulkEditService.apply( edits).then(() => resolve(true), err => resolve(false));
this.bulkEditService.apply(edits).then(() => resolve(true), err => resolve(false));
});
}

Expand All @@ -122,11 +124,11 @@ export class TextEditorsMainImpl implements TextEditorsMain {
}

$registerTextEditorDecorationType(key: string, options: DecorationRenderOptions): void {
monaco.services.StaticServices.codeEditorService.get().registerDecorationType(key, options);
this.monacoEditorService.registerDecorationType(key, options);
}

$removeTextEditorDecorationType(key: string): void {
monaco.services.StaticServices.codeEditorService.get().removeDecorationType(key);
this.monacoEditorService.removeDecorationType(key);
}

$trySetDecorations(id: string, key: string, ranges: DecorationOptions[]): Promise<void> {
Expand Down