@dash0hq/codemirror-promql
Version:
a CodeMirror mode for the PromQL language
61 lines (60 loc) • 2.45 kB
TypeScript
import { CompleteStrategy } from './index';
import { SyntaxNode } from '@lezer/common';
import { PrometheusClient } from '../client';
import { CompletionContext, CompletionResult } from '@codemirror/autocomplete';
import { EditorState } from '@codemirror/state';
import { Matcher } from '../types';
export declare const METRIC_NAME_LABELS: readonly string[];
export interface MetricNameResult {
metricName: string;
definingMatchers: Matcher | null;
}
export declare enum ContextKind {
MetricName = 0,
LabelName = 1,
LabelValue = 2,
Function = 3,
Aggregation = 4,
BinOpModifier = 5,
BinOp = 6,
MatchOp = 7,
AggregateOpModifier = 8,
Duration = 9,
Offset = 10,
Bool = 11,
AtModifiers = 12,
Number = 13
}
export interface Context {
kind: ContextKind;
metricName?: string;
labelName?: string;
matchers?: Matcher[];
}
export declare function getMetricNameInVectorSelector(tree: SyntaxNode, state: EditorState): MetricNameResult;
/**
* Attempts to extract the metric name from a label matcher block such as:
* `{__name__="http_requests_total"}`.
*
* This is a fallback strategy when the metric name is not provided as an identifier
* but instead is stored as a label matcher using one of the metric-defining labels
* (e.g., `__name__` or custom labels defined in `METRIC_NAME_LABELS`)
*
* It only considers exact match expressions like `__name__="metric"` and ignores
* regex matches (`=~`, `!~`) or inequality operators (`!=`, `<`, etc).
*
* Useful when autocompleting or analyzing metric selectors in PromQL syntax trees.
*/
export declare function findMetricNameInLabelMatchers(labelMatchers: SyntaxNode | null, state: EditorState): MetricNameResult;
export declare function computeStartCompletePosition(state: EditorState, node: SyntaxNode, pos: number): number;
export declare function analyzeCompletion(state: EditorState, node: SyntaxNode, pos: number): Context[];
export declare class HybridComplete implements CompleteStrategy {
private readonly prometheusClient;
private readonly maxMetricsMetadata;
constructor(prometheusClient?: PrometheusClient, maxMetricsMetadata?: number);
getPrometheusClient(): PrometheusClient | undefined;
promQL(context: CompletionContext): Promise<CompletionResult | null> | CompletionResult | null;
private autocompleteMetricName;
private autocompleteLabelName;
private autocompleteLabelValue;
}