Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Auto Suggest] DQL Parsing updates and Fixes #8931

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/8931.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- DQL autocomplete better parsing and fixes ([#8931](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8931))
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ mode names:
DEFAULT_MODE

atn:
[4, 0, 13, 78, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 5, 10, 57, 8, 10, 10, 10, 12, 10, 60, 9, 10, 1, 10, 3, 10, 63, 8, 10, 1, 11, 1, 11, 5, 11, 67, 8, 11, 10, 11, 12, 11, 70, 9, 11, 1, 12, 4, 12, 73, 8, 12, 11, 12, 12, 12, 74, 1, 12, 1, 12, 0, 0, 13, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 1, 0, 10, 2, 0, 79, 79, 111, 111, 2, 0, 82, 82, 114, 114, 2, 0, 65, 65, 97, 97, 2, 0, 78, 78, 110, 110, 2, 0, 68, 68, 100, 100, 2, 0, 84, 84, 116, 116, 2, 0, 34, 34, 92, 92, 5, 0, 42, 42, 48, 57, 65, 90, 95, 95, 97, 122, 6, 0, 42, 42, 46, 46, 48, 57, 65, 90, 95, 95, 97, 122, 3, 0, 9, 10, 13, 13, 32, 32, 81, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 1, 27, 1, 0, 0, 0, 3, 30, 1, 0, 0, 0, 5, 34, 1, 0, 0, 0, 7, 38, 1, 0, 0, 0, 9, 40, 1, 0, 0, 0, 11, 42, 1, 0, 0, 0, 13, 45, 1, 0, 0, 0, 15, 48, 1, 0, 0, 0, 17, 50, 1, 0, 0, 0, 19, 52, 1, 0, 0, 0, 21, 54, 1, 0, 0, 0, 23, 64, 1, 0, 0, 0, 25, 72, 1, 0, 0, 0, 27, 28, 7, 0, 0, 0, 28, 29, 7, 1, 0, 0, 29, 2, 1, 0, 0, 0, 30, 31, 7, 2, 0, 0, 31, 32, 7, 3, 0, 0, 32, 33, 7, 4, 0, 0, 33, 4, 1, 0, 0, 0, 34, 35, 7, 3, 0, 0, 35, 36, 7, 0, 0, 0, 36, 37, 7, 5, 0, 0, 37, 6, 1, 0, 0, 0, 38, 39, 5, 62, 0, 0, 39, 8, 1, 0, 0, 0, 40, 41, 5, 60, 0, 0, 41, 10, 1, 0, 0, 0, 42, 43, 5, 62, 0, 0, 43, 44, 5, 61, 0, 0, 44, 12, 1, 0, 0, 0, 45, 46, 5, 60, 0, 0, 46, 47, 5, 61, 0, 0, 47, 14, 1, 0, 0, 0, 48, 49, 5, 58, 0, 0, 49, 16, 1, 0, 0, 0, 50, 51, 5, 40, 0, 0, 51, 18, 1, 0, 0, 0, 52, 53, 5, 41, 0, 0, 53, 20, 1, 0, 0, 0, 54, 58, 5, 34, 0, 0, 55, 57, 8, 6, 0, 0, 56, 55, 1, 0, 0, 0, 57, 60, 1, 0, 0, 0, 58, 56, 1, 0, 0, 0, 58, 59, 1, 0, 0, 0, 59, 62, 1, 0, 0, 0, 60, 58, 1, 0, 0, 0, 61, 63, 5, 34, 0, 0, 62, 61, 1, 0, 0, 0, 62, 63, 1, 0, 0, 0, 63, 22, 1, 0, 0, 0, 64, 68, 7, 7, 0, 0, 65, 67, 7, 8, 0, 0, 66, 65, 1, 0, 0, 0, 67, 70, 1, 0, 0, 0, 68, 66, 1, 0, 0, 0, 68, 69, 1, 0, 0, 0, 69, 24, 1, 0, 0, 0, 70, 68, 1, 0, 0, 0, 71, 73, 7, 9, 0, 0, 72, 71, 1, 0, 0, 0, 73, 74, 1, 0, 0, 0, 74, 72, 1, 0, 0, 0, 74, 75, 1, 0, 0, 0, 75, 76, 1, 0, 0, 0, 76, 77, 6, 12, 0, 0, 77, 26, 1, 0, 0, 0, 5, 0, 58, 62, 68, 74, 1, 0, 1, 0]
[4, 0, 13, 82, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 5, 10, 57, 8, 10, 10, 10, 12, 10, 60, 9, 10, 1, 10, 3, 10, 63, 8, 10, 1, 11, 4, 11, 66, 8, 11, 11, 11, 12, 11, 67, 1, 11, 5, 11, 71, 8, 11, 10, 11, 12, 11, 74, 9, 11, 1, 12, 4, 12, 77, 8, 12, 11, 12, 12, 12, 78, 1, 12, 1, 12, 0, 0, 13, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 1, 0, 10, 2, 0, 79, 79, 111, 111, 2, 0, 82, 82, 114, 114, 2, 0, 65, 65, 97, 97, 2, 0, 78, 78, 110, 110, 2, 0, 68, 68, 100, 100, 2, 0, 84, 84, 116, 116, 2, 0, 34, 34, 92, 92, 5, 0, 42, 42, 48, 57, 64, 90, 95, 95, 97, 122, 6, 0, 42, 42, 46, 46, 48, 57, 65, 90, 95, 95, 97, 122, 3, 0, 9, 10, 13, 13, 32, 32, 86, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 1, 27, 1, 0, 0, 0, 3, 30, 1, 0, 0, 0, 5, 34, 1, 0, 0, 0, 7, 38, 1, 0, 0, 0, 9, 40, 1, 0, 0, 0, 11, 42, 1, 0, 0, 0, 13, 45, 1, 0, 0, 0, 15, 48, 1, 0, 0, 0, 17, 50, 1, 0, 0, 0, 19, 52, 1, 0, 0, 0, 21, 54, 1, 0, 0, 0, 23, 65, 1, 0, 0, 0, 25, 76, 1, 0, 0, 0, 27, 28, 7, 0, 0, 0, 28, 29, 7, 1, 0, 0, 29, 2, 1, 0, 0, 0, 30, 31, 7, 2, 0, 0, 31, 32, 7, 3, 0, 0, 32, 33, 7, 4, 0, 0, 33, 4, 1, 0, 0, 0, 34, 35, 7, 3, 0, 0, 35, 36, 7, 0, 0, 0, 36, 37, 7, 5, 0, 0, 37, 6, 1, 0, 0, 0, 38, 39, 5, 62, 0, 0, 39, 8, 1, 0, 0, 0, 40, 41, 5, 60, 0, 0, 41, 10, 1, 0, 0, 0, 42, 43, 5, 62, 0, 0, 43, 44, 5, 61, 0, 0, 44, 12, 1, 0, 0, 0, 45, 46, 5, 60, 0, 0, 46, 47, 5, 61, 0, 0, 47, 14, 1, 0, 0, 0, 48, 49, 5, 58, 0, 0, 49, 16, 1, 0, 0, 0, 50, 51, 5, 40, 0, 0, 51, 18, 1, 0, 0, 0, 52, 53, 5, 41, 0, 0, 53, 20, 1, 0, 0, 0, 54, 58, 5, 34, 0, 0, 55, 57, 8, 6, 0, 0, 56, 55, 1, 0, 0, 0, 57, 60, 1, 0, 0, 0, 58, 56, 1, 0, 0, 0, 58, 59, 1, 0, 0, 0, 59, 62, 1, 0, 0, 0, 60, 58, 1, 0, 0, 0, 61, 63, 5, 34, 0, 0, 62, 61, 1, 0, 0, 0, 62, 63, 1, 0, 0, 0, 63, 22, 1, 0, 0, 0, 64, 66, 7, 7, 0, 0, 65, 64, 1, 0, 0, 0, 66, 67, 1, 0, 0, 0, 67, 65, 1, 0, 0, 0, 67, 68, 1, 0, 0, 0, 68, 72, 1, 0, 0, 0, 69, 71, 7, 8, 0, 0, 70, 69, 1, 0, 0, 0, 71, 74, 1, 0, 0, 0, 72, 70, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, 73, 24, 1, 0, 0, 0, 74, 72, 1, 0, 0, 0, 75, 77, 7, 9, 0, 0, 76, 75, 1, 0, 0, 0, 77, 78, 1, 0, 0, 0, 78, 76, 1, 0, 0, 0, 78, 79, 1, 0, 0, 0, 79, 80, 1, 0, 0, 0, 80, 81, 6, 12, 0, 0, 81, 26, 1, 0, 0, 0, 6, 0, 58, 62, 67, 72, 78, 1, 0, 1, 0]
55 changes: 28 additions & 27 deletions src/plugins/data/public/antlr/dql/.generated/DQLLexer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated from grammar/DQLLexer.g4 by ANTLR 4.13.1
// Generated from ./src/plugins/data/public/antlr/dql/grammar/DQLLexer.g4 by ANTLR 4.13.1

import * as antlr from "antlr4ng";
import { Token } from "antlr4ng";
Expand Down Expand Up @@ -61,35 +61,36 @@ export class DQLLexer extends antlr.Lexer {
public get modeNames(): string[] { return DQLLexer.modeNames; }

public static readonly _serializedATN: number[] = [
4,0,13,78,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,
4,0,13,82,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,
6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,1,0,
1,0,1,0,1,1,1,1,1,1,1,1,1,2,1,2,1,2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,
1,5,1,6,1,6,1,6,1,7,1,7,1,8,1,8,1,9,1,9,1,10,1,10,5,10,57,8,10,10,
10,12,10,60,9,10,1,10,3,10,63,8,10,1,11,1,11,5,11,67,8,11,10,11,
12,11,70,9,11,1,12,4,12,73,8,12,11,12,12,12,74,1,12,1,12,0,0,13,
1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,
1,0,10,2,0,79,79,111,111,2,0,82,82,114,114,2,0,65,65,97,97,2,0,78,
78,110,110,2,0,68,68,100,100,2,0,84,84,116,116,2,0,34,34,92,92,5,
0,42,42,48,57,65,90,95,95,97,122,6,0,42,42,46,46,48,57,65,90,95,
95,97,122,3,0,9,10,13,13,32,32,81,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,
0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,
0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,
0,0,1,27,1,0,0,0,3,30,1,0,0,0,5,34,1,0,0,0,7,38,1,0,0,0,9,40,1,0,
0,0,11,42,1,0,0,0,13,45,1,0,0,0,15,48,1,0,0,0,17,50,1,0,0,0,19,52,
1,0,0,0,21,54,1,0,0,0,23,64,1,0,0,0,25,72,1,0,0,0,27,28,7,0,0,0,
28,29,7,1,0,0,29,2,1,0,0,0,30,31,7,2,0,0,31,32,7,3,0,0,32,33,7,4,
0,0,33,4,1,0,0,0,34,35,7,3,0,0,35,36,7,0,0,0,36,37,7,5,0,0,37,6,
1,0,0,0,38,39,5,62,0,0,39,8,1,0,0,0,40,41,5,60,0,0,41,10,1,0,0,0,
42,43,5,62,0,0,43,44,5,61,0,0,44,12,1,0,0,0,45,46,5,60,0,0,46,47,
5,61,0,0,47,14,1,0,0,0,48,49,5,58,0,0,49,16,1,0,0,0,50,51,5,40,0,
0,51,18,1,0,0,0,52,53,5,41,0,0,53,20,1,0,0,0,54,58,5,34,0,0,55,57,
8,6,0,0,56,55,1,0,0,0,57,60,1,0,0,0,58,56,1,0,0,0,58,59,1,0,0,0,
59,62,1,0,0,0,60,58,1,0,0,0,61,63,5,34,0,0,62,61,1,0,0,0,62,63,1,
0,0,0,63,22,1,0,0,0,64,68,7,7,0,0,65,67,7,8,0,0,66,65,1,0,0,0,67,
70,1,0,0,0,68,66,1,0,0,0,68,69,1,0,0,0,69,24,1,0,0,0,70,68,1,0,0,
0,71,73,7,9,0,0,72,71,1,0,0,0,73,74,1,0,0,0,74,72,1,0,0,0,74,75,
1,0,0,0,75,76,1,0,0,0,76,77,6,12,0,0,77,26,1,0,0,0,5,0,58,62,68,
74,1,0,1,0
10,12,10,60,9,10,1,10,3,10,63,8,10,1,11,4,11,66,8,11,11,11,12,11,
67,1,11,5,11,71,8,11,10,11,12,11,74,9,11,1,12,4,12,77,8,12,11,12,
12,12,78,1,12,1,12,0,0,13,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,
9,19,10,21,11,23,12,25,13,1,0,10,2,0,79,79,111,111,2,0,82,82,114,
114,2,0,65,65,97,97,2,0,78,78,110,110,2,0,68,68,100,100,2,0,84,84,
116,116,2,0,34,34,92,92,5,0,42,42,48,57,64,90,95,95,97,122,6,0,42,
42,46,46,48,57,65,90,95,95,97,122,3,0,9,10,13,13,32,32,86,0,1,1,
0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,
0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,
0,0,23,1,0,0,0,0,25,1,0,0,0,1,27,1,0,0,0,3,30,1,0,0,0,5,34,1,0,0,
0,7,38,1,0,0,0,9,40,1,0,0,0,11,42,1,0,0,0,13,45,1,0,0,0,15,48,1,
0,0,0,17,50,1,0,0,0,19,52,1,0,0,0,21,54,1,0,0,0,23,65,1,0,0,0,25,
76,1,0,0,0,27,28,7,0,0,0,28,29,7,1,0,0,29,2,1,0,0,0,30,31,7,2,0,
0,31,32,7,3,0,0,32,33,7,4,0,0,33,4,1,0,0,0,34,35,7,3,0,0,35,36,7,
0,0,0,36,37,7,5,0,0,37,6,1,0,0,0,38,39,5,62,0,0,39,8,1,0,0,0,40,
41,5,60,0,0,41,10,1,0,0,0,42,43,5,62,0,0,43,44,5,61,0,0,44,12,1,
0,0,0,45,46,5,60,0,0,46,47,5,61,0,0,47,14,1,0,0,0,48,49,5,58,0,0,
49,16,1,0,0,0,50,51,5,40,0,0,51,18,1,0,0,0,52,53,5,41,0,0,53,20,
1,0,0,0,54,58,5,34,0,0,55,57,8,6,0,0,56,55,1,0,0,0,57,60,1,0,0,0,
58,56,1,0,0,0,58,59,1,0,0,0,59,62,1,0,0,0,60,58,1,0,0,0,61,63,5,
34,0,0,62,61,1,0,0,0,62,63,1,0,0,0,63,22,1,0,0,0,64,66,7,7,0,0,65,
64,1,0,0,0,66,67,1,0,0,0,67,65,1,0,0,0,67,68,1,0,0,0,68,72,1,0,0,
0,69,71,7,8,0,0,70,69,1,0,0,0,71,74,1,0,0,0,72,70,1,0,0,0,72,73,
1,0,0,0,73,24,1,0,0,0,74,72,1,0,0,0,75,77,7,9,0,0,76,75,1,0,0,0,
77,78,1,0,0,0,78,76,1,0,0,0,78,79,1,0,0,0,79,80,1,0,0,0,80,81,6,
12,0,0,81,26,1,0,0,0,6,0,58,62,67,72,78,1,0,1,0
];

private static __ATN: antlr.ATN;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated from grammar/DQLParser.g4 by ANTLR 4.13.1
// Generated from ./src/plugins/data/public/antlr/dql/grammar/DQLParser.g4 by ANTLR 4.13.1

import * as antlr from "antlr4ng";
import { Token } from "antlr4ng";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated from grammar/DQLParser.g4 by ANTLR 4.13.1
// Generated from ./src/plugins/data/public/antlr/dql/grammar/DQLParser.g4 by ANTLR 4.13.1

import { AbstractParseTreeVisitor } from "antlr4ng";

Expand Down
43 changes: 23 additions & 20 deletions src/plugins/data/public/antlr/dql/code_completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ const testingIndex = ({
subType: undefined,
},
],
getFieldByName: jest.fn((fieldName: string) => {
return testingIndex.fields.find((field) => field.name === fieldName);
}),
} as unknown) as IndexPattern;

const booleanOperatorSuggestions = [
Expand All @@ -186,19 +189,19 @@ const fieldNameSuggestions: Array<{
insertText?: string;
detail: string;
}> = [
{ text: 'Carrier', type: 3, insertText: 'Carrier: ', detail: 'Field: keyword' },
{ text: 'DestCityName', type: 3, insertText: 'DestCityName: ', detail: 'Field: keyword' },
{ text: 'DestCountry', type: 3, insertText: 'DestCountry: ', detail: 'Field: keyword' },
{ text: 'DestWeather', type: 3, insertText: 'DestWeather: ', detail: 'Field: keyword' },
{ text: 'DistanceMiles', type: 3, insertText: 'DistanceMiles: ', detail: 'Field: float' },
{ text: 'FlightDelay', type: 3, insertText: 'FlightDelay: ', detail: 'Field: boolean' },
{ text: 'FlightNum', type: 3, insertText: 'FlightNum: ', detail: 'Field: keyword' },
{ text: 'OriginWeather', type: 3, insertText: 'OriginWeather: ', detail: 'Field: keyword' },
{ text: '_id', type: 3, insertText: '_id: ', detail: 'Field: _id' },
{ text: '_index', type: 3, insertText: '_index: ', detail: 'Field: _index' },
{ text: '_score', type: 3, insertText: '_score: ', detail: 'Field: number' },
{ text: '_source', type: 3, insertText: '_source: ', detail: 'Field: _source' },
{ text: '_type', type: 3, insertText: '_type: ', detail: 'Field: _type' },
{ text: 'Carrier', type: 3, insertText: 'Carrier : ', detail: 'Field: keyword' },
{ text: 'DestCityName', type: 3, insertText: 'DestCityName : ', detail: 'Field: keyword' },
{ text: 'DestCountry', type: 3, insertText: 'DestCountry : ', detail: 'Field: keyword' },
{ text: 'DestWeather', type: 3, insertText: 'DestWeather : ', detail: 'Field: keyword' },
{ text: 'DistanceMiles', type: 3, insertText: 'DistanceMiles ', detail: 'Field: float' },
{ text: 'FlightDelay', type: 3, insertText: 'FlightDelay : ', detail: 'Field: boolean' },
{ text: 'FlightNum', type: 3, insertText: 'FlightNum : ', detail: 'Field: keyword' },
{ text: 'OriginWeather', type: 3, insertText: 'OriginWeather : ', detail: 'Field: keyword' },
{ text: '_id', type: 3, insertText: '_id : ', detail: 'Field: _id' },
{ text: '_index', type: 3, insertText: '_index : ', detail: 'Field: _index' },
{ text: '_score', type: 3, insertText: '_score ', detail: 'Field: number' },
{ text: '_source', type: 3, insertText: '_source ', detail: 'Field: _source' },
{ text: '_type', type: 3, insertText: '_type : ', detail: 'Field: _type' },
];

const fieldNameWithNotSuggestions = fieldNameSuggestions.concat(notOperatorSuggestion);
Expand All @@ -211,31 +214,31 @@ const carrierValues = [
];

const allCarrierValueSuggestions = [
{ text: 'Logstash Airways', type: 13, detail: 'Value', insertText: 'Logstash Airways ' },
{ text: 'BeatsWest', type: 13, detail: 'Value', insertText: 'BeatsWest ' },
{ text: 'Logstash Airways', type: 13, detail: 'Value', insertText: '"Logstash Airways" ' },
{ text: 'BeatsWest', type: 13, detail: 'Value', insertText: '"BeatsWest" ' },
{
text: 'OpenSearch Dashboards Airlines',
type: 13,
detail: 'Value',
insertText: 'OpenSearch Dashboards Airlines ',
insertText: '"OpenSearch Dashboards Airlines" ',
},
{ text: 'OpenSearch-Air', type: 13, detail: 'Value', insertText: 'OpenSearch-Air ' },
{ text: 'OpenSearch-Air', type: 13, detail: 'Value', insertText: '"OpenSearch-Air" ' },
];

const carrierWithNotSuggestions = allCarrierValueSuggestions.concat(notOperatorSuggestion);

const logCarrierValueSuggestion = [
{ text: 'Logstash Airways', type: 13, detail: 'Value', insertText: 'Logstash Airways ' },
{ text: 'Logstash Airways', type: 13, detail: 'Value', insertText: '"Logstash Airways" ' },
];

const openCarrierValueSuggestion = [
{
text: 'OpenSearch Dashboards Airlines',
type: 13,
detail: 'Value',
insertText: 'OpenSearch Dashboards Airlines ',
insertText: '"OpenSearch Dashboards Airlines" ',
},
{ text: 'OpenSearch-Air', type: 13, detail: 'Value', insertText: 'OpenSearch-Air ' },
{ text: 'OpenSearch-Air', type: 13, detail: 'Value', insertText: '"OpenSearch-Air" ' },
];

const addPositionToValue = (vals: any, start: number, end: number) =>
Expand Down
39 changes: 25 additions & 14 deletions src/plugins/data/public/antlr/dql/code_completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,7 @@
core.preferredRules = new Set([DQLParser.RULE_field]);

// specify tokens to ignore
core.ignoredTokens = new Set([
DQLParser.LPAREN,
DQLParser.RPAREN,
DQLParser.EQ,
DQLParser.GE,
DQLParser.GT,
DQLParser.LE,
DQLParser.LT,
]);
core.ignoredTokens = new Set([DQLParser.LPAREN, DQLParser.RPAREN]);

Check warning on line 116 in src/plugins/data/public/antlr/dql/code_completion.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/antlr/dql/code_completion.ts#L116

Added line #L116 was not covered by tests

// gets candidates at specified token index
const candidates = core.collectCandidates(cursorIndex);
Expand All @@ -135,7 +127,15 @@

// check to see if field rule is a candidate. if so, suggest field names
if (candidates.rules.has(DQLParser.RULE_field)) {
completions.push(...fetchFieldSuggestions(indexPattern, (f: any) => `${f}: `));
completions.push(

Check warning on line 130 in src/plugins/data/public/antlr/dql/code_completion.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/antlr/dql/code_completion.ts#L130

Added line #L130 was not covered by tests
...fetchFieldSuggestions(indexPattern, (field: string) => {
const indexField = indexPattern.getFieldByName(field);

Check warning on line 132 in src/plugins/data/public/antlr/dql/code_completion.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/antlr/dql/code_completion.ts#L132

Added line #L132 was not covered by tests
if (indexField && ['boolean', 'string'].includes(indexField.type)) {
return `${field} : `;

Check warning on line 134 in src/plugins/data/public/antlr/dql/code_completion.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/antlr/dql/code_completion.ts#L134

Added line #L134 was not covered by tests
}
return `${field} `;

Check warning on line 136 in src/plugins/data/public/antlr/dql/code_completion.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/antlr/dql/code_completion.ts#L136

Added line #L136 was not covered by tests
})
);
}

interface FoundLastValue {
Expand Down Expand Up @@ -247,14 +247,21 @@
cursorLine,
cursorColumn + 1
),
insertText: `${val} `,
insertText: `"${val}" `,
};
})
);
}
}

