Add line number to validation errors/warnings in DSL thing provider#5433
Add line number to validation errors/warnings in DSL thing provider#5433lolodomo wants to merge 1 commit intoopenhab:mainfrom
Conversation
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
|
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. |
There was a problem hiding this comment.
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
ThingValidatorto use the line-prefixed messages. - Adjusts imports and warning/error call sites to pass the validated
EObjectexplicitly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| getMessageAcceptor().acceptWarning( | ||
| buildMsgWithLineNb(thing, "Provide a thing UID in this format:\n <bindingId>:<thingTypeId>:<thingId>"), |
There was a problem hiding this comment.
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.
| 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, |
| 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) | ||
| } |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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).
No description provided.