pub struct LanguageService { /* private fields */ }Expand description
Completion, diagnostics, hover and signature help for expressions over a schema.
use jlens_schema::{LanguageService, Schema};
use serde_json::json;
let schema = Schema::infer(&[json!({"items": [{"type": "x", "price": 1}]})]);
let service = LanguageService::new(Some(schema));
let text = "items[type = 'x'].";
let completions = service.complete(text, text.len());
let labels: Vec<_> = completions.items.iter().map(|i| i.label.as_str()).collect();
assert_eq!(labels, ["type", "price"]);Implementations§
Source§impl LanguageService
impl LanguageService
Sourcepub fn new(schema: Option<Schema>) -> Self
pub fn new(schema: Option<Schema>) -> Self
A service for expressions over documents described by schema (or without a schema:
functions and variables are still completed).
Sourcepub fn with_variable(
self,
name: impl Into<String>,
shape: Option<Shape>,
) -> Self
pub fn with_variable( self, name: impl Into<String>, shape: Option<Shape>, ) -> Self
Declares a variable the expression is evaluated with (a binding), optionally with the shape of its value.
Sourcepub fn with_function(self, function: FunctionDecl) -> Self
pub fn with_function(self, function: FunctionDecl) -> Self
Declares a host function the expression is evaluated with. It is completed, and shown by hover and signature help, like a built-in function, and replaces a built-in function of the same name.
Sourcepub fn complete(&self, text: &str, offset: usize) -> Completions
pub fn complete(&self, text: &str, offset: usize) -> Completions
Suggestions for the word at offset.
Sourcepub fn diagnostics(&self, text: &str) -> Vec<Diagnostic>
pub fn diagnostics(&self, text: &str) -> Vec<Diagnostic>
Syntax errors, annotation warnings, references to fields the schema does not have, calls of unknown functions, with the wrong number of arguments or with arguments of types the signature does not accept, and, when variables are declared, references to variables that are not.
Sourcepub fn hover(&self, text: &str, offset: usize) -> Option<Hover>
pub fn hover(&self, text: &str, offset: usize) -> Option<Hover>
Information about the field, variable or function at offset.
Sourcepub fn signature_help(&self, text: &str, offset: usize) -> Option<SignatureHelp>
pub fn signature_help(&self, text: &str, offset: usize) -> Option<SignatureHelp>
The function call around offset and the argument being edited.