mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 16:15:41 +01:00
Add prettier
This commit is contained in:
parent
1ca4a3a0aa
commit
3efc637414
156 changed files with 51562 additions and 37461 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -9,7 +9,8 @@ import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration;
|
|||
import ILanguage = monaco.languages.IMonarchLanguage;
|
||||
|
||||
// Allow for running under nodejs/requirejs in tests
|
||||
const _monaco: typeof monaco = (typeof monaco === 'undefined' ? (<any>self).monaco : monaco);
|
||||
const _monaco: typeof monaco =
|
||||
typeof monaco === 'undefined' ? (<any>self).monaco : monaco;
|
||||
|
||||
export const conf: IRichLanguageConfiguration = {
|
||||
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
|
||||
|
|
@ -30,22 +31,34 @@ export const conf: IRichLanguageConfiguration = {
|
|||
// e.g. /** | */
|
||||
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
|
||||
afterText: /^\s*\*\/$/,
|
||||
action: { indentAction: _monaco.languages.IndentAction.IndentOutdent, appendText: ' * ' }
|
||||
action: {
|
||||
indentAction: _monaco.languages.IndentAction.IndentOutdent,
|
||||
appendText: ' * '
|
||||
}
|
||||
},
|
||||
{
|
||||
// e.g. /** ...|
|
||||
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
|
||||
action: { indentAction: _monaco.languages.IndentAction.None, appendText: ' * ' }
|
||||
action: {
|
||||
indentAction: _monaco.languages.IndentAction.None,
|
||||
appendText: ' * '
|
||||
}
|
||||
},
|
||||
{
|
||||
// e.g. * ...|
|
||||
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
|
||||
action: { indentAction: _monaco.languages.IndentAction.None, appendText: '* ' }
|
||||
action: {
|
||||
indentAction: _monaco.languages.IndentAction.None,
|
||||
appendText: '* '
|
||||
}
|
||||
},
|
||||
{
|
||||
// e.g. */|
|
||||
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
|
||||
action: { indentAction: _monaco.languages.IndentAction.None, removeText: 1 }
|
||||
action: {
|
||||
indentAction: _monaco.languages.IndentAction.None,
|
||||
removeText: 1
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
|
|
@ -54,15 +67,15 @@ export const conf: IRichLanguageConfiguration = {
|
|||
{ open: '[', close: ']' },
|
||||
{ open: '(', close: ')' },
|
||||
{ open: '"', close: '"', notIn: ['string'] },
|
||||
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
|
||||
{ open: "'", close: "'", notIn: ['string', 'comment'] },
|
||||
{ open: '`', close: '`', notIn: ['string', 'comment'] },
|
||||
{ open: "/**", close: " */", notIn: ["string"] }
|
||||
{ open: '/**', close: ' */', notIn: ['string'] }
|
||||
],
|
||||
|
||||
folding: {
|
||||
markers: {
|
||||
start: new RegExp("^\\s*//\\s*#?region\\b"),
|
||||
end: new RegExp("^\\s*//\\s*#?endregion\\b")
|
||||
start: new RegExp('^\\s*//\\s*#?region\\b'),
|
||||
end: new RegExp('^\\s*//\\s*#?endregion\\b')
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -75,23 +88,128 @@ export const language = {
|
|||
keywords: [
|
||||
// Should match the keys of textToKeywordObj in
|
||||
// https://github.com/microsoft/TypeScript/blob/master/src/compiler/scanner.ts
|
||||
'abstract', 'any', 'as', 'asserts', 'bigint', 'boolean', 'break', 'case', 'catch',
|
||||
'class', 'continue', 'const', 'constructor', 'debugger', 'declare', 'default',
|
||||
'delete', 'do', 'else', 'enum', 'export', 'extends', 'false', 'finally', 'for',
|
||||
'from', 'function', 'get', 'if', 'implements', 'import', 'in', 'infer',
|
||||
'instanceof', 'interface', 'is', 'keyof', 'let', 'module', 'namespace', 'never',
|
||||
'new', 'null', 'number', 'object', 'package', 'private', 'protected', 'public',
|
||||
'readonly', 'require', 'global', 'return', 'set', 'static', 'string', 'super',
|
||||
'switch', 'symbol', 'this', 'throw', 'true', 'try', 'type', 'typeof', 'undefined',
|
||||
'unique', 'unknown', 'var', 'void', 'while', 'with', 'yield', 'async', 'await', 'of'
|
||||
'abstract',
|
||||
'any',
|
||||
'as',
|
||||
'asserts',
|
||||
'bigint',
|
||||
'boolean',
|
||||
'break',
|
||||
'case',
|
||||
'catch',
|
||||
'class',
|
||||
'continue',
|
||||
'const',
|
||||
'constructor',
|
||||
'debugger',
|
||||
'declare',
|
||||
'default',
|
||||
'delete',
|
||||
'do',
|
||||
'else',
|
||||
'enum',
|
||||
'export',
|
||||
'extends',
|
||||
'false',
|
||||
'finally',
|
||||
'for',
|
||||
'from',
|
||||
'function',
|
||||
'get',
|
||||
'if',
|
||||
'implements',
|
||||
'import',
|
||||
'in',
|
||||
'infer',
|
||||
'instanceof',
|
||||
'interface',
|
||||
'is',
|
||||
'keyof',
|
||||
'let',
|
||||
'module',
|
||||
'namespace',
|
||||
'never',
|
||||
'new',
|
||||
'null',
|
||||
'number',
|
||||
'object',
|
||||
'package',
|
||||
'private',
|
||||
'protected',
|
||||
'public',
|
||||
'readonly',
|
||||
'require',
|
||||
'global',
|
||||
'return',
|
||||
'set',
|
||||
'static',
|
||||
'string',
|
||||
'super',
|
||||
'switch',
|
||||
'symbol',
|
||||
'this',
|
||||
'throw',
|
||||
'true',
|
||||
'try',
|
||||
'type',
|
||||
'typeof',
|
||||
'undefined',
|
||||
'unique',
|
||||
'unknown',
|
||||
'var',
|
||||
'void',
|
||||
'while',
|
||||
'with',
|
||||
'yield',
|
||||
'async',
|
||||
'await',
|
||||
'of'
|
||||
],
|
||||
|
||||
operators: [
|
||||
'<=', '>=', '==', '!=', '===', '!==', '=>', '+', '-', '**',
|
||||
'*', '/', '%', '++', '--', '<<', '</', '>>', '>>>', '&',
|
||||
'|', '^', '!', '~', '&&', '||', '??', '?', ':', '=', '+=', '-=',
|
||||
'*=', '**=', '/=', '%=', '<<=', '>>=', '>>>=', '&=', '|=',
|
||||
'^=', '@',
|
||||
'<=',
|
||||
'>=',
|
||||
'==',
|
||||
'!=',
|
||||
'===',
|
||||
'!==',
|
||||
'=>',
|
||||
'+',
|
||||
'-',
|
||||
'**',
|
||||
'*',
|
||||
'/',
|
||||
'%',
|
||||
'++',
|
||||
'--',
|
||||
'<<',
|
||||
'</',
|
||||
'>>',
|
||||
'>>>',
|
||||
'&',
|
||||
'|',
|
||||
'^',
|
||||
'!',
|
||||
'~',
|
||||
'&&',
|
||||
'||',
|
||||
'??',
|
||||
'?',
|
||||
':',
|
||||
'=',
|
||||
'+=',
|
||||
'-=',
|
||||
'*=',
|
||||
'**=',
|
||||
'/=',
|
||||
'%=',
|
||||
'<<=',
|
||||
'>>=',
|
||||
'>>>=',
|
||||
'&=',
|
||||
'|=',
|
||||
'^=',
|
||||
'@'
|
||||
],
|
||||
|
||||
// we include these common regular expressions
|
||||
|
|
@ -107,38 +225,44 @@ export const language = {
|
|||
|
||||
// The main tokenizer for our languages
|
||||
tokenizer: {
|
||||
root: [
|
||||
[/[{}]/, 'delimiter.bracket'],
|
||||
{ include: 'common' }
|
||||
],
|
||||
root: [[/[{}]/, 'delimiter.bracket'], { include: 'common' }],
|
||||
|
||||
common: [
|
||||
// identifiers and keywords
|
||||
[/[a-z_$][\w$]*/, {
|
||||
cases: {
|
||||
'@keywords': 'keyword',
|
||||
'@default': 'identifier'
|
||||
[
|
||||
/[a-z_$][\w$]*/,
|
||||
{
|
||||
cases: {
|
||||
'@keywords': 'keyword',
|
||||
'@default': 'identifier'
|
||||
}
|
||||
}
|
||||
}],
|
||||
[/[A-Z][\w\$]*/, 'type.identifier'], // to show class names nicely
|
||||
],
|
||||
[/[A-Z][\w\$]*/, 'type.identifier'], // to show class names nicely
|
||||
// [/[A-Z][\w\$]*/, 'identifier'],
|
||||
|
||||
// whitespace
|
||||
{ include: '@whitespace' },
|
||||
|
||||
// regular expression: ensure it is terminated before beginning (otherwise it is an opeator)
|
||||
[/\/(?=([^\\\/]|\\.)+\/([gimsuy]*)(\s*)(\.|;|,|\)|\]|\}|$))/, { token: 'regexp', bracket: '@open', next: '@regexp' }],
|
||||
[
|
||||
/\/(?=([^\\\/]|\\.)+\/([gimsuy]*)(\s*)(\.|;|,|\)|\]|\}|$))/,
|
||||
{ token: 'regexp', bracket: '@open', next: '@regexp' }
|
||||
],
|
||||
|
||||
// delimiters and operators
|
||||
[/[()\[\]]/, '@brackets'],
|
||||
[/[<>](?!@symbols)/, '@brackets'],
|
||||
[/!(?=([^=]|$))/, 'delimiter'],
|
||||
[/@symbols/, {
|
||||
cases: {
|
||||
'@operators': 'delimiter',
|
||||
'@default': ''
|
||||
[
|
||||
/@symbols/,
|
||||
{
|
||||
cases: {
|
||||
'@operators': 'delimiter',
|
||||
'@default': ''
|
||||
}
|
||||
}
|
||||
}],
|
||||
],
|
||||
|
||||
// numbers
|
||||
[/(@digits)[eE]([\-+]?(@digits))?/, 'number.float'],
|
||||
|
|
@ -152,18 +276,18 @@ export const language = {
|
|||
[/[;,.]/, 'delimiter'],
|
||||
|
||||
// strings
|
||||
[/"([^"\\]|\\.)*$/, 'string.invalid'], // non-teminated string
|
||||
[/'([^'\\]|\\.)*$/, 'string.invalid'], // non-teminated string
|
||||
[/"([^"\\]|\\.)*$/, 'string.invalid'], // non-teminated string
|
||||
[/'([^'\\]|\\.)*$/, 'string.invalid'], // non-teminated string
|
||||
[/"/, 'string', '@string_double'],
|
||||
[/'/, 'string', '@string_single'],
|
||||
[/`/, 'string', '@string_backtick'],
|
||||
[/`/, 'string', '@string_backtick']
|
||||
],
|
||||
|
||||
whitespace: [
|
||||
[/[ \t\r\n]+/, ''],
|
||||
[/\/\*\*(?!\/)/, 'comment.doc', '@jsdoc'],
|
||||
[/\/\*/, 'comment', '@comment'],
|
||||
[/\/\/.*$/, 'comment'],
|
||||
[/\/\/.*$/, 'comment']
|
||||
],
|
||||
|
||||
comment: [
|
||||
|
|
@ -180,15 +304,37 @@ export const language = {
|
|||
|
||||
// We match regular expression quite precisely
|
||||
regexp: [
|
||||
[/(\{)(\d+(?:,\d*)?)(\})/, ['regexp.escape.control', 'regexp.escape.control', 'regexp.escape.control']],
|
||||
[/(\[)(\^?)(?=(?:[^\]\\\/]|\\.)+)/, ['regexp.escape.control', { token: 'regexp.escape.control', next: '@regexrange' }]],
|
||||
[/(\()(\?:|\?=|\?!)/, ['regexp.escape.control', 'regexp.escape.control']],
|
||||
[
|
||||
/(\{)(\d+(?:,\d*)?)(\})/,
|
||||
[
|
||||
'regexp.escape.control',
|
||||
'regexp.escape.control',
|
||||
'regexp.escape.control'
|
||||
]
|
||||
],
|
||||
[
|
||||
/(\[)(\^?)(?=(?:[^\]\\\/]|\\.)+)/,
|
||||
[
|
||||
'regexp.escape.control',
|
||||
{ token: 'regexp.escape.control', next: '@regexrange' }
|
||||
]
|
||||
],
|
||||
[
|
||||
/(\()(\?:|\?=|\?!)/,
|
||||
['regexp.escape.control', 'regexp.escape.control']
|
||||
],
|
||||
[/[()]/, 'regexp.escape.control'],
|
||||
[/@regexpctl/, 'regexp.escape.control'],
|
||||
[/[^\\\/]/, 'regexp'],
|
||||
[/@regexpesc/, 'regexp.escape'],
|
||||
[/\\\./, 'regexp.invalid'],
|
||||
[/(\/)([gimsuy]*)/, [{ token: 'regexp', bracket: '@close', next: '@pop' }, 'keyword.other']],
|
||||
[
|
||||
/(\/)([gimsuy]*)/,
|
||||
[
|
||||
{ token: 'regexp', bracket: '@close', next: '@pop' },
|
||||
'keyword.other'
|
||||
]
|
||||
]
|
||||
],
|
||||
|
||||
regexrange: [
|
||||
|
|
@ -196,7 +342,14 @@ export const language = {
|
|||
[/\^/, 'regexp.invalid'],
|
||||
[/@regexpesc/, 'regexp.escape'],
|
||||
[/[^\]]/, 'regexp'],
|
||||
[/\]/, { token: 'regexp.escape.control', next: '@pop', bracket: '@close' }]
|
||||
[
|
||||
/\]/,
|
||||
{
|
||||
token: 'regexp.escape.control',
|
||||
next: '@pop',
|
||||
bracket: '@close'
|
||||
}
|
||||
]
|
||||
],
|
||||
|
||||
string_double: [
|
||||
|
|
@ -225,6 +378,6 @@ export const language = {
|
|||
[/\{/, 'delimiter.bracket', '@bracketCounting'],
|
||||
[/\}/, 'delimiter.bracket', '@pop'],
|
||||
{ include: 'common' }
|
||||
],
|
||||
},
|
||||
]
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue