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>
impl<C: Clone + PartialEq + Send + 'static> SimpleLanguage<C>
Sourcepub fn new(engine: Engine<C>, root_ctx: C) -> Self
pub fn new(engine: Engine<C>, root_ctx: C) -> Self
Creates a builder over an engine and a root context.
Sourcepub fn encoding(self, encoding: PositionEncoding) -> Self
pub fn encoding(self, encoding: PositionEncoding) -> Self
Sets the negotiated position encoding (default UTF-16).
Sourcepub fn diagnostic_fn(
self,
f: impl Fn(&Document<C>, &FailedNode<'_, C>) -> Option<Diagnostic> + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn extra_diagnostics(
self,
f: impl Fn(&Document<C>) -> Vec<Diagnostic> + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn symbols_fn(
self,
f: impl Fn(&Document<C>) -> Vec<DocumentSymbol> + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn label_fn(
self,
f: impl Fn(&C) -> Option<NodeLabel> + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn describe_fn(
self,
f: impl Fn(&C) -> Option<String> + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn hover_fn(
self,
f: impl Fn(&Document<C>, usize) -> Option<Hover> + Send + Sync + 'static,
) -> Self
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).
Sourcepub fn definition_fn(
self,
f: impl Fn(&Document<C>, usize) -> Option<Vec<Location>> + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn completion_fn(
self,
f: impl Fn(&Document<C>, usize) -> Option<CompletionResponse> + Send + Sync + 'static,
) -> Self
pub fn completion_fn( self, f: impl Fn(&Document<C>, usize) -> Option<CompletionResponse> + Send + Sync + 'static, ) -> Self
Completions for the cursor position.
Sourcepub fn code_action_fn(
self,
f: impl Fn(&Document<C>, Range) -> Vec<CodeAction> + Send + Sync + 'static,
) -> Self
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.
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
fn supports_symbols(&self) -> bool
SUPPORTS_SYMBOLS.Source§fn supports_hover(&self) -> bool
fn supports_hover(&self) -> bool
false.Source§fn supports_definition(&self) -> bool
fn supports_definition(&self) -> bool
false.Source§fn supports_completion(&self) -> bool
fn supports_completion(&self) -> bool
false.Source§fn supports_code_actions(&self) -> bool
fn supports_code_actions(&self) -> bool
false.Source§fn code_action(&self, doc: &Document<C>, range: Range) -> Vec<CodeAction>
fn code_action(&self, doc: &Document<C>, range: Range) -> Vec<CodeAction>
textDocument/codeAction when
supports_code_actions is true.Source§fn definition(&self, doc: &Document<C>, offset: usize) -> Option<Vec<Location>>
fn definition(&self, doc: &Document<C>, offset: usize) -> Option<Vec<Location>>
offset in doc, or None.Source§fn completion(
&self,
doc: &Document<C>,
offset: usize,
) -> Option<CompletionResponse>
fn completion( &self, doc: &Document<C>, offset: usize, ) -> Option<CompletionResponse>
offset in doc, or None.Source§fn encoding(&self) -> PositionEncoding
fn encoding(&self) -> PositionEncoding
Source§fn diagnostic(
&self,
doc: &Document<C>,
node: FailedNode<'_, C>,
) -> Option<Diagnostic>
fn diagnostic( &self, doc: &Document<C>, node: FailedNode<'_, C>, ) -> Option<Diagnostic>
None to stay
silent (e.g. for contexts whose failure is expected). Read moreSource§fn extra_diagnostics(&self, doc: &Document<C>) -> Vec<Diagnostic>
fn extra_diagnostics(&self, doc: &Document<C>) -> Vec<Diagnostic>
publishDiagnostics notification, after the parse diagnostics.Source§fn symbols(&self, doc: &Document<C>) -> Vec<DocumentSymbol>
fn symbols(&self, doc: &Document<C>) -> Vec<DocumentSymbol>
supports_symbols is true.