Skip to content

Commit 9c7f30b

Browse files
authored
Cannot read properties of undefined (reading 'localeCompare') (microsoft#211329)
* Cannot read properties of undefined (reading 'localeCompare') * remove unused import
1 parent a8823c3 commit 9c7f30b

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

src/vs/workbench/services/language/common/languageService.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { FILES_ASSOCIATIONS_CONFIG, IFilesConfiguration } from 'vs/platform/file
1515
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
1616
import { ExtensionMessageCollector, ExtensionsRegistry, IExtensionPoint, IExtensionPointUser } from 'vs/workbench/services/extensions/common/extensionsRegistry';
1717
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
18-
import { IExtensionDescription, IExtensionManifest } from 'vs/platform/extensions/common/extensions';
18+
import { IExtensionManifest } from 'vs/platform/extensions/common/extensions';
1919
import { ILogService } from 'vs/platform/log/common/log';
2020
import { Disposable } from 'vs/base/common/lifecycle';
2121
import { Extensions, IExtensionFeatureTableRenderer, IExtensionFeaturesRegistry, IRenderedData, IRowData, ITableData } from 'vs/workbench/services/extensionManagement/common/extensionFeatures';
@@ -131,14 +131,18 @@ class LanguageTableRenderer extends Disposable implements IExtensionFeatureTable
131131
render(manifest: IExtensionManifest): IRenderedData<ITableData> {
132132
const contributes = manifest.contributes;
133133
const rawLanguages = contributes?.languages || [];
134-
const languages = rawLanguages.map(l => ({
135-
id: l.id,
136-
name: (l.aliases || [])[0] || l.id,
137-
extensions: l.extensions || [],
138-
hasGrammar: false,
139-
hasSnippets: false
140-
}));
141-
134+
const languages: { id: string; name: string; extensions: string[]; hasGrammar: boolean; hasSnippets: boolean }[] = [];
135+
for (const l of rawLanguages) {
136+
if (isValidLanguageExtensionPoint(l)) {
137+
languages.push({
138+
id: l.id,
139+
name: (l.aliases || [])[0] || l.id,
140+
extensions: l.extensions || [],
141+
hasGrammar: false,
142+
hasSnippets: false
143+
});
144+
}
145+
}
142146
const byId = index(languages, l => l.id);
143147

144148
const grammars = contributes?.grammars || [];
@@ -235,7 +239,7 @@ export class WorkbenchLanguageService extends LanguageService {
235239

236240
for (let j = 0, lenJ = extension.value.length; j < lenJ; j++) {
237241
const ext = extension.value[j];
238-
if (isValidLanguageExtensionPoint(ext, extension.description, extension.collector)) {
242+
if (isValidLanguageExtensionPoint(ext, extension.collector)) {
239243
let configuration: URI | undefined = undefined;
240244
if (ext.configuration) {
241245
configuration = joinPath(extension.description.extensionLocation, ext.configuration);
@@ -315,42 +319,42 @@ function isUndefinedOrStringArray(value: string[]): boolean {
315319
return value.every(item => typeof item === 'string');
316320
}
317321

318-
function isValidLanguageExtensionPoint(value: IRawLanguageExtensionPoint, extension: IExtensionDescription, collector: ExtensionMessageCollector): boolean {
322+
function isValidLanguageExtensionPoint(value: any, collector?: ExtensionMessageCollector): value is IRawLanguageExtensionPoint {
319323
if (!value) {
320-
collector.error(localize('invalid.empty', "Empty value for `contributes.{0}`", languagesExtPoint.name));
324+
collector?.error(localize('invalid.empty', "Empty value for `contributes.{0}`", languagesExtPoint.name));
321325
return false;
322326
}
323327
if (typeof value.id !== 'string') {
324-
collector.error(localize('require.id', "property `{0}` is mandatory and must be of type `string`", 'id'));
328+
collector?.error(localize('require.id', "property `{0}` is mandatory and must be of type `string`", 'id'));
325329
return false;
326330
}
327331
if (!isUndefinedOrStringArray(value.extensions)) {
328-
collector.error(localize('opt.extensions', "property `{0}` can be omitted and must be of type `string[]`", 'extensions'));
332+
collector?.error(localize('opt.extensions', "property `{0}` can be omitted and must be of type `string[]`", 'extensions'));
329333
return false;
330334
}
331335
if (!isUndefinedOrStringArray(value.filenames)) {
332-
collector.error(localize('opt.filenames', "property `{0}` can be omitted and must be of type `string[]`", 'filenames'));
336+
collector?.error(localize('opt.filenames', "property `{0}` can be omitted and must be of type `string[]`", 'filenames'));
333337
return false;
334338
}
335339
if (typeof value.firstLine !== 'undefined' && typeof value.firstLine !== 'string') {
336-
collector.error(localize('opt.firstLine', "property `{0}` can be omitted and must be of type `string`", 'firstLine'));
340+
collector?.error(localize('opt.firstLine', "property `{0}` can be omitted and must be of type `string`", 'firstLine'));
337341
return false;
338342
}
339343
if (typeof value.configuration !== 'undefined' && typeof value.configuration !== 'string') {
340-
collector.error(localize('opt.configuration', "property `{0}` can be omitted and must be of type `string`", 'configuration'));
344+
collector?.error(localize('opt.configuration', "property `{0}` can be omitted and must be of type `string`", 'configuration'));
341345
return false;
342346
}
343347
if (!isUndefinedOrStringArray(value.aliases)) {
344-
collector.error(localize('opt.aliases', "property `{0}` can be omitted and must be of type `string[]`", 'aliases'));
348+
collector?.error(localize('opt.aliases', "property `{0}` can be omitted and must be of type `string[]`", 'aliases'));
345349
return false;
346350
}
347351
if (!isUndefinedOrStringArray(value.mimetypes)) {
348-
collector.error(localize('opt.mimetypes', "property `{0}` can be omitted and must be of type `string[]`", 'mimetypes'));
352+
collector?.error(localize('opt.mimetypes', "property `{0}` can be omitted and must be of type `string[]`", 'mimetypes'));
349353
return false;
350354
}
351355
if (typeof value.icon !== 'undefined') {
352356
if (typeof value.icon !== 'object' || typeof value.icon.light !== 'string' || typeof value.icon.dark !== 'string') {
353-
collector.error(localize('opt.icon', "property `{0}` can be omitted and must be of type `object` with properties `{1}` and `{2}` of type `string`", 'icon', 'light', 'dark'));
357+
collector?.error(localize('opt.icon', "property `{0}` can be omitted and must be of type `object` with properties `{1}` and `{2}` of type `string`", 'icon', 'light', 'dark'));
354358
return false;
355359
}
356360
}

0 commit comments

Comments
 (0)