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A4B,QAAUmB,GAKtC,MAAMC,GAAe,IAAM,CACzB,MAAMC,EAAe1B,EAAa,QAClC,GAAI0B,IAAiB,KAAM,CACzB,MAAMC,EAAcnB,EAAO,iBAAiB,EAC5CkB,EAAa,MAAM,OAAS,GAAGC,EAAc1C,OAC7C,MAAM2C,EAAaF,EAAa,YAChClB,EAAO,OAAO,CAAE,MAAOoB,EAAY,OAAQD,CAAY,CAAC,EAE5D,EAEAnB,EAAO,uBAAuBiB,EAAY,EAC1CA,GAAa,EAGbjB,EAAO,WACLvC,EAAO,OAAO,MAAQA,EAAO,QAAQ,MACrC,IAAM,CACJkC,EAAc,QAAQK,EAAO,SAAS,CAAC,CACzC,EACA,kBAAoBV,CACtB,EAEAU,EAAO,qBAAqB,IAAM,CAChCO,GAAgB,IAAI,EAAI,EACpBP,EAAO,SAAS,EAAE,KAAK,IAAM,IAC/BA,EAAO,QAAQ,GAAI,+BAAgC,CAAC,CAAC,CAEzD,CAAC,EAEDD,GAAetC,EAAQuC,CAAM,CAC/B,EACF,CACF,CAEJ,C,mDC5QIN,EAAY,SAAUtL,EAAO,CAC7B,IAAIuO,KAAM,UAAOvO,CAAK,EACtB,OAAAuO,EAAI,QAAUvO,EACPuO,CACX,EACA,QAAejD,C","sources":["webpack://grafana/./node_modules/@grafana/monaco-logql/index.js","webpack://grafana/./public/app/plugins/datasource/loki/components/monaco-query-field/getOverrideServices.ts","webpack://grafana/./public/app/plugins/datasource/loki/components/monaco-query-field/monaco-completion-provider/CompletionDataProvider.ts","webpack://grafana/./public/app/plugins/datasource/loki/components/monaco-query-field/monaco-completion-provider/NeverCaseError.ts","webpack://grafana/./public/app/plugins/datasource/loki/components/monaco-query-field/monaco-completion-provider/completions.ts","webpack://grafana/./public/app/plugins/datasource/loki/components/monaco-query-field/monaco-completion-provider/situation.ts","webpack://grafana/./public/app/plugins/datasource/loki/components/monaco-query-field/monaco-completion-provider/completionUtils.ts","webpack://grafana/./public/app/plugins/datasource/loki/components/monaco-query-field/MonacoQueryField.tsx","webpack://grafana/./public/app/plugins/datasource/tempo/_importedDependencies/datasources/loki/monaco-query-field/getOverrideServices.ts","webpack://grafana/./public/app/plugins/datasource/tempo/_importedDependencies/datasources/loki/monaco-query-field/monaco-completion-provider/NeverCaseError.ts","webpack://grafana/./public/app/plugins/datasource/tempo/_importedDependencies/datasources/loki/monaco-query-field/monaco-completion-provider/situation.ts","webpack://grafana/./public/app/plugins/datasource/tempo/_importedDependencies/datasources/loki/monaco-query-field/monaco-completion-provider/index.ts","webpack://grafana/./public/app/plugins/datasource/tempo/_importedDependencies/datasources/loki/monaco-query-field/monaco-completion-provider/CompletionDataProvider.ts","webpack://grafana/./public/app/plugins/datasource/tempo/_importedDependencies/datasources/loki/monaco-query-field/monaco-completion-provider/validation.ts","webpack://grafana/./public/app/plugins/datasource/tempo/_importedDependencies/datasources/loki/monaco-query-field/MonacoQueryField.tsx","webpack://grafana/./node_modules/react-use/esm/useLatest.js"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.monarchlanguage = exports.languageConfiguration = void 0;\nexports.languageConfiguration = {\n // the default separators except `@$`\n wordPattern: /(-?\\d*\\.\\d\\w*)|([^`~!#%^&*()\\-=+\\[{\\]}\\\\|;:'\",.<>\\/?\\s]+)/g,\n comments: {\n lineComment: \"#\",\n },\n brackets: [\n [\"{\", \"}\"],\n [\"[\", \"]\"],\n [\"(\", \")\"],\n ],\n autoClosingPairs: [\n { open: \"{\", close: \"}\" },\n { open: \"[\", close: \"]\" },\n { open: \"(\", close: \")\" },\n { open: '\"', close: '\"' },\n { open: \"'\", close: \"'\" },\n { open: \"`\", close: \"`\" },\n ],\n surroundingPairs: [\n { open: \"{\", close: \"}\" },\n { open: \"[\", close: \"]\" },\n { open: \"(\", close: \")\" },\n { open: '\"', close: '\"' },\n { open: \"'\", close: \"'\" },\n { open: \"`\", close: \"`\" },\n { open: \"<\", close: \">\" },\n ],\n folding: {},\n};\n// LogQL built-in aggregation operators\n// https://grafana.com/docs/loki/latest/logql/metric_queries/#built-in-aggregation-operators\nvar aggregations = [\n \"sum\",\n \"avg\",\n \"min\",\n \"max\",\n \"stddev\",\n \"stdvar\",\n \"count\",\n \"topk\",\n \"bottomk\",\n];\n// LogQL parser expressions\n// https://grafana.com/docs/loki/latest/logql/log_queries/#parser-expression\nvar parsers = [\"json\", \"logfmt\", \"regexp\", \"unpack\", \"pattern\"];\n// LogQL format expressions\n// https://grafana.com/docs/loki/latest/logql/log_queries/#parser-expression\nvar format_expressions = [\"line_format\", \"label_format\"];\n// LogQL vector aggregations\n// https://grafana.com/docs/loki/latest/logql/metric_queries/#range-vector-aggregation\nvar vector_aggregations = [\n \"count_over_time\",\n \"rate\",\n \"bytes_over_time\",\n \"bytes_rate\",\n \"avg_over_time\",\n \"sum_over_time\",\n \"min_over_time\",\n \"max_over_time\",\n \"stdvar_over_time\",\n \"stddev_over_time\",\n \"quantile_over_time\",\n \"first_over_time\",\n \"last_over_time\",\n \"absent_over_time\",\n];\n// LogQL by and without clauses\nvar vector_matching = [\"by\", \"without\"];\n// Produce a regex matching elements : (by|without)\nvar vectorMatchingRegex = \"(\".concat(vector_matching.reduce(function (prev, curr) { return \"\".concat(prev, \"|\").concat(curr); }), \")\");\n// LogQL Operators\nvar operators = [\n \"+\",\n \"-\",\n \"*\",\n \"/\",\n \"%\",\n \"^\",\n \"==\",\n \"!=\",\n \">\",\n \"<\",\n \">=\",\n \"<=\",\n \"|=\",\n \"!=\",\n \"|~\",\n \"!~\",\n \"and\",\n \"or\",\n \"unless\",\n \"|\",\n];\n// Merging all the keywords in one list\nvar keywords = aggregations\n .concat(parsers)\n .concat(format_expressions)\n .concat(vector_aggregations)\n .concat(vector_matching);\nexports.monarchlanguage = {\n ignoreCase: false,\n defaultToken: \"\",\n tokenPostfix: \".logql\",\n keywords: keywords,\n operators: operators,\n vectorMatching: vectorMatchingRegex,\n // we include these common regular expressions\n symbols: /[=>](?!@symbols)/, \"@brackets\"],\n [\n /@symbols/,\n {\n cases: {\n \"@operators\": \"delimiter\",\n \"@default\": \"\",\n },\n },\n ],\n // numbers\n [/\\d+(?:ms|[smhdwy])/, \"number\"],\n [/\\d*\\d+[eE]([\\-+]?\\d+)?(@floatsuffix)/, \"number.float\"],\n [/\\d*\\.\\d+([eE][\\-+]?\\d+)?(@floatsuffix)/, \"number.float\"],\n [/0[xX][0-9a-fA-F']*[0-9a-fA-F](@integersuffix)/, \"number.hex\"],\n [/0[0-7']*[0-7](@integersuffix)/, \"number.octal\"],\n [/0[bB][0-1']*[0-1](@integersuffix)/, \"number.binary\"],\n [/\\d[\\d']*\\d(@integersuffix)/, \"number\"],\n [/\\d(@integersuffix)/, \"number\"],\n ],\n string_double: [\n // Set to token: number to differentiate color\n [/\\{\\{(.*?)\\}\\}/, { token: 'number' }],\n [/[^\\\\\"]/, \"string\"],\n [/@escapes/, \"string.escape\"],\n [/\\\\./, \"string.escape.invalid\"],\n [/\"/, \"string\", \"@pop\"],\n ],\n string_single: [\n [/[^\\\\']+/, \"string\"],\n [/@escapes/, \"string.escape\"],\n [/\\\\./, \"string.escape.invalid\"],\n [/'/, \"string\", \"@pop\"],\n ],\n string_backtick: [\n // Set to token: number to differentiate color\n [/\\{\\{(.*?)\\}\\}/, { token: 'number' }],\n [/[^\\\\`]/, \"string\"],\n [/@escapes/, \"string.escape\"],\n [/\\\\./, \"string.escape.invalid\"],\n [/`/, \"string\", \"@pop\"],\n ],\n clauses: [\n [/[^(,)]/, \"tag\"],\n [/\\)/, \"identifier\", \"@pop\"],\n ],\n whitespace: [[/[ \\t\\r\\n]+/, \"white\"]],\n },\n};\n","import { monacoTypes } from '@grafana/ui';\n\n// this thing here is a workaround in a way.\n// what we want to achieve, is that when the autocomplete-window\n// opens, the \"second, extra popup\" with the extra help,\n// also opens automatically.\n// but there is no API to achieve it.\n// the way to do it is to implement the `storageService`\n// interface, and provide our custom implementation,\n// which will default to `true` for the correct string-key.\n// unfortunately, while the typescript-interface exists,\n// it is not exported from monaco-editor,\n// so we cannot rely on typescript to make sure\n// we do it right. all we can do is to manually\n// lookup the interface, and make sure we code our code right.\n// our code is a \"best effort\" approach,\n// i am not 100% how the `scope` and `target` things work,\n// but so far it seems to work ok.\n// i would use an another approach, if there was one available.\n\nfunction makeStorageService() {\n // we need to return an object that fulfills this interface:\n // https://github.com/microsoft/vscode/blob/ff1e16eebb93af79fd6d7af1356c4003a120c563/src/vs/platform/storage/common/storage.ts#L37\n // unfortunately it is not export from monaco-editor\n\n const strings = new Map();\n\n // we want this to be true by default\n strings.set('expandSuggestionDocs', true.toString());\n\n return {\n // we do not implement the on* handlers\n onDidChangeValue: (data: unknown): void => undefined,\n onDidChangeTarget: (data: unknown): void => undefined,\n onWillSaveState: (data: unknown): void => undefined,\n\n get: (key: string, scope: unknown, fallbackValue?: string): string | undefined => {\n return strings.get(key) ?? fallbackValue;\n },\n\n getBoolean: (key: string, scope: unknown, fallbackValue?: boolean): boolean | undefined => {\n const val = strings.get(key);\n if (val !== undefined) {\n // the interface docs say the value will be converted\n // to a boolean but do not specify how, so we improvise\n return val === 'true';\n } else {\n return fallbackValue;\n }\n },\n\n getNumber: (key: string, scope: unknown, fallbackValue?: number): number | undefined => {\n const val = strings.get(key);\n if (val !== undefined) {\n return parseInt(val, 10);\n } else {\n return fallbackValue;\n }\n },\n\n store: (\n key: string,\n value: string | boolean | number | undefined | null,\n scope: unknown,\n target: unknown\n ): void => {\n // the interface docs say if the value is nullish, it should act as delete\n if (value === null || value === undefined) {\n strings.delete(key);\n } else {\n strings.set(key, value.toString());\n }\n },\n\n remove: (key: string, scope: unknown): void => {\n strings.delete(key);\n },\n\n keys: (scope: unknown, target: unknown): string[] => {\n return Array.from(strings.keys());\n },\n\n logStorage: (): void => {\n console.log('logStorage: not implemented');\n },\n\n migrate: (): Promise => {\n // we do not implement this\n return Promise.resolve(undefined);\n },\n\n isNew: (scope: unknown): boolean => {\n // we create a new storage for every session, we do not persist it,\n // so we return `true`.\n return true;\n },\n\n flush: (reason?: unknown): Promise => {\n // we do not implement this\n return Promise.resolve(undefined);\n },\n };\n}\n\nlet overrideServices: monacoTypes.editor.IEditorOverrideServices = {\n storageService: makeStorageService(),\n};\n\nexport function getOverrideServices(): monacoTypes.editor.IEditorOverrideServices {\n // One instance of this for every query editor\n return overrideServices;\n}\n","import { chain } from 'lodash';\n\nimport { HistoryItem, TimeRange } from '@grafana/data';\n\nimport LanguageProvider from '../../../LanguageProvider';\nimport { escapeLabelValueInExactSelector } from '../../../languageUtils';\nimport { ParserAndLabelKeysResult, LokiQuery } from '../../../types';\n\nimport { Label } from './situation';\n\ninterface HistoryRef {\n current: Array>;\n}\n\nexport class CompletionDataProvider {\n constructor(\n private languageProvider: LanguageProvider,\n private historyRef: HistoryRef = { current: [] },\n private timeRange: TimeRange | undefined\n ) {\n this.queryToLabelKeysCache = new Map();\n }\n private queryToLabelKeysCache: Map;\n\n private buildSelector(labels: Label[]): string {\n const allLabelTexts = labels.map(\n (label) => `${label.name}${label.op}\"${escapeLabelValueInExactSelector(label.value)}\"`\n );\n\n return `{${allLabelTexts.join(',')}}`;\n }\n\n getHistory() {\n return chain(this.historyRef.current)\n .map((history: HistoryItem) => history.query.expr)\n .filter()\n .uniq()\n .value();\n }\n\n async getLabelNames(otherLabels: Label[] = []) {\n if (otherLabels.length === 0) {\n // if there is no filtering, we have to use a special endpoint\n return this.languageProvider.getLabelKeys();\n }\n const data = await this.getSeriesLabels(otherLabels);\n const possibleLabelNames = Object.keys(data); // all names from datasource\n const usedLabelNames = new Set(otherLabels.map((l) => l.name)); // names used in the query\n return possibleLabelNames.filter((label) => !usedLabelNames.has(label));\n }\n\n async getLabelValues(labelName: string, otherLabels: Label[]) {\n if (otherLabels.length === 0) {\n // if there is no filtering, we have to use a special endpoint\n return await this.languageProvider.fetchLabelValues(labelName, { timeRange: this.timeRange });\n }\n\n const data = await this.getSeriesLabels(otherLabels);\n return data[labelName] ?? [];\n }\n\n /**\n * Runs a Loki query to extract label keys from the result.\n * The result is cached for the query string.\n *\n * Since various \"situations\" in the monaco code editor trigger this function, it is prone to being called multiple times for the same query\n * Here is a lightweight and simple cache to avoid calling the backend multiple times for the same query.\n *\n * @param logQuery\n */\n async getParserAndLabelKeys(logQuery: string): Promise {\n const EXTRACTED_LABEL_KEYS_MAX_CACHE_SIZE = 2;\n const cachedLabelKeys = this.queryToLabelKeysCache.has(logQuery) ? this.queryToLabelKeysCache.get(logQuery) : null;\n if (cachedLabelKeys) {\n // cache hit! Serve stale result from cache\n return cachedLabelKeys;\n } else {\n // If cache is larger than max size, delete the first (oldest) index\n if (this.queryToLabelKeysCache.size >= EXTRACTED_LABEL_KEYS_MAX_CACHE_SIZE) {\n // Make room in the cache for the fresh result by deleting the \"first\" index\n const keys = this.queryToLabelKeysCache.keys();\n const firstKey = keys.next().value;\n this.queryToLabelKeysCache.delete(firstKey);\n }\n // Fetch a fresh result from the backend\n const labelKeys = await this.languageProvider.getParserAndLabelKeys(logQuery, { timeRange: this.timeRange });\n // Add the result to the cache\n this.queryToLabelKeysCache.set(logQuery, labelKeys);\n return labelKeys;\n }\n }\n\n async getSeriesLabels(labels: Label[]) {\n return await this.languageProvider\n .fetchSeriesLabels(this.buildSelector(labels), { timeRange: this.timeRange })\n .then((data) => data ?? {});\n }\n}\n","// This helper class is used to make typescript warn you when you miss a case-block in a switch statement.\n// For example:\n//\n// const x:'A'|'B'|'C' = 'A';\n//\n// switch(x) {\n// case 'A':\n// // something\n// case 'B':\n// // something\n// default:\n// throw new NeverCaseError(x);\n// }\n//\n//\n// TypeScript detect the missing case and display an error.\n\nexport class NeverCaseError extends Error {\n constructor(value: never) {\n super(`Unexpected case in switch statement: ${JSON.stringify(value)}`);\n }\n}\n","import { trimEnd } from 'lodash';\n\nimport { escapeLabelValueInExactSelector } from '../../../languageUtils';\nimport { isQueryWithParser } from '../../../queryUtils';\nimport { explainOperator } from '../../../querybuilder/operations';\nimport { LokiOperationId } from '../../../querybuilder/types';\nimport { AGGREGATION_OPERATORS, RANGE_VEC_FUNCTIONS, BUILT_IN_FUNCTIONS } from '../../../syntax';\n\nimport { CompletionDataProvider } from './CompletionDataProvider';\nimport { NeverCaseError } from './NeverCaseError';\nimport type { Situation, Label } from './situation';\n\nexport type CompletionType =\n | 'HISTORY'\n | 'FUNCTION'\n | 'DURATION'\n | 'LABEL_NAME'\n | 'LABEL_VALUE'\n | 'PATTERN'\n | 'PARSER'\n | 'LINE_FILTER'\n | 'PIPE_OPERATION';\n\ntype Completion = {\n type: CompletionType;\n label: string;\n insertText: string;\n detail?: string;\n documentation?: string;\n triggerOnInsert?: boolean;\n isSnippet?: boolean;\n};\n\nconst LOG_COMPLETIONS: Completion[] = [\n {\n type: 'PATTERN',\n label: '{}',\n insertText: '{$0}',\n isSnippet: true,\n triggerOnInsert: true,\n },\n];\n\nconst AGGREGATION_COMPLETIONS: Completion[] = AGGREGATION_OPERATORS.map((f) => ({\n type: 'FUNCTION',\n label: f.label,\n insertText: `${f.insertText ?? ''}($0)`, // i don't know what to do when this is nullish. it should not be.\n isSnippet: true,\n triggerOnInsert: true,\n detail: f.detail,\n documentation: f.documentation,\n}));\n\nconst FUNCTION_COMPLETIONS: Completion[] = RANGE_VEC_FUNCTIONS.map((f) => ({\n type: 'FUNCTION',\n label: f.label,\n insertText: `${f.insertText ?? ''}({$0}[\\\\$__auto])`, // i don't know what to do when this is nullish. it should not be.\n isSnippet: true,\n triggerOnInsert: true,\n detail: f.detail,\n documentation: f.documentation,\n}));\n\nconst BUILT_IN_FUNCTIONS_COMPLETIONS: Completion[] = BUILT_IN_FUNCTIONS.map((f) => ({\n type: 'FUNCTION',\n label: f.label,\n insertText: `${f.insertText ?? ''}($0)`,\n isSnippet: true,\n triggerOnInsert: true,\n detail: f.detail,\n documentation: f.documentation,\n}));\n\nconst DURATION_COMPLETIONS: Completion[] = ['$__auto', '1m', '5m', '10m', '30m', '1h', '1d'].map((text) => ({\n type: 'DURATION',\n label: text,\n insertText: text,\n}));\n\nconst UNWRAP_FUNCTION_COMPLETIONS: Completion[] = [\n {\n type: 'FUNCTION',\n label: 'duration_seconds',\n documentation: 'Will convert the label value in seconds from the go duration format (e.g 5m, 24s30ms).',\n insertText: 'duration_seconds()',\n },\n {\n type: 'FUNCTION',\n label: 'duration',\n documentation: 'Short version of duration_seconds().',\n insertText: 'duration()',\n },\n {\n type: 'FUNCTION',\n label: 'bytes',\n documentation: 'Will convert the label value to raw bytes applying the bytes unit (e.g. 5 MiB, 3k, 1G).',\n insertText: 'bytes()',\n },\n];\n\nconst LOGFMT_ARGUMENT_COMPLETIONS: Completion[] = [\n {\n type: 'FUNCTION',\n label: '--strict',\n documentation:\n 'Strict parsing. The logfmt parser stops scanning the log line and returns early with an error when it encounters any poorly formatted key/value pair.',\n insertText: '--strict',\n },\n {\n type: 'FUNCTION',\n label: '--keep-empty',\n documentation:\n 'Retain standalone keys with empty value. The logfmt parser retains standalone keys (keys without a value) as labels with value set to empty string.',\n insertText: '--keep-empty',\n },\n];\n\nconst LINE_FILTER_COMPLETIONS = [\n {\n operator: '|=',\n documentation: explainOperator(LokiOperationId.LineContains),\n afterPipe: true,\n },\n {\n operator: '!=',\n documentation: explainOperator(LokiOperationId.LineContainsNot),\n },\n {\n operator: '|~',\n documentation: explainOperator(LokiOperationId.LineMatchesRegex),\n afterPipe: true,\n },\n {\n operator: '!~',\n documentation: explainOperator(LokiOperationId.LineMatchesRegexNot),\n },\n];\n\nfunction getLineFilterCompletions(afterPipe: boolean): Completion[] {\n return LINE_FILTER_COMPLETIONS.filter((completion) => !afterPipe || completion.afterPipe).map(\n ({ operator, documentation }) => ({\n type: 'LINE_FILTER',\n label: `${operator} \"\"`,\n insertText: `${afterPipe ? operator.replace('|', '') : operator} \"$0\"`,\n isSnippet: true,\n documentation,\n })\n );\n}\n\nfunction getPipeOperationsCompletions(prefix = ''): Completion[] {\n const completions: Completion[] = [];\n completions.push({\n type: 'PIPE_OPERATION',\n label: 'line_format',\n insertText: `${prefix}line_format \"{{.$0}}\"`,\n isSnippet: true,\n documentation: explainOperator(LokiOperationId.LineFormat),\n });\n\n completions.push({\n type: 'PIPE_OPERATION',\n label: 'label_format',\n insertText: `${prefix}label_format`,\n isSnippet: true,\n documentation: explainOperator(LokiOperationId.LabelFormat),\n });\n\n completions.push({\n type: 'PIPE_OPERATION',\n label: 'unwrap',\n insertText: `${prefix}unwrap`,\n documentation: explainOperator(LokiOperationId.Unwrap),\n });\n\n completions.push({\n type: 'PIPE_OPERATION',\n label: 'decolorize',\n insertText: `${prefix}decolorize`,\n documentation: explainOperator(LokiOperationId.Decolorize),\n });\n\n completions.push({\n type: 'PIPE_OPERATION',\n label: 'drop',\n insertText: `${prefix}drop`,\n documentation: explainOperator(LokiOperationId.Drop),\n });\n\n completions.push({\n type: 'PIPE_OPERATION',\n label: 'keep',\n insertText: `${prefix}keep`,\n documentation: explainOperator(LokiOperationId.Keep),\n });\n\n return completions;\n}\n\nasync function getAllHistoryCompletions(dataProvider: CompletionDataProvider): Promise {\n const history = await dataProvider.getHistory();\n\n return history.map((expr) => ({\n type: 'HISTORY',\n label: expr,\n insertText: expr,\n }));\n}\n\nasync function getLabelNamesForSelectorCompletions(\n otherLabels: Label[],\n dataProvider: CompletionDataProvider\n): Promise {\n const labelNames = await dataProvider.getLabelNames(otherLabels);\n\n return labelNames.map((label) => ({\n type: 'LABEL_NAME',\n label,\n insertText: `${label}=`,\n triggerOnInsert: true,\n }));\n}\n\nasync function getInGroupingCompletions(logQuery: string, dataProvider: CompletionDataProvider): Promise {\n const { extractedLabelKeys } = await dataProvider.getParserAndLabelKeys(logQuery);\n\n return extractedLabelKeys.map((label) => ({\n type: 'LABEL_NAME',\n label,\n insertText: label,\n triggerOnInsert: false,\n }));\n}\n\nconst PARSERS = ['json', 'logfmt', 'pattern', 'regexp', 'unpack'];\n\nasync function getParserCompletions(\n prefix: string,\n hasJSON: boolean,\n hasLogfmt: boolean,\n hasPack: boolean,\n extractedLabelKeys: string[],\n hasParserInQuery: boolean\n) {\n const allParsers = new Set(PARSERS);\n const completions: Completion[] = [];\n // We use this to improve documentation specifically for level label as it is tied to showing color-coded logs volume\n const hasLevelInExtractedLabels = extractedLabelKeys.some((key) => key === 'level');\n\n if (hasJSON) {\n // We show \"detected\" label only if there is no previous parser in the query\n const extra = hasParserInQuery ? '' : ' (detected)';\n if (hasPack) {\n allParsers.delete('unpack');\n completions.push({\n type: 'PARSER',\n label: `unpack${extra}`,\n insertText: `${prefix}unpack`,\n documentation: explainOperator(LokiOperationId.Unpack),\n });\n } else {\n allParsers.delete('json');\n completions.push({\n type: 'PARSER',\n label: `json${extra}`,\n insertText: `${prefix}json`,\n documentation: hasLevelInExtractedLabels\n ? 'Use it to get log-levels in the histogram'\n : explainOperator(LokiOperationId.Json),\n });\n }\n }\n\n if (hasLogfmt) {\n allParsers.delete('logfmt');\n // We show \"detected\" label only if there is no previous parser in the query\n const extra = hasParserInQuery ? '' : ' (detected)';\n completions.push({\n type: 'PARSER',\n label: `logfmt${extra}`,\n insertText: `${prefix}logfmt`,\n documentation: hasLevelInExtractedLabels\n ? 'Get detected levels in the histogram'\n : explainOperator(LokiOperationId.Logfmt),\n });\n }\n\n const remainingParsers = Array.from(allParsers).sort();\n remainingParsers.forEach((parser) => {\n completions.push({\n type: 'PARSER',\n label: parser,\n insertText: `${prefix}${parser}`,\n documentation: explainOperator(parser),\n });\n });\n\n return completions;\n}\n\nexport async function getAfterSelectorCompletions(\n logQuery: string,\n afterPipe: boolean,\n hasSpace: boolean,\n dataProvider: CompletionDataProvider\n): Promise {\n let query = logQuery;\n if (afterPipe) {\n query = trimEnd(logQuery, '| ');\n }\n\n const { extractedLabelKeys, structuredMetadataKeys, hasJSON, hasLogfmt, hasPack } =\n await dataProvider.getParserAndLabelKeys(query);\n const hasQueryParser = isQueryWithParser(query).queryWithParser;\n\n const prefix = `${hasSpace ? '' : ' '}${afterPipe ? '' : '| '}`;\n\n const parserCompletions = await getParserCompletions(\n prefix,\n hasJSON,\n hasLogfmt,\n hasPack,\n extractedLabelKeys,\n hasQueryParser\n );\n const pipeOperations = getPipeOperationsCompletions(prefix);\n\n const completions = [...parserCompletions, ...pipeOperations];\n\n structuredMetadataKeys.forEach((key) => {\n completions.push({\n type: 'LABEL_NAME',\n label: `${key} (detected)`,\n insertText: `${prefix}${key}`,\n documentation: `\"${key}\" was suggested based on structured metadata attached to your loglines.`,\n });\n });\n\n // Let's show label options only if query has parser\n if (hasQueryParser) {\n extractedLabelKeys.forEach((key) => {\n completions.push({\n type: 'LABEL_NAME',\n label: `${key} (detected)`,\n insertText: `${prefix}${key}`,\n documentation: `\"${key}\" was suggested based on the content of your log lines for the label filter expression.`,\n });\n });\n }\n\n // If we have parser, we don't need to consider line filters\n if (hasQueryParser) {\n return [...completions];\n }\n // With a space between the pipe and the cursor, we omit line filters\n // E.g. `{label=\"value\"} | `\n const lineFilters = afterPipe && hasSpace ? [] : getLineFilterCompletions(afterPipe);\n return [...lineFilters, ...completions];\n}\n\nexport async function getLogfmtCompletions(\n logQuery: string,\n flags: boolean,\n trailingComma: boolean | undefined,\n trailingSpace: boolean | undefined,\n otherLabels: string[],\n dataProvider: CompletionDataProvider\n): Promise {\n let completions: Completion[] = [];\n\n if (trailingComma) {\n // Remove the trailing comma, otherwise the sample query will fail.\n logQuery = trimEnd(logQuery, ', ');\n }\n const { extractedLabelKeys, hasJSON, hasLogfmt, hasPack } = await dataProvider.getParserAndLabelKeys(logQuery);\n const pipeOperations = getPipeOperationsCompletions('| ');\n\n /**\n * The user is not in the process of writing another label, and has not specified 2 flags.\n * The current grammar doesn't allow us to know which flags were used (by node name), so we consider flags = true\n * when 2 have been used.\n * For example:\n * - {label=\"value\"} | logfmt ^\n * - {label=\"value\"} | logfmt --strict ^\n * - {label=\"value\"} | logfmt --strict --keep-empty ^\n */\n if (!trailingComma && !flags) {\n completions = [...LOGFMT_ARGUMENT_COMPLETIONS];\n }\n\n /**\n * If the user has no trailing comma and has a trailing space it can mean that they finished writing the logfmt\n * part and want to move on, for example, with other parsers or pipe operations.\n * For example:\n * - {label=\"value\"} | logfmt --flag ^\n * - {label=\"value\"} | logfmt label, label2 ^\n */\n if (!trailingComma && trailingSpace) {\n /**\n * Don't offer parsers if there is no label argument: {label=\"value\"} | logfmt ^\n * The reason is that it would be unusual that they would want to use another parser just after logfmt, and\n * more likely that they would want a flag, labels, or continue with pipe operations.\n *\n * Offer parsers with at least one label argument: {label=\"value\"} | logfmt label ^\n * The rationale here is to offer the same completions as getAfterSelectorCompletions().\n */\n const parserCompletions =\n otherLabels.length > 0\n ? await getParserCompletions('| ', hasJSON, hasLogfmt, hasPack, extractedLabelKeys, true)\n : [];\n completions = [...completions, ...parserCompletions, ...pipeOperations];\n }\n\n const labels = extractedLabelKeys.filter((label) => !otherLabels.includes(label));\n\n /**\n * We want to decide whether to use a trailing comma or not based on the data we have of the current\n * situation. In particular, the following scenarios will not lead to a trailing comma:\n * {label=\"value\"} | logfmt ^\n * - trailingSpace: true, trailingComma: false, otherLabels: []\n * {label=\"value\"} | logfmt lab^\n * trailingSpace: false, trailignComma: false, otherLabels: [lab]\n * {label=\"value\"} | logfmt label,^\n * trailingSpace: false, trailingComma: true, otherLabels: [label]\n * {label=\"value\"} | logfmt label, ^\n * trailingSpace: true, trailingComma: true, otherLabels: [label]\n */\n let labelPrefix = '';\n if (otherLabels.length > 0 && trailingSpace) {\n labelPrefix = trailingComma ? '' : ', ';\n }\n\n const labelCompletions: Completion[] = labels.map((label) => ({\n type: 'LABEL_NAME',\n label,\n insertText: labelPrefix + label,\n triggerOnInsert: false,\n }));\n\n completions = [...completions, ...labelCompletions];\n\n return completions;\n}\n\nasync function getLabelValuesForMetricCompletions(\n labelName: string,\n betweenQuotes: boolean,\n otherLabels: Label[],\n dataProvider: CompletionDataProvider\n): Promise {\n const values = await dataProvider.getLabelValues(labelName, otherLabels);\n return values.map((text) => ({\n type: 'LABEL_VALUE',\n label: text,\n insertText: betweenQuotes ? escapeLabelValueInExactSelector(text) : `\"${escapeLabelValueInExactSelector(text)}\"`,\n }));\n}\n\nasync function getAfterUnwrapCompletions(\n logQuery: string,\n dataProvider: CompletionDataProvider\n): Promise {\n const { unwrapLabelKeys } = await dataProvider.getParserAndLabelKeys(logQuery);\n\n const labelCompletions: Completion[] = unwrapLabelKeys.map((label) => ({\n type: 'LABEL_NAME',\n label,\n insertText: label,\n triggerOnInsert: false,\n }));\n\n return [...labelCompletions, ...UNWRAP_FUNCTION_COMPLETIONS];\n}\n\nasync function getAfterKeepAndDropCompletions(logQuery: string, dataProvider: CompletionDataProvider) {\n const { extractedLabelKeys } = await dataProvider.getParserAndLabelKeys(logQuery);\n const labelCompletions: Completion[] = extractedLabelKeys.map((label) => ({\n type: 'LABEL_NAME',\n label,\n insertText: label,\n triggerOnInsert: false,\n }));\n\n return [...labelCompletions];\n}\n\nexport async function getCompletions(\n situation: Situation,\n dataProvider: CompletionDataProvider\n): Promise {\n switch (situation.type) {\n case 'EMPTY':\n case 'AT_ROOT':\n const historyCompletions = await getAllHistoryCompletions(dataProvider);\n return [\n ...historyCompletions,\n ...LOG_COMPLETIONS,\n ...AGGREGATION_COMPLETIONS,\n ...BUILT_IN_FUNCTIONS_COMPLETIONS,\n ...FUNCTION_COMPLETIONS,\n ];\n case 'IN_RANGE':\n return DURATION_COMPLETIONS;\n case 'IN_GROUPING':\n return getInGroupingCompletions(situation.logQuery, dataProvider);\n case 'IN_LABEL_SELECTOR_NO_LABEL_NAME':\n return getLabelNamesForSelectorCompletions(situation.otherLabels, dataProvider);\n case 'IN_LABEL_SELECTOR_WITH_LABEL_NAME':\n return getLabelValuesForMetricCompletions(\n situation.labelName,\n situation.betweenQuotes,\n situation.otherLabels,\n dataProvider\n );\n case 'AFTER_SELECTOR':\n return getAfterSelectorCompletions(situation.logQuery, situation.afterPipe, situation.hasSpace, dataProvider);\n case 'AFTER_UNWRAP':\n return getAfterUnwrapCompletions(situation.logQuery, dataProvider);\n case 'IN_AGGREGATION':\n return [...FUNCTION_COMPLETIONS, ...AGGREGATION_COMPLETIONS];\n case 'AFTER_KEEP_AND_DROP':\n return getAfterKeepAndDropCompletions(situation.logQuery, dataProvider);\n case 'IN_LOGFMT':\n return getLogfmtCompletions(\n situation.logQuery,\n situation.flags,\n situation.trailingComma,\n situation.trailingSpace,\n situation.otherLabels,\n dataProvider\n );\n default:\n throw new NeverCaseError(situation);\n }\n}\n","import type { SyntaxNode, TreeCursor } from '@lezer/common';\n\nimport {\n parser,\n VectorAggregationExpr,\n String,\n Selector,\n RangeAggregationExpr,\n Range,\n PipelineExpr,\n PipelineStage,\n Matchers,\n Matcher,\n LogQL,\n LogRangeExpr,\n LogExpr,\n Logfmt,\n Identifier,\n Grouping,\n Expr,\n LiteralExpr,\n MetricExpr,\n UnwrapExpr,\n DropLabelsExpr,\n KeepLabelsExpr,\n DropLabels,\n KeepLabels,\n ParserFlag,\n LabelExtractionExpression,\n LabelExtractionExpressionList,\n LogfmtExpressionParser,\n} from '@grafana/lezer-logql';\n\nimport { getLogQueryFromMetricsQueryAtPosition, getNodesFromQuery } from '../../../queryUtils';\n\ntype Direction = 'parent' | 'firstChild' | 'lastChild' | 'nextSibling';\ntype NodeType = number;\n\ntype Path = Array<[Direction, NodeType]>;\n\nfunction move(node: SyntaxNode, direction: Direction): SyntaxNode | null {\n return node[direction];\n}\n\n/**\n * Iteratively calls walk with given path until it returns null, then we return the last non-null node.\n * @param node\n * @param path\n */\nfunction traverse(node: SyntaxNode, path: Path): SyntaxNode | null {\n let current: SyntaxNode | null = node;\n let next = walk(current, path);\n while (next) {\n let nextTmp = walk(next, path);\n if (nextTmp) {\n next = nextTmp;\n } else {\n return next;\n }\n }\n return null;\n}\n\n/**\n * Walks a single step from the provided node, following the path.\n * @param node\n * @param path\n */\nfunction walk(node: SyntaxNode, path: Path): SyntaxNode | null {\n let current: SyntaxNode | null = node;\n for (const [direction, expectedNode] of path) {\n current = move(current, direction);\n if (current === null) {\n // we could not move in the direction, we stop\n return null;\n }\n if (current.type.id !== expectedNode) {\n // the reached node has wrong type, we stop\n return null;\n }\n }\n return current;\n}\n\nfunction getNodeText(node: SyntaxNode, text: string): string {\n return text.slice(node.from, node.to);\n}\n\nfunction parseStringLiteral(text: string): string {\n // If it is a string-literal, it is inside quotes of some kind\n const inside = text.slice(1, text.length - 1);\n\n // Very simple un-escaping:\n\n // Double quotes\n if (text.startsWith('\"') && text.endsWith('\"')) {\n // NOTE: this is not 100% perfect, we only unescape the double-quote,\n // there might be other characters too\n return inside.replace(/\\\\\"/gm, '\"');\n }\n\n // Single quotes\n if (text.startsWith(\"'\") && text.endsWith(\"'\")) {\n // NOTE: this is not 100% perfect, we only unescape the single-quote,\n // there might be other characters too\n return inside.replace(/\\\\'/gm, \"'\");\n }\n\n // Backticks\n if (text.startsWith('`') && text.endsWith('`')) {\n return inside;\n }\n\n throw new Error(`Invalid string literal: ${text}`);\n}\n\nexport type LabelOperator = '=' | '!=' | '=~' | '!~';\n\nexport type Label = {\n name: string;\n value: string;\n op: LabelOperator;\n};\n\nexport type Situation =\n | {\n type: 'EMPTY';\n }\n | {\n type: 'AT_ROOT';\n }\n | {\n type: 'IN_LOGFMT';\n otherLabels: string[];\n flags: boolean;\n trailingSpace: boolean;\n trailingComma: boolean;\n logQuery: string;\n }\n | {\n type: 'IN_RANGE';\n }\n | {\n type: 'IN_AGGREGATION';\n }\n | {\n type: 'IN_GROUPING';\n logQuery: string;\n }\n | {\n type: 'IN_LABEL_SELECTOR_NO_LABEL_NAME';\n otherLabels: Label[];\n }\n | {\n type: 'IN_LABEL_SELECTOR_WITH_LABEL_NAME';\n labelName: string;\n betweenQuotes: boolean;\n otherLabels: Label[];\n }\n | {\n type: 'AFTER_SELECTOR';\n afterPipe: boolean;\n hasSpace: boolean;\n logQuery: string;\n }\n | {\n type: 'AFTER_UNWRAP';\n logQuery: string;\n }\n | {\n type: 'AFTER_KEEP_AND_DROP';\n logQuery: string;\n };\n\ntype Resolver = {\n paths: NodeType[][];\n fun: (node: SyntaxNode, text: string, pos: number) => Situation | null;\n};\n\nfunction isPathMatch(resolverPath: NodeType[], cursorPath: number[]): boolean {\n return resolverPath.every((item, index) => item === cursorPath[index]);\n}\n\nconst ERROR_NODE_ID = 0;\n\nconst RESOLVERS: Resolver[] = [\n {\n paths: [[Selector], [Selector, Matchers], [Matchers], [ERROR_NODE_ID, Matchers, Selector]],\n fun: resolveSelector,\n },\n {\n paths: [\n [LogQL],\n [RangeAggregationExpr],\n [ERROR_NODE_ID, LogRangeExpr, RangeAggregationExpr],\n [ERROR_NODE_ID, LabelExtractionExpressionList],\n [LogRangeExpr],\n [ERROR_NODE_ID, LabelExtractionExpressionList],\n [LabelExtractionExpressionList],\n [LogfmtExpressionParser],\n ],\n fun: resolveLogfmtParser,\n },\n {\n paths: [[LogQL], [ERROR_NODE_ID, Selector]],\n fun: resolveTopLevel,\n },\n {\n paths: [[String, Matcher]],\n fun: resolveMatcher,\n },\n {\n paths: [[Grouping]],\n fun: resolveLabelsForGrouping,\n },\n {\n paths: [[LogRangeExpr]],\n fun: resolveLogRange,\n },\n {\n paths: [\n [ERROR_NODE_ID, Matcher],\n [ERROR_NODE_ID, Matchers, Selector],\n ],\n fun: resolveMatcher,\n },\n {\n paths: [[ERROR_NODE_ID, Range]],\n fun: resolveDurations,\n },\n {\n paths: [[ERROR_NODE_ID, LogRangeExpr]],\n fun: resolveLogRangeFromError,\n },\n {\n paths: [[ERROR_NODE_ID, LiteralExpr, MetricExpr, VectorAggregationExpr]],\n fun: () => ({ type: 'IN_AGGREGATION' }),\n },\n {\n paths: [\n [ERROR_NODE_ID, PipelineStage, PipelineExpr],\n [PipelineStage, PipelineExpr],\n ],\n fun: resolvePipeError,\n },\n {\n paths: [[ERROR_NODE_ID, UnwrapExpr], [UnwrapExpr]],\n fun: resolveAfterUnwrap,\n },\n {\n paths: [\n [ERROR_NODE_ID, DropLabelsExpr],\n [ERROR_NODE_ID, DropLabels],\n [ERROR_NODE_ID, KeepLabelsExpr],\n [ERROR_NODE_ID, KeepLabels],\n ],\n fun: resolveAfterKeepAndDrop,\n },\n];\n\nconst LABEL_OP_MAP = new Map([\n ['Eq', '='],\n ['Re', '=~'],\n ['Neq', '!='],\n ['Nre', '!~'],\n]);\n\nfunction getLabelOp(opNode: SyntaxNode): LabelOperator | null {\n return LABEL_OP_MAP.get(opNode.name) ?? null;\n}\n\nfunction getLabel(matcherNode: SyntaxNode, text: string): Label | null {\n if (matcherNode.type.id !== Matcher) {\n return null;\n }\n\n const nameNode = walk(matcherNode, [['firstChild', Identifier]]);\n\n if (nameNode === null) {\n return null;\n }\n\n const opNode = nameNode.nextSibling;\n if (opNode === null) {\n return null;\n }\n\n const op = getLabelOp(opNode);\n if (op === null) {\n return null;\n }\n\n const valueNode = walk(matcherNode, [['lastChild', String]]);\n\n if (valueNode === null) {\n return null;\n }\n\n const name = getNodeText(nameNode, text);\n const value = parseStringLiteral(getNodeText(valueNode, text));\n\n return { name, value, op };\n}\n\nfunction getLabels(selectorNode: SyntaxNode, text: string): Label[] {\n if (selectorNode.type.id !== Selector && selectorNode.type.id !== Matchers) {\n return [];\n }\n\n let listNode: SyntaxNode | null = null;\n\n // If parent node is selector, we want to start with the current Matcher node\n if (selectorNode?.parent?.type.id === Selector) {\n listNode = selectorNode;\n } else {\n // Parent node needs to be returned first because otherwise both of the other walks will return a non-null node and this function will return the labels on the left side of the current node, the other two walks should be mutually exclusive when the parent is null\n listNode =\n // Node in-between labels\n traverse(selectorNode, [['parent', Matchers]]) ??\n // Node after all other labels\n walk(selectorNode, [['firstChild', Matchers]]) ??\n // Node before all other labels\n walk(selectorNode, [['lastChild', Matchers]]);\n }\n\n const labels: Label[] = [];\n\n while (listNode !== null) {\n const matcherNode = walk(listNode, [['lastChild', Matcher]]);\n if (matcherNode !== null) {\n const label = getLabel(matcherNode, text);\n if (label !== null) {\n labels.push(label);\n }\n }\n\n // there might be more labels\n listNode = walk(listNode, [['firstChild', Matchers]]);\n }\n\n // our labels-list is last-first, so we reverse it\n labels.reverse();\n\n return labels;\n}\n\nfunction resolveAfterUnwrap(node: SyntaxNode, text: string, pos: number): Situation | null {\n return {\n type: 'AFTER_UNWRAP',\n logQuery: getLogQueryFromMetricsQueryAtPosition(text, pos).trim(),\n };\n}\n\nfunction resolvePipeError(node: SyntaxNode, text: string, pos: number): Situation | null {\n /**\n * Examples:\n * - {level=\"info\"} |^\n * - count_over_time({level=\"info\"} |^ [4m])\n */\n let exprNode: SyntaxNode | null = null;\n if (node.type.id === ERROR_NODE_ID) {\n exprNode = walk(node, [\n ['parent', PipelineStage],\n ['parent', PipelineExpr],\n ]);\n } else if (node.type.id === PipelineStage) {\n exprNode = walk(node, [['parent', PipelineExpr]]);\n }\n\n if (exprNode?.parent?.type.id === LogExpr || exprNode?.parent?.type.id === LogRangeExpr) {\n return resolveLogOrLogRange(exprNode.parent, text, pos, true);\n }\n\n return null;\n}\n\nfunction resolveLabelsForGrouping(node: SyntaxNode, text: string, pos: number): Situation | null {\n const aggrExpNode = walk(node, [['parent', VectorAggregationExpr]]);\n if (aggrExpNode === null) {\n return null;\n }\n const bodyNode = aggrExpNode.getChild('MetricExpr');\n if (bodyNode === null) {\n return null;\n }\n\n const selectorNode = walk(bodyNode, [\n ['firstChild', RangeAggregationExpr],\n ['lastChild', LogRangeExpr],\n ['firstChild', Selector],\n ]);\n\n if (selectorNode === null) {\n return null;\n }\n\n return {\n type: 'IN_GROUPING',\n logQuery: getLogQueryFromMetricsQueryAtPosition(text, pos).trim(),\n };\n}\n\nfunction resolveMatcher(node: SyntaxNode, text: string, pos: number): Situation | null {\n // we can arrive here for two reasons. `node` is either:\n // - a StringNode (like in `{job=\"^\"}`)\n // - or an error node (like in `{job=^}`)\n const inStringNode = !node.type.isError;\n\n const parent = walk(node, [['parent', Matcher]]);\n if (parent === null) {\n return null;\n }\n\n const labelNameNode = walk(parent, [['firstChild', Identifier]]);\n if (labelNameNode === null) {\n return null;\n }\n\n const labelName = getNodeText(labelNameNode, text);\n\n // now we need to go up, to the parent of Matcher,\n // there can be one or many `Matchers` parents, we have\n // to go through all of them\n\n const firstListNode = walk(parent, [['parent', Matchers]]);\n if (firstListNode === null) {\n return null;\n }\n\n let listNode = firstListNode;\n\n // we keep going through the parent-nodes as long as they are Matchers.\n // as soon as we reach Selector, we stop\n let selectorNode: SyntaxNode | null = null;\n while (selectorNode === null) {\n const parent = listNode.parent;\n if (parent === null) {\n return null;\n }\n\n switch (parent.type.id) {\n case Matchers:\n //we keep looping\n listNode = parent;\n continue;\n case Selector:\n // we reached the end, we can stop the loop\n selectorNode = parent;\n continue;\n default:\n // we reached some other node, we stop\n return null;\n }\n }\n\n // now we need to find the other names\n const allLabels = getLabels(selectorNode, text);\n\n // we need to remove \"our\" label from all-labels, if it is in there\n const otherLabels = allLabels.filter((label) => label.name !== labelName);\n\n return {\n type: 'IN_LABEL_SELECTOR_WITH_LABEL_NAME',\n labelName,\n betweenQuotes: inStringNode,\n otherLabels,\n };\n}\n\nfunction resolveLogfmtParser(_: SyntaxNode, text: string, cursorPosition: number): Situation | null {\n // We want to know if the cursor if after a log query with logfmt parser.\n // E.g. `{x=\"y\"} | logfmt ^`\n /**\n * Wait until the user adds a space to be sure of what the last identifier is. Otherwise\n * it creates suggestion bugs with queries like {label=\"value\"} | parser^ suggest \"parser\"\n * and it can be inserted with extra pipes or commas.\n */\n const tree = parser.parse(text);\n\n // Adjust the cursor position if there are spaces at the end of the text.\n const trimRightTextLen = text.substring(0, cursorPosition).trimEnd().length;\n const position = trimRightTextLen < cursorPosition ? trimRightTextLen : cursorPosition;\n\n const cursor = tree.cursorAt(position);\n\n // Check if the user cursor is in any node that requires logfmt suggestions.\n const expectedNodes = [Logfmt, ParserFlag, LabelExtractionExpression, LabelExtractionExpressionList];\n let inLogfmt = false;\n do {\n const { node } = cursor;\n if (!expectedNodes.includes(node.type.id)) {\n continue;\n }\n if (cursor.from <= position && cursor.to >= position) {\n inLogfmt = true;\n break;\n }\n } while (cursor.next());\n\n if (!inLogfmt) {\n return null;\n }\n\n const flags = getNodesFromQuery(text, [ParserFlag]).length > 1;\n const labelNodes = getNodesFromQuery(text, [LabelExtractionExpression]);\n const otherLabels = labelNodes\n .map((label: SyntaxNode) => label.getChild(Identifier))\n .filter((label: SyntaxNode | null): label is SyntaxNode => label !== null)\n .map((label: SyntaxNode) => getNodeText(label, text));\n\n const logQuery = getLogQueryFromMetricsQueryAtPosition(text, position).trim();\n const trailingSpace = text.charAt(cursorPosition - 1) === ' ';\n const trailingComma = text.trimEnd().charAt(position - 1) === ',';\n\n return {\n type: 'IN_LOGFMT',\n otherLabels,\n flags,\n trailingSpace,\n trailingComma,\n logQuery,\n };\n}\n\nfunction resolveTopLevel(node: SyntaxNode, text: string, pos: number): Situation | null {\n /**\n * The following queries trigger resolveTopLevel().\n * - Empty query\n * - {label=\"value\"} ^\n * - {label=\"value\"} | parser ^\n * From here, we need to determine if the user is in a resolveLogOrLogRange() or simply at the root.\n */\n const logExprNode = walk(node, [\n ['lastChild', Expr],\n ['lastChild', LogExpr],\n ]);\n\n /**\n * Wait until the user adds a space to be sure of what the last identifier is. Otherwise\n * it creates suggestion bugs with queries like {label=\"value\"} | parser^ suggest \"parser\"\n * and it can be inserted with extra pipes.\n */\n if (logExprNode != null && text.endsWith(' ')) {\n return resolveLogOrLogRange(logExprNode, text, pos, false);\n }\n\n // `s` situation, with the cursor at the end.\n // (basically, user enters a non-special characters as first\n // character in query field)\n const idNode = walk(node, [\n ['firstChild', ERROR_NODE_ID],\n ['firstChild', Identifier],\n ]);\n\n if (idNode != null) {\n return {\n type: 'AT_ROOT',\n };\n }\n\n // no patterns match\n return null;\n}\n\nfunction resolveDurations(node: SyntaxNode, text: string, pos: number): Situation {\n return {\n type: 'IN_RANGE',\n };\n}\n\nfunction resolveLogRange(node: SyntaxNode, text: string, pos: number): Situation | null {\n const partialQuery = text.substring(0, pos).trimEnd();\n const afterPipe = partialQuery.endsWith('|');\n\n return resolveLogOrLogRange(node, text, pos, afterPipe);\n}\n\nfunction resolveLogRangeFromError(node: SyntaxNode, text: string, pos: number): Situation | null {\n const parent = walk(node, [['parent', LogRangeExpr]]);\n if (parent === null) {\n return null;\n }\n\n const partialQuery = text.substring(0, pos).trimEnd();\n const afterPipe = partialQuery.endsWith('|');\n\n return resolveLogOrLogRange(parent, text, pos, afterPipe);\n}\n\nfunction resolveLogOrLogRange(node: SyntaxNode, text: string, pos: number, afterPipe: boolean): Situation | null {\n // Here the `node` is either a LogExpr or a LogRangeExpr\n // We want to handle the case where we are next to a selector\n const selectorNode = walk(node, [['firstChild', Selector]]);\n\n // Check that the selector is before the cursor, not after it\n if (!selectorNode || selectorNode.to > pos) {\n return null;\n }\n\n return {\n type: 'AFTER_SELECTOR',\n afterPipe,\n hasSpace: text.charAt(pos - 1) === ' ',\n logQuery: getLogQueryFromMetricsQueryAtPosition(text, pos).trim(),\n };\n}\n\nfunction resolveSelector(node: SyntaxNode, text: string, pos: number): Situation | null {\n // for example `{^}`\n\n // false positive:\n // `{a=\"1\"^}`\n const child = walk(node, [['firstChild', Matchers]]);\n if (child !== null) {\n // means the label-matching part contains at least one label already.\n //\n // in this case, we will need to have a `,` character at the end,\n // to be able to suggest adding the next label.\n // the area between the end-of-the-child-node and the cursor-pos\n // must contain a `,` in this case.\n const textToCheck = text.slice(child.from, pos);\n if (!textToCheck.trim().endsWith(',')) {\n return null;\n }\n }\n\n const selectorNode =\n node.type.id === ERROR_NODE_ID\n ? walk(node, [\n ['parent', Matchers],\n ['parent', Selector],\n ])\n : node;\n if (!selectorNode) {\n return null;\n }\n\n const otherLabels = getLabels(selectorNode, text);\n\n return {\n type: 'IN_LABEL_SELECTOR_NO_LABEL_NAME',\n otherLabels,\n };\n}\n\nfunction resolveAfterKeepAndDrop(node: SyntaxNode, text: string, pos: number): Situation | null {\n let logQuery = getLogQueryFromMetricsQueryAtPosition(text, pos).trim();\n let keepAndDropParent: SyntaxNode | null = null;\n let parent = node.parent;\n while (parent !== null) {\n if (parent.type.id === PipelineStage) {\n keepAndDropParent = parent;\n break;\n }\n parent = parent.parent;\n }\n\n if (keepAndDropParent?.type.id === PipelineStage) {\n logQuery = logQuery.slice(0, keepAndDropParent.from);\n }\n\n return {\n type: 'AFTER_KEEP_AND_DROP',\n logQuery,\n };\n}\n\n// If there is an error in the current cursor position, it's likely that the user is\n// in the middle of writing a query. If we can't find an error node, we use the node\n// at the cursor position to identify the situation.\nfunction resolveCursor(text: string, cursorPos: number): TreeCursor {\n // Sometimes the cursor is a couple spaces after the end of the expression.\n // To account for this situation, we \"move\" the cursor position back to the real end\n // of the expression.\n const trimRightTextLen = text.trimEnd().length;\n const pos = trimRightTextLen < cursorPos ? trimRightTextLen : cursorPos;\n\n const tree = parser.parse(text);\n const cursor = tree.cursorAt(pos);\n\n do {\n if (cursor.from === pos && cursor.to === pos && cursor.node.type.isError) {\n return cursor;\n }\n } while (cursor.next());\n\n return tree.cursorAt(pos);\n}\n\nexport function getSituation(text: string, pos: number): Situation | null {\n // there is a special case when we are at the start of writing text,\n // so we handle that case first\n\n if (text === '') {\n return {\n type: 'EMPTY',\n };\n }\n\n const cursor = resolveCursor(text, pos);\n const currentNode = cursor.node;\n\n const ids = [cursor.type.id];\n while (cursor.parent()) {\n ids.push(cursor.type.id);\n }\n\n for (let resolver of RESOLVERS) {\n for (let path of resolver.paths) {\n if (isPathMatch(path, ids)) {\n const situation = resolver.fun(currentNode, text, pos);\n if (situation) {\n return situation;\n }\n }\n }\n }\n\n return null;\n}\n","import type { Monaco, monacoTypes } from '@grafana/ui';\n\nimport { CompletionDataProvider } from './CompletionDataProvider';\nimport { NeverCaseError } from './NeverCaseError';\nimport { CompletionType, getCompletions } from './completions';\nimport { getSituation, Situation } from './situation';\n\n// from: monacoTypes.languages.CompletionItemInsertTextRule.InsertAsSnippet\nconst INSERT_AS_SNIPPET_ENUM_VALUE = 4;\n\nexport function getSuggestOptions(): monacoTypes.editor.ISuggestOptions {\n return {\n // monaco-editor sometimes provides suggestions automatically, i am not\n // sure based on what, seems to be by analyzing the words already\n // written.\n // to try it out:\n // - enter `go_goroutines{job~`\n // - have the cursor at the end of the string\n // - press ctrl-enter\n // - you will get two suggestions\n // those were not provided by grafana, they are offered automatically.\n // i want to remove those. the only way i found is:\n // - every suggestion-item has a `kind` attribute,\n // that controls the icon to the left of the suggestion.\n // - items auto-generated by monaco have `kind` set to `text`.\n // - we make sure grafana-provided suggestions do not have `kind` set to `text`.\n // - and then we tell monaco not to show suggestions of kind `text`\n showWords: false,\n };\n}\n\nfunction getMonacoCompletionItemKind(type: CompletionType, monaco: Monaco): monacoTypes.languages.CompletionItemKind {\n switch (type) {\n case 'DURATION':\n return monaco.languages.CompletionItemKind.Unit;\n case 'FUNCTION':\n return monaco.languages.CompletionItemKind.Variable;\n case 'HISTORY':\n return monaco.languages.CompletionItemKind.Snippet;\n case 'LABEL_NAME':\n return monaco.languages.CompletionItemKind.Enum;\n case 'LABEL_VALUE':\n return monaco.languages.CompletionItemKind.EnumMember;\n case 'PATTERN':\n return monaco.languages.CompletionItemKind.Constructor;\n case 'PARSER':\n return monaco.languages.CompletionItemKind.Class;\n case 'LINE_FILTER':\n return monaco.languages.CompletionItemKind.TypeParameter;\n case 'PIPE_OPERATION':\n return monaco.languages.CompletionItemKind.Interface;\n default:\n throw new NeverCaseError(type);\n }\n}\n\nexport function getCompletionProvider(\n monaco: Monaco,\n dataProvider: CompletionDataProvider\n): monacoTypes.languages.CompletionItemProvider {\n const provideCompletionItems = (\n model: monacoTypes.editor.ITextModel,\n position: monacoTypes.Position\n ): monacoTypes.languages.ProviderResult => {\n const word = model.getWordAtPosition(position);\n const wordUntil = model.getWordUntilPosition(position);\n\n // documentation says `position` will be \"adjusted\" in `getOffsetAt`\n // i don't know what that means, to be sure i clone it\n const positionClone = {\n column: position.column,\n lineNumber: position.lineNumber,\n };\n const offset = model.getOffsetAt(positionClone);\n const situation = getSituation(model.getValue(), offset);\n const range = calculateRange(situation, word, wordUntil, monaco, position);\n const completionsPromise = situation != null ? getCompletions(situation, dataProvider) : Promise.resolve([]);\n return completionsPromise.then((items) => {\n // monaco by default alphabetically orders the items.\n // to stop it, we use a number-as-string sortkey,\n // so that monaco keeps the order we use\n const maxIndexDigits = items.length.toString().length;\n const suggestions: monacoTypes.languages.CompletionItem[] = items.map((item, index) => ({\n kind: getMonacoCompletionItemKind(item.type, monaco),\n label: item.label,\n insertText: item.insertText,\n insertTextRules: item.isSnippet ? INSERT_AS_SNIPPET_ENUM_VALUE : undefined,\n detail: item.detail,\n documentation: item.documentation,\n sortText: index.toString().padStart(maxIndexDigits, '0'), // to force the order we have\n range: range,\n command: item.triggerOnInsert\n ? {\n id: 'editor.action.triggerSuggest',\n title: '',\n }\n : undefined,\n }));\n return { suggestions };\n });\n };\n\n return {\n triggerCharacters: ['{', ',', '[', '(', '=', '~', ' ', '\"', '|'],\n provideCompletionItems,\n };\n}\n\nexport const calculateRange = (\n situation: Situation | null,\n word: monacoTypes.editor.IWordAtPosition | null,\n wordUntil: monacoTypes.editor.IWordAtPosition,\n monaco: Monaco,\n position: monacoTypes.Position\n): monacoTypes.Range => {\n if (\n situation &&\n situation?.type === 'IN_LABEL_SELECTOR_WITH_LABEL_NAME' &&\n 'betweenQuotes' in situation &&\n situation.betweenQuotes\n ) {\n // Word until won't have second quote if they are between quotes\n const indexOfFirstQuote = wordUntil?.word?.indexOf('\"') ?? 0;\n\n const indexOfLastQuote = word?.word?.lastIndexOf('\"') ?? 0;\n\n const indexOfEquals = word?.word.indexOf('=');\n const indexOfLastEquals = word?.word.lastIndexOf('=');\n\n // Just one equals \"=\" the cursor is somewhere within a label value\n // e.g. value=\"labe^l-value\" or value=\"^label-value\" etc\n // We want the word to include everything within the quotes, so the result from autocomplete overwrites the existing label value\n if (\n indexOfLastEquals === indexOfEquals &&\n indexOfFirstQuote !== -1 &&\n indexOfLastQuote !== -1 &&\n indexOfLastEquals !== -1\n ) {\n return word != null\n ? monaco.Range.lift({\n startLineNumber: position.lineNumber,\n endLineNumber: position.lineNumber,\n startColumn: wordUntil.startColumn + indexOfFirstQuote + 1,\n endColumn: wordUntil.startColumn + indexOfLastQuote,\n })\n : monaco.Range.fromPositions(position);\n }\n }\n\n if (situation && situation.type === 'IN_LABEL_SELECTOR_WITH_LABEL_NAME') {\n // Otherwise we want the range to be calculated as the cursor position, as we want to insert the autocomplete, instead of overwriting existing text\n // The cursor position is the length of the wordUntil\n return word != null\n ? monaco.Range.lift({\n startLineNumber: position.lineNumber,\n endLineNumber: position.lineNumber,\n startColumn: wordUntil.endColumn,\n endColumn: wordUntil.endColumn,\n })\n : monaco.Range.fromPositions(position);\n }\n\n // And for all other non-label cases, we want to use the word start and end column\n return word != null\n ? monaco.Range.lift({\n startLineNumber: position.lineNumber,\n endLineNumber: position.lineNumber,\n startColumn: word.startColumn,\n endColumn: word.endColumn,\n })\n : monaco.Range.fromPositions(position);\n};\n","import { css } from '@emotion/css';\nimport { debounce } from 'lodash';\nimport React, { useRef, useEffect } from 'react';\nimport { useLatest } from 'react-use';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { GrafanaTheme2 } from '@grafana/data';\nimport { selectors } from '@grafana/e2e-selectors';\nimport { parser } from '@grafana/lezer-logql';\nimport { languageConfiguration, monarchlanguage } from '@grafana/monaco-logql';\nimport { useTheme2, ReactMonacoEditor, Monaco, monacoTypes, MonacoEditor } from '@grafana/ui';\n\nimport { Props } from './MonacoQueryFieldProps';\nimport { getOverrideServices } from './getOverrideServices';\nimport { CompletionDataProvider } from './monaco-completion-provider/CompletionDataProvider';\nimport { getCompletionProvider, getSuggestOptions } from './monaco-completion-provider/completionUtils';\nimport { placeHolderScopedVars, validateQuery } from './monaco-completion-provider/validation';\n\nconst options: monacoTypes.editor.IStandaloneEditorConstructionOptions = {\n codeLens: false,\n contextmenu: false,\n // we need `fixedOverflowWidgets` because otherwise in grafana-dashboards\n // the popup is clipped by the panel-visualizations.\n fixedOverflowWidgets: true,\n folding: false,\n fontSize: 14,\n lineDecorationsWidth: 8, // used as \"padding-left\"\n lineNumbers: 'off',\n minimap: { enabled: false },\n overviewRulerBorder: false,\n overviewRulerLanes: 0,\n padding: {\n // these numbers were picked so that visually this matches the previous version\n // of the query-editor the best\n top: 4,\n bottom: 5,\n },\n renderLineHighlight: 'none',\n scrollbar: {\n vertical: 'hidden',\n verticalScrollbarSize: 8, // used as \"padding-right\"\n horizontal: 'hidden',\n horizontalScrollbarSize: 0,\n alwaysConsumeMouseWheel: false,\n },\n scrollBeyondLastLine: false,\n suggest: getSuggestOptions(),\n suggestFontSize: 12,\n wordWrap: 'on',\n};\n\n// this number was chosen by testing various values. it might be necessary\n// because of the width of the border, not sure.\n//it needs to do 2 things:\n// 1. when the editor is single-line, it should make the editor height be visually correct\n// 2. when the editor is multi-line, the editor should not be \"scrollable\" (meaning,\n// you do a scroll-movement in the editor, and it will scroll the content by a couple pixels\n// up & down. this we want to avoid)\nconst EDITOR_HEIGHT_OFFSET = 2;\n\nconst LANG_ID = 'logql';\n\n// we must only run the lang-setup code once\nlet LANGUAGE_SETUP_STARTED = false;\n\nexport const defaultWordPattern = /(-?\\d*\\.\\d\\w*)|([^`~!#%^&*()\\-=+\\[{\\]}\\\\|;:'\",.<>\\/?\\s]+)/g;\n\nfunction ensureLogQL(monaco: Monaco) {\n if (LANGUAGE_SETUP_STARTED === false) {\n LANGUAGE_SETUP_STARTED = true;\n monaco.languages.register({ id: LANG_ID });\n\n monaco.languages.setMonarchTokensProvider(LANG_ID, monarchlanguage);\n monaco.languages.setLanguageConfiguration(LANG_ID, {\n ...languageConfiguration,\n wordPattern: /(-?\\d*\\.\\d\\w*)|([^`~!#%^&*()+\\[{\\]}\\\\|;:',.<>\\/?\\s]+)/g,\n // Default: /(-?\\d*\\.\\d\\w*)|([^`~!#%^&*()\\-=+\\[{\\]}\\\\|;:'\",.<>\\/?\\s]+)/g\n // Removed `\"`, `=`, and `-`, from the exclusion list, so now the completion provider can decide to overwrite any matching words, or just insert text at the cursor\n });\n }\n}\n\nconst getStyles = (theme: GrafanaTheme2, placeholder: string) => {\n return {\n container: css`\n border-radius: ${theme.shape.radius.default};\n border: 1px solid ${theme.components.input.borderColor};\n width: 100%;\n .monaco-editor .suggest-widget {\n min-width: 50%;\n }\n `,\n placeholder: css`\n ::after {\n content: '${placeholder}';\n font-family: ${theme.typography.fontFamilyMonospace};\n opacity: 0.3;\n }\n `,\n };\n};\n\nconst MonacoQueryField = ({\n history,\n onBlur,\n onRunQuery,\n initialValue,\n datasource,\n placeholder,\n onChange,\n timeRange,\n}: Props) => {\n const id = uuidv4();\n // we need only one instance of `overrideServices` during the lifetime of the react component\n const overrideServicesRef = useRef(getOverrideServices());\n const containerRef = useRef(null);\n\n const langProviderRef = useLatest(datasource.languageProvider);\n const historyRef = useLatest(history);\n const onRunQueryRef = useLatest(onRunQuery);\n const onBlurRef = useLatest(onBlur);\n\n const autocompleteCleanupCallback = useRef<(() => void) | null>(null);\n\n const theme = useTheme2();\n const styles = getStyles(theme, placeholder);\n\n useEffect(() => {\n // when we unmount, we unregister the autocomplete-function, if it was registered\n return () => {\n autocompleteCleanupCallback.current?.();\n };\n }, []);\n\n const setPlaceholder = (monaco: Monaco, editor: MonacoEditor) => {\n const placeholderDecorators = [\n {\n range: new monaco.Range(1, 1, 1, 1),\n options: {\n className: styles.placeholder,\n isWholeLine: true,\n },\n },\n ];\n\n let decorators: string[] = [];\n\n const checkDecorators: () => void = () => {\n const model = editor.getModel();\n\n if (!model) {\n return;\n }\n\n const newDecorators = model.getValueLength() === 0 ? placeholderDecorators : [];\n decorators = model.deltaDecorations(decorators, newDecorators);\n };\n\n checkDecorators();\n editor.onDidChangeModelContent(checkDecorators);\n };\n\n const onTypeDebounced = debounce(async (query: string) => {\n onChange(query);\n }, 1000);\n\n return (\n \n {\n ensureLogQL(monaco);\n }}\n onMount={(editor, monaco) => {\n // Monaco has a bug where it runs actions on all instances (https://github.com/microsoft/monaco-editor/issues/2947), so we ensure actions are executed on instance-level with this ContextKey.\n const isEditorFocused = editor.createContextKey('isEditorFocused' + id, false);\n // we setup on-blur\n editor.onDidBlurEditorWidget(() => {\n isEditorFocused.set(false);\n onBlurRef.current(editor.getValue());\n });\n editor.onDidChangeModelContent((e) => {\n const model = editor.getModel();\n if (!model) {\n return;\n }\n const query = model.getValue();\n const errors =\n validateQuery(\n query,\n datasource.interpolateString(query, placeHolderScopedVars),\n model.getLinesContent(),\n parser\n ) || [];\n\n const markers = errors.map(({ error, ...boundary }) => ({\n message: `${\n error ? `Error parsing \"${error}\"` : 'Parse error'\n }. The query appears to be incorrect and could fail to be executed.`,\n severity: monaco.MarkerSeverity.Error,\n ...boundary,\n }));\n\n onTypeDebounced(query);\n monaco.editor.setModelMarkers(model, 'owner', markers);\n });\n const dataProvider = new CompletionDataProvider(langProviderRef.current, historyRef, timeRange);\n const completionProvider = getCompletionProvider(monaco, dataProvider);\n\n // completion-providers in monaco are not registered directly to editor-instances,\n // they are registered to languages. this makes it hard for us to have\n // separate completion-providers for every query-field-instance\n // (but we need that, because they might connect to different datasources).\n // the trick we do is, we wrap the callback in a \"proxy\",\n // and in the proxy, the first thing is, we check if we are called from\n // \"our editor instance\", and if not, we just return nothing. if yes,\n // we call the completion-provider.\n const filteringCompletionProvider: monacoTypes.languages.CompletionItemProvider = {\n ...completionProvider,\n provideCompletionItems: (model, position, context, token) => {\n // if the model-id does not match, then this call is from a different editor-instance,\n // not \"our instance\", so return nothing\n if (editor.getModel()?.id !== model.id) {\n return { suggestions: [] };\n }\n return completionProvider.provideCompletionItems(model, position, context, token);\n },\n };\n\n const { dispose } = monaco.languages.registerCompletionItemProvider(LANG_ID, filteringCompletionProvider);\n\n autocompleteCleanupCallback.current = dispose;\n // this code makes the editor resize itself so that the content fits\n // (it will grow taller when necessary)\n // FIXME: maybe move this functionality into CodeEditor, like:\n // \n const handleResize = () => {\n const containerDiv = containerRef.current;\n if (containerDiv !== null) {\n const pixelHeight = editor.getContentHeight();\n containerDiv.style.height = `${pixelHeight + EDITOR_HEIGHT_OFFSET}px`;\n const pixelWidth = containerDiv.clientWidth;\n editor.layout({ width: pixelWidth, height: pixelHeight });\n }\n };\n\n editor.onDidContentSizeChange(handleResize);\n handleResize();\n // handle: shift + enter\n // FIXME: maybe move this functionality into CodeEditor?\n editor.addCommand(\n monaco.KeyMod.Shift | monaco.KeyCode.Enter,\n () => {\n onRunQueryRef.current(editor.getValue());\n },\n 'isEditorFocused' + id\n );\n\n editor.onDidFocusEditorText(() => {\n isEditorFocused.set(true);\n if (editor.getValue().trim() === '') {\n editor.trigger('', 'editor.action.triggerSuggest', {});\n }\n });\n\n setPlaceholder(monaco, editor);\n }}\n />\n \n );\n};\n\n// Default export for lazy load.\nexport default MonacoQueryField;\n","import { monacoTypes } from '@grafana/ui';\n\n// this thing here is a workaround in a way.\n// what we want to achieve, is that when the autocomplete-window\n// opens, the \"second, extra popup\" with the extra help,\n// also opens automatically.\n// but there is no API to achieve it.\n// the way to do it is to implement the `storageService`\n// interface, and provide our custom implementation,\n// which will default to `true` for the correct string-key.\n// unfortunately, while the typescript-interface exists,\n// it is not exported from monaco-editor,\n// so we cannot rely on typescript to make sure\n// we do it right. all we can do is to manually\n// lookup the interface, and make sure we code our code right.\n// our code is a \"best effort\" approach,\n// i am not 100% how the `scope` and `target` things work,\n// but so far it seems to work ok.\n// i would use an another approach, if there was one available.\n\nfunction makeStorageService() {\n // we need to return an object that fulfills this interface:\n // https://github.com/microsoft/vscode/blob/ff1e16eebb93af79fd6d7af1356c4003a120c563/src/vs/platform/storage/common/storage.ts#L37\n // unfortunately it is not export from monaco-editor\n\n const strings = new Map();\n\n // we want this to be true by default\n strings.set('expandSuggestionDocs', true.toString());\n\n return {\n // we do not implement the on* handlers\n onDidChangeValue: (data: unknown): void => undefined,\n onDidChangeTarget: (data: unknown): void => undefined,\n onWillSaveState: (data: unknown): void => undefined,\n\n get: (key: string, scope: unknown, fallbackValue?: string): string | undefined => {\n return strings.get(key) ?? fallbackValue;\n },\n\n getBoolean: (key: string, scope: unknown, fallbackValue?: boolean): boolean | undefined => {\n const val = strings.get(key);\n if (val !== undefined) {\n // the interface docs say the value will be converted\n // to a boolean but do not specify how, so we improvise\n return val === 'true';\n } else {\n return fallbackValue;\n }\n },\n\n getNumber: (key: string, scope: unknown, fallbackValue?: number): number | undefined => {\n const val = strings.get(key);\n if (val !== undefined) {\n return parseInt(val, 10);\n } else {\n return fallbackValue;\n }\n },\n\n store: (\n key: string,\n value: string | boolean | number | undefined | null,\n scope: unknown,\n target: unknown\n ): void => {\n // the interface docs say if the value is nullish, it should act as delete\n if (value === null || value === undefined) {\n strings.delete(key);\n } else {\n strings.set(key, value.toString());\n }\n },\n\n remove: (key: string, scope: unknown): void => {\n strings.delete(key);\n },\n\n keys: (scope: unknown, target: unknown): string[] => {\n return Array.from(strings.keys());\n },\n\n logStorage: (): void => {\n console.log('logStorage: not implemented');\n },\n\n migrate: (): Promise => {\n // we do not implement this\n return Promise.resolve(undefined);\n },\n\n isNew: (scope: unknown): boolean => {\n // we create a new storage for every session, we do not persist it,\n // so we return `true`.\n return true;\n },\n\n flush: (reason?: unknown): Promise => {\n // we do not implement this\n return Promise.resolve(undefined);\n },\n };\n}\n\nlet overrideServices: monacoTypes.editor.IEditorOverrideServices = {\n storageService: makeStorageService(),\n};\n\nexport function getOverrideServices(): monacoTypes.editor.IEditorOverrideServices {\n // One instance of this for every query editor\n return overrideServices;\n}\n","// This helper class is used to make typescript warn you when you miss a case-block in a switch statement.\n// For example:\n//\n// const x:'A'|'B'|'C' = 'A';\n//\n// switch(x) {\n// case 'A':\n// // something\n// case 'B':\n// // something\n// default:\n// throw new NeverCaseError(x);\n// }\n//\n//\n// TypeScript detect the missing case and display an error.\n\nexport class NeverCaseError extends Error {\n constructor(value: never) {\n super(`Unexpected case in switch statement: ${JSON.stringify(value)}`);\n }\n}\n","export type LabelOperator = '=' | '!=' | '=~' | '!~';\n\nexport type Label = {\n name: string;\n value: string;\n op: LabelOperator;\n};\n\nexport type Situation =\n | {\n type: 'EMPTY';\n }\n | {\n type: 'AT_ROOT';\n }\n | {\n type: 'IN_LOGFMT';\n otherLabels: string[];\n flags: boolean;\n trailingSpace: boolean;\n trailingComma: boolean;\n logQuery: string;\n }\n | {\n type: 'IN_RANGE';\n }\n | {\n type: 'IN_AGGREGATION';\n }\n | {\n type: 'IN_GROUPING';\n logQuery: string;\n }\n | {\n type: 'IN_LABEL_SELECTOR_NO_LABEL_NAME';\n otherLabels: Label[];\n }\n | {\n type: 'IN_LABEL_SELECTOR_WITH_LABEL_NAME';\n labelName: string;\n betweenQuotes: boolean;\n otherLabels: Label[];\n }\n | {\n type: 'AFTER_SELECTOR';\n afterPipe: boolean;\n hasSpace: boolean;\n logQuery: string;\n }\n | {\n type: 'AFTER_UNWRAP';\n logQuery: string;\n }\n | {\n type: 'AFTER_KEEP_AND_DROP';\n logQuery: string;\n };\n\n/**\n * THIS METHOD IS KNOWN TO BE INCOMPLETE due to the decoupling of the Tempo datasource from Grafana core:\n * Incomplete support for LogQL autocomplete from 'public/app/plugins/datasource/loki/components/monaco-query-field/monaco-completion-provider/situation.ts';\n */\nexport const getSituation = (text: string, pos: number): Situation | null => {\n return {\n type: 'EMPTY',\n };\n};\n","import type { Monaco, monacoTypes } from '@grafana/ui';\n\nimport { CompletionDataProvider } from './CompletionDataProvider';\nimport { NeverCaseError } from './NeverCaseError';\nimport { Situation, getSituation } from './situation';\n\ntype CompletionType =\n | 'HISTORY'\n | 'FUNCTION'\n | 'DURATION'\n | 'LABEL_NAME'\n | 'LABEL_VALUE'\n | 'PATTERN'\n | 'PARSER'\n | 'LINE_FILTER'\n | 'PIPE_OPERATION';\n\ntype Completion = {\n type: CompletionType;\n label: string;\n insertText: string;\n detail?: string;\n documentation?: string;\n triggerOnInsert?: boolean;\n isSnippet?: boolean;\n};\n\nconst DURATION_COMPLETIONS: Completion[] = ['$__auto', '1m', '5m', '10m', '30m', '1h', '1d'].map((text) => ({\n type: 'DURATION',\n label: text,\n insertText: text,\n}));\nconst getCompletions = async (situation: Situation, dataProvider: CompletionDataProvider) => {\n return DURATION_COMPLETIONS;\n};\n\n// from: monacoTypes.languages.CompletionItemInsertTextRule.InsertAsSnippet\nconst INSERT_AS_SNIPPET_ENUM_VALUE = 4;\n\nexport function getSuggestOptions(): monacoTypes.editor.ISuggestOptions {\n return {\n // monaco-editor sometimes provides suggestions automatically, i am not\n // sure based on what, seems to be by analyzing the words already\n // written.\n // to try it out:\n // - enter `go_goroutines{job~`\n // - have the cursor at the end of the string\n // - press ctrl-enter\n // - you will get two suggestions\n // those were not provided by grafana, they are offered automatically.\n // i want to remove those. the only way i found is:\n // - every suggestion-item has a `kind` attribute,\n // that controls the icon to the left of the suggestion.\n // - items auto-generated by monaco have `kind` set to `text`.\n // - we make sure grafana-provided suggestions do not have `kind` set to `text`.\n // - and then we tell monaco not to show suggestions of kind `text`\n showWords: false,\n };\n}\n\nfunction getMonacoCompletionItemKind(type: CompletionType, monaco: Monaco): monacoTypes.languages.CompletionItemKind {\n switch (type) {\n case 'DURATION':\n return monaco.languages.CompletionItemKind.Unit;\n case 'FUNCTION':\n return monaco.languages.CompletionItemKind.Variable;\n case 'HISTORY':\n return monaco.languages.CompletionItemKind.Snippet;\n case 'LABEL_NAME':\n return monaco.languages.CompletionItemKind.Enum;\n case 'LABEL_VALUE':\n return monaco.languages.CompletionItemKind.EnumMember;\n case 'PATTERN':\n return monaco.languages.CompletionItemKind.Constructor;\n case 'PARSER':\n return monaco.languages.CompletionItemKind.Class;\n case 'LINE_FILTER':\n return monaco.languages.CompletionItemKind.TypeParameter;\n case 'PIPE_OPERATION':\n return monaco.languages.CompletionItemKind.Interface;\n default:\n throw new NeverCaseError(type as never);\n }\n}\n\nexport function getCompletionProvider(\n monaco: Monaco,\n dataProvider: CompletionDataProvider\n): monacoTypes.languages.CompletionItemProvider {\n const provideCompletionItems = (\n model: monacoTypes.editor.ITextModel,\n position: monacoTypes.Position\n ): monacoTypes.languages.ProviderResult => {\n const word = model.getWordAtPosition(position);\n const wordUntil = model.getWordUntilPosition(position);\n\n // documentation says `position` will be \"adjusted\" in `getOffsetAt`\n // i don't know what that means, to be sure i clone it\n const positionClone = {\n column: position.column,\n lineNumber: position.lineNumber,\n };\n const offset = model.getOffsetAt(positionClone);\n const situation = getSituation(model.getValue(), offset);\n const range = calculateRange(situation, word, wordUntil, monaco, position);\n const completionsPromise = situation != null ? getCompletions(situation, dataProvider) : Promise.resolve([]);\n return completionsPromise.then((items) => {\n // monaco by default alphabetically orders the items.\n // to stop it, we use a number-as-string sortkey,\n // so that monaco keeps the order we use\n const maxIndexDigits = items.length.toString().length;\n const suggestions: monacoTypes.languages.CompletionItem[] = items.map((item, index) => ({\n kind: getMonacoCompletionItemKind(item.type, monaco),\n label: item.label,\n insertText: item.insertText,\n insertTextRules: item.isSnippet ? INSERT_AS_SNIPPET_ENUM_VALUE : undefined,\n detail: item.detail,\n documentation: item.documentation,\n sortText: index.toString().padStart(maxIndexDigits, '0'), // to force the order we have\n range: range,\n command: item.triggerOnInsert\n ? {\n id: 'editor.action.triggerSuggest',\n title: '',\n }\n : undefined,\n }));\n return { suggestions };\n });\n };\n\n return {\n triggerCharacters: ['{', ',', '[', '(', '=', '~', ' ', '\"', '|'],\n provideCompletionItems,\n };\n}\n\nexport const calculateRange = (\n situation: Situation | null,\n word: monacoTypes.editor.IWordAtPosition | null,\n wordUntil: monacoTypes.editor.IWordAtPosition,\n monaco: Monaco,\n position: monacoTypes.Position\n): monacoTypes.Range => {\n if (\n situation &&\n situation?.type === 'IN_LABEL_SELECTOR_WITH_LABEL_NAME' &&\n 'betweenQuotes' in situation &&\n situation.betweenQuotes\n ) {\n // Word until won't have second quote if they are between quotes\n const indexOfFirstQuote = wordUntil?.word?.indexOf('\"') ?? 0;\n\n const indexOfLastQuote = word?.word?.lastIndexOf('\"') ?? 0;\n\n const indexOfEquals = word?.word.indexOf('=');\n const indexOfLastEquals = word?.word.lastIndexOf('=');\n\n // Just one equals \"=\" the cursor is somewhere within a label value\n // e.g. value=\"labe^l-value\" or value=\"^label-value\" etc\n // We want the word to include everything within the quotes, so the result from autocomplete overwrites the existing label value\n if (\n indexOfLastEquals === indexOfEquals &&\n indexOfFirstQuote !== -1 &&\n indexOfLastQuote !== -1 &&\n indexOfLastEquals !== -1\n ) {\n return word != null\n ? monaco.Range.lift({\n startLineNumber: position.lineNumber,\n endLineNumber: position.lineNumber,\n startColumn: wordUntil.startColumn + indexOfFirstQuote + 1,\n endColumn: wordUntil.startColumn + indexOfLastQuote,\n })\n : monaco.Range.fromPositions(position);\n }\n }\n\n if (situation && situation.type === 'IN_LABEL_SELECTOR_WITH_LABEL_NAME') {\n // Otherwise we want the range to be calculated as the cursor position, as we want to insert the autocomplete, instead of overwriting existing text\n // The cursor position is the length of the wordUntil\n return word != null\n ? monaco.Range.lift({\n startLineNumber: position.lineNumber,\n endLineNumber: position.lineNumber,\n startColumn: wordUntil.endColumn,\n endColumn: wordUntil.endColumn,\n })\n : monaco.Range.fromPositions(position);\n }\n\n // And for all other non-label cases, we want to use the word start and end column\n return word != null\n ? monaco.Range.lift({\n startLineNumber: position.lineNumber,\n endLineNumber: position.lineNumber,\n startColumn: word.startColumn,\n endColumn: word.endColumn,\n })\n : monaco.Range.fromPositions(position);\n};\n","import { chain } from 'lodash';\n\nimport { HistoryItem } from '@grafana/data';\n\nimport { LokiQuery, ParserAndLabelKeysResult, LanguageProvider } from '../../types';\n\nexport function escapeLabelValueInExactSelector(labelValue: string): string {\n return labelValue.replace(/\\\\/g, '\\\\\\\\').replace(/\\n/g, '\\\\n').replace(/\"/g, '\\\\\"');\n}\n\nimport { Label } from './situation';\n\ninterface HistoryRef {\n current: Array>;\n}\n\nexport class CompletionDataProvider {\n constructor(\n private languageProvider: LanguageProvider,\n private historyRef: HistoryRef = { current: [] }\n ) {\n this.queryToLabelKeysCache = new Map();\n }\n private queryToLabelKeysCache: Map;\n\n private buildSelector(labels: Label[]): string {\n const allLabelTexts = labels.map(\n (label) => `${label.name}${label.op}\"${escapeLabelValueInExactSelector(label.value)}\"`\n );\n\n return `{${allLabelTexts.join(',')}}`;\n }\n\n getHistory() {\n return chain(this.historyRef.current)\n .map((history: HistoryItem) => history.query.expr)\n .filter()\n .uniq()\n .value();\n }\n\n async getLabelNames(otherLabels: Label[] = []) {\n if (otherLabels.length === 0) {\n // if there is no filtering, we have to use a special endpoint\n return this.languageProvider.getLabelKeys();\n }\n const data = await this.getSeriesLabels(otherLabels);\n const possibleLabelNames = Object.keys(data); // all names from datasource\n const usedLabelNames = new Set(otherLabels.map((l) => l.name)); // names used in the query\n return possibleLabelNames.filter((label) => !usedLabelNames.has(label));\n }\n\n async getLabelValues(labelName: string, otherLabels: Label[]) {\n if (otherLabels.length === 0) {\n // if there is no filtering, we have to use a special endpoint\n return await this.languageProvider.fetchLabelValues(labelName);\n }\n\n const data = await this.getSeriesLabels(otherLabels);\n return data[labelName] ?? [];\n }\n\n /**\n * Runs a Loki query to extract label keys from the result.\n * The result is cached for the query string.\n *\n * Since various \"situations\" in the monaco code editor trigger this function, it is prone to being called multiple times for the same query\n * Here is a lightweight and simple cache to avoid calling the backend multiple times for the same query.\n *\n * @param logQuery\n */\n async getParserAndLabelKeys(logQuery: string): Promise {\n const EXTRACTED_LABEL_KEYS_MAX_CACHE_SIZE = 2;\n const cachedLabelKeys = this.queryToLabelKeysCache.has(logQuery) ? this.queryToLabelKeysCache.get(logQuery) : null;\n if (cachedLabelKeys) {\n // cache hit! Serve stale result from cache\n return cachedLabelKeys;\n } else {\n // If cache is larger than max size, delete the first (oldest) index\n if (this.queryToLabelKeysCache.size >= EXTRACTED_LABEL_KEYS_MAX_CACHE_SIZE) {\n // Make room in the cache for the fresh result by deleting the \"first\" index\n const keys = this.queryToLabelKeysCache.keys();\n const firstKey = keys.next().value;\n this.queryToLabelKeysCache.delete(firstKey);\n }\n // Fetch a fresh result from the backend\n const labelKeys = await this.languageProvider.getParserAndLabelKeys(logQuery);\n // Add the result to the cache\n this.queryToLabelKeysCache.set(logQuery, labelKeys);\n return labelKeys;\n }\n }\n\n async getSeriesLabels(labels: Label[]) {\n return await this.languageProvider.fetchSeriesLabels(this.buildSelector(labels)).then((data: any) => data ?? {});\n }\n}\n","import { SyntaxNode } from '@lezer/common';\nimport { LRParser } from '@lezer/lr';\n\n// import { ErrorId } from 'app/plugins/datasource/prometheus/querybuilder/shared/parsingUtils';\nconst ErrorId = 0;\n\ninterface ParserErrorBoundary {\n startLineNumber: number;\n startColumn: number;\n endLineNumber: number;\n endColumn: number;\n error: string;\n}\n\ninterface ParseError {\n text: string;\n node: SyntaxNode;\n}\n\n/**\n * Conceived to work in combination with the MonacoQueryField component.\n * Given an original query, and it's interpolated version, it will return an array of ParserErrorBoundary\n * objects containing nodes which are actual errors. The interpolated version (even with placeholder variables)\n * is required because variables look like errors for Lezer.\n * @internal\n */\nexport function validateQuery(\n query: string,\n interpolatedQuery: string,\n queryLines: string[],\n parser: LRParser\n): ParserErrorBoundary[] | false {\n if (!query) {\n return false;\n }\n\n /**\n * To provide support to variable interpolation in query validation, we run the parser in the interpolated\n * query. If there are errors there, we trace them back to the original unparsed query, so we can more\n * accurately highlight the error in the query, since it's likely that the variable name and variable value\n * have different lengths. With this, we also exclude irrelevant parser errors that are produced by\n * lezer not understanding $variables and $__variables, which usually generate 2 or 3 error SyntaxNode.\n */\n const interpolatedErrors: ParseError[] = parseQuery(interpolatedQuery, parser);\n if (!interpolatedErrors.length) {\n return false;\n }\n\n let parseErrors: ParseError[] = interpolatedErrors;\n if (query !== interpolatedQuery) {\n const queryErrors: ParseError[] = parseQuery(query, parser);\n parseErrors = interpolatedErrors.flatMap(\n (interpolatedError) =>\n queryErrors.filter((queryError) => interpolatedError.text === queryError.text) || interpolatedError\n );\n }\n\n return parseErrors.map((parseError) => findErrorBoundary(query, queryLines, parseError)).filter(isErrorBoundary);\n}\n\nfunction parseQuery(query: string, parser: LRParser) {\n const parseErrors: ParseError[] = [];\n const tree = parser.parse(query);\n tree.iterate({\n enter: (nodeRef): false | void => {\n if (nodeRef.type.id === ErrorId) {\n const node = nodeRef.node;\n parseErrors.push({\n node: node,\n text: query.substring(node.from, node.to),\n });\n }\n },\n });\n return parseErrors;\n}\n\nfunction findErrorBoundary(query: string, queryLines: string[], parseError: ParseError): ParserErrorBoundary | null {\n if (queryLines.length === 1) {\n const isEmptyString = parseError.node.from === parseError.node.to;\n const errorNode = isEmptyString && parseError.node.parent ? parseError.node.parent : parseError.node;\n const error = isEmptyString ? query.substring(errorNode.from, errorNode.to) : parseError.text;\n return {\n startLineNumber: 1,\n startColumn: errorNode.from + 1,\n endLineNumber: 1,\n endColumn: errorNode.to + 1,\n error,\n };\n }\n\n let startPos = 0,\n endPos = 0;\n for (let line = 0; line < queryLines.length; line++) {\n endPos = startPos + queryLines[line].length;\n\n if (parseError.node.from > endPos) {\n startPos += queryLines[line].length + 1;\n continue;\n }\n\n return {\n startLineNumber: line + 1,\n startColumn: parseError.node.from - startPos + 1,\n endLineNumber: line + 1,\n endColumn: parseError.node.to - startPos + 1,\n error: parseError.text,\n };\n }\n\n return null;\n}\n\nfunction isErrorBoundary(boundary: ParserErrorBoundary | null): boundary is ParserErrorBoundary {\n return boundary !== null;\n}\n\nexport const placeHolderScopedVars = {\n __interval: { text: '1s', value: '1s' },\n __rate_interval: { text: '1s', value: '1s' },\n __auto: { text: '1s', value: '1s' },\n __interval_ms: { text: '1000', value: 1000 },\n __range_ms: { text: '1000', value: 1000 },\n __range_s: { text: '1', value: 1 },\n __range: { text: '1s', value: '1s' },\n};\n","import { css } from '@emotion/css';\nimport { debounce } from 'lodash';\nimport React, { useRef, useEffect } from 'react';\nimport { useLatest } from 'react-use';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { GrafanaTheme2 } from '@grafana/data';\nimport { selectors } from '@grafana/e2e-selectors';\nimport { parser } from '@grafana/lezer-logql';\nimport { languageConfiguration, monarchlanguage } from '@grafana/monaco-logql';\nimport { useTheme2, ReactMonacoEditor, Monaco, monacoTypes, MonacoEditor } from '@grafana/ui';\n\nimport { Props } from './MonacoQueryFieldProps';\nimport { getOverrideServices } from './getOverrideServices';\nimport { getCompletionProvider, getSuggestOptions } from './monaco-completion-provider';\nimport { CompletionDataProvider } from './monaco-completion-provider/CompletionDataProvider';\nimport { placeHolderScopedVars, validateQuery } from './monaco-completion-provider/validation';\n\nconst options: monacoTypes.editor.IStandaloneEditorConstructionOptions = {\n codeLens: false,\n contextmenu: false,\n // we need `fixedOverflowWidgets` because otherwise in grafana-dashboards\n // the popup is clipped by the panel-visualizations.\n fixedOverflowWidgets: true,\n folding: false,\n fontSize: 14,\n lineDecorationsWidth: 8, // used as \"padding-left\"\n lineNumbers: 'off',\n minimap: { enabled: false },\n overviewRulerBorder: false,\n overviewRulerLanes: 0,\n padding: {\n // these numbers were picked so that visually this matches the previous version\n // of the query-editor the best\n top: 4,\n bottom: 5,\n },\n renderLineHighlight: 'none',\n scrollbar: {\n vertical: 'hidden',\n verticalScrollbarSize: 8, // used as \"padding-right\"\n horizontal: 'hidden',\n horizontalScrollbarSize: 0,\n alwaysConsumeMouseWheel: false,\n },\n scrollBeyondLastLine: false,\n suggest: getSuggestOptions(),\n suggestFontSize: 12,\n wordWrap: 'on',\n};\n\n// this number was chosen by testing various values. it might be necessary\n// because of the width of the border, not sure.\n//it needs to do 2 things:\n// 1. when the editor is single-line, it should make the editor height be visually correct\n// 2. when the editor is multi-line, the editor should not be \"scrollable\" (meaning,\n// you do a scroll-movement in the editor, and it will scroll the content by a couple pixels\n// up & down. this we want to avoid)\nconst EDITOR_HEIGHT_OFFSET = 2;\n\nconst LANG_ID = 'logql';\n\n// we must only run the lang-setup code once\nlet LANGUAGE_SETUP_STARTED = false;\n\nexport const defaultWordPattern = /(-?\\d*\\.\\d\\w*)|([^`~!#%^&*()\\-=+\\[{\\]}\\\\|;:'\",.<>\\/?\\s]+)/g;\n\nfunction ensureLogQL(monaco: Monaco) {\n if (LANGUAGE_SETUP_STARTED === false) {\n LANGUAGE_SETUP_STARTED = true;\n monaco.languages.register({ id: LANG_ID });\n\n monaco.languages.setMonarchTokensProvider(LANG_ID, monarchlanguage);\n monaco.languages.setLanguageConfiguration(LANG_ID, {\n ...languageConfiguration,\n wordPattern: /(-?\\d*\\.\\d\\w*)|([^`~!#%^&*()+\\[{\\]}\\\\|;:',.<>\\/?\\s]+)/g,\n // Default: /(-?\\d*\\.\\d\\w*)|([^`~!#%^&*()\\-=+\\[{\\]}\\\\|;:'\",.<>\\/?\\s]+)/g\n // Removed `\"`, `=`, and `-`, from the exclusion list, so now the completion provider can decide to overwrite any matching words, or just insert text at the cursor\n });\n }\n}\n\nconst getStyles = (theme: GrafanaTheme2, placeholder: string) => {\n return {\n container: css`\n border-radius: ${theme.shape.radius.default};\n border: 1px solid ${theme.components.input.borderColor};\n width: 100%;\n .monaco-editor .suggest-widget {\n min-width: 50%;\n }\n `,\n placeholder: css`\n ::after {\n content: '${placeholder}';\n font-family: ${theme.typography.fontFamilyMonospace};\n opacity: 0.3;\n }\n `,\n };\n};\n\nconst MonacoQueryField = ({ history, onBlur, onRunQuery, initialValue, datasource, placeholder, onChange }: Props) => {\n const id = uuidv4();\n // we need only one instance of `overrideServices` during the lifetime of the react component\n const overrideServicesRef = useRef(getOverrideServices());\n const containerRef = useRef(null);\n\n const langProviderRef = useLatest(datasource.languageProvider);\n const historyRef = useLatest(history);\n const onRunQueryRef = useLatest(onRunQuery);\n const onBlurRef = useLatest(onBlur);\n\n const autocompleteCleanupCallback = useRef<(() => void) | null>(null);\n\n const theme = useTheme2();\n const styles = getStyles(theme, placeholder);\n\n useEffect(() => {\n // when we unmount, we unregister the autocomplete-function, if it was registered\n return () => {\n autocompleteCleanupCallback.current?.();\n };\n }, []);\n\n const setPlaceholder = (monaco: Monaco, editor: MonacoEditor) => {\n const placeholderDecorators = [\n {\n range: new monaco.Range(1, 1, 1, 1),\n options: {\n className: styles.placeholder,\n isWholeLine: true,\n },\n },\n ];\n\n let decorators: string[] = [];\n\n const checkDecorators: () => void = () => {\n const model = editor.getModel();\n\n if (!model) {\n return;\n }\n\n const newDecorators = model.getValueLength() === 0 ? placeholderDecorators : [];\n decorators = model.deltaDecorations(decorators, newDecorators);\n };\n\n checkDecorators();\n editor.onDidChangeModelContent(checkDecorators);\n };\n\n const onTypeDebounced = debounce(async (query: string) => {\n onChange(query);\n }, 1000);\n\n return (\n \n {\n ensureLogQL(monaco);\n }}\n onMount={(editor, monaco) => {\n // Monaco has a bug where it runs actions on all instances (https://github.com/microsoft/monaco-editor/issues/2947), so we ensure actions are executed on instance-level with this ContextKey.\n const isEditorFocused = editor.createContextKey('isEditorFocused' + id, false);\n // we setup on-blur\n editor.onDidBlurEditorWidget(() => {\n isEditorFocused.set(false);\n onBlurRef.current(editor.getValue());\n });\n editor.onDidChangeModelContent((e) => {\n const model = editor.getModel();\n if (!model) {\n return;\n }\n const query = model.getValue();\n const errors =\n validateQuery(\n query,\n datasource.interpolateString(query, placeHolderScopedVars),\n model.getLinesContent(),\n parser\n ) || [];\n\n const markers = errors.map(({ error, ...boundary }: any) => ({\n message: `${\n error ? `Error parsing \"${error}\"` : 'Parse error'\n }. The query appears to be incorrect and could fail to be executed.`,\n severity: monaco.MarkerSeverity.Error,\n ...boundary,\n }));\n\n onTypeDebounced(query);\n monaco.editor.setModelMarkers(model, 'owner', markers);\n });\n const dataProvider = new CompletionDataProvider(langProviderRef.current, historyRef);\n const completionProvider = getCompletionProvider(monaco, dataProvider);\n\n // completion-providers in monaco are not registered directly to editor-instances,\n // they are registered to languages. this makes it hard for us to have\n // separate completion-providers for every query-field-instance\n // (but we need that, because they might connect to different datasources).\n // the trick we do is, we wrap the callback in a \"proxy\",\n // and in the proxy, the first thing is, we check if we are called from\n // \"our editor instance\", and if not, we just return nothing. if yes,\n // we call the completion-provider.\n const filteringCompletionProvider: monacoTypes.languages.CompletionItemProvider = {\n ...completionProvider,\n provideCompletionItems: (model, position, context, token) => {\n // if the model-id does not match, then this call is from a different editor-instance,\n // not \"our instance\", so return nothing\n if (editor.getModel()?.id !== model.id) {\n return { suggestions: [] };\n }\n return completionProvider.provideCompletionItems(model, position, context, token);\n },\n };\n\n const { dispose } = monaco.languages.registerCompletionItemProvider(LANG_ID, filteringCompletionProvider);\n\n autocompleteCleanupCallback.current = dispose;\n // this code makes the editor resize itself so that the content fits\n // (it will grow taller when necessary)\n // FIXME: maybe move this functionality into CodeEditor, like:\n // \n const handleResize = () => {\n const containerDiv = containerRef.current;\n if (containerDiv !== null) {\n const pixelHeight = editor.getContentHeight();\n containerDiv.style.height = `${pixelHeight + EDITOR_HEIGHT_OFFSET}px`;\n const pixelWidth = containerDiv.clientWidth;\n editor.layout({ width: pixelWidth, height: pixelHeight });\n }\n };\n\n editor.onDidContentSizeChange(handleResize);\n handleResize();\n // handle: shift + enter\n // FIXME: maybe move this functionality into CodeEditor?\n editor.addCommand(\n monaco.KeyMod.Shift | monaco.KeyCode.Enter,\n () => {\n onRunQueryRef.current(editor.getValue());\n },\n 'isEditorFocused' + id\n );\n\n editor.onDidFocusEditorText(() => {\n isEditorFocused.set(true);\n if (editor.getValue().trim() === '') {\n editor.trigger('', 'editor.action.triggerSuggest', {});\n }\n });\n\n setPlaceholder(monaco, editor);\n }}\n />\n \n );\n};\n\n// Default export for lazy load.\nexport default MonacoQueryField;\n","import { useRef } from 'react';\nvar useLatest = function (value) {\n var ref = useRef(value);\n ref.current = value;\n return ref;\n};\nexport default useLatest;\n"],"names":["exports","aggregations","parsers","format_expressions","vector_aggregations","vector_matching","vectorMatchingRegex","prev","curr","operators","keywords","makeStorageService","strings","data","key","scope","fallbackValue","val","value","target","reason","overrideServices","getOverrideServices","CompletionDataProvider","languageProvider","historyRef","timeRange","labels","label","history","otherLabels","possibleLabelNames","usedLabelNames","l","labelName","logQuery","cachedLabelKeys","firstKey","labelKeys","NeverCaseError","LOG_COMPLETIONS","AGGREGATION_COMPLETIONS","f","FUNCTION_COMPLETIONS","BUILT_IN_FUNCTIONS_COMPLETIONS","DURATION_COMPLETIONS","text","UNWRAP_FUNCTION_COMPLETIONS","LOGFMT_ARGUMENT_COMPLETIONS","LINE_FILTER_COMPLETIONS","getLineFilterCompletions","afterPipe","completion","operator","documentation","getPipeOperationsCompletions","prefix","completions","getAllHistoryCompletions","dataProvider","expr","getLabelNamesForSelectorCompletions","getInGroupingCompletions","extractedLabelKeys","PARSERS","getParserCompletions","hasJSON","hasLogfmt","hasPack","hasParserInQuery","allParsers","hasLevelInExtractedLabels","extra","parser","getAfterSelectorCompletions","hasSpace","query","structuredMetadataKeys","hasQueryParser","parserCompletions","pipeOperations","getLogfmtCompletions","flags","trailingComma","trailingSpace","labelPrefix","labelCompletions","getLabelValuesForMetricCompletions","betweenQuotes","getAfterUnwrapCompletions","unwrapLabelKeys","getAfterKeepAndDropCompletions","getCompletions","situation","move","node","direction","traverse","path","next","walk","nextTmp","current","expectedNode","getNodeText","parseStringLiteral","inside","isPathMatch","resolverPath","cursorPath","item","index","ERROR_NODE_ID","RESOLVERS","resolveSelector","resolveLogfmtParser","resolveTopLevel","resolveMatcher","resolveLabelsForGrouping","resolveLogRange","resolveDurations","resolveLogRangeFromError","resolvePipeError","resolveAfterUnwrap","resolveAfterKeepAndDrop","LABEL_OP_MAP","getLabelOp","opNode","getLabel","matcherNode","nameNode","op","valueNode","name","getLabels","selectorNode","listNode","pos","exprNode","resolveLogOrLogRange","aggrExpNode","bodyNode","inStringNode","parent","labelNameNode","firstListNode","_","cursorPosition","tree","trimRightTextLen","position","cursor","expectedNodes","inLogfmt","logExprNode","child","keepAndDropParent","resolveCursor","cursorPos","getSituation","currentNode","ids","resolver","INSERT_AS_SNIPPET_ENUM_VALUE","getSuggestOptions","getMonacoCompletionItemKind","type","monaco","getCompletionProvider","model","word","wordUntil","positionClone","offset","range","calculateRange","items","maxIndexDigits","indexOfFirstQuote","indexOfLastQuote","indexOfEquals","indexOfLastEquals","options","EDITOR_HEIGHT_OFFSET","LANG_ID","LANGUAGE_SETUP_STARTED","defaultWordPattern","ensureLogQL","getStyles","theme","placeholder","onBlur","onRunQuery","initialValue","datasource","onChange","id","overrideServicesRef","containerRef","langProviderRef","useLatest","onRunQueryRef","onBlurRef","autocompleteCleanupCallback","styles","setPlaceholder","editor","placeholderDecorators","decorators","checkDecorators","newDecorators","onTypeDebounced","selectors","isEditorFocused","e","markers","error","boundary","completionProvider","filteringCompletionProvider","context","token","dispose","handleResize","containerDiv","pixelHeight","pixelWidth","escapeLabelValueInExactSelector","labelValue","ErrorId","validateQuery","interpolatedQuery","queryLines","interpolatedErrors","parseQuery","parseErrors","queryErrors","interpolatedError","queryError","parseError","findErrorBoundary","isErrorBoundary","nodeRef","isEmptyString","errorNode","startPos","endPos","line","placeHolderScopedVars","ref"],"sourceRoot":""}