Skip to main content

Language

Trait Language 

Source
pub trait Language<C: Clone + PartialEq + Send + 'static>:
    Send
    + Sync
    + 'static {
    const SUPPORTS_SYMBOLS: bool = false;
Show 15 methods // Required methods fn engine(&self) -> &Engine<C>; fn root_ctx(&self) -> C; fn diagnostic( &self, doc: &Document<C>, node: FailedNode<'_, C>, ) -> Option<Diagnostic>; // Provided methods fn supports_symbols(&self) -> bool { ... } fn encoding(&self) -> PositionEncoding { ... } fn extra_diagnostics(&self, doc: &Document<C>) -> Vec<Diagnostic> { ... } fn symbols(&self, doc: &Document<C>) -> Vec<DocumentSymbol> { ... } fn supports_hover(&self) -> bool { ... } fn supports_definition(&self) -> bool { ... } fn supports_completion(&self) -> bool { ... } fn supports_code_actions(&self) -> bool { ... } fn code_action(&self, doc: &Document<C>, range: Range) -> Vec<CodeAction> { ... } fn hover(&self, doc: &Document<C>, offset: usize) -> Option<Hover> { ... } fn definition( &self, doc: &Document<C>, offset: usize, ) -> Option<Vec<Location>> { ... } fn completion( &self, doc: &Document<C>, offset: usize, ) -> Option<CompletionResponse> { ... }
}
Expand description

The language-specific half of a server.

Implement this and hand it to serve (stdio) or serve_on (any transport). Everything else — lifecycle, change bookkeeping, diagnostics publishing, symbol dispatch — is the skeleton’s job.///

§Examples

A minimal server that parses files and reports nothing:

use increparse::{Engine, Outcome, Pass, Schedule, Span};
use increparse_lsp::{Document, FailedNode, Language, serve};
use lsp_types::Diagnostic;

#[derive(Clone, Debug, PartialEq, Eq)]
enum Ctx {
    File,
}

struct Accept;
impl Pass for Accept {
    type Ctx = Ctx;
    fn parse(&self, _source: &str, _span: Span, _ctx: &Ctx) -> Outcome<Ctx> {
        Outcome::Done
    }
}

struct MyLang {
    engine: Engine<Ctx>,
}

impl MyLang {
    fn new() -> Self {
        let mut schedule = Schedule::new();
        schedule.push(Accept);
        Self {
            engine: Engine::new(schedule),
        }
    }
}

impl Language<Ctx> for MyLang {
    fn engine(&self) -> &Engine<Ctx> {
        &self.engine
    }

    fn root_ctx(&self) -> Ctx {
        Ctx::File
    }

    fn diagnostic(&self, _doc: &Document<Ctx>, _node: FailedNode<'_, Ctx>) -> Option<Diagnostic> {
        None
    }
}

// serve(MyLang::new())?;

Provided Associated Constants§

Source

const SUPPORTS_SYMBOLS: bool = false

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

For per-instance decisions (e.g. capability discovered from a config file), override supports_symbols instead — it defaults to this constant.

Required Methods§

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 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).

doc gives access to the document’s text, URI, and version; the returned diagnostic’s range may be left empty, in which case it is filled in from the node’s span.

Provided Methods§

Source

fn supports_symbols(&self) -> bool

Runtime hook for symbol support; defaults to SUPPORTS_SYMBOLS.

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 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

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.

The skeleton converts the client’s position (in the negotiated encoding) to a byte offset before calling this, so implementations never touch position math.

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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

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.