Skip to content

Commit 97570d9

Browse files
committed
Move MainThreadModeServiceImpl to /workbench/
1 parent da14669 commit 97570d9

3 files changed

Lines changed: 151 additions & 139 deletions

File tree

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

Lines changed: 2 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@
77
import * as nls from 'vs/nls';
88
import { onUnexpectedError } from 'vs/base/common/errors';
99
import Event, { Emitter } from 'vs/base/common/event';
10-
import * as paths from 'vs/base/common/paths';
1110
import { TPromise } from 'vs/base/common/winjs.base';
12-
import mime = require('vs/base/common/mime');
13-
import { IFilesConfiguration } from 'vs/platform/files/common/files';
14-
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
15-
import { IExtensionPoint, IExtensionPointUser, ExtensionMessageCollector, ExtensionsRegistry } from 'vs/platform/extensions/common/extensionsRegistry';
11+
import { IExtensionPoint, ExtensionsRegistry } from 'vs/platform/extensions/common/extensionsRegistry';
1612
import { IMode, LanguageId, LanguageIdentifier } from 'vs/editor/common/modes';
1713
import { FrankensteinMode } from 'vs/editor/common/modes/abstractMode';
18-
import { ModesRegistry } from 'vs/editor/common/modes/modesRegistry';
1914
import { LanguagesRegistry } from 'vs/editor/common/services/languagesRegistry';
20-
import { ILanguageExtensionPoint, IValidLanguageExtensionPoint, IModeLookupResult, IModeService } from 'vs/editor/common/services/modeService';
21-
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
15+
import { ILanguageExtensionPoint, IModeLookupResult, IModeService } from 'vs/editor/common/services/modeService';
2216

2317
export const languagesExtPoint: IExtensionPoint<ILanguageExtensionPoint[]> = ExtensionsRegistry.registerExtensionPoint<ILanguageExtensionPoint[]>('languages', [], {
2418
description: nls.localize('vscode.extension.contributes.languages', 'Contributes language declarations.'),
@@ -80,52 +74,6 @@ export const languagesExtPoint: IExtensionPoint<ILanguageExtensionPoint[]> = Ext
8074
}
8175
});
8276

83-
function isUndefinedOrStringArray(value: string[]): boolean {
84-
if (typeof value === 'undefined') {
85-
return true;
86-
}
87-
if (!Array.isArray(value)) {
88-
return false;
89-
}
90-
return value.every(item => typeof item === 'string');
91-
}
92-
93-
function isValidLanguageExtensionPoint(value: ILanguageExtensionPoint, collector: ExtensionMessageCollector): boolean {
94-
if (!value) {
95-
collector.error(nls.localize('invalid.empty', "Empty value for `contributes.{0}`", languagesExtPoint.name));
96-
return false;
97-
}
98-
if (typeof value.id !== 'string') {
99-
collector.error(nls.localize('require.id', "property `{0}` is mandatory and must be of type `string`", 'id'));
100-
return false;
101-
}
102-
if (!isUndefinedOrStringArray(value.extensions)) {
103-
collector.error(nls.localize('opt.extensions', "property `{0}` can be omitted and must be of type `string[]`", 'extensions'));
104-
return false;
105-
}
106-
if (!isUndefinedOrStringArray(value.filenames)) {
107-
collector.error(nls.localize('opt.filenames', "property `{0}` can be omitted and must be of type `string[]`", 'filenames'));
108-
return false;
109-
}
110-
if (typeof value.firstLine !== 'undefined' && typeof value.firstLine !== 'string') {
111-
collector.error(nls.localize('opt.firstLine', "property `{0}` can be omitted and must be of type `string`", 'firstLine'));
112-
return false;
113-
}
114-
if (typeof value.configuration !== 'undefined' && typeof value.configuration !== 'string') {
115-
collector.error(nls.localize('opt.configuration', "property `{0}` can be omitted and must be of type `string`", 'configuration'));
116-
return false;
117-
}
118-
if (!isUndefinedOrStringArray(value.aliases)) {
119-
collector.error(nls.localize('opt.aliases', "property `{0}` can be omitted and must be of type `string[]`", 'aliases'));
120-
return false;
121-
}
122-
if (!isUndefinedOrStringArray(value.mimetypes)) {
123-
collector.error(nls.localize('opt.mimetypes', "property `{0}` can be omitted and must be of type `string[]`", 'mimetypes'));
124-
return false;
125-
}
126-
return true;
127-
}
128-
12977
export class ModeServiceImpl implements IModeService {
13078
public _serviceBrand: any;
13179

@@ -293,86 +241,3 @@ export class ModeServiceImpl implements IModeService {
293241
return this._instantiatedModes[modeId];
294242
}
295243
}
296-
297-
export class MainThreadModeServiceImpl extends ModeServiceImpl {
298-
private _configurationService: IConfigurationService;
299-
private _extensionService: IExtensionService;
300-
private _onReadyPromise: TPromise<boolean>;
301-
302-
constructor(
303-
@IExtensionService extensionService: IExtensionService,
304-
@IConfigurationService configurationService: IConfigurationService
305-
) {
306-
super();
307-
this._configurationService = configurationService;
308-
this._extensionService = extensionService;
309-
310-
languagesExtPoint.setHandler((extensions: IExtensionPointUser<ILanguageExtensionPoint[]>[]) => {
311-
let allValidLanguages: IValidLanguageExtensionPoint[] = [];
312-
313-
for (let i = 0, len = extensions.length; i < len; i++) {
314-
let extension = extensions[i];
315-
316-
if (!Array.isArray(extension.value)) {
317-
extension.collector.error(nls.localize('invalid', "Invalid `contributes.{0}`. Expected an array.", languagesExtPoint.name));
318-
continue;
319-
}
320-
321-
for (let j = 0, lenJ = extension.value.length; j < lenJ; j++) {
322-
let ext = extension.value[j];
323-
if (isValidLanguageExtensionPoint(ext, extension.collector)) {
324-
let configuration = (ext.configuration ? paths.join(extension.description.extensionFolderPath, ext.configuration) : ext.configuration);
325-
allValidLanguages.push({
326-
id: ext.id,
327-
extensions: ext.extensions,
328-
filenames: ext.filenames,
329-
filenamePatterns: ext.filenamePatterns,
330-
firstLine: ext.firstLine,
331-
aliases: ext.aliases,
332-
mimetypes: ext.mimetypes,
333-
configuration: configuration
334-
});
335-
}
336-
}
337-
}
338-
339-
ModesRegistry.registerLanguages(allValidLanguages);
340-
341-
});
342-
343-
this._configurationService.onDidUpdateConfiguration(e => this.onConfigurationChange(e.config));
344-
345-
this.onDidCreateMode((mode) => {
346-
this._extensionService.activateByEvent(`onLanguage:${mode.getId()}`).done(null, onUnexpectedError);
347-
});
348-
}
349-
350-
protected _onReady(): TPromise<boolean> {
351-
if (!this._onReadyPromise) {
352-
const configuration = this._configurationService.getConfiguration<IFilesConfiguration>();
353-
this._onReadyPromise = this._extensionService.onReady().then(() => {
354-
this.onConfigurationChange(configuration);
355-
356-
return true;
357-
});
358-
}
359-
360-
return this._onReadyPromise;
361-
}
362-
363-
private onConfigurationChange(configuration: IFilesConfiguration): void {
364-
365-
// Clear user configured mime associations
366-
mime.clearTextMimes(true /* user configured */);
367-
368-
// Register based on settings
369-
if (configuration.files && configuration.files.associations) {
370-
Object.keys(configuration.files.associations).forEach(pattern => {
371-
const langId = configuration.files.associations[pattern];
372-
const mimetype = this.getMimeForMode(langId) || `text/x-${langId}`;
373-
374-
mime.registerTextMime({ id: langId, mime: mimetype, filepattern: pattern, userConfigured: true });
375-
});
376-
}
377-
}
378-
}

