Skip to content

Commit caf8541

Browse files
committed
fix(analyze): if a imported resource has import errors it is shown as releated information
1 parent c8b66c8 commit caf8541

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

packages/robot/src/robotcode/robot/diagnostics/namespace.py

+24
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,7 @@ def _import(
11231123
top_level: bool = False,
11241124
source: Optional[str] = None,
11251125
parent_import: Optional[Import] = None,
1126+
parent_source: Optional[str] = None,
11261127
) -> Optional[LibraryEntry]:
11271128
result: Optional[LibraryEntry] = None
11281129
try:
@@ -1304,6 +1305,26 @@ def _import(
13041305
source=DIAGNOSTICS_SOURCE_NAME,
13051306
code=type(e).__qualname__,
13061307
)
1308+
elif parent_import is not None:
1309+
self.append_diagnostics(
1310+
range=parent_import.range,
1311+
message="Import definition contains errors.",
1312+
severity=DiagnosticSeverity.ERROR,
1313+
source=DIAGNOSTICS_SOURCE_NAME,
1314+
code=Error.IMPORT_CONTAINS_ERRORS,
1315+
related_information=(
1316+
(
1317+
[
1318+
DiagnosticRelatedInformation(
1319+
location=Location(str(Uri.from_path(parent_source)), value.range),
1320+
message=str(e),
1321+
),
1322+
]
1323+
)
1324+
if parent_source
1325+
else None
1326+
),
1327+
)
13071328
finally:
13081329
self._reset_global_variables()
13091330

@@ -1318,6 +1339,7 @@ def _import_imports(
13181339
variables: Optional[Dict[str, Any]] = None,
13191340
source: Optional[str] = None,
13201341
parent_import: Optional[Import] = None,
1342+
parent_source: Optional[str] = None,
13211343
depth: int = 0,
13221344
) -> Optional[Dict[str, Any]]:
13231345

@@ -1335,6 +1357,7 @@ def _import_imports(
13351357
top_level=top_level,
13361358
source=source,
13371359
parent_import=parent_import,
1360+
parent_source=parent_source if parent_source else source,
13381361
)
13391362

13401363
if entry is not None:
@@ -1358,6 +1381,7 @@ def _import_imports(
13581381
variables=variables,
13591382
source=entry.library_doc.source,
13601383
parent_import=imp if top_level else parent_import,
1384+
parent_source=parent_source if top_level else source,
13611385
depth=depth + 1,
13621386
)
13631387
except (SystemExit, KeyboardInterrupt):

0 commit comments

Comments
 (0)