Skip to content

Commit

Permalink
Improve range-accuracy on value definition diagnostics
Browse files Browse the repository at this point in the history
Co-Authored-By: Marco Roth <[email protected]>
  • Loading branch information
nachiket87 and marcoroth committed Apr 29, 2024
1 parent 72719d6 commit 82a3460
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion server/src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,11 @@ export class Diagnostics {
if (controller.values.length === 0) return

controller.values.forEach((valueDefinition) => {
const range = this.rangeFromLoc(textDocument, valueDefinition.node.loc)
const defaultValueType = this.parseValueType(valueDefinition.default)

if (!["Array", "Boolean", "Number", "Object", "String"].includes(valueDefinition.type)) {
const range = this.rangeFromLoc(textDocument, valueDefinition.typeLoc)

this.pushDiagnostic(
`Unknown Value type. The "${valueDefinition.name}" value is defined as type "${valueDefinition.type}". \nPossible Values: \`Array\`, \`Boolean\`, \`Number\`, \`Object\`, or \`String\`.\n`,
"stimulus.controller.value_definition.unknown_type",
Expand All @@ -373,6 +374,8 @@ export class Diagnostics {
}

if (valueDefinition.type !== defaultValueType) {
const range = this.rangeFromLoc(textDocument, valueDefinition.defaultValueLoc)

const message = dedent`
The type of the default value you provided doesn't match the type you defined.
The "${valueDefinition.name}" Stimulus Value is of type \`${valueDefinition.type}\`.
Expand Down

0 comments on commit 82a3460

Please sign in to comment.