src/vs/workbench/electron-browser/shell.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
6868
import { CommandService } from 'vs/platform/commands/common/commandService';
6969
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
7070
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
71-
import { MainThreadModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
71+
import { WorkbenchModeServiceImpl } from 'vs/workbench/services/mode/common/workbenchModeService';
7272
import { IModeService } from 'vs/editor/common/services/modeService';
7373
import { IUntitledEditorService, UntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
7474
import { CrashReporter } from 'vs/workbench/electron-browser/crashReporter';
@@ -346,7 +346,7 @@ export class WorkbenchShell {
346346

347347
serviceCollection.set(IMarkerService, new SyncDescriptor(MarkerService));
348348

349-
serviceCollection.set(IModeService, new SyncDescriptor(MainThreadModeServiceImpl));
349+
serviceCollection.set(IModeService, new SyncDescriptor(WorkbenchModeServiceImpl));
350350

351351
serviceCollection.set(IModelService, new SyncDescriptor(ModelServiceImpl));
352352

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
'use strict';
6+
7+
import * as nls from 'vs/nls';
8+
import { onUnexpectedError } from 'vs/base/common/errors';
9+
import * as paths from 'vs/base/common/paths';
10+
import { TPromise } from 'vs/base/common/winjs.base';
11+
import mime = require('vs/base/common/mime');
12+
import { IFilesConfiguration } from 'vs/platform/files/common/files';
13+
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
14+
import { IExtensionPointUser, ExtensionMessageCollector } from 'vs/platform/extensions/common/extensionsRegistry';
15+
import { ModesRegistry } from 'vs/editor/common/modes/modesRegistry';
16+
import { ILanguageExtensionPoint, IValidLanguageExtensionPoint } from 'vs/editor/common/services/modeService';
17+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
18+
import { languagesExtPoint, ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
19+
20+
export class WorkbenchModeServiceImpl extends ModeServiceImpl {
21+
private _configurationService: IConfigurationService;
22+
private _extensionService: IExtensionService;
23+
private _onReadyPromise: TPromise<boolean>;
24+
25+
constructor(
26+
@IExtensionService extensionService: IExtensionService,
27+
@IConfigurationService configurationService: IConfigurationService
28+
) {
29+
super();
30+
this._configurationService = configurationService;
31+
this._extensionService = extensionService;
32+
33+
languagesExtPoint.setHandler((extensions: IExtensionPointUser<ILanguageExtensionPoint[]>[]) => {
34+
let allValidLanguages: IValidLanguageExtensionPoint[] = [];
35+
36+
for (let i = 0, len = extensions.length; i < len; i++) {
37+
let extension = extensions[i];
38+
39+
if (!Array.isArray(extension.value)) {
40+
extension.collector.error(nls.localize('invalid', "Invalid `contributes.{0}`. Expected an array.", languagesExtPoint.name));
41+
continue;
42+
}
43+
44+
for (let j = 0, lenJ = extension.value.length; j < lenJ; j++) {
45+
let ext = extension.value[j];
46+
if (isValidLanguageExtensionPoint(ext, extension.collector)) {
47+
let configuration = (ext.configuration ? paths.join(extension.description.extensionFolderPath, ext.configuration) : ext.configuration);
48+
allValidLanguages.push({
49+
id: ext.id,
50+
extensions: ext.extensions,
51+
filenames: ext.filenames,
52+
filenamePatterns: ext.filenamePatterns,
53+
firstLine: ext.firstLine,
54+
aliases: ext.aliases,
55+
mimetypes: ext.mimetypes,
56+
configuration: configuration
57+
});
58+
}
59+
}
60+
}
61+
62+
ModesRegistry.registerLanguages(allValidLanguages);
63+
64+
});
65+
66+
this._configurationService.onDidUpdateConfiguration(e => this.onConfigurationChange(e.config));
67+
68+
this.onDidCreateMode((mode) => {
69+
this._extensionService.activateByEvent(`onLanguage:${mode.getId()}`).done(null, onUnexpectedError);
70+
});
71+
}
72+
73+
protected _onReady(): TPromise<boolean> {
74+
if (!this._onReadyPromise) {
75+
const configuration = this._configurationService.getConfiguration<IFilesConfiguration>();
76+
this._onReadyPromise = this._extensionService.onReady().then(() => {
77+
this.onConfigurationChange(configuration);
78+
79+
return true;
80+
});
81+
}
82+
83+
return this._onReadyPromise;
84+
}
85+
86+
private onConfigurationChange(configuration: IFilesConfiguration): void {
87+
88+
// Clear user configured mime associations
89+
mime.clearTextMimes(true /* user configured */);
90+
91+
// Register based on settings
92+
if (configuration.files && configuration.files.associations) {
93+
Object.keys(configuration.files.associations).forEach(pattern => {
94+
const langId = configuration.files.associations[pattern];
95+
const mimetype = this.getMimeForMode(langId) || `text/x-${langId}`;
96+
97+
mime.registerTextMime({ id: langId, mime: mimetype, filepattern: pattern, userConfigured: true });
98+
});
99+
}
100+
}
101+
}
102+
103+
function isUndefinedOrStringArray(value: string[]): boolean {
104+
if (typeof value === 'undefined') {
105+
return true;
106+
}
107+
if (!Array.isArray(value)) {
108+
return false;
109+
}
110+
return value.every(item => typeof item === 'string');
111+
}
112+
113+
function isValidLanguageExtensionPoint(value: ILanguageExtensionPoint, collector: ExtensionMessageCollector): boolean {
114+
if (!value) {
115+
collector.error(nls.localize('invalid.empty', "Empty value for `contributes.{0}`", languagesExtPoint.name));
116+
return false;
117+
}
118+
if (typeof value.id !== 'string') {
119+
collector.error(nls.localize('require.id', "property `{0}` is mandatory and must be of type `string`", 'id'));
120+
return false;
121+
}
122+
if (!isUndefinedOrStringArray(value.extensions)) {
123+
collector.error(nls.localize('opt.extensions', "property `{0}` can be omitted and must be of type `string[]`", 'extensions'));
124+
return false;
125+
}
126+
if (!isUndefinedOrStringArray(value.filenames)) {
127+
collector.error(nls.localize('opt.filenames', "property `{0}` can be omitted and must be of type `string[]`", 'filenames'));
128+
return false;
129+
}
130+
if (typeof value.firstLine !== 'undefined' && typeof value.firstLine !== 'string') {
131+
collector.error(nls.localize('opt.firstLine', "property `{0}` can be omitted and must be of type `string`", 'firstLine'));
132+
return false;
133+
}
134+
if (typeof value.configuration !== 'undefined' && typeof value.configuration !== 'string') {
135+
collector.error(nls.localize('opt.configuration', "property `{0}` can be omitted and must be of type `string`", 'configuration'));
136+
return false;
137+
}
138+
if (!isUndefinedOrStringArray(value.aliases)) {
139+
collector.error(nls.localize('opt.aliases', "property `{0}` can be omitted and must be of type `string[]`", 'aliases'));
140+
return false;
141+
}
142+
if (!isUndefinedOrStringArray(value.mimetypes)) {
143+
collector.error(nls.localize('opt.mimetypes', "property `{0}` can be omitted and must be of type `string[]`", 'mimetypes'));
144+
return false;
145+
}
146+
return true;
147+
}

0 commit comments

Comments
 (0)