Skip to content

Commit de78c0e

Browse files
committed
Fix corner case for 'flow sequence forbidden' quickfix
- Do not include any trailing spaces in the error range - This is a change in behaviour; it seems this behaviour was intentional based on the test cases, but I don't agree with it, since the error range should only cover the erroneous code. - Fix a bug where `]` or `}` are not included in the error range if they're the last character in the document Fixes #1060 Signed-off-by: David Thompson <[email protected]>
1 parent 4e25b52 commit de78c0e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/languageservice/services/validation/yaml-style.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ export class YAMLStyleValidator implements AdditionalValidator {
4242
}
4343

4444
private getRangeOf(document: TextDocument, node: FlowCollection): Range {
45-
return Range.create(document.positionAt(node.start.offset), document.positionAt(node.end.pop().offset));
45+
const endOffset = node.end[0].offset;
46+
let endPosition = document.positionAt(endOffset);
47+
endPosition = { character: endPosition.character + 1, line: endPosition.line };
48+
return Range.create(document.positionAt(node.start.offset), endPosition);
4649
}
4750
}

test/yamlValidation.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ animals: [dog , cat , mouse] `;
142142
expect(result).not.to.be.empty;
143143
expect(result.length).to.be.equal(2);
144144
expect(result).to.include.deep.members([
145-
createExpectedError('Flow style mapping is forbidden', 1, 12, 1, 42, DiagnosticSeverity.Error, 'YAML', 'flowMap'),
145+
createExpectedError('Flow style mapping is forbidden', 1, 12, 1, 40, DiagnosticSeverity.Error, 'YAML', 'flowMap'),
146146
createExpectedError('Flow style sequence is forbidden', 2, 9, 2, 28, DiagnosticSeverity.Error, 'YAML', 'flowSeq'),
147147
]);
148148
});
@@ -185,8 +185,8 @@ animals: [dog , cat , mouse] `;
185185
expect(result).not.to.be.empty;
186186
expect(result.length).to.be.equal(2);
187187
expect(result).to.include.deep.members([
188-
createExpectedError('Flow style mapping is forbidden', 0, 8, 0, 11, DiagnosticSeverity.Error, 'YAML', 'flowMap'),
189-
createExpectedError('Flow style sequence is forbidden', 1, 9, 1, 10, DiagnosticSeverity.Error, 'YAML', 'flowSeq'),
188+
createExpectedError('Flow style mapping is forbidden', 0, 8, 0, 10, DiagnosticSeverity.Error, 'YAML', 'flowMap'),
189+
createExpectedError('Flow style sequence is forbidden', 1, 9, 1, 11, DiagnosticSeverity.Error, 'YAML', 'flowSeq'),
190190
]);
191191
});
192192
});

0 commit comments

Comments
 (0)