diff --git a/src/vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors.ts b/src/vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors.ts index 503b0a3254e..fda3bec2f7c 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors.ts @@ -315,7 +315,7 @@ export class MainThreadDocumentsAndEditors { const mainThreadDocuments = new MainThreadDocuments(this, extHostContext, this._modelService, modeService, this._textFileService, fileService, textModelResolverService, untitledEditorService); extHostContext.set(MainContext.MainThreadDocuments, mainThreadDocuments); - const mainThreadTextEditors = new MainThreadTextEditors(this, extHostContext, codeEditorService, bulkEditService, this._editorService, this._editorGroupService); + const mainThreadTextEditors = new MainThreadTextEditors(this, extHostContext, this._modelService, modeService, codeEditorService, bulkEditService, this._editorService, this._editorGroupService); extHostContext.set(MainContext.MainThreadTextEditors, mainThreadTextEditors); // It is expected that the ctor of the state computer calls our `_onDelta`. diff --git a/src/vs/workbench/api/electron-browser/mainThreadEditors.ts b/src/vs/workbench/api/electron-browser/mainThreadEditors.ts index 8636585f8c2..dfc675d2ec0 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadEditors.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadEditors.ts @@ -27,6 +27,8 @@ import { ExtHostContext, ExtHostEditorsShape, IExtHostContext, ITextDocumentShow import { MainThreadDocumentsAndEditors } from './mainThreadDocumentsAndEditors'; import { MainThreadTextEditor } from './mainThreadEditor'; import { IOpenerService } from 'vs/platform/opener/common/opener'; +import { IModeService } from 'vs/editor/common/services/modeService'; +import { IModelService } from 'vs/editor/common/services/modelService'; export class MainThreadTextEditors implements MainThreadTextEditorsShape { @@ -43,6 +45,8 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape { constructor( documentsAndEditors: MainThreadDocumentsAndEditors, extHostContext: IExtHostContext, + @IModelService private readonly _modelService: IModelService, + @IModeService private readonly _modeService: IModeService, @ICodeEditorService private readonly _codeEditorService: ICodeEditorService, @IBulkEditService private readonly _bulkEditService: IBulkEditService, @IEditorService private readonly _editorService: IEditorService, @@ -170,6 +174,22 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape { return TPromise.as(null); } + $trySetLanguageById(id: string, languageId: string): TPromise { + let mainThreadEditor = this._documentsAndEditors.getEditor(id); + if (!mainThreadEditor) { + return TPromise.wrapError(disposed(`TextEditor(${id})`)); + } + let textModel = mainThreadEditor.getModel(); + let modelService = this._modelService; + let modeService = this._modeService; + if (!modelService || !modeService) { + return TPromise.wrapError(new Error('modeService is null for some unit tests')); + } + let mode = modeService.getOrCreateModeByLanguageName(languageId); + modelService.setMode(textModel, mode); + return TPromise.as(null); + } + $trySetDecorations(id: string, key: string, ranges: IDecorationOptions[]): TPromise { key = `${this._instanceId}-${key}`; if (!this._documentsAndEditors.getEditor(id)) { diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 44947586fd5..d0d4b9c9756 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -193,6 +193,7 @@ export interface MainThreadTextEditorsShape extends IDisposable { $tryShowEditor(id: string, position: EditorViewColumn): TPromise; $tryHideEditor(id: string): TPromise; $trySetOptions(id: string, options: ITextEditorConfigurationUpdate): TPromise; + $trySetLanguageById(id: string, languageId: string): TPromise; $trySetDecorations(id: string, key: string, ranges: editorCommon.IDecorationOptions[]): TPromise; $trySetDecorationsFast(id: string, key: string, ranges: number[]): TPromise; $tryRevealRange(id: string, range: IRange, revealType: TextEditorRevealType): TPromise; diff --git a/src/vs/workbench/api/node/extHostTextEditor.ts b/src/vs/workbench/api/node/extHostTextEditor.ts index 0d9d7c2d9a7..62a1971ab7c 100644 --- a/src/vs/workbench/api/node/extHostTextEditor.ts +++ b/src/vs/workbench/api/node/extHostTextEditor.ts @@ -435,6 +435,10 @@ export class ExtHostTextEditor implements vscode.TextEditor { this._trySetSelection(); } + setLanguageById(language_id: string): void { + this._runOnProxy(() => this._proxy.$trySetLanguageById(this._id, language_id)); + } + setDecorations(decorationType: vscode.TextEditorDecorationType, ranges: Range[] | vscode.DecorationOptions[]): void { this._runOnProxy( () => { diff --git a/src/vs/workbench/test/electron-browser/api/extHostTextEditor.test.ts b/src/vs/workbench/test/electron-browser/api/extHostTextEditor.test.ts index ff187f60156..42e2dc3dacb 100644 --- a/src/vs/workbench/test/electron-browser/api/extHostTextEditor.test.ts +++ b/src/vs/workbench/test/electron-browser/api/extHostTextEditor.test.ts @@ -60,6 +60,7 @@ suite('ExtHostTextEditorOptions', () => { $removeTextEditorDecorationType: undefined, $tryShowEditor: undefined, $tryHideEditor: undefined, + $trySetLanguageById: undefined, $trySetDecorations: undefined, $trySetDecorationsFast: undefined, $tryRevealRange: undefined, diff --git a/src/vs/workbench/test/electron-browser/api/mainThreadEditors.test.ts b/src/vs/workbench/test/electron-browser/api/mainThreadEditors.test.ts index fdb4b5575c3..5bc1131da84 100644 --- a/src/vs/workbench/test/electron-browser/api/mainThreadEditors.test.ts +++ b/src/vs/workbench/test/electron-browser/api/mainThreadEditors.test.ts @@ -94,13 +94,15 @@ suite('MainThreadEditors', () => { } }); + const emptyModeService = null; + const documentAndEditor = new MainThreadDocumentsAndEditors( rpcProtocol, modelService, textFileService, workbenchEditorService, codeEditorService, - null, + emptyModeService, fileService, null, null, @@ -111,6 +113,8 @@ suite('MainThreadEditors', () => { editors = new MainThreadTextEditors( documentAndEditor, SingleProxyRPCProtocol(null), + modelService, + emptyModeService, codeEditorService, bulkEditService, workbenchEditorService,