Skip to main content

LexHandler

Trait LexHandler 

Source
pub trait LexHandler: Send + Sync {
    // Provided methods
    fn on_label(&self, _ctx: &LabelCtx) { ... }
    fn on_validate(
        &self,
        _ctx: &LabelCtx,
    ) -> Result<Vec<Diagnostic>, HandlerError> { ... }
    fn on_resolve(
        &self,
        _ctx: &LabelCtx,
    ) -> Result<Option<WireNode>, HandlerError> { ... }
    fn on_render(
        &self,
        _ctx: &LabelCtx,
        _fmt: Format,
    ) -> Result<Option<RenderOut>, HandlerError> { ... }
    fn on_hover(&self, _ctx: &LabelCtx) -> Result<Option<Hover>, HandlerError> { ... }
    fn on_completion(
        &self,
        _ctx: &LabelCtx,
    ) -> Result<Vec<Completion>, HandlerError> { ... }
    fn on_code_action(
        &self,
        _ctx: &LabelCtx,
    ) -> Result<Vec<CodeAction>, HandlerError> { ... }
}
Expand description

The hook-event interface a Lex extension implements.

Every method has a default implementation that returns the identity (Ok(None), Ok(Vec::new()), ()), so an extension only needs to override the methods it cares about. An empty impl LexHandler for Foo {} is a no-op handler that compiles and runs.

Provided Methods§

Source

fn on_label(&self, _ctx: &LabelCtx)

Informational notification fired during the analyse phase. No response is expected. Use this for handlers that maintain external state (caches, indices, link graphs).

Source

fn on_validate(&self, _ctx: &LabelCtx) -> Result<Vec<Diagnostic>, HandlerError>

Returns diagnostics for a labelled node. Fires during analyse, after resolve.

Source

fn on_resolve(&self, _ctx: &LabelCtx) -> Result<Option<WireNode>, HandlerError>

Returns an AST replacement subtree, which the host splices into the parent in place of the labelled node. Fires during the resolve phase, before analyse. Ok(None) leaves the original node in place.

Source

fn on_render( &self, _ctx: &LabelCtx, _fmt: Format, ) -> Result<Option<RenderOut>, HandlerError>

Returns the labelled node’s representation in a target format. Fires during lexd convert or library-driven rendering. Ok(None) falls back to default rendering of the underlying node.

Source

fn on_hover(&self, _ctx: &LabelCtx) -> Result<Option<Hover>, HandlerError>

Returns hover content for a labelled node. Fires in response to textDocument/hover LSP requests.

Source

fn on_completion( &self, _ctx: &LabelCtx, ) -> Result<Vec<Completion>, HandlerError>

Returns completion items for a position inside a labelled node’s params or body. Fires in response to textDocument/completion.

Source

fn on_code_action( &self, _ctx: &LabelCtx, ) -> Result<Vec<CodeAction>, HandlerError>

Returns code actions for a labelled node. Fires in response to textDocument/codeAction.

Implementors§