kql_language_tools/
classification.rs1use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
12#[serde(rename_all = "PascalCase")]
13pub enum ClassificationKind {
14 PlainText,
16 Comment,
18 Punctuation,
20 Directive,
22 Literal,
24 StringLiteral,
26 Type,
28 Identifier,
30 Column,
32 Table,
34 Database,
36 ScalarFunction,
38 AggregateFunction,
40 Keyword,
42 Operator,
44 Variable,
46 Parameter,
48 CommandKeyword,
50 QueryOperator,
52 ScalarOperator,
54 MaterializedViewFunction,
56 Plugin,
58 Option,
60 ClientDirective,
62 QueryParameter,
64 Cluster,
66}
67
68impl ClassificationKind {
69 #[allow(dead_code)]
71 #[must_use]
72 pub fn parse(s: &str) -> Self {
73 match s {
74 "Comment" => Self::Comment,
75 "Punctuation" => Self::Punctuation,
76 "Directive" => Self::Directive,
77 "Literal" => Self::Literal,
78 "StringLiteral" => Self::StringLiteral,
79 "Type" => Self::Type,
80 "Identifier" => Self::Identifier,
81 "Column" => Self::Column,
82 "Table" => Self::Table,
83 "Database" => Self::Database,
84 "ScalarFunction" => Self::ScalarFunction,
85 "AggregateFunction" => Self::AggregateFunction,
86 "Keyword" => Self::Keyword,
87 "Operator" => Self::Operator,
88 "Variable" => Self::Variable,
89 "Parameter" => Self::Parameter,
90 "CommandKeyword" => Self::CommandKeyword,
91 "QueryOperator" => Self::QueryOperator,
92 "ScalarOperator" => Self::ScalarOperator,
93 "MaterializedViewFunction" => Self::MaterializedViewFunction,
94 "Plugin" => Self::Plugin,
95 "Option" => Self::Option,
96 "ClientDirective" => Self::ClientDirective,
97 "QueryParameter" => Self::QueryParameter,
98 "Cluster" => Self::Cluster,
99 _ => Self::PlainText,
101 }
102 }
103}
104
105#[derive(Debug, Clone, Serialize, Deserialize)]
107pub struct ClassifiedSpan {
108 pub start: usize,
110 pub length: usize,
112 pub kind: ClassificationKind,
114}
115
116#[derive(Debug, Clone, Default, Serialize, Deserialize)]
118pub struct ClassificationResult {
119 pub spans: Vec<ClassifiedSpan>,
121}