Skip to content

Add line number to validation errors/warnings in DSL thing provider#5433

Open
lolodomo wants to merge 1 commit intoopenhab:mainfrom
lolodomo:dsl_thing_add_line_number
Open

Add line number to validation errors/warnings in DSL thing provider#5433
lolodomo wants to merge 1 commit intoopenhab:mainfrom
lolodomo:dsl_thing_add_line_number

Conversation

@lolodomo
Copy link
Copy Markdown
Contributor

No description provided.

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
@lolodomo lolodomo requested a review from a team as a code owner March 22, 2026 09:25
@holgerfriedrich
Copy link
Copy Markdown
Member

may fix #5167?

@lolodomo
Copy link
Copy Markdown
Contributor Author

lolodomo commented Mar 22, 2026

may fix #5167?

No as the issue was about rule file. At least, it is the example provided.

But different submitted PRs will already fix that for items, things and sitemaps.

I will have a look for rules & scripts later.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds line number context to DSL Thing validation warnings/errors so users can more easily locate issues in .things models.

Changes:

  • Introduces a helper to prefix validation messages with the semantic element’s line (or line range).
  • Updates existing warnings/errors in ThingValidator to use the line-prefixed messages.
  • Adjusts imports and warning/error call sites to pass the validated EObject explicitly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +58 to +59
getMessageAcceptor().acceptWarning(
buildMsgWithLineNb(thing, "Provide a thing UID in this format:\n <bindingId>:<thingTypeId>:<thingId>"),
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line numbers added via buildMsgWithLineNb(thing, …) are derived from the whole ModelThing node, but the warning here highlights only the thingTypeId..thingId range (startOffset/endOffset from the feature nodes). If the thing spans multiple lines, the message’s "Line …" prefix can disagree with the actual marked location. Consider deriving the line(s) from the same node(s)/offset range you pass to acceptWarning (e.g., using the feature nodes’ start/end line), or passing the relevant INode into the helper so the prefix matches the highlighted region.

Suggested change
getMessageAcceptor().acceptWarning(
buildMsgWithLineNb(thing, "Provide a thing UID in this format:\n <bindingId>:<thingTypeId>:<thingId>"),
val baseMsg = "Provide a thing UID in this format:\n <bindingId>:<thingTypeId>:<thingId>"
val startLine = thingTypeIdFeature.startLine
val endLine = thingIdFeature.endLine
val warnMsg = if (startLine == endLine) {
"Line " + startLine + ": " + baseMsg
} else {
"Line " + startLine + "-" + endLine + ": " + baseMsg
}
getMessageAcceptor().acceptWarning(
warnMsg,

Copilot uses AI. Check for mistakes.
Comment on lines +37 to 45
val warnMsg = buildMsgWithLineNb(thing, "Provide a thing type ID and a thing ID in this format:\n <thingTypeId> <thingId>")
// We have to provide thingTypeId and a thingId
if (!thing.eIsSet(ThingPackage.Literals.MODEL_THING__THING_TYPE_ID)) {
if (thing.eIsSet(ThingPackage.Literals.MODEL_PROPERTY_CONTAINER__ID)) {
warning("Provide a thing type ID and a thing ID in this format:\n <thingTypeId> <thingId>", ThingPackage.Literals.MODEL_PROPERTY_CONTAINER__ID)
warning(warnMsg, thing, ThingPackage.Literals.MODEL_PROPERTY_CONTAINER__ID)
} else {
if (thing.eIsSet(ThingPackage.Literals.MODEL_BRIDGE__BRIDGE)) {
warning("Provide a thing type ID and a thing ID in this format:\n <thingTypeId> <thingId>", ThingPackage.Literals.MODEL_BRIDGE__BRIDGE)
warning(warnMsg, thing, ThingPackage.Literals.MODEL_BRIDGE__BRIDGE)
}
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these nested-thing warnings you attach the marker to a specific feature (MODEL_PROPERTY_CONTAINER__ID, MODEL_BRIDGE__BRIDGE, etc.), but the "Line …" prefix is computed from NodeModelUtils.getNode(thing) (the entire thing). If the relevant feature is on a different line than the thing declaration, the reported line number can be misleading. Consider computing the line from the node(s) for the same feature you pass to warning(...) (or from getMessageAcceptor() offset/length) so the prefix matches the actual marker location.

Copilot uses AI. Check for mistakes.
new ThingUID(thing.id)
} catch (IllegalArgumentException e) {
error(e.message, ThingPackage.Literals.MODEL_PROPERTY_CONTAINER__ID)
error(buildMsgWithLineNb(thing, e.message), thing, ThingPackage.Literals.MODEL_PROPERTY_CONTAINER__ID)
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error marker is attached to MODEL_PROPERTY_CONTAINER__ID, but the line number prefix is computed from the whole thing node. If the id appears on a different line than the start of the thing declaration, the reported line can be inaccurate. Consider computing the line number from the node for the ID feature (or the acceptor offset) instead of from NodeModelUtils.getNode(thing).

Copilot uses AI. Check for mistakes.
@lolodomo lolodomo changed the title [DSL thing provider] Add line number to validation errors/warnings Add line number to validation errors/warnings in DSL thing provider Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants