-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Painless] Language Service (#60612)
* Added language service * Use the correct monaco instance and add wordwise operations * Remove plugin context initializer for now
- Loading branch information
1 parent
4506714
commit ec81bf6
Showing
8 changed files
with
244 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 0 additions & 195 deletions
195
x-pack/plugins/painless_lab/public/application/register_painless.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { monacoPainlessLang } from './monaco_painless_lang'; |
174 changes: 174 additions & 0 deletions
174
x-pack/plugins/painless_lab/public/lib/monaco_painless_lang.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import * as monaco from 'monaco-editor'; | ||
|
||
/** | ||
* Extends the default type for a Monarch language so we can use | ||
* attribute references (like @keywords to reference the keywords list) | ||
* in the defined tokenizer | ||
*/ | ||
interface Language extends monaco.languages.IMonarchLanguage { | ||
default: string; | ||
brackets: any; | ||
keywords: string[]; | ||
symbols: RegExp; | ||
escapes: RegExp; | ||
digits: RegExp; | ||
primitives: string[]; | ||
octaldigits: RegExp; | ||
binarydigits: RegExp; | ||
constants: string[]; | ||
operators: string[]; | ||
} | ||
|
||
export const monacoPainlessLang = { | ||
default: '', | ||
// painless does not use < >, so we define our own | ||
brackets: [ | ||
['{', '}', 'delimiter.curly'], | ||
['[', ']', 'delimiter.square'], | ||
['(', ')', 'delimiter.parenthesis'], | ||
], | ||
keywords: [ | ||
'if', | ||
'in', | ||
'else', | ||
'while', | ||
'do', | ||
'for', | ||
'continue', | ||
'break', | ||
'return', | ||
'new', | ||
'try', | ||
'catch', | ||
'throw', | ||
'this', | ||
'instanceof', | ||
], | ||
primitives: ['void', 'boolean', 'byte', 'short', 'char', 'int', 'long', 'float', 'double', 'def'], | ||
constants: ['true', 'false'], | ||
operators: [ | ||
'=', | ||
'>', | ||
'<', | ||
'!', | ||
'~', | ||
'?', | ||
'?:', | ||
'?.', | ||
':', | ||
'==', | ||
'===', | ||
'<=', | ||
'>=', | ||
'!=', | ||
'!==', | ||
'&&', | ||
'||', | ||
'++', | ||
'--', | ||
'+', | ||
'-', | ||
'*', | ||
'/', | ||
'&', | ||
'|', | ||
'^', | ||
'%', | ||
'<<', | ||
'>>', | ||
'>>>', | ||
'+=', | ||
'-=', | ||
'*=', | ||
'/=', | ||
'&=', | ||
'|=', | ||
'^=', | ||
'%=', | ||
'<<=', | ||
'>>=', | ||
'>>>=', | ||
'->', | ||
'::', | ||
'=~', | ||
'==~', | ||
], | ||
symbols: /[=><!~?:&|+\-*\/^%]+/, | ||
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/, | ||
digits: /\d+(_+\d+)*/, | ||
octaldigits: /[0-7]+(_+[0-7]+)*/, | ||
binarydigits: /[0-1]+(_+[0-1]+)*/, | ||
hexdigits: /[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/, | ||
tokenizer: { | ||
root: [ | ||
// identifiers and keywords | ||
[ | ||
/[a-zA-Z_][\w]*/, | ||
{ | ||
cases: { | ||
'@keywords': 'keyword', | ||
'@primitives': 'type', | ||
'@constants': 'constant', | ||
'@default': 'identifier', | ||
}, | ||
}, | ||
], | ||
// whitespace | ||
[/[ \t\r\n]+/, '@whitespace'], | ||
// comments | ||
// [/\/\*/, 'comment', '@comment'], | ||
[/\/\/.*$/, 'comment'], | ||
// brackets | ||
[/[{}()\[\]]/, '@brackets'], | ||
// operators | ||
[ | ||
/@symbols/, | ||
{ | ||
cases: { | ||
'@operators': 'operators', | ||
'@default': '', | ||
}, | ||
}, | ||
], | ||
// numbers | ||
[/(@digits)[eE]([\-+]?(@digits))?[fFdD]?/, 'number.float'], | ||
[/(@digits)\.(@digits)([eE][\-+]?(@digits))?[fFdD]?/, 'number.float'], | ||
[/0[xX](@hexdigits)[Ll]?/, 'number.hex'], | ||
[/0(@octaldigits)[Ll]?/, 'number.octal'], | ||
[/0[bB](@binarydigits)[Ll]?/, 'number.binary'], | ||
[/(@digits)[fFdD]/, 'number.float'], | ||
[/(@digits)[lL]?/, 'number'], | ||
// delimiter: after numbers due to conflict with decimals and dot | ||
[/[;,.]/, 'delimiter'], | ||
// strings double quoted | ||
[/"([^"\\]|\\.)*$/, 'string.invalid'], // string without termination | ||
[/"/, 'string', '@string_dq'], | ||
// strings single quoted | ||
[/'([^'\\]|\\.)*$/, 'string.invalid'], // string without termination | ||
[/'/, 'string', '@string_sq'], | ||
], | ||
comment: [ | ||
[/[^\/*]+/, 'comment'], | ||
[/\*\//, 'comment', '@pop'], | ||
[/[\/*]/, 'comment'], | ||
], | ||
string_dq: [ | ||
[/[^\\"]+/, 'string'], | ||
[/@escapes/, 'string.escape'], | ||
[/\\./, 'string.escape.invalid'], | ||
[/"/, 'string', '@pop'], | ||
], | ||
string_sq: [ | ||
[/[^\\']+/, 'string'], | ||
[/@escapes/, 'string.escape'], | ||
[/\\./, 'string.escape.invalid'], | ||
[/'/, 'string', '@pop'], | ||
], | ||
}, | ||
} as Language; |
Oops, something went wrong.