Skip to main content

RouteNavigator

Struct RouteNavigator 

Source
pub struct RouteNavigator {
    pub index: RouteIndex,
}
Expand description

路由导航器

负责识别、索引和导航项目中的所有路由

Fields§

§index: RouteIndex

路由索引

Implementations§

Source§

impl RouteNavigator

Source

pub fn new() -> Self

创建新的路由导航器

Source

pub fn build_index(&mut self, documents: &[RustDocument])

构建路由索引

从 Rust 文档列表中提取所有路由信息,构建路由索引

§Arguments
  • documents - Rust 文档列表,包含已解析的宏信息
§Requirements
  • 8.1: 识别所有路由宏标注的函数
  • 8.2: 解析路径参数
  • 8.3: 处理多方法路由
  • 8.4: 解析路由前缀
Source

pub fn find_routes(&self, pattern: &str) -> Vec<&RouteInfo>

查找路由

支持模糊匹配和正则表达式搜索路由

§Arguments
  • pattern - 搜索模式,可以是:
    • 普通字符串:进行模糊匹配(路径包含该字符串)
    • 正则表达式:以 “regex:” 开头,如 “regex:^/api/.*”
§Returns

返回匹配的路由信息列表

§Requirements
  • 9.4: 支持模糊匹配和正则表达式搜索
§Examples
use spring_lsp::route::RouteNavigator;

let navigator = RouteNavigator::new();
// 模糊匹配
let routes = navigator.find_routes("users");
// 正则表达式匹配
let routes = navigator.find_routes("regex:^/api/v[0-9]+/.*");
Source

pub fn get_all_routes(&self) -> &[RouteInfo]

获取所有路由

返回项目中所有已识别的路由

§Returns

返回所有路由信息的引用

§Requirements
  • 9.1: 返回项目中所有路由的列表
§Examples
use spring_lsp::route::RouteNavigator;

let navigator = RouteNavigator::new();
let all_routes = navigator.get_all_routes();
println!("Total routes: {}", all_routes.len());
Source

pub fn find_routes_by_handler(&self, handler_name: &str) -> Vec<&RouteInfo>

根据处理器函数名查找路由

实现处理器路由反查功能,根据处理器函数名查找对应的所有路由

§Arguments
  • handler_name - 处理器函数名称
§Returns

返回该处理器对应的所有路由信息

§Requirements
  • 9.3: 实现处理器路由反查
§Examples
use spring_lsp::route::RouteNavigator;

let navigator = RouteNavigator::new();
let routes = navigator.find_routes_by_handler("get_user");
for route in routes {
    println!("Handler 'get_user' handles: {:?} {}", route.methods[0], route.path);
}
Source

pub fn validate_routes(&self) -> Vec<Diagnostic>

验证路由

验证所有路由的正确性,包括:

  • 路径字符验证
  • 路径参数语法验证
  • 路径参数类型匹配验证
  • RESTful 风格检查
§Returns

返回诊断信息列表

§Requirements
  • 10.1: 路径字符验证
  • 10.2: 路径参数语法验证
  • 10.3: 路径参数类型匹配验证
  • 10.5: RESTful 风格检查
§Examples
use spring_lsp::route::RouteNavigator;

let navigator = RouteNavigator::new();
let diagnostics = navigator.validate_routes();
for diagnostic in diagnostics {
    println!("Validation error: {}", diagnostic.message);
}
Source

pub fn detect_conflicts(&self) -> Vec<RouteConflict>

检测路由冲突

检测具有相同路径和 HTTP 方法的路由冲突

§Returns

返回路由冲突列表

§Requirements
  • 9.5: 检测路由冲突
  • 10.4: 路由路径冲突检测
§Examples
use spring_lsp::route::RouteNavigator;

let navigator = RouteNavigator::new();
let conflicts = navigator.detect_conflicts();
for conflict in conflicts {
    println!("Route conflict detected between routes {} and {}",
             conflict.index1, conflict.index2);
}

Trait Implementations§

Source§

impl Clone for RouteNavigator

Source§

fn clone(&self) -> RouteNavigator

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RouteNavigator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RouteNavigator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more