You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
monaco-editor/src/monaco.contribution.ts

269 lines
6.9 KiB
TypeScript

9 years ago
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
8 years ago
declare var require: <T>(moduleId: [string], callback: (module: T) => void, error: (err: any) => void) => void;
9 years ago
// Allow for running under nodejs/requirejs in tests
var _monaco: typeof monaco = (typeof monaco === 'undefined' ? (<any>self).monaco : monaco);
interface ILang extends monaco.languages.ILanguageExtensionPoint {
module: string;
}
interface ILangImpl {
conf: monaco.languages.LanguageConfiguration;
9 years ago
language: monaco.languages.IMonarchLanguage;
}
8 years ago
let languageDefinitions: { [languageId: string]: ILang } = {};
9 years ago
8 years ago
function _loadLanguage(languageId: string): monaco.Promise<void> {
9 years ago
let module = languageDefinitions[languageId].module;
return new _monaco.Promise<void>((c, e, p) => {
require<ILangImpl>([module], (mod) => {
_monaco.languages.setMonarchTokensProvider(languageId, mod.language);
_monaco.languages.setLanguageConfiguration(languageId, mod.conf);
c(void 0);
}, e);
});
}
8 years ago
let languagePromises: { [languageId: string]: monaco.Promise<void> } = {};
8 years ago
export function loadLanguage(languageId: string): monaco.Promise<void> {
if (!languagePromises[languageId]) {
languagePromises[languageId] = _loadLanguage(languageId);
}
return languagePromises[languageId];
}
8 years ago
function registerLanguage(def: ILang): void {
9 years ago
let languageId = def.id;
languageDefinitions[languageId] = def;
_monaco.languages.register(def);
_monaco.languages.onLanguage(languageId, () => {
loadLanguage(languageId);
});
}
registerLanguage({
id: 'bat',
8 years ago
extensions: ['.bat', '.cmd'],
aliases: ['Batch', 'bat'],
9 years ago
module: './bat'
});
registerLanguage({
id: 'coffeescript',
8 years ago
extensions: ['.coffee'],
aliases: ['CoffeeScript', 'coffeescript', 'coffee'],
9 years ago
mimetypes: ['text/x-coffeescript', 'text/coffeescript'],
module: './coffee'
});
registerLanguage({
id: 'c',
8 years ago
extensions: ['.c', '.h'],
aliases: ['C', 'c'],
9 years ago
module: './cpp'
});
registerLanguage({
id: 'cpp',
8 years ago
extensions: ['.cpp', '.cc', '.cxx', '.hpp', '.hh', '.hxx'],
aliases: ['C++', 'Cpp', 'cpp'],
9 years ago
module: './cpp'
});
registerLanguage({
id: 'csharp',
8 years ago
extensions: ['.cs', '.csx'],
aliases: ['C#', 'csharp'],
9 years ago
module: './csharp'
});
registerLanguage({
id: 'dockerfile',
8 years ago
extensions: ['.dockerfile'],
filenames: ['Dockerfile'],
aliases: ['Dockerfile'],
9 years ago
module: './dockerfile'
});
registerLanguage({
id: 'fsharp',
8 years ago
extensions: ['.fs', '.fsi', '.ml', '.mli', '.fsx', '.fsscript'],
aliases: ['F#', 'FSharp', 'fsharp'],
9 years ago
module: './fsharp'
});
registerLanguage({
id: 'go',
8 years ago
extensions: ['.go'],
aliases: ['Go'],
9 years ago
module: './go'
});
9 years ago
registerLanguage({
id: 'handlebars',
extensions: ['.handlebars', '.hbs'],
aliases: ['Handlebars', 'handlebars'],
mimetypes: ['text/x-handlebars-template'],
module: './handlebars'
});
9 years ago
registerLanguage({
id: 'html',
extensions: ['.html', '.htm', '.shtml', '.xhtml', '.mdoc', '.jsp', '.asp', '.aspx', '.jshtm'],
aliases: ['HTML', 'htm', 'html', 'xhtml'],
mimetypes: ['text/html', 'text/x-jshtm', 'text/template', 'text/ng-template'],
module: './html'
});
9 years ago
registerLanguage({
id: 'ini',
8 years ago
extensions: ['.ini', '.properties', '.gitconfig'],
9 years ago
filenames: ['config', '.gitattributes', '.gitconfig', '.editorconfig'],
8 years ago
aliases: ['Ini', 'ini'],
9 years ago
module: './ini'
});
registerLanguage({
id: 'jade',
8 years ago
extensions: ['.jade', '.pug'],
aliases: ['Jade', 'jade'],
9 years ago
module: './jade'
});
registerLanguage({
id: 'java',
8 years ago
extensions: ['.java', '.jav'],
aliases: ['Java', 'java'],
9 years ago
mimetypes: ['text/x-java-source', 'text/x-java'],
module: './java'
});
registerLanguage({
id: 'lua',
8 years ago
extensions: ['.lua'],
aliases: ['Lua', 'lua'],
9 years ago
module: './lua'
});
9 years ago
registerLanguage({
9 years ago
id: 'markdown',
extensions: ['.md', '.markdown', '.mdown', '.mkdn', '.mkd', '.mdwn', '.mdtxt', '.mdtext'],
9 years ago
aliases: ['Markdown', 'markdown'],
9 years ago
module: './markdown'
9 years ago
});
8 years ago
registerLanguage({
id: 'msdax',
extensions: ['.dax', '.msdax'],
aliases: ['DAX', 'MSDAX'],
module: './msdax'
});
9 years ago
registerLanguage({
id: 'objective-c',
8 years ago
extensions: ['.m'],
aliases: ['Objective-C'],
9 years ago
module: './objective-c'
});
8 years ago
registerLanguage({
id: 'postiats',
8 years ago
extensions: ['.dats', '.sats', '.hats'],
aliases: ['ATS', 'ATS/Postiats'],
module: './postiats'
9 years ago
});
9 years ago
registerLanguage({
id: 'php',
extensions: ['.php', '.php4', '.php5', '.phtml', '.ctp'],
aliases: ['PHP', 'php'],
mimetypes: ['application/x-php'],
module: './php'
});
9 years ago
registerLanguage({
id: 'powershell',
8 years ago
extensions: ['.ps1', '.psm1', '.psd1'],
aliases: ['PowerShell', 'powershell', 'ps', 'ps1'],
9 years ago
module: './powershell'
});
registerLanguage({
id: 'python',
8 years ago
extensions: ['.py', '.rpy', '.pyw', '.cpy', '.gyp', '.gypi'],
aliases: ['Python', 'py'],
9 years ago
firstLine: '^#!/.*\\bpython[0-9.-]*\\b',
module: './python'
});
registerLanguage({
id: 'r',
8 years ago
extensions: ['.r', '.rhistory', '.rprofile', '.rt'],
aliases: ['R', 'r'],
9 years ago
module: './r'
});
9 years ago
registerLanguage({
id: 'razor',
extensions: ['.cshtml'],
aliases: ['Razor', 'razor'],
mimetypes: ['text/x-cshtml'],
module: './razor'
});
9 years ago
registerLanguage({
id: 'ruby',
8 years ago
extensions: ['.rb', '.rbx', '.rjs', '.gemspec', '.pp'],
filenames: ['rakefile'],
aliases: ['Ruby', 'rb'],
9 years ago
module: './ruby'
});
registerLanguage({
id: 'swift',
8 years ago
aliases: ['Swift', 'swift'],
9 years ago
extensions: ['.swift'],
mimetypes: ['text/swift'],
module: './swift'
});
registerLanguage({
id: 'sql',
8 years ago
extensions: ['.sql'],
aliases: ['SQL'],
9 years ago
module: './sql'
});
registerLanguage({
id: 'vb',
8 years ago
extensions: ['.vb'],
aliases: ['Visual Basic', 'vb'],
9 years ago
module: './vb'
});
registerLanguage({
id: 'xml',
8 years ago
extensions: ['.xml', '.dtd', '.ascx', '.csproj', '.config', '.wxi', '.wxl', '.wxs', '.xaml', '.svg', '.svgz'],
firstLine: '(\\<\\?xml.*)|(\\<svg)|(\\<\\!doctype\\s+svg)',
aliases: ['XML', 'xml'],
9 years ago
mimetypes: ['text/xml', 'application/xml', 'application/xaml+xml', 'application/xml-dtd'],
module: './xml'
});
registerLanguage({
id: 'less',
extensions: ['.less'],
aliases: ['Less', 'less'],
mimetypes: ['text/x-less', 'text/less'],
module: './less'
});
registerLanguage({
id: 'scss',
extensions: ['.scss'],
aliases: ['Sass', 'sass', 'scss'],
mimetypes: ['text/x-scss', 'text/scss'],
module: './scss'
});
registerLanguage({
id: 'css',
extensions: ['.css'],
aliases: ['CSS', 'css'],
mimetypes: ['text/css'],
module: './css'
});
8 years ago
registerLanguage({
id: 'yaml',
extensions: ['.yaml', '.yml'],
aliases: ['YAML', 'yaml', 'YML', 'yml'],
mimetypes: ['application/x-yaml'],
module: './yaml'
});
8 years ago
registerLanguage({
8 years ago
id: 'sol',
extensions: ['.sol'],
aliases: ['sol', 'solidity', 'Solidity'],
module: './solidity'
8 years ago
});