sql_lsp/
dialect.rs

1use crate::schema::Schema;
2use async_trait::async_trait;
3use tower_lsp::lsp_types::{CompletionItem, Diagnostic, Hover, Location, Position};
4
5/// SQL 方言抽象 trait
6/// 所有 SQL 方言都需要实现这个 trait
7#[async_trait]
8pub trait Dialect: Send + Sync {
9    /// 方言名称
10    fn name(&self) -> &str;
11
12    /// 解析 SQL 并返回诊断信息
13    async fn parse(&self, sql: &str, schema: Option<&Schema>) -> Vec<Diagnostic>;
14
15    /// 获取代码补全
16    async fn completion(
17        &self,
18        sql: &str,
19        position: Position,
20        schema: Option<&Schema>,
21    ) -> Vec<CompletionItem>;
22
23    /// 获取悬停信息
24    async fn hover(&self, sql: &str, position: Position, schema: Option<&Schema>) -> Option<Hover>;
25
26    /// 跳转到定义
27    async fn goto_definition(
28        &self,
29        sql: &str,
30        position: Position,
31        schema: Option<&Schema>,
32    ) -> Option<Location>;
33
34    /// 查找引用
35    async fn references(
36        &self,
37        sql: &str,
38        position: Position,
39        schema: Option<&Schema>,
40    ) -> Vec<Location>;
41
42    /// 格式化 SQL
43    async fn format(&self, sql: &str) -> String;
44
45    /// 验证 SQL 语法
46    async fn validate(&self, sql: &str, schema: Option<&Schema>) -> Vec<Diagnostic>;
47}