Repository navigation
SHACL shape templates and property shape docs, preferred language, valid prefixed names - #38
Merged
Merged
Conversation
At a predicate position, offer two snippet completions built from the SHACL shapes that apply to the subject: - "shape template: required properties": every property with `sh:minCount >= 1`, - "shape template: all properties": every property the shapes declare. Properties the subject already has are left out. Shapes apply through `sh:targetClass` (including superclasses from the ontologies, and implicit class targets), `sh:targetSubjectsOf`, `sh:targetObjectsOf` (so blank nodes such as RML predicate-object maps get templates) and `sh:targetNode`. A shape's properties include those of the shapes and property shapes it lists in `sh:node` / `sh:and`. Values are snippet placeholders shaped by the constraints: - `sh:hasValue` is filled in, and `sh:in` becomes a choice. - `sh:alternativePath` becomes a choice of predicates. Optional declarations it covers are folded into it, and it is satisfied by any one of its paths. - A nested value (`sh:node`, the first `sh:or` / `sh:xone` branch with a node shape, shapes targeting the objects of the predicate, or shapes for its `sh:class`) expands to `[ … ]` with its required properties, up to two levels deep. - `sh:nodeKind` / `sh:datatype` choose between `<…>`, `"…"`, typed literals and plain placeholders. The template is inserted at the cursor without eating a following `.` or `]`, replaces a partially typed predicate, and continuation lines follow the indentation. Templates are offered for Turtle-family languages with shape validation (`LangHelper::shape_templates`) and can be disabled with `completion_shape_template`.
…uage Hover on a predicate now also shows every SHACL property shape that applies to it for this subject: - `sh:name` and `sh:description`, and also the property shape's `rdfs:label` and `rdfs:comment` (unless they repeat the SHACL text), - the alternatives of an `sh:alternativePath`, - a constraint summary: cardinality, node kind, datatype, class, `sh:in`, `sh:hasValue`, `sh:node` and `sh:or` / `sh:xone` shapes, pattern, lengths and ranges, languages, and a non-default severity. Shapes apply by the same targets as the shape templates. That code moved to `shapes::model`, so hover, completion and templates agree. Property completions get the same documentation, and predicates only the shapes declare are offered too, marked when a shape requires them. IRIs in this documentation fall back to the shape documents' prefixes and are only shortened to valid prefixed names. The hover can be disabled with `hover_shape_property`. Wherever text is shown, one language is chosen: untagged text, then English (`en`, `en-*`), then the first language (`util::lang_text`). This now applies to ontology class and property titles and descriptions (previously every language, in random order), SHACL validation messages (`sh:message`, else `rdfs:comment`), shape template placeholders and the new shape documentation. Fixes found on the way: - `MyTerm`'s sophia `Term` impl reported no datatype or language for literals, so every literal entered the store as a plain string. It now reports `xsd:string`, `rdf:langString` or the literal's datatype, and its language tag. - The conversions to oxigraph checked the datatype before the language, which would turn a language-tagged literal into an `rdf:langString` typed literal without a language. - Removed imports `open_imports` left behind in `lov::fetch`.
`Prefixes::shorten` stripped the first matching namespace and wrote whatever remained, so with `@prefix rml: <http://w3id.org/rml/>` the IRI `http://w3id.org/rml/shapes/X` became `rml:shapes/X`. That is not a valid prefixed name in Turtle, TriG, N3 or SPARQL, and completion inserted it as is. - `Prefixes::shorten` only returns names whose local part is a valid `PN_LOCAL` (`is_local_name`); otherwise the IRI is written in full. When several prefixes match, the longest namespace wins, so a declared `rmlsh: <http://w3id.org/rml/shapes/>` gives `rmlsh:X`. - `Prefixes::shorten_compact` keeps the permissive form for JSON-LD, whose compact IRIs accept any suffix (`css:dist/Server#port`), also preferring the longest prefix. - `LangHelper::shorten` / `LangHelper::write_iri` let completion write an IRI the way the language needs it. Class and property completion used to insert an IRI that could not be shortened as a bare `http://…`, which is invalid Turtle. It is now `<…>` in Turtle-family languages, and a plain string in JSON-LD. - Shape documentation drops its own workaround and uses `shorten`, falling back to the shape documents' prefixes as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SHACL shape templates in completion
At a predicate position, two snippet completions are built from the SHACL shapes that apply to the subject:
sh:minCount >= 1.Properties the subject already has are left out.
sh:targetClass, including superclasses from the ontologies and implicit class targets;sh:targetSubjectsOf;sh:targetObjectsOf, so blank nodes such as RML predicate-object maps get templates;sh:targetNode.sh:node/sh:and. Branches ofsh:or/sh:xoneare alternatives, so none of them is assumed.sh:hasValueis filled in, andsh:inbecomes a choice.sh:alternativePathbecomes a choice of predicates and counts as satisfied by any one of them.[ … ]with their required properties, up to two levels deep. They come fromsh:node, the firstsh:orbranch with a node shape, shapes targeting the objects of the predicate, or shapes for itssh:class.sh:nodeKind/sh:datatypechoose between<…>,"…", typed literals and plain placeholders..or], replaces a partially typed predicate, and continuation lines follow the indentation.completion_shape_template.SHACL property shapes on predicates
Hover on a predicate shows every property shape that applies to it for this subject:
sh:nameandsh:description, and also the property shape'srdfs:labelandrdfs:comment(unless they repeat the SHACL text);sh:alternativePath;sh:in,sh:hasValue,sh:nodeandsh:or/sh:xoneshapes, pattern, lengths and ranges, languages, and a non-default severity.Property completions get the same documentation. Predicates that only the shapes declare are offered too, marked "required by shape" where a shape requires them. The hover can be disabled with
hover_shape_property.Templates, hover and completion share one shape model (
shapes::model), so they agree on which shapes apply.One language for displayed text
Wherever text is shown, one language is chosen: untagged text, then English (
en,en-*), then the first language (util::lang_text). This applies to:sh:message, elserdfs:comment);Fixes found on the way:
MyTerm's sophiaTermimpl reported no datatype or language for literals, so every literal entered the store as a plain string. It now reportsxsd:string,rdf:langStringor the literal's datatype, and its language tag.rdf:langStringtyped literal without a language.Valid prefixed names
Prefixes::shortenstripped the first matching namespace and wrote whatever remained. With@prefix rml: <http://w3id.org/rml/>, the IRIhttp://w3id.org/rml/shapes/Xbecamerml:shapes/X, which is not a valid prefixed name in Turtle, TriG, N3 or SPARQL. Completion inserted it as is.Prefixes::shortenonly returns names whose local part is a validPN_LOCAL; otherwise the IRI is written in full. When several prefixes match, the longest namespace wins.Prefixes::shorten_compactkeeps the permissive form for JSON-LD compact IRIs (css:dist/Server#port).LangHelper::shorten/write_irilet completion write IRIs per language. Class and property completion used to insert an IRI that could not be shortened as a barehttp://…, which is invalid Turtle. It is now<…>in Turtle-family languages, and a plain string in JSON-LD.Testing
shape_templates.rs(11);shape_docs.rs(7);prefixed_names.rs(4, each failing on the previous code).PN_LOCALvalidation, longest-prefix selection and snippet helpers.cargo test --workspacepasses (561 tests).rml:TriplesMapgetsrml:logicalSourceplus a choice ofrml:subjectMap/rml:subject/rml:quotedTriplesMap;rml:subjectMapshows the ontology docs followed by both property shapes and their constraints.Note: the RML shapes declare
rml:template/rml:constant/rml:referencewithsh:maxCount 1but nosh:minCount. That is why neither the templates nor validation treat them as required (the second symptom in #30).Generated by Claude Code