Skip to content

Commit

Permalink
fix #4459: register text decoration key in proper service
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Apr 6, 2019
1 parent 95c962c commit 44c49a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
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

0 comments on commit 44c49a6

Please sign in to comment.