mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-03 06:51:53 +01:00
Add two alternative language-changing interface functions
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
'use strict';
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import URI, { UriComponents } from 'vs/base/common/uri';
|
||||
import { IModeService } from 'vs/editor/common/services/modeService';
|
||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
import { MainThreadLanguagesShape, MainContext, IExtHostContext } from '../node/extHost.protocol';
|
||||
import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
|
||||
|
||||
@@ -13,12 +15,15 @@ import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostC
|
||||
export class MainThreadLanguages implements MainThreadLanguagesShape {
|
||||
|
||||
private _modeService: IModeService;
|
||||
private _modelService: IModelService;
|
||||
|
||||
constructor(
|
||||
extHostContext: IExtHostContext,
|
||||
@IModeService modeService: IModeService
|
||||
@IModeService modeService: IModeService,
|
||||
@IModelService modelService: IModelService
|
||||
) {
|
||||
this._modeService = modeService;
|
||||
this._modelService = modelService;
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
@@ -27,4 +32,15 @@ export class MainThreadLanguages implements MainThreadLanguagesShape {
|
||||
$getLanguages(): TPromise<string[]> {
|
||||
return TPromise.as(this._modeService.getRegisteredModes());
|
||||
}
|
||||
|
||||
$setLanguageById(resource: UriComponents, languageId: string): TPromise<void> {
|
||||
const uri = URI.revive(resource);
|
||||
let model = this._modelService.getModel(uri);
|
||||
if (!model) {
|
||||
return TPromise.wrapError(new Error('Invalid uri'));
|
||||
}
|
||||
let mode = this._modeService.getOrCreateModeByLanguageId(languageId);
|
||||
this._modelService.setMode(model, mode);
|
||||
return TPromise.as(null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user