monaco-editor11 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/css.worker-C7FogG4G.js +93 -0
- package/dist/assets/editor.worker-iXcRX1Tq.js +26 -0
- package/dist/assets/html.worker-C8VxctEJ.js +470 -0
- package/dist/assets/json.worker-CMC9kgPL.js +58 -0
- package/dist/assets/ts.worker-CtTJ3hNN.js +67731 -0
- package/dist/index.d.ts +0 -6
- package/dist/monaco-editor11.es.js +49 -78
- package/dist/monaco-editor11.umd.js +1 -50
- package/dist/monaco.d.ts +8 -0
- package/dist/workers/common/initialize.js +16 -0
- package/dist/workers/common/workers.js +141 -0
- package/dist/workers/editor/common/abstractSyntaxTokenBackend.js +128 -0
- package/dist/workers/editor/common/abstractText.js +89 -0
- package/dist/workers/editor/common/ast.js +485 -0
- package/dist/workers/editor/common/autoIndent.js +390 -0
- package/dist/workers/editor/common/beforeEditPositionMapper.js +110 -0
- package/dist/workers/editor/common/bracketPairsImpl.js +717 -0
- package/dist/workers/editor/common/bracketPairsTree.js +343 -0
- package/dist/workers/editor/common/brackets.js +108 -0
- package/dist/workers/editor/common/characterClassifier.js +59 -0
- package/dist/workers/editor/common/characterPair.js +40 -0
- package/dist/workers/editor/common/colorizedBracketPairsDecorationProvider.js +97 -0
- package/dist/workers/editor/common/columnRange.js +35 -0
- package/dist/workers/editor/common/combineTextEditInfos.js +124 -0
- package/dist/workers/editor/common/common.js +20 -0
- package/dist/workers/editor/common/computeMovedLines.js +249 -0
- package/dist/workers/editor/common/concat23Trees.js +192 -0
- package/dist/workers/editor/common/contiguousMultilineTokens.js +32 -0
- package/dist/workers/editor/common/contiguousMultilineTokensBuilder.js +23 -0
- package/dist/workers/editor/common/contiguousTokensEditing.js +128 -0
- package/dist/workers/editor/common/contiguousTokensStore.js +207 -0
- package/dist/workers/editor/common/coordinatesConverter.js +51 -0
- package/dist/workers/editor/common/cursor.js +899 -0
- package/dist/workers/editor/common/cursorAtomicMoveOperations.js +145 -0
- package/dist/workers/editor/common/cursorCollection.js +194 -0
- package/dist/workers/editor/common/cursorColumnSelection.js +93 -0
- package/dist/workers/editor/common/cursorColumns.js +112 -0
- package/dist/workers/editor/common/cursorCommon.js +250 -0
- package/dist/workers/editor/common/cursorContext.js +15 -0
- package/dist/workers/editor/common/cursorDeleteOperations.js +231 -0
- package/dist/workers/editor/common/cursorMoveCommands.js +676 -0
- package/dist/workers/editor/common/cursorMoveOperations.js +290 -0
- package/dist/workers/editor/common/cursorTypeEditOperations.js +968 -0
- package/dist/workers/editor/common/cursorTypeOperations.js +173 -0
- package/dist/workers/editor/common/cursorUtils.js +75 -0
- package/dist/workers/editor/common/cursorWordOperations.js +720 -0
- package/dist/workers/editor/common/defaultDocumentColorsComputer.js +138 -0
- package/dist/workers/editor/common/defaultLinesDiffComputer.js +188 -0
- package/dist/workers/editor/common/diffAlgorithm.js +139 -0
- package/dist/workers/editor/common/diffEditor.js +38 -0
- package/dist/workers/editor/common/dynamicProgrammingDiffing.js +101 -0
- package/dist/workers/editor/common/edit.js +183 -0
- package/dist/workers/editor/common/editOperation.js +36 -0
- package/dist/workers/editor/common/editStack.js +363 -0
- package/dist/workers/editor/common/editorAction.js +26 -0
- package/dist/workers/editor/common/editorBaseApi.js +43 -0
- package/dist/workers/editor/common/editorColorRegistry.js +102 -0
- package/dist/workers/editor/common/editorCommon.js +13 -0
- package/dist/workers/editor/common/editorConfigurationSchema.js +338 -0
- package/dist/workers/editor/common/editorContextKeys.js +84 -0
- package/dist/workers/editor/common/editorFeatures.js +17 -0
- package/dist/workers/editor/common/editorOptions.js +3440 -0
- package/dist/workers/editor/common/editorTheme.js +23 -0
- package/dist/workers/editor/common/editorWebWorker.js +299 -0
- package/dist/workers/editor/common/editorWorker.js +9 -0
- package/dist/workers/editor/common/editorWorkerHost.js +15 -0
- package/dist/workers/editor/common/editorZoom.js +26 -0
- package/dist/workers/editor/common/electricCharacter.js +55 -0
- package/dist/workers/editor/common/encodedTokenAttributes.js +79 -0
- package/dist/workers/editor/common/enterAction.js +53 -0
- package/dist/workers/editor/common/eolCounter.js +44 -0
- package/dist/workers/editor/common/findSectionHeaders.js +128 -0
- package/dist/workers/editor/common/fixBrackets.js +67 -0
- package/dist/workers/editor/common/fixedArray.js +70 -0
- package/dist/workers/editor/common/fontInfo.js +172 -0
- package/dist/workers/editor/common/fontInfoFromSettings.js +29 -0
- package/dist/workers/editor/common/getIconClasses.js +106 -0
- package/dist/workers/editor/common/getPositionOffsetTransformerFromTextModel.js +24 -0
- package/dist/workers/editor/common/glyphLanesModel.js +61 -0
- package/dist/workers/editor/common/guidesTextModelPart.js +405 -0
- package/dist/workers/editor/common/heuristicSequenceOptimizations.js +374 -0
- package/dist/workers/editor/common/indentRules.js +63 -0
- package/dist/workers/editor/common/indentation.js +39 -0
- package/dist/workers/editor/common/indentationGuesser.js +178 -0
- package/dist/workers/editor/common/indentationLineProcessor.js +193 -0
- package/dist/workers/editor/common/inlineDecorations.js +26 -0
- package/dist/workers/editor/common/inplaceReplaceSupport.js +87 -0
- package/dist/workers/editor/common/inputMode.js +22 -0
- package/dist/workers/editor/common/intervalTree.js +1002 -0
- package/dist/workers/editor/common/language.js +9 -0
- package/dist/workers/editor/common/languageBracketsConfiguration.js +133 -0
- package/dist/workers/editor/common/languageConfiguration.js +138 -0
- package/dist/workers/editor/common/languageConfigurationRegistry.js +361 -0
- package/dist/workers/editor/common/languageFeatureDebounce.js +137 -0
- package/dist/workers/editor/common/languageFeatureRegistry.js +180 -0
- package/dist/workers/editor/common/languageFeatures.js +9 -0
- package/dist/workers/editor/common/languageFeaturesService.js +47 -0
- package/dist/workers/editor/common/languageSelector.js +112 -0
- package/dist/workers/editor/common/languageService.js +92 -0
- package/dist/workers/editor/common/languages.js +522 -0
- package/dist/workers/editor/common/languagesAssociations.js +193 -0
- package/dist/workers/editor/common/languagesRegistry.js +237 -0
- package/dist/workers/editor/common/legacyLinesDiffComputer.js +468 -0
- package/dist/workers/editor/common/length.js +129 -0
- package/dist/workers/editor/common/lineDecorations.js +208 -0
- package/dist/workers/editor/common/lineEdit.js +75 -0
- package/dist/workers/editor/common/lineHeights.js +370 -0
- package/dist/workers/editor/common/linePart.js +25 -0
- package/dist/workers/editor/common/lineRange.js +312 -0
- package/dist/workers/editor/common/lineSequence.js +36 -0
- package/dist/workers/editor/common/lineTokens.js +405 -0
- package/dist/workers/editor/common/linesDiffComputer.js +29 -0
- package/dist/workers/editor/common/linesDiffComputers.js +13 -0
- package/dist/workers/editor/common/linesLayout.js +765 -0
- package/dist/workers/editor/common/linesSliceCharSequence.js +205 -0
- package/dist/workers/editor/common/linkComputer.js +269 -0
- package/dist/workers/editor/common/markerDecorations.js +9 -0
- package/dist/workers/editor/common/markerDecorationsService.js +248 -0
- package/dist/workers/editor/common/minimapTokensColorTracker.js +58 -0
- package/dist/workers/editor/common/mirrorTextModel.js +117 -0
- package/dist/workers/editor/common/model.js +9 -0
- package/dist/workers/editor/common/modelLineProjection.js +350 -0
- package/dist/workers/editor/common/modelLineProjectionData.js +297 -0
- package/dist/workers/editor/common/modelService.js +413 -0
- package/dist/workers/editor/common/modesRegistry.js +75 -0
- package/dist/workers/editor/common/monospaceLineBreaksComputer.js +473 -0
- package/dist/workers/editor/common/myersDiffAlgorithm.js +159 -0
- package/dist/workers/editor/common/nodeReader.js +127 -0
- package/dist/workers/editor/common/nullTokenize.js +29 -0
- package/dist/workers/editor/common/offsetRange.js +225 -0
- package/dist/workers/editor/common/onEnter.js +109 -0
- package/dist/workers/editor/common/oneCursor.js +117 -0
- package/dist/workers/editor/common/overviewZoneManager.js +176 -0
- package/dist/workers/editor/common/parser.js +121 -0
- package/dist/workers/editor/common/pieceTreeBase.js +1473 -0
- package/dist/workers/editor/common/pieceTreeTextBuffer.js +461 -0
- package/dist/workers/editor/common/pieceTreeTextBufferBuilder.js +140 -0
- package/dist/workers/editor/common/point.js +50 -0
- package/dist/workers/editor/common/position.js +142 -0
- package/dist/workers/editor/common/positionToOffset.js +17 -0
- package/dist/workers/editor/common/positionToOffsetImpl.js +98 -0
- package/dist/workers/editor/common/prefixSumComputer.js +226 -0
- package/dist/workers/editor/common/range.js +421 -0
- package/dist/workers/editor/common/rangeMapping.js +229 -0
- package/dist/workers/editor/common/rangeSingleLine.js +17 -0
- package/dist/workers/editor/common/rbTreeBase.js +362 -0
- package/dist/workers/editor/common/rect.js +163 -0
- package/dist/workers/editor/common/replaceCommand.js +158 -0
- package/dist/workers/editor/common/resolverService.js +5 -0
- package/dist/workers/editor/common/rgba.js +35 -0
- package/dist/workers/editor/common/richEditBrackets.js +356 -0
- package/dist/workers/editor/common/selection.js +145 -0
- package/dist/workers/editor/common/semanticTokensDto.js +82 -0
- package/dist/workers/editor/common/semanticTokensProviderStyling.js +263 -0
- package/dist/workers/editor/common/semanticTokensStyling.js +9 -0
- package/dist/workers/editor/common/semanticTokensStylingService.js +47 -0
- package/dist/workers/editor/common/shiftCommand.js +241 -0
- package/dist/workers/editor/common/smallImmutableSet.js +108 -0
- package/dist/workers/editor/common/sparseMultilineTokens.js +548 -0
- package/dist/workers/editor/common/sparseTokensStore.js +210 -0
- package/dist/workers/editor/common/standaloneEnums.js +1017 -0
- package/dist/workers/editor/common/standaloneStrings.js +42 -0
- package/dist/workers/editor/common/stringBuilder.js +122 -0
- package/dist/workers/editor/common/stringEdit.js +165 -0
- package/dist/workers/editor/common/supports.js +58 -0
- package/dist/workers/editor/common/surroundSelectionCommand.js +44 -0
- package/dist/workers/editor/common/textChange.js +248 -0
- package/dist/workers/editor/common/textEdit.js +269 -0
- package/dist/workers/editor/common/textLength.js +87 -0
- package/dist/workers/editor/common/textModel.js +2031 -0
- package/dist/workers/editor/common/textModelBracketPairs.js +45 -0
- package/dist/workers/editor/common/textModelDefaults.js +18 -0
- package/dist/workers/editor/common/textModelEditSource.js +166 -0
- package/dist/workers/editor/common/textModelEvents.js +216 -0
- package/dist/workers/editor/common/textModelGuides.js +40 -0
- package/dist/workers/editor/common/textModelPart.js +23 -0
- package/dist/workers/editor/common/textModelSearch.js +455 -0
- package/dist/workers/editor/common/textModelStringEdit.js +11 -0
- package/dist/workers/editor/common/textModelSync.impl.js +307 -0
- package/dist/workers/editor/common/textModelText.js +26 -0
- package/dist/workers/editor/common/textModelTokens.js +436 -0
- package/dist/workers/editor/common/textResourceConfiguration.js +6 -0
- package/dist/workers/editor/common/textToHtmlTokenizer.js +139 -0
- package/dist/workers/editor/common/tokenStore.js +407 -0
- package/dist/workers/editor/common/tokenWithTextArray.js +73 -0
- package/dist/workers/editor/common/tokenization.js +287 -0
- package/dist/workers/editor/common/tokenizationRegistry.js +123 -0
- package/dist/workers/editor/common/tokenizationTextModelPart.js +275 -0
- package/dist/workers/editor/common/tokenizer.js +301 -0
- package/dist/workers/editor/common/tokenizerSyntaxTokenBackend.js +261 -0
- package/dist/workers/editor/common/treeSitterLibraryService.js +9 -0
- package/dist/workers/editor/common/treeSitterSyntaxTokenBackend.js +167 -0
- package/dist/workers/editor/common/treeSitterThemeService.js +9 -0
- package/dist/workers/editor/common/treeSitterTokenizationImpl.js +713 -0
- package/dist/workers/editor/common/treeSitterTree.js +395 -0
- package/dist/workers/editor/common/treeViewsDnd.js +24 -0
- package/dist/workers/editor/common/treeViewsDndService.js +12 -0
- package/dist/workers/editor/common/trimTrailingWhitespaceCommand.js +98 -0
- package/dist/workers/editor/common/unicodeTextModelHighlighter.js +188 -0
- package/dist/workers/editor/common/utils.js +62 -0
- package/dist/workers/editor/common/viewContext.js +22 -0
- package/dist/workers/editor/common/viewEventHandler.js +186 -0
- package/dist/workers/editor/common/viewEvents.js +180 -0
- package/dist/workers/editor/common/viewLayout.js +368 -0
- package/dist/workers/editor/common/viewLineRenderer.js +948 -0
- package/dist/workers/editor/common/viewLinesViewportData.js +30 -0
- package/dist/workers/editor/common/viewModel.js +98 -0
- package/dist/workers/editor/common/viewModelDecoration.js +55 -0
- package/dist/workers/editor/common/viewModelDecorations.js +132 -0
- package/dist/workers/editor/common/viewModelEventDispatcher.js +398 -0
- package/dist/workers/editor/common/viewModelImpl.js +1163 -0
- package/dist/workers/editor/common/viewModelLines.js +938 -0
- package/dist/workers/editor/common/wordCharacterClassifier.js +87 -0
- package/dist/workers/editor/common/wordHelper.js +127 -0
- package/dist/workers/editor/editor.worker.js +11 -0
- package/dist/workers/language/css.worker.js +8 -0
- package/dist/workers/language/cssMode.js +198 -0
- package/dist/workers/language/cssWorker.js +183 -0
- package/dist/workers/language/html.worker.js +8 -0
- package/dist/workers/language/htmlMode.js +213 -0
- package/dist/workers/language/htmlWorker.js +126 -0
- package/dist/workers/language/json.worker.js +8 -0
- package/dist/workers/language/jsonMode.js +224 -0
- package/dist/workers/language/jsonWorker.js +187 -0
- package/dist/workers/language/languageFeatures.js +1009 -0
- package/dist/workers/language/lib.index.js +103 -0
- package/dist/workers/language/lib.js +1107 -0
- package/dist/workers/language/lspLanguageFeatures.js +716 -0
- package/dist/workers/language/monaco.contribution.js +144 -0
- package/dist/workers/language/tokenization.js +189 -0
- package/dist/workers/language/ts.worker.js +14 -0
- package/dist/workers/language/tsMode.js +212 -0
- package/dist/workers/language/tsWorker.js +352 -0
- package/dist/workers/language/typescriptServices.js +210154 -0
- package/dist/workers/language/typescriptServicesMetadata.js +3 -0
- package/dist/workers/language/workerManager.js +65 -0
- package/package.json +3 -2
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { parse } from '../../../base/common/glob.js';
|
|
2
|
+
import { Mimes } from '../../../base/common/mime.js';
|
|
3
|
+
import { Schemas } from '../../../base/common/network.js';
|
|
4
|
+
import { basename, posix } from '../../../base/common/path.js';
|
|
5
|
+
import { DataUri } from '../../../base/common/resources.js';
|
|
6
|
+
import { startsWithUTF8BOM } from '../../../base/common/strings.js';
|
|
7
|
+
import { PLAINTEXT_LANGUAGE_ID } from '../languages/modesRegistry.js';
|
|
8
|
+
|
|
9
|
+
/*---------------------------------------------------------------------------------------------
|
|
10
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
11
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
12
|
+
*--------------------------------------------------------------------------------------------*/
|
|
13
|
+
let registeredAssociations = [];
|
|
14
|
+
let nonUserRegisteredAssociations = [];
|
|
15
|
+
let userRegisteredAssociations = [];
|
|
16
|
+
/**
|
|
17
|
+
* Associate a language to the registry (platform).
|
|
18
|
+
* * **NOTE**: This association will lose over associations registered using `registerConfiguredLanguageAssociation`.
|
|
19
|
+
* * **NOTE**: Use `clearPlatformLanguageAssociations` to remove all associations registered using this function.
|
|
20
|
+
*/
|
|
21
|
+
function registerPlatformLanguageAssociation(association, warnOnOverwrite = false) {
|
|
22
|
+
_registerLanguageAssociation(association, false, warnOnOverwrite);
|
|
23
|
+
}
|
|
24
|
+
function _registerLanguageAssociation(association, userConfigured, warnOnOverwrite) {
|
|
25
|
+
// Register
|
|
26
|
+
const associationItem = toLanguageAssociationItem(association, userConfigured);
|
|
27
|
+
registeredAssociations.push(associationItem);
|
|
28
|
+
if (!associationItem.userConfigured) {
|
|
29
|
+
nonUserRegisteredAssociations.push(associationItem);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
userRegisteredAssociations.push(associationItem);
|
|
33
|
+
}
|
|
34
|
+
// Check for conflicts unless this is a user configured association
|
|
35
|
+
if (warnOnOverwrite && !associationItem.userConfigured) {
|
|
36
|
+
registeredAssociations.forEach(a => {
|
|
37
|
+
if (a.mime === associationItem.mime || a.userConfigured) {
|
|
38
|
+
return; // same mime or userConfigured is ok
|
|
39
|
+
}
|
|
40
|
+
if (associationItem.extension && a.extension === associationItem.extension) {
|
|
41
|
+
console.warn(`Overwriting extension <<${associationItem.extension}>> to now point to mime <<${associationItem.mime}>>`);
|
|
42
|
+
}
|
|
43
|
+
if (associationItem.filename && a.filename === associationItem.filename) {
|
|
44
|
+
console.warn(`Overwriting filename <<${associationItem.filename}>> to now point to mime <<${associationItem.mime}>>`);
|
|
45
|
+
}
|
|
46
|
+
if (associationItem.filepattern && a.filepattern === associationItem.filepattern) {
|
|
47
|
+
console.warn(`Overwriting filepattern <<${associationItem.filepattern}>> to now point to mime <<${associationItem.mime}>>`);
|
|
48
|
+
}
|
|
49
|
+
if (associationItem.firstline && a.firstline === associationItem.firstline) {
|
|
50
|
+
console.warn(`Overwriting firstline <<${associationItem.firstline}>> to now point to mime <<${associationItem.mime}>>`);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function toLanguageAssociationItem(association, userConfigured) {
|
|
56
|
+
return {
|
|
57
|
+
id: association.id,
|
|
58
|
+
mime: association.mime,
|
|
59
|
+
filename: association.filename,
|
|
60
|
+
extension: association.extension,
|
|
61
|
+
filepattern: association.filepattern,
|
|
62
|
+
firstline: association.firstline,
|
|
63
|
+
userConfigured: userConfigured,
|
|
64
|
+
filenameLowercase: association.filename ? association.filename.toLowerCase() : undefined,
|
|
65
|
+
extensionLowercase: association.extension ? association.extension.toLowerCase() : undefined,
|
|
66
|
+
filepatternLowercase: association.filepattern ? parse(association.filepattern.toLowerCase()) : undefined,
|
|
67
|
+
filepatternOnPath: association.filepattern ? association.filepattern.indexOf(posix.sep) >= 0 : false
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Clear language associations from the registry (platform).
|
|
72
|
+
*/
|
|
73
|
+
function clearPlatformLanguageAssociations() {
|
|
74
|
+
registeredAssociations = registeredAssociations.filter(a => a.userConfigured);
|
|
75
|
+
nonUserRegisteredAssociations = [];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* @see `getMimeTypes`
|
|
79
|
+
*/
|
|
80
|
+
function getLanguageIds(resource, firstLine) {
|
|
81
|
+
return getAssociations(resource, firstLine).map(item => item.id);
|
|
82
|
+
}
|
|
83
|
+
function getAssociations(resource, firstLine) {
|
|
84
|
+
let path;
|
|
85
|
+
if (resource) {
|
|
86
|
+
switch (resource.scheme) {
|
|
87
|
+
case Schemas.file:
|
|
88
|
+
path = resource.fsPath;
|
|
89
|
+
break;
|
|
90
|
+
case Schemas.data: {
|
|
91
|
+
const metadata = DataUri.parseMetaData(resource);
|
|
92
|
+
path = metadata.get(DataUri.META_DATA_LABEL);
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case Schemas.vscodeNotebookCell:
|
|
96
|
+
// File path not relevant for language detection of cell
|
|
97
|
+
path = undefined;
|
|
98
|
+
break;
|
|
99
|
+
default:
|
|
100
|
+
path = resource.path;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (!path) {
|
|
104
|
+
return [{ id: 'unknown', mime: Mimes.unknown }];
|
|
105
|
+
}
|
|
106
|
+
path = path.toLowerCase();
|
|
107
|
+
const filename = basename(path);
|
|
108
|
+
// 1.) User configured mappings have highest priority
|
|
109
|
+
const configuredLanguage = getAssociationByPath(path, filename, userRegisteredAssociations);
|
|
110
|
+
if (configuredLanguage) {
|
|
111
|
+
return [configuredLanguage, { id: PLAINTEXT_LANGUAGE_ID, mime: Mimes.text }];
|
|
112
|
+
}
|
|
113
|
+
// 2.) Registered mappings have middle priority
|
|
114
|
+
const registeredLanguage = getAssociationByPath(path, filename, nonUserRegisteredAssociations);
|
|
115
|
+
if (registeredLanguage) {
|
|
116
|
+
return [registeredLanguage, { id: PLAINTEXT_LANGUAGE_ID, mime: Mimes.text }];
|
|
117
|
+
}
|
|
118
|
+
// 3.) Firstline has lowest priority
|
|
119
|
+
if (firstLine) {
|
|
120
|
+
const firstlineLanguage = getAssociationByFirstline(firstLine);
|
|
121
|
+
if (firstlineLanguage) {
|
|
122
|
+
return [firstlineLanguage, { id: PLAINTEXT_LANGUAGE_ID, mime: Mimes.text }];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return [{ id: 'unknown', mime: Mimes.unknown }];
|
|
126
|
+
}
|
|
127
|
+
function getAssociationByPath(path, filename, associations) {
|
|
128
|
+
let filenameMatch = undefined;
|
|
129
|
+
let patternMatch = undefined;
|
|
130
|
+
let extensionMatch = undefined;
|
|
131
|
+
// We want to prioritize associations based on the order they are registered so that the last registered
|
|
132
|
+
// association wins over all other. This is for https://github.com/microsoft/vscode/issues/20074
|
|
133
|
+
for (let i = associations.length - 1; i >= 0; i--) {
|
|
134
|
+
const association = associations[i];
|
|
135
|
+
// First exact name match
|
|
136
|
+
if (filename === association.filenameLowercase) {
|
|
137
|
+
filenameMatch = association;
|
|
138
|
+
break; // take it!
|
|
139
|
+
}
|
|
140
|
+
// Longest pattern match
|
|
141
|
+
if (association.filepattern) {
|
|
142
|
+
if (!patternMatch || association.filepattern.length > patternMatch.filepattern.length) {
|
|
143
|
+
const target = association.filepatternOnPath ? path : filename; // match on full path if pattern contains path separator
|
|
144
|
+
if (association.filepatternLowercase?.(target)) {
|
|
145
|
+
patternMatch = association;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// Longest extension match
|
|
150
|
+
if (association.extension) {
|
|
151
|
+
if (!extensionMatch || association.extension.length > extensionMatch.extension.length) {
|
|
152
|
+
if (filename.endsWith(association.extensionLowercase)) {
|
|
153
|
+
extensionMatch = association;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// 1.) Exact name match has second highest priority
|
|
159
|
+
if (filenameMatch) {
|
|
160
|
+
return filenameMatch;
|
|
161
|
+
}
|
|
162
|
+
// 2.) Match on pattern
|
|
163
|
+
if (patternMatch) {
|
|
164
|
+
return patternMatch;
|
|
165
|
+
}
|
|
166
|
+
// 3.) Match on extension comes next
|
|
167
|
+
if (extensionMatch) {
|
|
168
|
+
return extensionMatch;
|
|
169
|
+
}
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
function getAssociationByFirstline(firstLine) {
|
|
173
|
+
if (startsWithUTF8BOM(firstLine)) {
|
|
174
|
+
firstLine = firstLine.substr(1);
|
|
175
|
+
}
|
|
176
|
+
if (firstLine.length > 0) {
|
|
177
|
+
// We want to prioritize associations based on the order they are registered so that the last registered
|
|
178
|
+
// association wins over all other. This is for https://github.com/microsoft/vscode/issues/20074
|
|
179
|
+
for (let i = registeredAssociations.length - 1; i >= 0; i--) {
|
|
180
|
+
const association = registeredAssociations[i];
|
|
181
|
+
if (!association.firstline) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
const matches = firstLine.match(association.firstline);
|
|
185
|
+
if (matches && matches.length > 0) {
|
|
186
|
+
return association;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export { clearPlatformLanguageAssociations, getLanguageIds, registerPlatformLanguageAssociation };
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { Emitter } from '../../../base/common/event.js';
|
|
2
|
+
import { Disposable } from '../../../base/common/lifecycle.js';
|
|
3
|
+
import { regExpLeadsToEndlessLoop } from '../../../base/common/strings.js';
|
|
4
|
+
import { clearPlatformLanguageAssociations, registerPlatformLanguageAssociation, getLanguageIds } from './languagesAssociations.js';
|
|
5
|
+
import { ModesRegistry, PLAINTEXT_LANGUAGE_ID } from '../languages/modesRegistry.js';
|
|
6
|
+
import { Extensions } from '../../../platform/configuration/common/configurationRegistry.js';
|
|
7
|
+
import { Registry } from '../../../platform/registry/common/platform.js';
|
|
8
|
+
|
|
9
|
+
/*---------------------------------------------------------------------------------------------
|
|
10
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
11
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
12
|
+
*--------------------------------------------------------------------------------------------*/
|
|
13
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
14
|
+
const NULL_LANGUAGE_ID = 'vs.editor.nullLanguage';
|
|
15
|
+
class LanguageIdCodec {
|
|
16
|
+
constructor() {
|
|
17
|
+
this._languageIdToLanguage = [];
|
|
18
|
+
this._languageToLanguageId = new Map();
|
|
19
|
+
this._register(NULL_LANGUAGE_ID, 0 /* LanguageId.Null */);
|
|
20
|
+
this._register(PLAINTEXT_LANGUAGE_ID, 1 /* LanguageId.PlainText */);
|
|
21
|
+
this._nextLanguageId = 2;
|
|
22
|
+
}
|
|
23
|
+
_register(language, languageId) {
|
|
24
|
+
this._languageIdToLanguage[languageId] = language;
|
|
25
|
+
this._languageToLanguageId.set(language, languageId);
|
|
26
|
+
}
|
|
27
|
+
register(language) {
|
|
28
|
+
if (this._languageToLanguageId.has(language)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const languageId = this._nextLanguageId++;
|
|
32
|
+
this._register(language, languageId);
|
|
33
|
+
}
|
|
34
|
+
encodeLanguageId(languageId) {
|
|
35
|
+
return this._languageToLanguageId.get(languageId) || 0 /* LanguageId.Null */;
|
|
36
|
+
}
|
|
37
|
+
decodeLanguageId(languageId) {
|
|
38
|
+
return this._languageIdToLanguage[languageId] || NULL_LANGUAGE_ID;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
class LanguagesRegistry extends Disposable {
|
|
42
|
+
static { this.instanceCount = 0; }
|
|
43
|
+
constructor(useModesRegistry = true, warnOnOverwrite = false) {
|
|
44
|
+
super();
|
|
45
|
+
this._onDidChange = this._register(new Emitter());
|
|
46
|
+
this.onDidChange = this._onDidChange.event;
|
|
47
|
+
LanguagesRegistry.instanceCount++;
|
|
48
|
+
this._warnOnOverwrite = warnOnOverwrite;
|
|
49
|
+
this.languageIdCodec = new LanguageIdCodec();
|
|
50
|
+
this._dynamicLanguages = [];
|
|
51
|
+
this._languages = {};
|
|
52
|
+
this._mimeTypesMap = {};
|
|
53
|
+
this._nameMap = {};
|
|
54
|
+
this._lowercaseNameMap = {};
|
|
55
|
+
if (useModesRegistry) {
|
|
56
|
+
this._initializeFromRegistry();
|
|
57
|
+
this._register(ModesRegistry.onDidChangeLanguages((m) => {
|
|
58
|
+
this._initializeFromRegistry();
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
dispose() {
|
|
63
|
+
LanguagesRegistry.instanceCount--;
|
|
64
|
+
super.dispose();
|
|
65
|
+
}
|
|
66
|
+
_initializeFromRegistry() {
|
|
67
|
+
this._languages = {};
|
|
68
|
+
this._mimeTypesMap = {};
|
|
69
|
+
this._nameMap = {};
|
|
70
|
+
this._lowercaseNameMap = {};
|
|
71
|
+
clearPlatformLanguageAssociations();
|
|
72
|
+
const desc = [].concat(ModesRegistry.getLanguages()).concat(this._dynamicLanguages);
|
|
73
|
+
this._registerLanguages(desc);
|
|
74
|
+
}
|
|
75
|
+
_registerLanguages(desc) {
|
|
76
|
+
for (const d of desc) {
|
|
77
|
+
this._registerLanguage(d);
|
|
78
|
+
}
|
|
79
|
+
// Rebuild fast path maps
|
|
80
|
+
this._mimeTypesMap = {};
|
|
81
|
+
this._nameMap = {};
|
|
82
|
+
this._lowercaseNameMap = {};
|
|
83
|
+
Object.keys(this._languages).forEach((langId) => {
|
|
84
|
+
const language = this._languages[langId];
|
|
85
|
+
if (language.name) {
|
|
86
|
+
this._nameMap[language.name] = language.identifier;
|
|
87
|
+
}
|
|
88
|
+
language.aliases.forEach((alias) => {
|
|
89
|
+
this._lowercaseNameMap[alias.toLowerCase()] = language.identifier;
|
|
90
|
+
});
|
|
91
|
+
language.mimetypes.forEach((mimetype) => {
|
|
92
|
+
this._mimeTypesMap[mimetype] = language.identifier;
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
Registry.as(Extensions.Configuration).registerOverrideIdentifiers(this.getRegisteredLanguageIds());
|
|
96
|
+
this._onDidChange.fire();
|
|
97
|
+
}
|
|
98
|
+
_registerLanguage(lang) {
|
|
99
|
+
const langId = lang.id;
|
|
100
|
+
let resolvedLanguage;
|
|
101
|
+
if (hasOwnProperty.call(this._languages, langId)) {
|
|
102
|
+
resolvedLanguage = this._languages[langId];
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
this.languageIdCodec.register(langId);
|
|
106
|
+
resolvedLanguage = {
|
|
107
|
+
identifier: langId,
|
|
108
|
+
name: null,
|
|
109
|
+
mimetypes: [],
|
|
110
|
+
aliases: [],
|
|
111
|
+
extensions: [],
|
|
112
|
+
filenames: [],
|
|
113
|
+
configurationFiles: [],
|
|
114
|
+
icons: []
|
|
115
|
+
};
|
|
116
|
+
this._languages[langId] = resolvedLanguage;
|
|
117
|
+
}
|
|
118
|
+
this._mergeLanguage(resolvedLanguage, lang);
|
|
119
|
+
}
|
|
120
|
+
_mergeLanguage(resolvedLanguage, lang) {
|
|
121
|
+
const langId = lang.id;
|
|
122
|
+
let primaryMime = null;
|
|
123
|
+
if (Array.isArray(lang.mimetypes) && lang.mimetypes.length > 0) {
|
|
124
|
+
resolvedLanguage.mimetypes.push(...lang.mimetypes);
|
|
125
|
+
primaryMime = lang.mimetypes[0];
|
|
126
|
+
}
|
|
127
|
+
if (!primaryMime) {
|
|
128
|
+
primaryMime = `text/x-${langId}`;
|
|
129
|
+
resolvedLanguage.mimetypes.push(primaryMime);
|
|
130
|
+
}
|
|
131
|
+
if (Array.isArray(lang.extensions)) {
|
|
132
|
+
if (lang.configuration) {
|
|
133
|
+
// insert first as this appears to be the 'primary' language definition
|
|
134
|
+
resolvedLanguage.extensions = lang.extensions.concat(resolvedLanguage.extensions);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
resolvedLanguage.extensions = resolvedLanguage.extensions.concat(lang.extensions);
|
|
138
|
+
}
|
|
139
|
+
for (const extension of lang.extensions) {
|
|
140
|
+
registerPlatformLanguageAssociation({ id: langId, mime: primaryMime, extension: extension }, this._warnOnOverwrite);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (Array.isArray(lang.filenames)) {
|
|
144
|
+
for (const filename of lang.filenames) {
|
|
145
|
+
registerPlatformLanguageAssociation({ id: langId, mime: primaryMime, filename: filename }, this._warnOnOverwrite);
|
|
146
|
+
resolvedLanguage.filenames.push(filename);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (Array.isArray(lang.filenamePatterns)) {
|
|
150
|
+
for (const filenamePattern of lang.filenamePatterns) {
|
|
151
|
+
registerPlatformLanguageAssociation({ id: langId, mime: primaryMime, filepattern: filenamePattern }, this._warnOnOverwrite);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (typeof lang.firstLine === 'string' && lang.firstLine.length > 0) {
|
|
155
|
+
let firstLineRegexStr = lang.firstLine;
|
|
156
|
+
if (firstLineRegexStr.charAt(0) !== '^') {
|
|
157
|
+
firstLineRegexStr = '^' + firstLineRegexStr;
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
const firstLineRegex = new RegExp(firstLineRegexStr);
|
|
161
|
+
if (!regExpLeadsToEndlessLoop(firstLineRegex)) {
|
|
162
|
+
registerPlatformLanguageAssociation({ id: langId, mime: primaryMime, firstline: firstLineRegex }, this._warnOnOverwrite);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
// Most likely, the regex was bad
|
|
167
|
+
console.warn(`[${lang.id}]: Invalid regular expression \`${firstLineRegexStr}\`: `, err);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
resolvedLanguage.aliases.push(langId);
|
|
171
|
+
let langAliases = null;
|
|
172
|
+
if (typeof lang.aliases !== 'undefined' && Array.isArray(lang.aliases)) {
|
|
173
|
+
if (lang.aliases.length === 0) {
|
|
174
|
+
// signal that this language should not get a name
|
|
175
|
+
langAliases = [null];
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
langAliases = lang.aliases;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (langAliases !== null) {
|
|
182
|
+
for (const langAlias of langAliases) {
|
|
183
|
+
if (!langAlias || langAlias.length === 0) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
resolvedLanguage.aliases.push(langAlias);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const containsAliases = (langAliases !== null && langAliases.length > 0);
|
|
190
|
+
if (containsAliases && langAliases[0] === null) ;
|
|
191
|
+
else {
|
|
192
|
+
const bestName = (containsAliases ? langAliases[0] : null) || langId;
|
|
193
|
+
if (containsAliases || !resolvedLanguage.name) {
|
|
194
|
+
resolvedLanguage.name = bestName;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (lang.configuration) {
|
|
198
|
+
resolvedLanguage.configurationFiles.push(lang.configuration);
|
|
199
|
+
}
|
|
200
|
+
if (lang.icon) {
|
|
201
|
+
resolvedLanguage.icons.push(lang.icon);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
isRegisteredLanguageId(languageId) {
|
|
205
|
+
if (!languageId) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
return hasOwnProperty.call(this._languages, languageId);
|
|
209
|
+
}
|
|
210
|
+
getRegisteredLanguageIds() {
|
|
211
|
+
return Object.keys(this._languages);
|
|
212
|
+
}
|
|
213
|
+
getLanguageIdByLanguageName(languageName) {
|
|
214
|
+
const languageNameLower = languageName.toLowerCase();
|
|
215
|
+
if (!hasOwnProperty.call(this._lowercaseNameMap, languageNameLower)) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
return this._lowercaseNameMap[languageNameLower];
|
|
219
|
+
}
|
|
220
|
+
getLanguageIdByMimeType(mimeType) {
|
|
221
|
+
if (!mimeType) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
if (hasOwnProperty.call(this._mimeTypesMap, mimeType)) {
|
|
225
|
+
return this._mimeTypesMap[mimeType];
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
guessLanguageIdByFilepathOrFirstLine(resource, firstLine) {
|
|
230
|
+
if (!resource && !firstLine) {
|
|
231
|
+
return [];
|
|
232
|
+
}
|
|
233
|
+
return getLanguageIds(resource, firstLine);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export { LanguageIdCodec, LanguagesRegistry };
|