|
7 | 7 | import * as nls from 'vs/nls'; |
8 | 8 | import { onUnexpectedError } from 'vs/base/common/errors'; |
9 | 9 | import Event, { Emitter } from 'vs/base/common/event'; |
10 | | -import * as paths from 'vs/base/common/paths'; |
11 | 10 | 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'; |
16 | 12 | import { IMode, LanguageId, LanguageIdentifier } from 'vs/editor/common/modes'; |
17 | 13 | import { FrankensteinMode } from 'vs/editor/common/modes/abstractMode'; |
18 | | -import { ModesRegistry } from 'vs/editor/common/modes/modesRegistry'; |
19 | 14 | 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'; |
22 | 16 |
|
23 | 17 | export const languagesExtPoint: IExtensionPoint<ILanguageExtensionPoint[]> = ExtensionsRegistry.registerExtensionPoint<ILanguageExtensionPoint[]>('languages', [], { |
24 | 18 | description: nls.localize('vscode.extension.contributes.languages', 'Contributes language declarations.'), |
@@ -80,52 +74,6 @@ export const languagesExtPoint: IExtensionPoint<ILanguageExtensionPoint[]> = Ext |
80 | 74 | } |
81 | 75 | }); |
82 | 76 |
|
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 | | - |
129 | 77 | export class ModeServiceImpl implements IModeService { |
130 | 78 | public _serviceBrand: any; |
131 | 79 |
|
@@ -293,86 +241,3 @@ export class ModeServiceImpl implements IModeService { |
293 | 241 | return this._instantiatedModes[modeId]; |
294 | 242 | } |
295 | 243 | } |
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 | | -} |
0 commit comments