Skip to main content

LangHelper

Trait LangHelper 

Source
pub trait LangHelper: Debug {
Show 16 methods // Required method fn keyword(&self) -> &[&'static str]; // Provided methods fn default_position(&self) -> TripleTarget { ... } fn unquote<'a>(&self, inp: &'a str) -> &'a str { ... } fn quote(&self, inp: &str) -> String { ... } fn prefix_keyword(&self) -> &str { ... } fn format_prefix_declaration( &self, name: &str, url: &str, format: PrefixFormat, ) -> String { ... } fn prefix_edits( &self, _source: &str, _rope: &LineIndex, name: &str, namespace: &str, format: PrefixFormat, ) -> Option<Vec<TextEdit>> { ... } fn supports_prefix_diagnostics(&self) -> bool { ... } fn prefix_name_at<'a>( &self, source: &'a str, offset: usize, ) -> Option<&'a str> { ... } fn rename_placeholder<'a>(&self, raw: &'a str) -> &'a str { ... } fn rename_wrap(&self, new_text: &str) -> String { ... } fn handles_prefix_completion(&self) -> bool { ... } fn model_based_rename(&self) -> bool { ... } fn blank_node_code_actions(&self) -> bool { ... } fn supports_shape_validation(&self) -> bool { ... } fn inlay_types_hint( &self, subject: &Range<usize>, rope: &LineIndex, last_type: Option<&Range<usize>>, types: Vec<Cow<'_, str>>, ) -> Option<InlayHint> { ... }
}

Required Methods§

Source

fn keyword(&self) -> &[&'static str]

Provided Methods§

Source

fn default_position(&self) -> TripleTarget

Source

fn unquote<'a>(&self, inp: &'a str) -> &'a str

Source

fn quote(&self, inp: &str) -> String

Source

fn prefix_keyword(&self) -> &str

Return the source keyword used to introduce a prefix declaration (used only for display / span-finding purposes).

Source

fn format_prefix_declaration( &self, name: &str, url: &str, format: PrefixFormat, ) -> String

Format a prefix declaration string to be inserted into a document.

Default (Turtle / TriG): honors the user’s [PrefixFormat] preference — @prefix {name}: <{url}>.\n (Turtle) or PREFIX {name}: <{url}>\n (SPARQL-style).

Source

fn prefix_edits( &self, _source: &str, _rope: &LineIndex, name: &str, namespace: &str, format: PrefixFormat, ) -> Option<Vec<TextEdit>>

Produce the text edit(s) that declare prefix namenamespace in this document, or None when it cannot / should not be inserted (e.g. the prefix is already present).

This is the single source of truth for “how do I add a prefix to a document of this language”, shared by prefix completion and the “add missing prefix” diagnostic quick-fix so the two paths stay consistent. The default (Turtle / SPARQL / TriG) inserts a declaration line at the very top of the file; JSON-LD overrides this to splice the prefix into the @context object.

Source

fn supports_prefix_diagnostics(&self) -> bool

Return true if the generic prefix-diagnostics system should analyse this language’s documents.

JSON-LD uses @context semantics where terms are pre-expanded before being stored as Triples; its prefix model is not compatible with the span-based detection used by the generic system. Override to return false to opt out.

Source

fn prefix_name_at<'a>(&self, source: &'a str, offset: usize) -> Option<&'a str>

Extract the prefix name of a prefixed term whose : was just typed at byte offset (the cursor sits immediately after the :), or None when the context is not a bare prefixed name. Used by on-type formatting to decide whether to auto-declare a prefix.

Default (Turtle / TriG / SPARQL): scan back over prefix-name characters and require a term boundary before them, skipping comments and @prefix/@base (or PREFIX/BASE) declaration lines. JSON-LD overrides this to scan inside a JSON string instead.

Source

fn rename_placeholder<'a>(&self, raw: &'a str) -> &'a str

Given a raw token string from the document (e.g. <http://ex.org/foo> or ex:foo), return the bare text that should be pre-filled in the editor’s rename input box.

Source

fn rename_wrap(&self, new_text: &str) -> String

Wrap the user-supplied rename text so that it is valid in the current language.

Default (Turtle / SPARQL / TriG) smart rules:

  • already has < > → keep as-is
  • starts with _: → blank node, keep as-is
  • contains :// → full IRI with scheme (e.g. http://), wrap in < >
  • contains : but no :// → prefixed name (e.g. ex:foo), keep as-is
  • otherwise → bare label, wrap in < > to be safe
Source

fn handles_prefix_completion(&self) -> bool

Return true if this language provides its own prefix completion and the generic [defined_prefix_completion] system should be skipped.

Source

fn model_based_rename(&self) -> bool

Return true if this language renames via the model-based systems in swls-lang-rdf-base (registered through setup_rename). When true, the core language-agnostic prepare_rename/rename systems skip this language’s documents to avoid producing duplicate edits.

Text RDF syntaxes (Turtle / TriG / SPARQL) override this to true; JSON-LD keeps the default and stays on the agnostic path.

Source

fn blank_node_code_actions(&self) -> bool

Return true if this language supports the generic blank-node refactor code actions (extract a nested [ … ] to a labelled _:bN, and inline a labelled _:bN back into [ … ]).

These actions emit Turtle-family syntax, so the text RDF syntaxes (Turtle / TriG / SPARQL / N3) override this to true. JSON-LD keeps the default because its blank nodes are JSON objects, not [ … ] / _:bN.

Source

fn supports_shape_validation(&self) -> bool

Source

fn inlay_types_hint( &self, subject: &Range<usize>, rope: &LineIndex, last_type: Option<&Range<usize>>, types: Vec<Cow<'_, str>>, ) -> Option<InlayHint>

Implementors§