diff --git a/changelogs/fragments/8931.yml b/changelogs/fragments/8931.yml new file mode 100644 index 000000000000..709c8efe2cf1 --- /dev/null +++ b/changelogs/fragments/8931.yml @@ -0,0 +1,2 @@ +fix: +- DQL autocomplete better parsing and fixes ([#8931](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8931)) \ No newline at end of file diff --git a/src/plugins/data/public/antlr/dql/.generated/DQLLexer.interp b/src/plugins/data/public/antlr/dql/.generated/DQLLexer.interp index 2a27c7a74895..0d269476dc0e 100644 --- a/src/plugins/data/public/antlr/dql/.generated/DQLLexer.interp +++ b/src/plugins/data/public/antlr/dql/.generated/DQLLexer.interp @@ -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] \ No newline at end of file +[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] \ No newline at end of file diff --git a/src/plugins/data/public/antlr/dql/.generated/DQLLexer.ts b/src/plugins/data/public/antlr/dql/.generated/DQLLexer.ts index 50516006fec0..7ac0e929de99 100644 --- a/src/plugins/data/public/antlr/dql/.generated/DQLLexer.ts +++ b/src/plugins/data/public/antlr/dql/.generated/DQLLexer.ts @@ -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"; @@ -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; diff --git a/src/plugins/data/public/antlr/dql/.generated/DQLParser.ts b/src/plugins/data/public/antlr/dql/.generated/DQLParser.ts index d666dc2089cb..cb7ed78571c4 100644 --- a/src/plugins/data/public/antlr/dql/.generated/DQLParser.ts +++ b/src/plugins/data/public/antlr/dql/.generated/DQLParser.ts @@ -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"; diff --git a/src/plugins/data/public/antlr/dql/.generated/DQLParserVisitor.ts b/src/plugins/data/public/antlr/dql/.generated/DQLParserVisitor.ts index 82a440ece047..efd302e86f7d 100644 --- a/src/plugins/data/public/antlr/dql/.generated/DQLParserVisitor.ts +++ b/src/plugins/data/public/antlr/dql/.generated/DQLParserVisitor.ts @@ -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"; diff --git a/src/plugins/data/public/antlr/dql/code_completion.test.ts b/src/plugins/data/public/antlr/dql/code_completion.test.ts index 547ccc615e31..e504d850f2e4 100644 --- a/src/plugins/data/public/antlr/dql/code_completion.test.ts +++ b/src/plugins/data/public/antlr/dql/code_completion.test.ts @@ -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 = [ @@ -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); @@ -211,21 +214,21 @@ 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 = [ @@ -233,9 +236,9 @@ 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) => diff --git a/src/plugins/data/public/antlr/dql/code_completion.ts b/src/plugins/data/public/antlr/dql/code_completion.ts index 5968d2408c11..ebc411cc8409 100644 --- a/src/plugins/data/public/antlr/dql/code_completion.ts +++ b/src/plugins/data/public/antlr/dql/code_completion.ts @@ -113,15 +113,7 @@ export const getSuggestions = async ({ 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]); // gets candidates at specified token index const candidates = core.collectCandidates(cursorIndex); @@ -135,7 +127,15 @@ export const getSuggestions = async ({ // 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( + ...fetchFieldSuggestions(indexPattern, (field: string) => { + const indexField = indexPattern.getFieldByName(field); + if (indexField && ['boolean', 'string'].includes(indexField.type)) { + return `${field} : `; + } + return `${field} `; + }) + ); } interface FoundLastValue { @@ -247,14 +247,21 @@ export const getSuggestions = async ({ 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([ + DQLParser.EQ, + DQLParser.GE, + DQLParser.GT, + DQLParser.LE, + DQLParser.LT, + ]); // suggest other candidates, mainly keywords [...candidates.tokens.keys()].forEach((token: number) => { @@ -263,15 +270,19 @@ export const getSuggestions = async ({ 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, diff --git a/src/plugins/data/public/antlr/dql/grammar/DQLLexer.g4 b/src/plugins/data/public/antlr/dql/grammar/DQLLexer.g4 index 1ff71a3e6dd5..53d0c33c84c0 100644 --- a/src/plugins/data/public/antlr/dql/grammar/DQLLexer.g4 +++ b/src/plugins/data/public/antlr/dql/grammar/DQLLexer.g4 @@ -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); \ No newline at end of file