pub struct SqlParser { /* private fields */ }Expand description
SQL 解析器(基于 Tree-sitter)
Implementations§
Source§impl SqlParser
impl SqlParser
Sourcepub fn parse(&mut self, sql: &str) -> ParseResult
pub fn parse(&mut self, sql: &str) -> ParseResult
解析 SQL 语句
Sourcepub fn tokenize(&self, tree: &Tree, source: &str) -> Vec<Token>
pub fn tokenize(&self, tree: &Tree, source: &str) -> Vec<Token>
提取所有 Token(参考 sqls 的 tokenizer)
Sourcepub fn get_node_at_position<'a>(
&self,
tree: &'a Tree,
position: Position,
) -> Option<Node<'a>>
pub fn get_node_at_position<'a>( &self, tree: &'a Tree, position: Position, ) -> Option<Node<'a>>
获取指定位置的节点
Sourcepub fn is_in_from_context(&self, node: Node<'_>, source: &str) -> bool
pub fn is_in_from_context(&self, node: Node<'_>, source: &str) -> bool
检查节点是否在 FROM/JOIN 上下文中
Sourcepub fn is_in_column_context(&self, node: Node<'_>, source: &str) -> bool
pub fn is_in_column_context(&self, node: Node<'_>, source: &str) -> bool
检查节点是否在列上下文中(SELECT/WHERE/ORDER BY 等)
Sourcepub fn node_range(&self, node: Node<'_>) -> Range
pub fn node_range(&self, node: Node<'_>) -> Range
获取节点的范围
Sourcepub fn analyze_completion_context(
&self,
node: Node<'_>,
source: &str,
_position: Position,
) -> CompletionContext
pub fn analyze_completion_context( &self, node: Node<'_>, source: &str, _position: Position, ) -> CompletionContext
分析补全上下文 (Text-based heuristics for reliability) 分析补全上下文 (AST-based) Uses Tree-sitter AST node traversal for robust context detection
Source§impl SqlParser
impl SqlParser
Sourcepub fn extract_aliases(
&self,
_tree: &Tree,
source: &str,
) -> HashMap<String, String>
pub fn extract_aliases( &self, _tree: &Tree, source: &str, ) -> HashMap<String, String>
提取表别名映射 (Alias -> Table Name) Uses text-based extraction for reliability
Sourcepub fn extract_referenced_tables(
&self,
_tree: &Tree,
source: &str,
) -> Vec<String>
pub fn extract_referenced_tables( &self, _tree: &Tree, source: &str, ) -> Vec<String>
提取SQL中引用的表名(从FROM和JOIN子句)
Sourcepub fn node_to_ast_node(&self, node: Node<'_>, source: &str) -> AstNode
pub fn node_to_ast_node(&self, node: Node<'_>, source: &str) -> AstNode
将 Tree-sitter Node 转换为 AstNode
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SqlParser
impl RefUnwindSafe for SqlParser
impl Send for SqlParser
impl Sync for SqlParser
impl Unpin for SqlParser
impl UnwindSafe for SqlParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more