Expand description
Core and common implementation for the semantic web language server.
Proivdes the backbone for the semantic web lsp binary and semantic web lsp wasm.
With the language server protocol, each different request is handled by an ECS schedule, combining different systems together. A system can generate new data and attach it to an entity, a document, or use this data to respond to requests.
Language specific implementations that handle things like tokenizing and parsing are
implemented in separate crates. The binary currently supports Turtle, JSON-LD and SPARQL.
The goal is that each language at least generates [Tokens], Triples and
Prefixes.
These components are then used to derive properties for autcompletion but also derive
TokenComponent and TripleComponent enabling completion.
The different schedules can be found at prelude::feature.
§Example add completion for all subjects that start with a
use bevy_ecs::prelude::*;
use swls_core::prelude::*;
// Define the extra data struct
#[derive(Component)]
struct MyCompletions {
subjects: Vec<String>,
}
// Define the generating system
// Don't forget to add it to the ecs later
fn generate_my_completion(
// Only derive the completions when the document is parsed fully, aka is not Dirty
query: Query<(Entity, &Triples), (Changed<Triples>, Without<Dirty>)>,
mut commands: Commands,
) {
for (e, triples) in &query {
let mut subjects = Vec::new();
for q in triples.quads().flatten() {
if q.s().as_str().starts_with('a') {
subjects.push(q.s().as_str().to_string());
}
}
commands.entity(e).insert(MyCompletions { subjects });
}
}
// Define a system that adds these completions to the completion request
fn complete_my_completion(
mut query: Query<(
&TokenComponent, &TripleComponent, &MyCompletions, &mut CompletionRequest
)>,
) {
for (token, this_triple, completions, mut request) in &mut query {
if this_triple.target == TripleTarget::Subject {
for my_completion in &completions.subjects {
request.push(
SimpleCompletion::new(
swls_core::lsp_types::CompletionItemKind::FIELD,
my_completion.clone(),
swls_core::lsp_types::TextEdit {
range: token.range.clone(),
new_text: my_completion.clone(),
}
)
)
}
}
}
}Note that Prefixes can help expand and shorten iri’s in a document.
Re-exports§
pub use lsp_types;
Modules§
- backend
- Main language server implementation.
- client
- Handle platform specific implementations for fetching and spawning tasks.
- components
- Defines all common
Components andResources - document
- Editor lifecycle of documents (open / close) and the cached-copy rules.
Editor lifecycle of documents:
didOpen/didClose. - feature
- Hosts all common features of the semantic language server.
All features supported by the language server.
Features like completion (
CompletionRequest) and hover expose a component that collects items returned to the client. - lang
- Defines common language traits
- navigation
- Document links, symbols, folding ranges and workspace symbols. Document links, document symbols (outline), folding ranges and workspace symbols. Read-only views of what the server already parsed.
- prelude
- revisions
- Change tracking for data shared by all documents.
- store
- systems
- text
- Minimal text indexing for LSP position math (replaces ropey). Minimal text indexing for LSP position math.
- util
- Common utils
- workspace
- The workspace’s RDF files, loaded in the background. The workspace’s RDF files, loaded in the background.
Structs§
- Config
Changed - Runs after
workspace/didChangeConfigurationreplaced theServerConfig: systems that load what the configuration names (ontologies, shapes) add themselves here. - Create
Event - Event triggers when a document is opened
- Started
- Startup
- Tasks
ScheduleLabelrelated to the Tasks schedule This schedule is used for async tasks, things that should be done at some point.