Remove PEG.js generator from the timelion runtime (#100327)

This commit is contained in:
Larry Gregory 2021-05-20 05:44:59 -04:00 committed by GitHub
parent 8ee78d393e
commit 9bf8e47941
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 21 deletions

View file

@ -31,8 +31,6 @@
import _ from 'lodash';
import $ from 'jquery';
import PEG from 'pegjs';
import grammar from 'raw-loader!../../../vis_type_timelion/common/chain.peg';
import timelionExpressionInputTemplate from './timelion_expression_input.html';
import {
SUGGESTION_TYPE,
@ -42,8 +40,6 @@ import {
} from './timelion_expression_input_helpers';
import { comboBoxKeyCodes } from '@elastic/eui';
const Parser = PEG.generate(grammar);
export function timelionExpInput(deps) {
return ($http, $timeout) => {
return {
@ -144,7 +140,6 @@ export function timelionExpInput(deps) {
const suggestions = await suggest(
scope.sheet,
functionReference.list,
Parser,
getCursorPosition(),
argValueSuggestions
);

View file

@ -7,6 +7,7 @@
*/
import _ from 'lodash';
import { parseTimelionExpressionAsync } from '../../../vis_type_timelion/public';
export const SUGGESTION_TYPE = {
ARGUMENTS: 'arguments',
@ -177,15 +178,9 @@ async function extractSuggestionsFromParsedResult(
return { list: argumentSuggestions, location: location, type: SUGGESTION_TYPE.ARGUMENTS };
}
export async function suggest(
expression,
functionList,
Parser,
cursorPosition,
argValueSuggestions
) {
export async function suggest(expression, functionList, cursorPosition, argValueSuggestions) {
try {
const result = await Parser.parse(expression);
const result = await parseTimelionExpressionAsync(expression);
return await extractSuggestionsFromParsedResult(
result,
cursorPosition,

View file

@ -19,5 +19,6 @@ export { xaxisFormatterProvider } from './helpers/xaxis_formatter';
export { generateTicksProvider } from './helpers/tick_generator';
export { DEFAULT_TIME_FORMAT, calculateInterval } from '../common/lib';
export { parseTimelionExpressionAsync } from '../common/parser_async';
export { VisTypeTimelionPluginStart, VisTypeTimelionPluginSetup } from './plugin';

View file

@ -17,14 +17,6 @@ export default function ({ getPageObjects }) {
await PageObjects.timePicker.setDefaultAbsoluteRange();
});
it('should display function suggestions filtered by function name', async () => {
await PageObjects.timelion.setExpression('.e');
const suggestions = await PageObjects.timelion.getSuggestionItemsText();
expect(suggestions.length).to.eql(2);
expect(suggestions[0].includes('.elasticsearch()')).to.eql(true);
expect(suggestions[1].includes('.es()')).to.eql(true);
});
it('should show argument suggestions when function suggestion is selected', async () => {
await PageObjects.timelion.setExpression('.es');
await PageObjects.timelion.clickSuggestion();
@ -46,6 +38,14 @@ export default function ({ getPageObjects }) {
expect(valueSuggestions[1].includes('place legend in north east corner')).to.eql(true);
});
it('should display function suggestions filtered by function name', async () => {
await PageObjects.timelion.setExpression('.e');
const suggestions = await PageObjects.timelion.getSuggestionItemsText();
expect(suggestions.length).to.eql(2);
expect(suggestions[0].includes('.elasticsearch()')).to.eql(true);
expect(suggestions[1].includes('.es()')).to.eql(true);
});
describe('dynamic suggestions for argument values', () => {
describe('.es()', () => {
before(async () => {