const dqlOperators = new Set([DQLParser.AND, DQLParser.OR, DQLParser.NOT]);
const booleanOperators = new Set([DQLParser.AND, DQLParser.OR, DQLParser.NOT]);
const operators = new Set([

Check warning on line 258 in src/plugins/data/public/antlr/dql/code_completion.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/antlr/dql/code_completion.ts#L257-L258

Added lines #L257 - L258 were not covered by tests
DQLParser.EQ,
DQLParser.GE,
DQLParser.GT,
DQLParser.LE,
DQLParser.LT,
]);

// suggest other candidates, mainly keywords
[...candidates.tokens.keys()].forEach((token: number) => {
Expand All @@ -263,15 +270,19 @@
return;
}

const tokenSymbolName = parser.vocabulary.getSymbolicName(token)?.toLowerCase();
const tokenSymbolName = operators.has(token)
? parser.vocabulary.getDisplayName(token)?.replace(/'/g, '')
: parser.vocabulary.getSymbolicName(token)?.toLowerCase();

if (tokenSymbolName) {
let type = monaco.languages.CompletionItemKind.Keyword;
let detail = SuggestionItemDetailsTags.Keyword;
if (dqlOperators.has(token)) {

if (booleanOperators.has(token) || operators.has(token)) {
type = monaco.languages.CompletionItemKind.Operator;
detail = SuggestionItemDetailsTags.Operator;
}

completions.push({
text: tokenSymbolName,
type,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/antlr/dql/grammar/DQLLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RPAREN: ')';

// Literals
PHRASE: '"' (~["\\])* '"'?;
ID: [a-zA-Z0-9_*][a-zA-Z0-9_*.]*;
ID: [a-zA-Z0-9_@*]+[a-zA-Z0-9_*.]*;

// SKIP
WS: [ \t\r\n]+ -> channel(HIDDEN);
Loading