Skip to content

Commit da14669

Browse files
committed
Simplify ModeServiceImpl
1 parent f13f22e commit da14669

2 files changed

Lines changed: 34 additions & 43 deletions

File tree

src/vs/editor/browser/standalone/standaloneServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export module StaticServices {
129129

130130
export const markerService = define(IMarkerService, () => new MarkerService());
131131

132-
export const modeService = define(IModeService, (o) => new ModeServiceImpl(instantiationService.get(o), extensionService.get(o)));
132+
export const modeService = define(IModeService, (o) => new ModeServiceImpl());
133133

134134
export const modelService = define(IModelService, (o) => new ModelServiceImpl(markerService.get(o), configurationService.get(o), messageService.get(o)));
135135

src/vs/editor/common/services/modeServiceImpl.ts

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import mime = require('vs/base/common/mime');
1313
import { IFilesConfiguration } from 'vs/platform/files/common/files';
1414
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
1515
import { IExtensionPoint, IExtensionPointUser, ExtensionMessageCollector, ExtensionsRegistry } from 'vs/platform/extensions/common/extensionsRegistry';
16-
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1716
import { IMode, LanguageId, LanguageIdentifier } from 'vs/editor/common/modes';
1817
import { FrankensteinMode } from 'vs/editor/common/modes/abstractMode';
1918
import { ModesRegistry } from 'vs/editor/common/modes/modesRegistry';
@@ -130,9 +129,6 @@ function isValidLanguageExtensionPoint(value: ILanguageExtensionPoint, collector
130129
export class ModeServiceImpl implements IModeService {
131130
public _serviceBrand: any;
132131

133-
private _instantiationService: IInstantiationService;
134-
protected _extensionService: IExtensionService;
135-
136132
private _instantiatedModes: { [modeId: string]: IMode; };
137133

138134
private _registry: LanguagesRegistry;
@@ -143,19 +139,17 @@ export class ModeServiceImpl implements IModeService {
143139
private _onDidCreateMode: Emitter<IMode> = new Emitter<IMode>();
144140
public onDidCreateMode: Event<IMode> = this._onDidCreateMode.event;
145141

146-
constructor(
147-
instantiationService: IInstantiationService,
148-
extensionService: IExtensionService
149-
) {
150-
this._instantiationService = instantiationService;
151-
this._extensionService = extensionService;
152-
142+
constructor() {
153143
this._instantiatedModes = {};
154144

155145
this._registry = new LanguagesRegistry();
156146
this._registry.onDidAddModes((modes) => this._onDidAddModes.fire(modes));
157147
}
158148

149+
protected _onReady(): TPromise<boolean> {
150+
return TPromise.as(true);
151+
}
152+
159153
public isRegisteredMode(mimetypeOrModeId: string): boolean {
160154
return this._registry.isRegisteredMode(mimetypeOrModeId);
161155
}
@@ -188,6 +182,16 @@ export class ModeServiceImpl implements IModeService {
188182
return this._registry.getModeIdForLanguageNameLowercase(alias);
189183
}
190184

185+
public getModeIdByFilenameOrFirstLine(filename: string, firstLine?: string): string {
186+
var modeIds = this._registry.getModeIdsFromFilenameOrFirstLine(filename, firstLine);
187+
188+
if (modeIds.length > 0) {
189+
return modeIds[0];
190+
}
191+
192+
return null;
193+
}
194+
191195
public getModeId(commaSeparatedMimetypesOrCommaSeparatedIds: string): string {
192196
var modeIds = this._registry.extractModeIds(commaSeparatedMimetypesOrCommaSeparatedIds);
193197

@@ -245,48 +249,34 @@ export class ModeServiceImpl implements IModeService {
245249
}
246250
}
247251

248-
public getModeIdByLanguageName(languageName: string): string {
249-
var modeIds = this._registry.getModeIdsFromLanguageName(languageName);
250-
251-
if (modeIds.length > 0) {
252-
return modeIds[0];
253-
}
254-
255-
return null;
256-
}
257-
258-
public getModeIdByFilenameOrFirstLine(filename: string, firstLine?: string): string {
259-
var modeIds = this._registry.getModeIdsFromFilenameOrFirstLine(filename, firstLine);
260-
261-
if (modeIds.length > 0) {
262-
return modeIds[0];
263-
}
264-
265-
return null;
266-
}
267-
268-
public onReady(): TPromise<boolean> {
269-
return this._extensionService.onReady();
270-
}
271-
272252
public getOrCreateMode(commaSeparatedMimetypesOrCommaSeparatedIds: string): TPromise<IMode> {
273-
return this.onReady().then(() => {
253+
return this._onReady().then(() => {
274254
var modeId = this.getModeId(commaSeparatedMimetypesOrCommaSeparatedIds);
275255
// Fall back to plain text if no mode was found
276256
return this._getOrCreateMode(modeId || 'plaintext');
277257
});
278258
}
279259

280260
public getOrCreateModeByLanguageName(languageName: string): TPromise<IMode> {
281-
return this.onReady().then(() => {
282-
var modeId = this.getModeIdByLanguageName(languageName);
261+
return this._onReady().then(() => {
262+
var modeId = this._getModeIdByLanguageName(languageName);
283263
// Fall back to plain text if no mode was found
284264
return this._getOrCreateMode(modeId || 'plaintext');
285265
});
286266
}
287267

268+
private _getModeIdByLanguageName(languageName: string): string {
269+
var modeIds = this._registry.getModeIdsFromLanguageName(languageName);
270+
271+
if (modeIds.length > 0) {
272+
return modeIds[0];
273+
}
274+
275+
return null;
276+
}
277+
288278
public getOrCreateModeByFilenameOrFirstLine(filename: string, firstLine?: string): TPromise<IMode> {
289-
return this.onReady().then(() => {
279+
return this._onReady().then(() => {
290280
var modeId = this.getModeIdByFilenameOrFirstLine(filename, firstLine);
291281
// Fall back to plain text if no mode was found
292282
return this._getOrCreateMode(modeId || 'plaintext');
@@ -306,15 +296,16 @@ export class ModeServiceImpl implements IModeService {
306296

307297
export class MainThreadModeServiceImpl extends ModeServiceImpl {
308298
private _configurationService: IConfigurationService;
299+
private _extensionService: IExtensionService;
309300
private _onReadyPromise: TPromise<boolean>;
310301

311302
constructor(
312-
@IInstantiationService instantiationService: IInstantiationService,
313303
@IExtensionService extensionService: IExtensionService,
314304
@IConfigurationService configurationService: IConfigurationService
315305
) {
316-
super(instantiationService, extensionService);
306+
super();
317307
this._configurationService = configurationService;
308+
this._extensionService = extensionService;
318309

319310
languagesExtPoint.setHandler((extensions: IExtensionPointUser<ILanguageExtensionPoint[]>[]) => {
320311
let allValidLanguages: IValidLanguageExtensionPoint[] = [];
@@ -356,7 +347,7 @@ export class MainThreadModeServiceImpl extends ModeServiceImpl {
356347
});
357348
}
358349

359-
public onReady(): TPromise<boolean> {
350+
protected _onReady(): TPromise<boolean> {
360351
if (!this._onReadyPromise) {
361352
const configuration = this._configurationService.getConfiguration<IFilesConfiguration>();
362353
this._onReadyPromise = this._extensionService.onReady().then(() => {

0 commit comments

Comments
 (0)