mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 22:02:55 +01:00
Reorganize project
This commit is contained in:
parent
49f2283894
commit
93c48edccc
121 changed files with 875 additions and 426 deletions
46
src/_.contribution.ts
Normal file
46
src/_.contribution.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
// Allow for running under nodejs/requirejs in tests
|
||||
const _monaco: typeof monaco = (typeof monaco === 'undefined' ? (<any>self).monaco : monaco);
|
||||
|
||||
interface ILang extends monaco.languages.ILanguageExtensionPoint {
|
||||
loader: () => monaco.Promise<ILangImpl>;
|
||||
}
|
||||
|
||||
interface ILangImpl {
|
||||
conf: monaco.languages.LanguageConfiguration;
|
||||
language: monaco.languages.IMonarchLanguage;
|
||||
}
|
||||
|
||||
let languageDefinitions: { [languageId: string]: ILang } = {};
|
||||
|
||||
function _loadLanguage(languageId: string): monaco.Promise<void> {
|
||||
const loader = languageDefinitions[languageId].loader;
|
||||
return loader().then((mod) => {
|
||||
_monaco.languages.setMonarchTokensProvider(languageId, mod.language);
|
||||
_monaco.languages.setLanguageConfiguration(languageId, mod.conf);
|
||||
});
|
||||
}
|
||||
|
||||
let languagePromises: { [languageId: string]: monaco.Promise<void> } = {};
|
||||
|
||||
export function loadLanguage(languageId: string): monaco.Promise<void> {
|
||||
if (!languagePromises[languageId]) {
|
||||
languagePromises[languageId] = _loadLanguage(languageId);
|
||||
}
|
||||
return languagePromises[languageId];
|
||||
}
|
||||
|
||||
export function registerLanguage(def: ILang): void {
|
||||
let languageId = def.id;
|
||||
|
||||
languageDefinitions[languageId] = def;
|
||||
_monaco.languages.register(def);
|
||||
_monaco.languages.onLanguage(languageId, () => {
|
||||
loadLanguage(languageId);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue