Skip to main content

SimpleLanguage

Struct SimpleLanguage 

Source
pub struct SimpleLanguage<C> { /* private fields */ }
Expand description

A Language built from closures — the Rust equivalent of a Lua language definition.

For the common server you never implement the Language trait; describe the language and hand the builder to serve:

use increparse::Engine;
use increparse_lsp::{Document, FailedNode, SimpleLanguage};
use lsp_types::Diagnostic;

let language = SimpleLanguage::new(engine, Ctx::File)
    .diagnostic_fn(|_doc, node| {
        Some(Diagnostic { message: "could not parse".into(), ..Diagnostic::default() })
    })
    .label_fn(|ctx| Some(increparse_lsp::NodeLabel::new("region")));

Implementations§

Source§

impl<C: Clone + PartialEq + Send + 'static> SimpleLanguage<C>

Source

pub fn new(engine: Engine<C>, root_ctx: C) -> Self

Creates a builder over an engine and a root context.

Source

pub fn encoding(self, encoding: PositionEncoding) -> Self

Sets the negotiated position encoding (default UTF-16).

Source

pub fn diagnostic_fn( self, f: impl Fn(&Document<C>, &FailedNode<'_, C>) -> Option<Diagnostic> + Send + Sync + 'static, ) -> Self

How a failing region becomes a diagnostic; None stays silent. Diagnostics returned with an empty range are filled in from the node’s span.

Source

pub fn extra_diagnostics( self, f: impl Fn(&Document<C>) -> Vec<Diagnostic> + Send + Sync + 'static, ) -> Self

Diagnostics that do not come from parse failures — lint-rule violations, style warnings, anything computed from the settled document. Called once per publish, after the parse pass; its output is appended to the parse diagnostics.

Source

pub fn symbols_fn( self, f: impl Fn(&Document<C>) -> Vec<DocumentSymbol> + Send + Sync + 'static, ) -> Self

Full-control outline symbols. Mutually exclusive in spirit with label_fn — when both are set, this wins.

Source

pub fn label_fn( self, f: impl Fn(&C) -> Option<NodeLabel> + Send + Sync + 'static, ) -> Self

Names tree nodes; every named node becomes an outline symbol with the node’s range — symbols without writing a tree walk.

Source

pub fn describe_fn( self, f: impl Fn(&C) -> Option<String> + Send + Sync + 'static, ) -> Self

One-sentence hover: describe a context and the skeleton finds the node under the cursor, builds the hover contents, and attaches the node’s range. The friendliest way to add hover — nothing about the language’s shape is assumed.

Source

pub fn hover_fn( self, f: impl Fn(&Document<C>, usize) -> Option<Hover> + Send + Sync + 'static, ) -> Self

Full-control hover: receives the document and the cursor’s byte offset (position encoding already handled).

Source

pub fn definition_fn( self, f: impl Fn(&Document<C>, usize) -> Option<Vec<Location>> + Send + Sync + 'static, ) -> Self

Go-to-definition: return the locations to jump to.

Source

pub fn completion_fn( self, f: impl Fn(&Document<C>, usize) -> Option<CompletionResponse> + Send + Sync + 'static, ) -> Self

Completions for the cursor position.

Source

pub fn code_action_fn( self, f: impl Fn(&Document<C>, Range) -> Vec<CodeAction> + Send + Sync + 'static, ) -> Self

Code actions for a range — typically quickfixes for the diagnostics published there.

Trait Implementations§

Source§

impl<C: Clone + PartialEq + Send + Sync + 'static> Language<C> for SimpleLanguage<C>

C must additionally be Sync because the stored closures accept &C from any thread.

Source§

fn supports_symbols(&self) -> bool

Runtime hook for symbol support; defaults to SUPPORTS_SYMBOLS.
Source§

fn supports_hover(&self) -> bool

Runtime hook for hover support; defaults to false.
Source§

fn supports_definition(&self) -> bool

Runtime hook for go-to-definition support; defaults to false.
Source§

fn supports_completion(&self) -> bool

Runtime hook for completion support; defaults to false.
Source§

fn supports_code_actions(&self) -> bool

Runtime hook for code-action support (the editor’s quickfix lightbulb); defaults to false.
Source§

fn code_action(&self, doc: &Document<C>, range: Range) -> Vec<CodeAction>

Code actions for the given range — typically quickfixes for the diagnostics published there. The skeleton dispatches textDocument/codeAction when supports_code_actions is true.
Source§

fn hover(&self, doc: &Document<C>, offset: usize) -> Option<Hover>

Hover contents for the byte offset in doc, or None. Read more
Source§

fn definition(&self, doc: &Document<C>, offset: usize) -> Option<Vec<Location>>

Definition locations for the byte offset in doc, or None.
Source§

fn completion( &self, doc: &Document<C>, offset: usize, ) -> Option<CompletionResponse>

Completions for the byte offset in doc, or None.
Source§

fn engine(&self) -> &Engine<C>

The pass schedule run over every document.
Source§

fn root_ctx(&self) -> C

Context for a freshly opened document’s root region.
Source§

fn encoding(&self) -> PositionEncoding

The position encoding to negotiate with the client. Defaults to UTF-16, the LSP default and what most clients use.
Source§

fn diagnostic( &self, doc: &Document<C>, node: FailedNode<'_, C>, ) -> Option<Diagnostic>

Renders the diagnostic for a failing region, or None to stay silent (e.g. for contexts whose failure is expected). Read more
Source§

fn extra_diagnostics(&self, doc: &Document<C>) -> Vec<Diagnostic>

Diagnostics that do not come from parse failures — lint-rule violations, style warnings, anything computed from the settled document rather than a failing tree node. Merged into the same publishDiagnostics notification, after the parse diagnostics.
Source§

fn symbols(&self, doc: &Document<C>) -> Vec<DocumentSymbol>

The document symbols for the outline view. Only consulted when supports_symbols is true.
Source§

const SUPPORTS_SYMBOLS: bool = false

Whether to advertise and answer textDocument/documentSymbol. Defaults to false; flip to true and override symbols. Read more

Auto Trait Implementations§

§

impl<C> !RefUnwindSafe for SimpleLanguage<C>

§

impl<C> !UnwindSafe for SimpleLanguage<C>

§

impl<C> Freeze for SimpleLanguage<C>

§

impl<C> Send for SimpleLanguage<C>

§

impl<C> Sync for SimpleLanguage<C>

§

impl<C> Unpin for SimpleLanguage<C>

§

impl<C> UnsafeUnpin for SimpleLanguage<C>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.