From f02b836e4a18c2914c4cbcdc286c23fcaf680a80 Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Fri, 16 Oct 2020 15:58:45 -0400 Subject: [PATCH] add support to specify context for autocomplete --- packages/kbn-monaco/src/painless/index.ts | 4 +- packages/kbn-monaco/src/painless/language.ts | 5 +- .../src/painless/painless_completion.ts | 9 +- packages/kbn-monaco/src/painless/types.ts | 2 + .../src/painless/worker/completion_manager.ts | 261 ++++ .../painless/worker/context/filter_context.ts | 1300 +++++++++++++++++ .../src/painless/worker/context/index.ts | 23 + .../painless_test_context.ts} | 3 +- .../painless/worker/context/score_context.ts | 1300 +++++++++++++++++ .../src/painless/worker/painless.worker.ts | 2 +- .../worker/painless_completion_utils.ts | 241 --- .../src/painless/worker/painless_worker.ts | 42 +- .../public/application/components/editor.tsx | 1 + 13 files changed, 2907 insertions(+), 286 deletions(-) create mode 100644 packages/kbn-monaco/src/painless/worker/completion_manager.ts create mode 100644 packages/kbn-monaco/src/painless/worker/context/filter_context.ts create mode 100644 packages/kbn-monaco/src/painless/worker/context/index.ts rename packages/kbn-monaco/src/painless/worker/{context.ts => context/painless_test_context.ts} (99%) create mode 100644 packages/kbn-monaco/src/painless/worker/context/score_context.ts delete mode 100644 packages/kbn-monaco/src/painless/worker/painless_completion_utils.ts diff --git a/packages/kbn-monaco/src/painless/index.ts b/packages/kbn-monaco/src/painless/index.ts index c9a3d830a398d..fa7baf8e842e1 100644 --- a/packages/kbn-monaco/src/painless/index.ts +++ b/packages/kbn-monaco/src/painless/index.ts @@ -20,6 +20,6 @@ /** * This import registers the painless monaco language contribution */ -import './language'; +import { getSuggestionProvider } from './language'; -export const PainlessLang = { ID: 'painless' }; +export const PainlessLang = { ID: 'painless', getSuggestionProvider }; diff --git a/packages/kbn-monaco/src/painless/language.ts b/packages/kbn-monaco/src/painless/language.ts index 1d8768960d0de..157e0df5d9457 100644 --- a/packages/kbn-monaco/src/painless/language.ts +++ b/packages/kbn-monaco/src/painless/language.ts @@ -23,6 +23,7 @@ import { painlessLanguage } from './painless_lexer_rules'; import { PainlessCompletionAdapter } from './painless_completion'; import { WorkerProxyService } from './worker_proxy_service'; import { ID } from './constants'; +import { PainlessContext } from './types'; const wps = new WorkerProxyService(); @@ -36,4 +37,6 @@ monaco.languages.onLanguage(ID, async () => { wps.setup(); }); monaco.languages.setMonarchTokensProvider(ID, painlessLanguage); -monaco.languages.registerCompletionItemProvider(ID, new PainlessCompletionAdapter(worker)); + +export const getSuggestionProvider = (context: PainlessContext) => + new PainlessCompletionAdapter(worker, context); diff --git a/packages/kbn-monaco/src/painless/painless_completion.ts b/packages/kbn-monaco/src/painless/painless_completion.ts index a2e8a6208c722..5057891589434 100644 --- a/packages/kbn-monaco/src/painless/painless_completion.ts +++ b/packages/kbn-monaco/src/painless/painless_completion.ts @@ -40,7 +40,7 @@ const getCompletionKind = (kind: PainlessCompletionKind): monaco.languages.Compl export class PainlessCompletionAdapter implements monaco.languages.CompletionItemProvider { // @ts-ignore - constructor(private _worker) {} + constructor(private _worker, private _painlessContext) {} public get triggerCharacters(): string[] { return ['.']; @@ -52,8 +52,6 @@ export class PainlessCompletionAdapter implements monaco.languages.CompletionIte context: monaco.languages.CompletionContext, token: monaco.CancellationToken ): Promise { - const resource = model.uri; - // Active line characters const currentLineChars = model.getValueInRange({ startLineNumber: position.lineNumber, @@ -61,10 +59,9 @@ export class PainlessCompletionAdapter implements monaco.languages.CompletionIte endLineNumber: position.lineNumber, endColumn: position.column, }); - - return this._worker(resource) + return this._worker() .then((worker: any) => { - return worker.provideAutocompleteSuggestions(resource.toString(), currentLineChars); + return worker.provideAutocompleteSuggestions(currentLineChars, this._painlessContext); }) .then((completionInfo: PainlessCompletionResult) => { const wordInfo = model.getWordUntilPosition(position); diff --git a/packages/kbn-monaco/src/painless/types.ts b/packages/kbn-monaco/src/painless/types.ts index 45f4610985d99..f4cabbf7d4f47 100644 --- a/packages/kbn-monaco/src/painless/types.ts +++ b/packages/kbn-monaco/src/painless/types.ts @@ -19,6 +19,8 @@ export type PainlessCompletionKind = 'type' | 'class' | 'method' | 'constructor' | 'property'; +export type PainlessContext = 'painless_test' | 'filter' | 'score'; + export interface PainlessCompletionItem { label: string; kind: PainlessCompletionKind; diff --git a/packages/kbn-monaco/src/painless/worker/completion_manager.ts b/packages/kbn-monaco/src/painless/worker/completion_manager.ts new file mode 100644 index 0000000000000..b071cbec88c69 --- /dev/null +++ b/packages/kbn-monaco/src/painless/worker/completion_manager.ts @@ -0,0 +1,261 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { PainlessCompletionResult, PainlessCompletionItem, PainlessContext } from '../types'; +import { painlessTestContext, scoreContext, filterContext } from './context'; + +interface Field { + name: string; + type: string; +} + +interface Method { + name: string; + parameters: string[]; + return: string; +} + +interface Constructor { + declaring: string; + parameters: string[]; +} + +interface ContextClass { + name: string; + imported: boolean; + constructors: Constructor[]; + static_methods: Method[]; + methods: Method[]; + static_fields: Field[]; + fields: Field[]; +} + +interface ClassNameMap { + [key: string]: ContextClass; +} + +interface Context { + name: string; + classes: ContextClass[]; +} + +const mapContextToData: { [key: string]: object } = { + painless_test: painlessTestContext, + score: scoreContext, + filter: filterContext, +}; + +// TODO making the assumption there will never be >5 parameters for a method +const parameterIndexToLetterMap: { + [key: number]: string; +} = { + 0: 'a', + 1: 'b', + 2: 'c', + 3: 'd', + 4: 'e', + 5: 'f', +}; + +// TODO for now assuming we will always have parameters and return value +const getMethodDescription = ( + methodName: string, + parameters: string[], + returnValue: string +): string => { + const parameterDescription: string = parameters.reduce( + (description: string, parameterType: string, index: number) => { + const newParameterDescription = `${parameterType} ${parameterIndexToLetterMap[index]}`; + const isLastParameter = parameters.length - 1 === index; + + description = `${description}${newParameterDescription}${isLastParameter ? '' : ', '}`; + + return description; + }, + '' + ); + + // Final format will look something like this: + // pow(double a, double b): double + return `${methodName}(${parameterDescription}): ${returnValue}`; +}; + +export class PainlessCompletionManager { + context: Context; + constructor(private _painlessContext: PainlessContext) { + this.context = mapContextToData[this._painlessContext] as Context; + } + + createClassNameMap() { + return this.context.classes.reduce((acc: ClassNameMap, currentVal) => { + const className = currentVal.name.split('.').pop(); + + if (className) { + acc[className] = currentVal; + } + + return acc; + }, {}); + } + + getTypes() { + return this.context.classes + .filter( + ({ + static_fields: staticFields, + fields, + static_methods: staticMethods, + methods, + constructors, + }) => { + if ( + staticMethods.length === 0 && + methods.length === 0 && + staticFields.length === 0 && + fields.length === 0 && + constructors.length === 0 + ) { + return true; + } + } + ) + .map((type) => type.name); + } + + getPainlessClassesToAutocomplete(): PainlessCompletionResult { + const painlessClasses: PainlessCompletionItem[] = this.context.classes.map(({ name }) => { + const className = name.split('.').pop() || name; // TODO ES to add "displayName" field so this won't be necessary + const isType = this.getTypes().includes(name); + + return { + label: className, + kind: isType ? 'type' : 'class', + documentation: `Class ${className}`, + insertText: className, + }; + }); + return { + isIncomplete: false, + suggestions: painlessClasses, + }; + } + + getPainlessConstructorsToAutocomplete(): PainlessCompletionResult { + const painlessConstructors = this.context.classes + .filter(({ constructors }) => constructors.length > 0) + .map(({ constructors }) => constructors) + .flat(); + + const constructors: PainlessCompletionItem[] = painlessConstructors + // There are sometimes multiple definitions for the same constructor + // This method filters them out so we don't display more than once in autocomplete + // TODO should check with ES and see if we can improve data structure + .filter((constructor, index, constructorArray) => { + return ( + constructorArray.findIndex(({ declaring }) => declaring === constructor.declaring) === + index + ); + }) + .map(({ declaring }) => { + const constructorName = declaring.split('.').pop() || declaring; // TODO ES to add "displayName" field so this won't be necessary + + return { + label: constructorName, + kind: 'constructor', + documentation: `Constructor ${constructorName}`, + insertText: constructorName, + }; + }); + + return { + isIncomplete: false, + suggestions: constructors, + }; + } + + getPainlessClassToAutocomplete(className: string): PainlessCompletionResult { + const classNameMap = this.createClassNameMap(); + + if (!classNameMap[className]) { + return { + isIncomplete: false, + suggestions: [], + }; + } + + const { + static_fields: staticFields, + fields, + static_methods: staticMethods, + methods, + } = classNameMap[className]; + + const staticFieldsAutocomplete: PainlessCompletionItem[] = staticFields.map( + ({ name, type }) => { + return { + label: name, + kind: 'property', + documentation: `${name}: ${type}`, + insertText: name, + }; + } + ); + + const fieldsAutocomplete: PainlessCompletionItem[] = fields.map(({ name, type }) => { + return { + label: name, + kind: 'property', + documentation: `${name}: ${type}`, + insertText: name, + }; + }); + + const staticMethodsAutocomplete: PainlessCompletionItem[] = staticMethods.map( + ({ name, parameters, return: returnValue }) => { + return { + label: name, + kind: 'method', + documentation: getMethodDescription(name, parameters, returnValue), + insertText: name, + }; + } + ); + + const methodsAutocomplete: PainlessCompletionItem[] = methods.map( + ({ name, parameters, return: returnValue }) => { + return { + label: name, + kind: 'method', + documentation: getMethodDescription(name, parameters, returnValue), + insertText: name, + }; + } + ); + + return { + isIncomplete: false, + suggestions: [ + ...staticFieldsAutocomplete, + ...staticMethodsAutocomplete, + ...methodsAutocomplete, + ...fieldsAutocomplete, + ], + }; + } +} diff --git a/packages/kbn-monaco/src/painless/worker/context/filter_context.ts b/packages/kbn-monaco/src/painless/worker/context/filter_context.ts new file mode 100644 index 0000000000000..059b87ddb1709 --- /dev/null +++ b/packages/kbn-monaco/src/painless/worker/context/filter_context.ts @@ -0,0 +1,1300 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export const filterContext = { + name: 'filter', + classes: [ + { + name: 'boolean', + imported: true, + constructors: [], + static_methods: [], + methods: [], + static_fields: [], + fields: [], + }, + { + name: 'byte', + imported: true, + constructors: [], + static_methods: [], + methods: [], + static_fields: [], + fields: [], + }, + { + name: 'char', + imported: true, + constructors: [], + static_methods: [], + methods: [], + static_fields: [], + fields: [], + }, + { + name: 'double', + imported: true, + constructors: [], + static_methods: [], + methods: [], + static_fields: [], + fields: [], + }, + { + name: 'float', + imported: true, + constructors: [], + static_methods: [], + methods: [], + static_fields: [], + fields: [], + }, + { + name: 'int', + imported: true, + constructors: [], + static_methods: [], + methods: [], + static_fields: [], + fields: [], + }, + { + name: 'java.lang.Appendable', + imported: true, + constructors: [], + static_methods: [], + methods: [ + { + declaring: 'java.lang.Appendable', + name: 'append', + return: 'java.lang.Appendable', + parameters: ['java.lang.CharSequence', 'int', 'int'], + }, + { + declaring: 'java.lang.Object', + name: 'equals', + return: 'boolean', + parameters: ['java.lang.Object'], + }, + { + declaring: 'java.lang.Object', + name: 'hashCode', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'toString', + return: 'java.lang.String', + parameters: [], + }, + ], + static_fields: [], + fields: [], + }, + { + name: 'java.lang.ArithmeticException', + imported: true, + constructors: [ + { + declaring: 'java.lang.ArithmeticException', + parameters: [], + }, + { + declaring: 'java.lang.ArithmeticException', + parameters: ['java.lang.String'], + }, + ], + static_methods: [], + methods: [ + { + declaring: 'java.lang.Object', + name: 'equals', + return: 'boolean', + parameters: ['java.lang.Object'], + }, + { + declaring: 'java.lang.Throwable', + name: 'getLocalizedMessage', + return: 'java.lang.String', + parameters: [], + }, + { + declaring: 'java.lang.Throwable', + name: 'getMessage', + return: 'java.lang.String', + parameters: [], + }, + { + declaring: 'java.lang.Throwable', + name: 'getStackTrace', + return: '[Ljava.lang.StackTraceElement;', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'hashCode', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'toString', + return: 'java.lang.String', + parameters: [], + }, + ], + static_fields: [], + fields: [], + }, + { + name: 'java.lang.ArrayIndexOutOfBoundsException', + imported: true, + constructors: [ + { + declaring: 'java.lang.ArrayIndexOutOfBoundsException', + parameters: [], + }, + { + declaring: 'java.lang.ArrayIndexOutOfBoundsException', + parameters: ['java.lang.String'], + }, + ], + static_methods: [], + methods: [ + { + declaring: 'java.lang.Object', + name: 'equals', + return: 'boolean', + parameters: ['java.lang.Object'], + }, + { + declaring: 'java.lang.Throwable', + name: 'getLocalizedMessage', + return: 'java.lang.String', + parameters: [], + }, + { + declaring: 'java.lang.Throwable', + name: 'getMessage', + return: 'java.lang.String', + parameters: [], + }, + { + declaring: 'java.lang.Throwable', + name: 'getStackTrace', + return: '[Ljava.lang.StackTraceElement;', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'hashCode', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'toString', + return: 'java.lang.String', + parameters: [], + }, + ], + static_fields: [], + fields: [], + }, + { + name: 'java.lang.ArrayStoreException', + imported: true, + constructors: [ + { + declaring: 'java.lang.ArrayStoreException', + parameters: [], + }, + { + declaring: 'java.lang.ArrayStoreException', + parameters: ['java.lang.String'], + }, + ], + static_methods: [], + methods: [ + { + declaring: 'java.lang.Object', + name: 'equals', + return: 'boolean', + parameters: ['java.lang.Object'], + }, + { + declaring: 'java.lang.Throwable', + name: 'getLocalizedMessage', + return: 'java.lang.String', + parameters: [], + }, + { + declaring: 'java.lang.Throwable', + name: 'getMessage', + return: 'java.lang.String', + parameters: [], + }, + { + declaring: 'java.lang.Throwable', + name: 'getStackTrace', + return: '[Ljava.lang.StackTraceElement;', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'hashCode', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'toString', + return: 'java.lang.String', + parameters: [], + }, + ], + static_fields: [], + fields: [], + }, + { + name: 'java.lang.Boolean', + imported: true, + constructors: [], + static_methods: [ + { + declaring: 'java.lang.Boolean', + name: 'compare', + return: 'int', + parameters: ['boolean', 'boolean'], + }, + { + declaring: 'java.lang.Boolean', + name: 'hashCode', + return: 'int', + parameters: ['boolean'], + }, + { + declaring: 'java.lang.Boolean', + name: 'logicalAnd', + return: 'boolean', + parameters: ['boolean', 'boolean'], + }, + { + declaring: 'java.lang.Boolean', + name: 'logicalOr', + return: 'boolean', + parameters: ['boolean', 'boolean'], + }, + { + declaring: 'java.lang.Boolean', + name: 'logicalXor', + return: 'boolean', + parameters: ['boolean', 'boolean'], + }, + { + declaring: 'java.lang.Boolean', + name: 'parseBoolean', + return: 'boolean', + parameters: ['java.lang.String'], + }, + { + declaring: 'java.lang.Boolean', + name: 'toString', + return: 'java.lang.String', + parameters: ['boolean'], + }, + { + declaring: 'java.lang.Boolean', + name: 'valueOf', + return: 'java.lang.Boolean', + parameters: ['boolean'], + }, + ], + methods: [ + { + declaring: 'java.lang.Boolean', + name: 'booleanValue', + return: 'boolean', + parameters: [], + }, + { + declaring: 'java.lang.Boolean', + name: 'compareTo', + return: 'int', + parameters: ['java.lang.Boolean'], + }, + { + declaring: 'java.lang.Object', + name: 'equals', + return: 'boolean', + parameters: ['java.lang.Object'], + }, + { + declaring: 'java.lang.Object', + name: 'hashCode', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'toString', + return: 'java.lang.String', + parameters: [], + }, + ], + static_fields: [ + { + declaring: 'java.lang.Boolean', + name: 'FALSE', + type: 'java.lang.Boolean', + }, + { + declaring: 'java.lang.Boolean', + name: 'TRUE', + type: 'java.lang.Boolean', + }, + ], + fields: [], + }, + { + name: 'java.lang.Byte', + imported: true, + constructors: [], + static_methods: [ + { + declaring: 'java.lang.Byte', + name: 'compare', + return: 'int', + parameters: ['byte', 'byte'], + }, + { + declaring: 'java.lang.Byte', + name: 'decode', + return: 'java.lang.Byte', + parameters: ['java.lang.String'], + }, + { + declaring: 'java.lang.Byte', + name: 'hashCode', + return: 'int', + parameters: ['byte'], + }, + { + declaring: 'java.lang.Byte', + name: 'parseByte', + return: 'byte', + parameters: ['java.lang.String'], + }, + { + declaring: 'java.lang.Byte', + name: 'parseByte', + return: 'byte', + parameters: ['java.lang.String', 'int'], + }, + { + declaring: 'java.lang.Byte', + name: 'toString', + return: 'java.lang.String', + parameters: ['byte'], + }, + { + declaring: 'java.lang.Byte', + name: 'toUnsignedInt', + return: 'int', + parameters: ['byte'], + }, + { + declaring: 'java.lang.Byte', + name: 'toUnsignedLong', + return: 'long', + parameters: ['byte'], + }, + { + declaring: 'java.lang.Byte', + name: 'valueOf', + return: 'java.lang.Byte', + parameters: ['byte'], + }, + { + declaring: 'java.lang.Byte', + name: 'valueOf', + return: 'java.lang.Byte', + parameters: ['java.lang.String', 'int'], + }, + ], + methods: [ + { + declaring: 'java.lang.Number', + name: 'byteValue', + return: 'byte', + parameters: [], + }, + { + declaring: 'java.lang.Byte', + name: 'compareTo', + return: 'int', + parameters: ['java.lang.Byte'], + }, + { + declaring: 'java.lang.Number', + name: 'doubleValue', + return: 'double', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'equals', + return: 'boolean', + parameters: ['java.lang.Object'], + }, + { + declaring: 'java.lang.Number', + name: 'floatValue', + return: 'float', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'hashCode', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.Number', + name: 'intValue', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.Number', + name: 'longValue', + return: 'long', + parameters: [], + }, + { + declaring: 'java.lang.Number', + name: 'shortValue', + return: 'short', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'toString', + return: 'java.lang.String', + parameters: [], + }, + ], + static_fields: [ + { + declaring: 'java.lang.Byte', + name: 'BYTES', + type: 'int', + }, + { + declaring: 'java.lang.Byte', + name: 'MAX_VALUE', + type: 'byte', + }, + { + declaring: 'java.lang.Byte', + name: 'MIN_VALUE', + type: 'byte', + }, + { + declaring: 'java.lang.Byte', + name: 'SIZE', + type: 'int', + }, + ], + fields: [], + }, + { + name: 'java.lang.CharSequence', + imported: true, + constructors: [], + static_methods: [], + methods: [ + { + declaring: 'java.lang.CharSequence', + name: 'charAt', + return: 'char', + parameters: ['int'], + }, + { + declaring: 'java.lang.CharSequence', + name: 'chars', + return: 'java.util.stream.IntStream', + parameters: [], + }, + { + declaring: 'java.lang.CharSequence', + name: 'codePoints', + return: 'java.util.stream.IntStream', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'equals', + return: 'boolean', + parameters: ['java.lang.Object'], + }, + { + declaring: 'java.lang.Object', + name: 'hashCode', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.CharSequence', + name: 'length', + return: 'int', + parameters: [], + }, + { + declaring: 'org.elasticsearch.painless.api.Augmentation', + name: 'replaceAll', + return: 'java.lang.String', + parameters: ['java.util.regex.Pattern', 'java.util.function.Function'], + }, + { + declaring: 'org.elasticsearch.painless.api.Augmentation', + name: 'replaceFirst', + return: 'java.lang.String', + parameters: ['java.util.regex.Pattern', 'java.util.function.Function'], + }, + { + declaring: 'java.lang.CharSequence', + name: 'subSequence', + return: 'java.lang.CharSequence', + parameters: ['int', 'int'], + }, + { + declaring: 'java.lang.CharSequence', + name: 'toString', + return: 'java.lang.String', + parameters: [], + }, + ], + static_fields: [], + fields: [], + }, + { + name: 'java.lang.Character', + imported: true, + constructors: [], + static_methods: [ + { + declaring: 'java.lang.Character', + name: 'charCount', + return: 'int', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'codePointAt', + return: 'int', + parameters: ['java.lang.CharSequence', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'codePointAt', + return: 'int', + parameters: ['[C', 'int', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'codePointBefore', + return: 'int', + parameters: ['java.lang.CharSequence', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'codePointBefore', + return: 'int', + parameters: ['[C', 'int', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'codePointCount', + return: 'int', + parameters: ['java.lang.CharSequence', 'int', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'compare', + return: 'int', + parameters: ['char', 'char'], + }, + { + declaring: 'java.lang.Character', + name: 'digit', + return: 'int', + parameters: ['int', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'forDigit', + return: 'char', + parameters: ['int', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'getDirectionality', + return: 'byte', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'getName', + return: 'java.lang.String', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'getNumericValue', + return: 'int', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'getType', + return: 'int', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'hashCode', + return: 'int', + parameters: ['char'], + }, + { + declaring: 'java.lang.Character', + name: 'highSurrogate', + return: 'char', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isAlphabetic', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isBmpCodePoint', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isDefined', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isDigit', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isHighSurrogate', + return: 'boolean', + parameters: ['char'], + }, + { + declaring: 'java.lang.Character', + name: 'isISOControl', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isIdentifierIgnorable', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isIdeographic', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isJavaIdentifierPart', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isJavaIdentifierStart', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isLetter', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isLetterOrDigit', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isLowerCase', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isMirrored', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isSpaceChar', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isSupplementaryCodePoint', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isSurrogate', + return: 'boolean', + parameters: ['char'], + }, + { + declaring: 'java.lang.Character', + name: 'isSurrogatePair', + return: 'boolean', + parameters: ['char', 'char'], + }, + { + declaring: 'java.lang.Character', + name: 'isTitleCase', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isUnicodeIdentifierPart', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isUnicodeIdentifierStart', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isUpperCase', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isValidCodePoint', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isWhitespace', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'lowSurrogate', + return: 'char', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'offsetByCodePoints', + return: 'int', + parameters: ['java.lang.CharSequence', 'int', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'offsetByCodePoints', + return: 'int', + parameters: ['[C', 'int', 'int', 'int', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'reverseBytes', + return: 'char', + parameters: ['char'], + }, + { + declaring: 'java.lang.Character', + name: 'toChars', + return: '[C', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'toChars', + return: 'int', + parameters: ['int', '[C', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'toCodePoint', + return: 'int', + parameters: ['char', 'char'], + }, + { + declaring: 'java.lang.Character', + name: 'toLowerCase', + return: 'char', + parameters: ['char'], + }, + { + declaring: 'java.lang.Character', + name: 'toString', + return: 'java.lang.String', + parameters: ['char'], + }, + { + declaring: 'java.lang.Character', + name: 'toTitleCase', + return: 'char', + parameters: ['char'], + }, + { + declaring: 'java.lang.Character', + name: 'toUpperCase', + return: 'char', + parameters: ['char'], + }, + { + declaring: 'java.lang.Character', + name: 'valueOf', + return: 'java.lang.Character', + parameters: ['char'], + }, + ], + methods: [ + { + declaring: 'java.lang.Character', + name: 'charValue', + return: 'char', + parameters: [], + }, + { + declaring: 'java.lang.Character', + name: 'compareTo', + return: 'int', + parameters: ['java.lang.Character'], + }, + { + declaring: 'java.lang.Object', + name: 'equals', + return: 'boolean', + parameters: ['java.lang.Object'], + }, + { + declaring: 'java.lang.Object', + name: 'hashCode', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'toString', + return: 'java.lang.String', + parameters: [], + }, + ], + static_fields: [ + { + declaring: 'java.lang.Character', + name: 'BYTES', + type: 'int', + }, + { + declaring: 'java.lang.Character', + name: 'COMBINING_SPACING_MARK', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'CONNECTOR_PUNCTUATION', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'CONTROL', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'CURRENCY_SYMBOL', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DASH_PUNCTUATION', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DECIMAL_DIGIT_NUMBER', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_ARABIC_NUMBER', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_BOUNDARY_NEUTRAL', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_COMMON_NUMBER_SEPARATOR', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_EUROPEAN_NUMBER', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_LEFT_TO_RIGHT', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_NONSPACING_MARK', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_OTHER_NEUTRALS', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_PARAGRAPH_SEPARATOR', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_POP_DIRECTIONAL_FORMAT', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_RIGHT_TO_LEFT', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_SEGMENT_SEPARATOR', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_UNDEFINED', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_WHITESPACE', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'ENCLOSING_MARK', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'END_PUNCTUATION', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'FINAL_QUOTE_PUNCTUATION', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'FORMAT', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'INITIAL_QUOTE_PUNCTUATION', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'LETTER_NUMBER', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'LINE_SEPARATOR', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'LOWERCASE_LETTER', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'MATH_SYMBOL', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'MAX_CODE_POINT', + type: 'int', + }, + { + declaring: 'java.lang.Character', + name: 'MAX_HIGH_SURROGATE', + type: 'char', + }, + { + declaring: 'java.lang.Character', + name: 'MAX_LOW_SURROGATE', + type: 'char', + }, + { + declaring: 'java.lang.Character', + name: 'MAX_RADIX', + type: 'int', + }, + { + declaring: 'java.lang.Character', + name: 'MAX_SURROGATE', + type: 'char', + }, + { + declaring: 'java.lang.Character', + name: 'MAX_VALUE', + type: 'char', + }, + { + declaring: 'java.lang.Character', + name: 'MIN_CODE_POINT', + type: 'int', + }, + { + declaring: 'java.lang.Character', + name: 'MIN_HIGH_SURROGATE', + type: 'char', + }, + { + declaring: 'java.lang.Character', + name: 'MIN_LOW_SURROGATE', + type: 'char', + }, + { + declaring: 'java.lang.Character', + name: 'MIN_RADIX', + type: 'int', + }, + { + declaring: 'java.lang.Character', + name: 'MIN_SUPPLEMENTARY_CODE_POINT', + type: 'int', + }, + { + declaring: 'java.lang.Character', + name: 'MIN_SURROGATE', + type: 'char', + }, + { + declaring: 'java.lang.Character', + name: 'MIN_VALUE', + type: 'char', + }, + { + declaring: 'java.lang.Character', + name: 'MODIFIER_LETTER', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'MODIFIER_SYMBOL', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'NON_SPACING_MARK', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'OTHER_LETTER', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'OTHER_NUMBER', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'OTHER_PUNCTUATION', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'OTHER_SYMBOL', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'PARAGRAPH_SEPARATOR', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'PRIVATE_USE', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'SIZE', + type: 'int', + }, + { + declaring: 'java.lang.Character', + name: 'SPACE_SEPARATOR', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'START_PUNCTUATION', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'SURROGATE', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'TITLECASE_LETTER', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'UNASSIGNED', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'UPPERCASE_LETTER', + type: 'byte', + }, + ], + fields: [], + }, + { + name: 'java.lang.Character$Subset', + imported: true, + constructors: [], + static_methods: [], + methods: [ + { + declaring: 'java.lang.Object', + name: 'equals', + return: 'boolean', + parameters: ['java.lang.Object'], + }, + { + declaring: 'java.lang.Object', + name: 'hashCode', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'toString', + return: 'java.lang.String', + parameters: [], + }, + ], + static_fields: [], + fields: [], + }, + ], +}; diff --git a/packages/kbn-monaco/src/painless/worker/context/index.ts b/packages/kbn-monaco/src/painless/worker/context/index.ts new file mode 100644 index 0000000000000..67fe9726b8fd2 --- /dev/null +++ b/packages/kbn-monaco/src/painless/worker/context/index.ts @@ -0,0 +1,23 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// TODO temporary exports of stubbed data to handle autocomplete +export { painlessTestContext } from './painless_test_context'; +export { filterContext } from './filter_context'; +export { scoreContext } from './score_context'; diff --git a/packages/kbn-monaco/src/painless/worker/context.ts b/packages/kbn-monaco/src/painless/worker/context/painless_test_context.ts similarity index 99% rename from packages/kbn-monaco/src/painless/worker/context.ts rename to packages/kbn-monaco/src/painless/worker/context/painless_test_context.ts index 977f2cd2ed2ee..bf88a8358b235 100644 --- a/packages/kbn-monaco/src/painless/worker/context.ts +++ b/packages/kbn-monaco/src/painless/worker/context/painless_test_context.ts @@ -17,8 +17,7 @@ * under the License. */ -// TODO temporary export for autcomplete definitions -export const context = { +export const painlessTestContext = { name: 'painless_test', classes: [ { diff --git a/packages/kbn-monaco/src/painless/worker/context/score_context.ts b/packages/kbn-monaco/src/painless/worker/context/score_context.ts new file mode 100644 index 0000000000000..656c4594d75b0 --- /dev/null +++ b/packages/kbn-monaco/src/painless/worker/context/score_context.ts @@ -0,0 +1,1300 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export const scoreContext = { + name: 'score', + classes: [ + { + name: 'boolean', + imported: true, + constructors: [], + static_methods: [], + methods: [], + static_fields: [], + fields: [], + }, + { + name: 'byte', + imported: true, + constructors: [], + static_methods: [], + methods: [], + static_fields: [], + fields: [], + }, + { + name: 'char', + imported: true, + constructors: [], + static_methods: [], + methods: [], + static_fields: [], + fields: [], + }, + { + name: 'double', + imported: true, + constructors: [], + static_methods: [], + methods: [], + static_fields: [], + fields: [], + }, + { + name: 'float', + imported: true, + constructors: [], + static_methods: [], + methods: [], + static_fields: [], + fields: [], + }, + { + name: 'int', + imported: true, + constructors: [], + static_methods: [], + methods: [], + static_fields: [], + fields: [], + }, + { + name: 'java.lang.Appendable', + imported: true, + constructors: [], + static_methods: [], + methods: [ + { + declaring: 'java.lang.Appendable', + name: 'append', + return: 'java.lang.Appendable', + parameters: ['java.lang.CharSequence', 'int', 'int'], + }, + { + declaring: 'java.lang.Object', + name: 'equals', + return: 'boolean', + parameters: ['java.lang.Object'], + }, + { + declaring: 'java.lang.Object', + name: 'hashCode', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'toString', + return: 'java.lang.String', + parameters: [], + }, + ], + static_fields: [], + fields: [], + }, + { + name: 'java.lang.ArithmeticException', + imported: true, + constructors: [ + { + declaring: 'java.lang.ArithmeticException', + parameters: [], + }, + { + declaring: 'java.lang.ArithmeticException', + parameters: ['java.lang.String'], + }, + ], + static_methods: [], + methods: [ + { + declaring: 'java.lang.Object', + name: 'equals', + return: 'boolean', + parameters: ['java.lang.Object'], + }, + { + declaring: 'java.lang.Throwable', + name: 'getLocalizedMessage', + return: 'java.lang.String', + parameters: [], + }, + { + declaring: 'java.lang.Throwable', + name: 'getMessage', + return: 'java.lang.String', + parameters: [], + }, + { + declaring: 'java.lang.Throwable', + name: 'getStackTrace', + return: '[Ljava.lang.StackTraceElement;', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'hashCode', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'toString', + return: 'java.lang.String', + parameters: [], + }, + ], + static_fields: [], + fields: [], + }, + { + name: 'java.lang.ArrayIndexOutOfBoundsException', + imported: true, + constructors: [ + { + declaring: 'java.lang.ArrayIndexOutOfBoundsException', + parameters: [], + }, + { + declaring: 'java.lang.ArrayIndexOutOfBoundsException', + parameters: ['java.lang.String'], + }, + ], + static_methods: [], + methods: [ + { + declaring: 'java.lang.Object', + name: 'equals', + return: 'boolean', + parameters: ['java.lang.Object'], + }, + { + declaring: 'java.lang.Throwable', + name: 'getLocalizedMessage', + return: 'java.lang.String', + parameters: [], + }, + { + declaring: 'java.lang.Throwable', + name: 'getMessage', + return: 'java.lang.String', + parameters: [], + }, + { + declaring: 'java.lang.Throwable', + name: 'getStackTrace', + return: '[Ljava.lang.StackTraceElement;', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'hashCode', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'toString', + return: 'java.lang.String', + parameters: [], + }, + ], + static_fields: [], + fields: [], + }, + { + name: 'java.lang.ArrayStoreException', + imported: true, + constructors: [ + { + declaring: 'java.lang.ArrayStoreException', + parameters: [], + }, + { + declaring: 'java.lang.ArrayStoreException', + parameters: ['java.lang.String'], + }, + ], + static_methods: [], + methods: [ + { + declaring: 'java.lang.Object', + name: 'equals', + return: 'boolean', + parameters: ['java.lang.Object'], + }, + { + declaring: 'java.lang.Throwable', + name: 'getLocalizedMessage', + return: 'java.lang.String', + parameters: [], + }, + { + declaring: 'java.lang.Throwable', + name: 'getMessage', + return: 'java.lang.String', + parameters: [], + }, + { + declaring: 'java.lang.Throwable', + name: 'getStackTrace', + return: '[Ljava.lang.StackTraceElement;', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'hashCode', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'toString', + return: 'java.lang.String', + parameters: [], + }, + ], + static_fields: [], + fields: [], + }, + { + name: 'java.lang.Boolean', + imported: true, + constructors: [], + static_methods: [ + { + declaring: 'java.lang.Boolean', + name: 'compare', + return: 'int', + parameters: ['boolean', 'boolean'], + }, + { + declaring: 'java.lang.Boolean', + name: 'hashCode', + return: 'int', + parameters: ['boolean'], + }, + { + declaring: 'java.lang.Boolean', + name: 'logicalAnd', + return: 'boolean', + parameters: ['boolean', 'boolean'], + }, + { + declaring: 'java.lang.Boolean', + name: 'logicalOr', + return: 'boolean', + parameters: ['boolean', 'boolean'], + }, + { + declaring: 'java.lang.Boolean', + name: 'logicalXor', + return: 'boolean', + parameters: ['boolean', 'boolean'], + }, + { + declaring: 'java.lang.Boolean', + name: 'parseBoolean', + return: 'boolean', + parameters: ['java.lang.String'], + }, + { + declaring: 'java.lang.Boolean', + name: 'toString', + return: 'java.lang.String', + parameters: ['boolean'], + }, + { + declaring: 'java.lang.Boolean', + name: 'valueOf', + return: 'java.lang.Boolean', + parameters: ['boolean'], + }, + ], + methods: [ + { + declaring: 'java.lang.Boolean', + name: 'booleanValue', + return: 'boolean', + parameters: [], + }, + { + declaring: 'java.lang.Boolean', + name: 'compareTo', + return: 'int', + parameters: ['java.lang.Boolean'], + }, + { + declaring: 'java.lang.Object', + name: 'equals', + return: 'boolean', + parameters: ['java.lang.Object'], + }, + { + declaring: 'java.lang.Object', + name: 'hashCode', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'toString', + return: 'java.lang.String', + parameters: [], + }, + ], + static_fields: [ + { + declaring: 'java.lang.Boolean', + name: 'FALSE', + type: 'java.lang.Boolean', + }, + { + declaring: 'java.lang.Boolean', + name: 'TRUE', + type: 'java.lang.Boolean', + }, + ], + fields: [], + }, + { + name: 'java.lang.Byte', + imported: true, + constructors: [], + static_methods: [ + { + declaring: 'java.lang.Byte', + name: 'compare', + return: 'int', + parameters: ['byte', 'byte'], + }, + { + declaring: 'java.lang.Byte', + name: 'decode', + return: 'java.lang.Byte', + parameters: ['java.lang.String'], + }, + { + declaring: 'java.lang.Byte', + name: 'hashCode', + return: 'int', + parameters: ['byte'], + }, + { + declaring: 'java.lang.Byte', + name: 'parseByte', + return: 'byte', + parameters: ['java.lang.String'], + }, + { + declaring: 'java.lang.Byte', + name: 'parseByte', + return: 'byte', + parameters: ['java.lang.String', 'int'], + }, + { + declaring: 'java.lang.Byte', + name: 'toString', + return: 'java.lang.String', + parameters: ['byte'], + }, + { + declaring: 'java.lang.Byte', + name: 'toUnsignedInt', + return: 'int', + parameters: ['byte'], + }, + { + declaring: 'java.lang.Byte', + name: 'toUnsignedLong', + return: 'long', + parameters: ['byte'], + }, + { + declaring: 'java.lang.Byte', + name: 'valueOf', + return: 'java.lang.Byte', + parameters: ['byte'], + }, + { + declaring: 'java.lang.Byte', + name: 'valueOf', + return: 'java.lang.Byte', + parameters: ['java.lang.String', 'int'], + }, + ], + methods: [ + { + declaring: 'java.lang.Number', + name: 'byteValue', + return: 'byte', + parameters: [], + }, + { + declaring: 'java.lang.Byte', + name: 'compareTo', + return: 'int', + parameters: ['java.lang.Byte'], + }, + { + declaring: 'java.lang.Number', + name: 'doubleValue', + return: 'double', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'equals', + return: 'boolean', + parameters: ['java.lang.Object'], + }, + { + declaring: 'java.lang.Number', + name: 'floatValue', + return: 'float', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'hashCode', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.Number', + name: 'intValue', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.Number', + name: 'longValue', + return: 'long', + parameters: [], + }, + { + declaring: 'java.lang.Number', + name: 'shortValue', + return: 'short', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'toString', + return: 'java.lang.String', + parameters: [], + }, + ], + static_fields: [ + { + declaring: 'java.lang.Byte', + name: 'BYTES', + type: 'int', + }, + { + declaring: 'java.lang.Byte', + name: 'MAX_VALUE', + type: 'byte', + }, + { + declaring: 'java.lang.Byte', + name: 'MIN_VALUE', + type: 'byte', + }, + { + declaring: 'java.lang.Byte', + name: 'SIZE', + type: 'int', + }, + ], + fields: [], + }, + { + name: 'java.lang.CharSequence', + imported: true, + constructors: [], + static_methods: [], + methods: [ + { + declaring: 'java.lang.CharSequence', + name: 'charAt', + return: 'char', + parameters: ['int'], + }, + { + declaring: 'java.lang.CharSequence', + name: 'chars', + return: 'java.util.stream.IntStream', + parameters: [], + }, + { + declaring: 'java.lang.CharSequence', + name: 'codePoints', + return: 'java.util.stream.IntStream', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'equals', + return: 'boolean', + parameters: ['java.lang.Object'], + }, + { + declaring: 'java.lang.Object', + name: 'hashCode', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.CharSequence', + name: 'length', + return: 'int', + parameters: [], + }, + { + declaring: 'org.elasticsearch.painless.api.Augmentation', + name: 'replaceAll', + return: 'java.lang.String', + parameters: ['java.util.regex.Pattern', 'java.util.function.Function'], + }, + { + declaring: 'org.elasticsearch.painless.api.Augmentation', + name: 'replaceFirst', + return: 'java.lang.String', + parameters: ['java.util.regex.Pattern', 'java.util.function.Function'], + }, + { + declaring: 'java.lang.CharSequence', + name: 'subSequence', + return: 'java.lang.CharSequence', + parameters: ['int', 'int'], + }, + { + declaring: 'java.lang.CharSequence', + name: 'toString', + return: 'java.lang.String', + parameters: [], + }, + ], + static_fields: [], + fields: [], + }, + { + name: 'java.lang.Character', + imported: true, + constructors: [], + static_methods: [ + { + declaring: 'java.lang.Character', + name: 'charCount', + return: 'int', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'codePointAt', + return: 'int', + parameters: ['java.lang.CharSequence', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'codePointAt', + return: 'int', + parameters: ['[C', 'int', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'codePointBefore', + return: 'int', + parameters: ['java.lang.CharSequence', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'codePointBefore', + return: 'int', + parameters: ['[C', 'int', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'codePointCount', + return: 'int', + parameters: ['java.lang.CharSequence', 'int', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'compare', + return: 'int', + parameters: ['char', 'char'], + }, + { + declaring: 'java.lang.Character', + name: 'digit', + return: 'int', + parameters: ['int', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'forDigit', + return: 'char', + parameters: ['int', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'getDirectionality', + return: 'byte', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'getName', + return: 'java.lang.String', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'getNumericValue', + return: 'int', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'getType', + return: 'int', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'hashCode', + return: 'int', + parameters: ['char'], + }, + { + declaring: 'java.lang.Character', + name: 'highSurrogate', + return: 'char', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isAlphabetic', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isBmpCodePoint', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isDefined', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isDigit', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isHighSurrogate', + return: 'boolean', + parameters: ['char'], + }, + { + declaring: 'java.lang.Character', + name: 'isISOControl', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isIdentifierIgnorable', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isIdeographic', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isJavaIdentifierPart', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isJavaIdentifierStart', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isLetter', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isLetterOrDigit', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isLowerCase', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isMirrored', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isSpaceChar', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isSupplementaryCodePoint', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isSurrogate', + return: 'boolean', + parameters: ['char'], + }, + { + declaring: 'java.lang.Character', + name: 'isSurrogatePair', + return: 'boolean', + parameters: ['char', 'char'], + }, + { + declaring: 'java.lang.Character', + name: 'isTitleCase', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isUnicodeIdentifierPart', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isUnicodeIdentifierStart', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isUpperCase', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isValidCodePoint', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'isWhitespace', + return: 'boolean', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'lowSurrogate', + return: 'char', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'offsetByCodePoints', + return: 'int', + parameters: ['java.lang.CharSequence', 'int', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'offsetByCodePoints', + return: 'int', + parameters: ['[C', 'int', 'int', 'int', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'reverseBytes', + return: 'char', + parameters: ['char'], + }, + { + declaring: 'java.lang.Character', + name: 'toChars', + return: '[C', + parameters: ['int'], + }, + { + declaring: 'java.lang.Character', + name: 'toChars', + return: 'int', + parameters: ['int', '[C', 'int'], + }, + { + declaring: 'java.lang.Character', + name: 'toCodePoint', + return: 'int', + parameters: ['char', 'char'], + }, + { + declaring: 'java.lang.Character', + name: 'toLowerCase', + return: 'char', + parameters: ['char'], + }, + { + declaring: 'java.lang.Character', + name: 'toString', + return: 'java.lang.String', + parameters: ['char'], + }, + { + declaring: 'java.lang.Character', + name: 'toTitleCase', + return: 'char', + parameters: ['char'], + }, + { + declaring: 'java.lang.Character', + name: 'toUpperCase', + return: 'char', + parameters: ['char'], + }, + { + declaring: 'java.lang.Character', + name: 'valueOf', + return: 'java.lang.Character', + parameters: ['char'], + }, + ], + methods: [ + { + declaring: 'java.lang.Character', + name: 'charValue', + return: 'char', + parameters: [], + }, + { + declaring: 'java.lang.Character', + name: 'compareTo', + return: 'int', + parameters: ['java.lang.Character'], + }, + { + declaring: 'java.lang.Object', + name: 'equals', + return: 'boolean', + parameters: ['java.lang.Object'], + }, + { + declaring: 'java.lang.Object', + name: 'hashCode', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'toString', + return: 'java.lang.String', + parameters: [], + }, + ], + static_fields: [ + { + declaring: 'java.lang.Character', + name: 'BYTES', + type: 'int', + }, + { + declaring: 'java.lang.Character', + name: 'COMBINING_SPACING_MARK', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'CONNECTOR_PUNCTUATION', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'CONTROL', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'CURRENCY_SYMBOL', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DASH_PUNCTUATION', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DECIMAL_DIGIT_NUMBER', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_ARABIC_NUMBER', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_BOUNDARY_NEUTRAL', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_COMMON_NUMBER_SEPARATOR', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_EUROPEAN_NUMBER', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_LEFT_TO_RIGHT', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_NONSPACING_MARK', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_OTHER_NEUTRALS', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_PARAGRAPH_SEPARATOR', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_POP_DIRECTIONAL_FORMAT', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_RIGHT_TO_LEFT', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_SEGMENT_SEPARATOR', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_UNDEFINED', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'DIRECTIONALITY_WHITESPACE', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'ENCLOSING_MARK', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'END_PUNCTUATION', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'FINAL_QUOTE_PUNCTUATION', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'FORMAT', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'INITIAL_QUOTE_PUNCTUATION', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'LETTER_NUMBER', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'LINE_SEPARATOR', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'LOWERCASE_LETTER', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'MATH_SYMBOL', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'MAX_CODE_POINT', + type: 'int', + }, + { + declaring: 'java.lang.Character', + name: 'MAX_HIGH_SURROGATE', + type: 'char', + }, + { + declaring: 'java.lang.Character', + name: 'MAX_LOW_SURROGATE', + type: 'char', + }, + { + declaring: 'java.lang.Character', + name: 'MAX_RADIX', + type: 'int', + }, + { + declaring: 'java.lang.Character', + name: 'MAX_SURROGATE', + type: 'char', + }, + { + declaring: 'java.lang.Character', + name: 'MAX_VALUE', + type: 'char', + }, + { + declaring: 'java.lang.Character', + name: 'MIN_CODE_POINT', + type: 'int', + }, + { + declaring: 'java.lang.Character', + name: 'MIN_HIGH_SURROGATE', + type: 'char', + }, + { + declaring: 'java.lang.Character', + name: 'MIN_LOW_SURROGATE', + type: 'char', + }, + { + declaring: 'java.lang.Character', + name: 'MIN_RADIX', + type: 'int', + }, + { + declaring: 'java.lang.Character', + name: 'MIN_SUPPLEMENTARY_CODE_POINT', + type: 'int', + }, + { + declaring: 'java.lang.Character', + name: 'MIN_SURROGATE', + type: 'char', + }, + { + declaring: 'java.lang.Character', + name: 'MIN_VALUE', + type: 'char', + }, + { + declaring: 'java.lang.Character', + name: 'MODIFIER_LETTER', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'MODIFIER_SYMBOL', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'NON_SPACING_MARK', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'OTHER_LETTER', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'OTHER_NUMBER', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'OTHER_PUNCTUATION', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'OTHER_SYMBOL', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'PARAGRAPH_SEPARATOR', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'PRIVATE_USE', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'SIZE', + type: 'int', + }, + { + declaring: 'java.lang.Character', + name: 'SPACE_SEPARATOR', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'START_PUNCTUATION', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'SURROGATE', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'TITLECASE_LETTER', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'UNASSIGNED', + type: 'byte', + }, + { + declaring: 'java.lang.Character', + name: 'UPPERCASE_LETTER', + type: 'byte', + }, + ], + fields: [], + }, + { + name: 'java.lang.Character$Subset', + imported: true, + constructors: [], + static_methods: [], + methods: [ + { + declaring: 'java.lang.Object', + name: 'equals', + return: 'boolean', + parameters: ['java.lang.Object'], + }, + { + declaring: 'java.lang.Object', + name: 'hashCode', + return: 'int', + parameters: [], + }, + { + declaring: 'java.lang.Object', + name: 'toString', + return: 'java.lang.String', + parameters: [], + }, + ], + static_fields: [], + fields: [], + }, + ], +}; diff --git a/packages/kbn-monaco/src/painless/worker/painless.worker.ts b/packages/kbn-monaco/src/painless/worker/painless.worker.ts index ce96c30591915..17405ad08d452 100644 --- a/packages/kbn-monaco/src/painless/worker/painless.worker.ts +++ b/packages/kbn-monaco/src/painless/worker/painless.worker.ts @@ -27,6 +27,6 @@ import { PainlessWorker } from './painless_worker'; self.onmessage = () => { worker.initialize((ctx: any, createData: any) => { - return new PainlessWorker(ctx); + return new PainlessWorker(); }); }; diff --git a/packages/kbn-monaco/src/painless/worker/painless_completion_utils.ts b/packages/kbn-monaco/src/painless/worker/painless_completion_utils.ts deleted file mode 100644 index 79d95db1955be..0000000000000 --- a/packages/kbn-monaco/src/painless/worker/painless_completion_utils.ts +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { PainlessCompletionResult, PainlessCompletionItem } from '../types'; -import { context } from './context'; - -interface Field { - name: string; - type: string; -} - -interface Method { - name: string; - parameters: string[]; - return: string; -} - -interface Constructor { - declaring: string; - parameters: string[]; -} - -interface ContextClass { - name: string; - imported: boolean; - constructors: Constructor[]; - static_methods: Method[]; - methods: Method[]; - static_fields: Field[]; - fields: Field[]; -} - -interface ClassNameMap { - [key: string]: ContextClass; -} - -const createClassNameMap = () => { - return context.classes.reduce((acc: ClassNameMap, currentVal) => { - const className = currentVal.name.split('.').pop(); - - if (className) { - acc[className] = currentVal; - } - - return acc; - }, {}); -}; - -const getTypes = (): string[] => { - return context.classes - .filter( - ({ - static_fields: staticFields, - fields, - static_methods: staticMethods, - methods, - constructors, - }) => { - if ( - staticMethods.length === 0 && - methods.length === 0 && - staticFields.length === 0 && - fields.length === 0 && - constructors.length === 0 - ) { - return true; - } - } - ) - .map((type) => type.name); -}; - -export const painlessTypes = getTypes(); - -export const getPainlessClassesToAutocomplete = (): PainlessCompletionResult => { - const painlessClasses: PainlessCompletionItem[] = context.classes.map(({ name }) => { - const className = name.split('.').pop() || name; // TODO ES to add "displayName" field so this won't be necessary - const isType = painlessTypes.includes(name); - - return { - label: className, - kind: isType ? 'type' : 'class', - documentation: `Class ${className}`, - insertText: className, - }; - }); - return { - isIncomplete: false, - suggestions: painlessClasses, - }; -}; - -// TODO making the assumption there will never be >5 parameters -const indexToLetterMap: { - [key: number]: string; -} = { - 0: 'a', - 1: 'b', - 2: 'c', - 3: 'd', - 4: 'e', - 5: 'f', -}; - -// TODO for now assuming we will always have parameters and return value -const getMethodDescription = ( - methodName: string, - parameters: string[], - returnValue: string -): string => { - const parameterDescription: string = parameters.reduce( - (description: string, parameterType: string, index: number) => { - const newParameterDescription = `${parameterType} ${indexToLetterMap[index]}`; - const isLastParameter = parameters.length - 1 === index; - - description = `${description}${newParameterDescription}${isLastParameter ? '' : ', '}`; - - return description; - }, - '' - ); - - // Final format will look something like this: - // pow(double a, double b): double - return `${methodName}(${parameterDescription}): ${returnValue}`; -}; - -export const getPainlessConstructorsToAutocomplete = (): PainlessCompletionResult => { - const painlessConstructors = context.classes - .filter(({ constructors }) => constructors.length > 0) - .map(({ constructors }) => constructors) - .flat(); - - const constructors: PainlessCompletionItem[] = painlessConstructors - // There are sometimes multiple definitions for the same constructor - // This method filters them out so we don't display more than once in autocomplete - .filter((constructor, index, constructorArray) => { - return ( - constructorArray.findIndex(({ declaring }) => declaring === constructor.declaring) === index - ); - }) - .map(({ declaring }) => { - const constructorName = declaring.split('.').pop() || declaring; // TODO ES to add "displayName" field so this won't be necessary - - return { - label: constructorName, - kind: 'constructor', - documentation: `Constructor ${constructorName}`, - insertText: constructorName, - }; - }); - - return { - isIncomplete: false, - suggestions: constructors, - }; -}; - -export const getPainlessClassToAutocomplete = (className: string): PainlessCompletionResult => { - const classNameMap = createClassNameMap(); - - if (!classNameMap[className]) { - return { - isIncomplete: false, - suggestions: [], - }; - } - - const { - static_fields: staticFields, - fields, - static_methods: staticMethods, - methods, - } = classNameMap[className]; - - const staticFieldsAutocomplete: PainlessCompletionItem[] = staticFields.map(({ name, type }) => { - return { - label: name, - kind: 'property', - documentation: `${name}: ${type}`, - insertText: name, - }; - }); - - const fieldsAutocomplete: PainlessCompletionItem[] = fields.map(({ name, type }) => { - return { - label: name, - kind: 'property', - documentation: `${name}: ${type}`, - insertText: name, - }; - }); - - const staticMethodsAutocomplete: PainlessCompletionItem[] = staticMethods.map( - ({ name, parameters, return: returnValue }) => { - return { - label: name, - kind: 'method', - documentation: getMethodDescription(name, parameters, returnValue), - insertText: name, - }; - } - ); - - const methodsAutocomplete: PainlessCompletionItem[] = methods.map( - ({ name, parameters, return: returnValue }) => { - return { - label: name, - kind: 'method', - documentation: getMethodDescription(name, parameters, returnValue), - insertText: name, - }; - } - ); - - return { - isIncomplete: false, - suggestions: [ - ...staticFieldsAutocomplete, - ...staticMethodsAutocomplete, - ...methodsAutocomplete, - ...fieldsAutocomplete, - ], - }; -}; diff --git a/packages/kbn-monaco/src/painless/worker/painless_worker.ts b/packages/kbn-monaco/src/painless/worker/painless_worker.ts index 1860c526a0d6c..96de345ecbf59 100644 --- a/packages/kbn-monaco/src/painless/worker/painless_worker.ts +++ b/packages/kbn-monaco/src/painless/worker/painless_worker.ts @@ -17,40 +17,16 @@ * under the License. */ -/* eslint-disable-next-line @kbn/eslint/module_migration */ -import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; +import { PainlessCompletionResult, PainlessContext } from '../types'; -import { PainlessCompletionResult } from '../types'; - -import { - getPainlessClassToAutocomplete, - painlessTypes, - getPainlessClassesToAutocomplete, - getPainlessConstructorsToAutocomplete, -} from './painless_completion_utils'; +import { PainlessCompletionManager } from './completion_manager'; export class PainlessWorker { - constructor(private ctx: monaco.worker.IWorkerContext) {} - - private _getModel(modelUri: string) { - return this.ctx.getMirrorModels().find((m) => m.uri.toString() === modelUri); - } - async provideAutocompleteSuggestions( - uri: string, - currentLineChars: any + currentLineChars: string, + context: PainlessContext ): Promise { - const model = this._getModel(uri); - - if (!model) { - return Promise.resolve({ - isIncomplete: false, - suggestions: [], - }); - } - - // const currentText = model.getValue(); - + const completionManager = new PainlessCompletionManager(context); // Array of the active line words, e.g., [boolean, isInCircle] const words = currentLineChars.replace('\t', '').split(' '); // What the user is currently typing @@ -59,7 +35,7 @@ export class PainlessWorker { // If the active typing contains dot notation, we assume we need to access the object's properties const isProperty = activeTyping.split('.').length === 2; // If the preceding word is a type, e.g., "boolean", we assume the user is declaring a variable and skip autocomplete - const hasDeclaredType = words.length === 2 && painlessTypes.includes(words[0]); + const hasDeclaredType = words.length === 2 && completionManager.getTypes().includes(words[0]); // If the preceding word contains the "new" keyword, we only provide constructor autcompletion const isConstructor = words[words.length - 2] === 'new'; @@ -69,14 +45,14 @@ export class PainlessWorker { }; if (isConstructor) { - autocompleteSuggestions = getPainlessConstructorsToAutocomplete(); + autocompleteSuggestions = completionManager.getPainlessConstructorsToAutocomplete(); } else if (isProperty) { const className = activeTyping.substring(0, activeTyping.length - 1).split('.')[0]; - autocompleteSuggestions = getPainlessClassToAutocomplete(className); + autocompleteSuggestions = completionManager.getPainlessClassToAutocomplete(className); } else { if (!hasDeclaredType) { - autocompleteSuggestions = getPainlessClassesToAutocomplete(); + autocompleteSuggestions = completionManager.getPainlessClassesToAutocomplete(); } } diff --git a/x-pack/plugins/painless_lab/public/application/components/editor.tsx b/x-pack/plugins/painless_lab/public/application/components/editor.tsx index 60561329dba8f..0fc4f18353f06 100644 --- a/x-pack/plugins/painless_lab/public/application/components/editor.tsx +++ b/x-pack/plugins/painless_lab/public/application/components/editor.tsx @@ -22,6 +22,7 @@ export function Editor({ code, onChange }: Props) { height="100%" value={code} onChange={onChange} + suggestionProvider={PainlessLang.getSuggestionProvider('painless_test')} options={{ fontSize: 12, minimap: {