mirror of
https://github.com/esphome/esphome.git
synced 2026-10-02 01:10:22 +00:00
[vscode] Mark the component key for "Component not found" errors
The `vscode --ace` validator resolves an error's range to the deepest matching node, which for a "Component not found" error is the component's value mapping — so the range starts at the first child, and editors underline the children instead of the offending top-level key. Request the key's range for these errors (as already done for "extra keys not allowed"). Backward compatible: only the range for this error type changes.
This commit is contained in:
@@ -97,6 +97,39 @@ esp8266:
|
||||
assert range["end_col"] == 7
|
||||
|
||||
|
||||
def test_component_not_found_marks_key():
|
||||
source_path = str(Path("dir_path", "x.yaml"))
|
||||
output_lines = _run_repl_test(
|
||||
[
|
||||
_validate(source_path),
|
||||
# read_file x.yaml
|
||||
_file_response("""esphome:
|
||||
name: test1
|
||||
esp8266:
|
||||
board: esp01_1m
|
||||
|
||||
apccci:
|
||||
id: foo
|
||||
"""),
|
||||
]
|
||||
)
|
||||
|
||||
error = json.loads(output_lines[-1])
|
||||
not_found = next(
|
||||
e
|
||||
for e in error["validation_errors"]
|
||||
if e["message"].startswith("Component not found:")
|
||||
)
|
||||
assert not_found["message"] == "Component not found: apccci."
|
||||
# Range covers the ``apccci`` key, not its child mapping.
|
||||
range = not_found["range"]
|
||||
assert range["document"] == source_path
|
||||
assert range["start_line"] == 5
|
||||
assert range["start_col"] == 0
|
||||
assert range["end_line"] == 5
|
||||
assert range["end_col"] == 6
|
||||
|
||||
|
||||
def test_shows_correct_loaded_file_error():
|
||||
source_path = str(Path("dir_path", "x.yaml"))
|
||||
output_lines = _run_repl_test(
|
||||
|
||||
Reference in New Issue
Block a user