robotcode-robot 0.74.0__py3-none-any.whl → 0.76.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- robotcode/robot/__version__.py +1 -1
- robotcode/robot/diagnostics/document_cache_helper.py +22 -0
- robotcode/robot/diagnostics/imports_manager.py +29 -16
- robotcode/robot/diagnostics/library_doc.py +93 -108
- robotcode/robot/diagnostics/namespace.py +288 -248
- robotcode/robot/diagnostics/namespace_analyzer.py +36 -6
- robotcode/robot/diagnostics/workspace_config.py +1 -0
- {robotcode_robot-0.74.0.dist-info → robotcode_robot-0.76.0.dist-info}/METADATA +2 -2
- {robotcode_robot-0.74.0.dist-info → robotcode_robot-0.76.0.dist-info}/RECORD +11 -11
- {robotcode_robot-0.74.0.dist-info → robotcode_robot-0.76.0.dist-info}/WHEEL +0 -0
- {robotcode_robot-0.74.0.dist-info → robotcode_robot-0.76.0.dist-info}/licenses/LICENSE.txt +0 -0
@@ -684,10 +684,17 @@ class Namespace:
|
|
684
684
|
|
685
685
|
def _invalidate(self) -> None:
|
686
686
|
self._invalid = True
|
687
|
+
self.imports_manager.imports_changed.remove(self.imports_changed)
|
688
|
+
self.imports_manager.libraries_changed.remove(self.libraries_changed)
|
689
|
+
self.imports_manager.resources_changed.remove(self.resources_changed)
|
690
|
+
self.imports_manager.variables_changed.remove(self.variables_changed)
|
687
691
|
|
688
692
|
@_logger.call
|
689
693
|
def invalidate(self) -> None:
|
690
694
|
with self._initialize_lock:
|
695
|
+
if self._invalid:
|
696
|
+
return
|
697
|
+
|
691
698
|
self._invalidate()
|
692
699
|
self.has_invalidated(self)
|
693
700
|
|
@@ -981,215 +988,228 @@ class Namespace:
|
|
981
988
|
|
982
989
|
return None
|
983
990
|
|
984
|
-
def
|
991
|
+
def _import(
|
985
992
|
self,
|
986
|
-
|
993
|
+
value: Import,
|
994
|
+
variables: Optional[Dict[str, Any]],
|
987
995
|
base_dir: str,
|
988
996
|
*,
|
989
997
|
top_level: bool = False,
|
990
|
-
variables: Optional[Dict[str, Any]] = None,
|
991
998
|
source: Optional[str] = None,
|
992
999
|
parent_import: Optional[Import] = None,
|
993
|
-
) ->
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1000
|
+
) -> Optional[LibraryEntry]:
|
1001
|
+
result: Optional[LibraryEntry] = None
|
1002
|
+
try:
|
1003
|
+
if isinstance(value, LibraryImport):
|
1004
|
+
if value.name is None:
|
1005
|
+
raise NameSpaceError("Library setting requires value.")
|
1006
|
+
|
1007
|
+
result = self._get_library_entry(
|
1008
|
+
value.name,
|
1009
|
+
value.args,
|
1010
|
+
value.alias,
|
1011
|
+
base_dir,
|
1012
|
+
sentinel=self,
|
1013
|
+
variables=variables,
|
1014
|
+
)
|
1015
|
+
result.import_range = value.range
|
1016
|
+
result.import_source = value.source
|
1017
|
+
result.alias_range = value.alias_range
|
1002
1018
|
|
1003
|
-
|
1019
|
+
self._import_entries[value] = result
|
1020
|
+
|
1021
|
+
if (
|
1022
|
+
top_level
|
1023
|
+
and result.library_doc.errors is None
|
1024
|
+
and (len(result.library_doc.keywords) == 0 and not bool(result.library_doc.has_listener))
|
1025
|
+
):
|
1026
|
+
self.append_diagnostics(
|
1027
|
+
range=value.range,
|
1028
|
+
message=f"Imported library '{value.name}' contains no keywords.",
|
1029
|
+
severity=DiagnosticSeverity.WARNING,
|
1030
|
+
source=DIAGNOSTICS_SOURCE_NAME,
|
1031
|
+
code=Error.LIBRARY_CONTAINS_NO_KEYWORDS,
|
1032
|
+
)
|
1033
|
+
elif isinstance(value, ResourceImport):
|
1034
|
+
if value.name is None:
|
1035
|
+
raise NameSpaceError("Resource setting requires value.")
|
1036
|
+
|
1037
|
+
source = self.imports_manager.find_resource(value.name, base_dir, variables=variables)
|
1038
|
+
|
1039
|
+
if self.source == source:
|
1040
|
+
if parent_import:
|
1041
|
+
self.append_diagnostics(
|
1042
|
+
range=parent_import.range,
|
1043
|
+
message="Possible circular import.",
|
1044
|
+
severity=DiagnosticSeverity.INFORMATION,
|
1045
|
+
source=DIAGNOSTICS_SOURCE_NAME,
|
1046
|
+
related_information=(
|
1047
|
+
[
|
1048
|
+
DiagnosticRelatedInformation(
|
1049
|
+
location=Location(
|
1050
|
+
str(Uri.from_path(value.source)),
|
1051
|
+
value.range,
|
1052
|
+
),
|
1053
|
+
message=f"'{Path(self.source).name}' is also imported here.",
|
1054
|
+
)
|
1055
|
+
]
|
1056
|
+
if value.source
|
1057
|
+
else None
|
1058
|
+
),
|
1059
|
+
code=Error.POSSIBLE_CIRCULAR_IMPORT,
|
1060
|
+
)
|
1061
|
+
else:
|
1062
|
+
result = self._get_resource_entry(
|
1004
1063
|
value.name,
|
1005
|
-
value.args,
|
1006
|
-
value.alias,
|
1007
1064
|
base_dir,
|
1008
|
-
sentinel=self,
|
1009
1065
|
variables=variables,
|
1010
1066
|
)
|
1011
1067
|
result.import_range = value.range
|
1012
1068
|
result.import_source = value.source
|
1013
|
-
result.alias_range = value.alias_range
|
1014
1069
|
|
1015
1070
|
self._import_entries[value] = result
|
1016
1071
|
|
1017
|
-
if (
|
1018
|
-
|
1019
|
-
and
|
1020
|
-
and
|
1072
|
+
if top_level and (
|
1073
|
+
not result.library_doc.errors
|
1074
|
+
and top_level
|
1075
|
+
and not result.imports
|
1076
|
+
and not result.variables
|
1077
|
+
and not result.library_doc.keywords
|
1021
1078
|
):
|
1022
1079
|
self.append_diagnostics(
|
1023
1080
|
range=value.range,
|
1024
|
-
message=f"Imported
|
1081
|
+
message=f"Imported resource file '{value.name}' is empty.",
|
1025
1082
|
severity=DiagnosticSeverity.WARNING,
|
1026
1083
|
source=DIAGNOSTICS_SOURCE_NAME,
|
1027
|
-
code=Error.
|
1028
|
-
)
|
1029
|
-
elif isinstance(value, ResourceImport):
|
1030
|
-
if value.name is None:
|
1031
|
-
raise NameSpaceError("Resource setting requires value.")
|
1032
|
-
|
1033
|
-
source = self.imports_manager.find_resource(value.name, base_dir, variables=variables)
|
1034
|
-
|
1035
|
-
if self.source == source:
|
1036
|
-
if parent_import:
|
1037
|
-
self.append_diagnostics(
|
1038
|
-
range=parent_import.range,
|
1039
|
-
message="Possible circular import.",
|
1040
|
-
severity=DiagnosticSeverity.INFORMATION,
|
1041
|
-
source=DIAGNOSTICS_SOURCE_NAME,
|
1042
|
-
related_information=(
|
1043
|
-
[
|
1044
|
-
DiagnosticRelatedInformation(
|
1045
|
-
location=Location(
|
1046
|
-
str(Uri.from_path(value.source)),
|
1047
|
-
value.range,
|
1048
|
-
),
|
1049
|
-
message=f"'{Path(self.source).name}' is also imported here.",
|
1050
|
-
)
|
1051
|
-
]
|
1052
|
-
if value.source
|
1053
|
-
else None
|
1054
|
-
),
|
1055
|
-
code=Error.POSSIBLE_CIRCULAR_IMPORT,
|
1056
|
-
)
|
1057
|
-
else:
|
1058
|
-
result = self._get_resource_entry(
|
1059
|
-
value.name,
|
1060
|
-
base_dir,
|
1061
|
-
variables=variables,
|
1084
|
+
code=Error.RESOURCE_EMPTY,
|
1062
1085
|
)
|
1063
|
-
result.import_range = value.range
|
1064
|
-
result.import_source = value.source
|
1065
|
-
|
1066
|
-
self._import_entries[value] = result
|
1067
|
-
if result.variables:
|
1068
|
-
variables = None
|
1069
|
-
|
1070
|
-
if top_level and (
|
1071
|
-
not result.library_doc.errors
|
1072
|
-
and top_level
|
1073
|
-
and not result.imports
|
1074
|
-
and not result.variables
|
1075
|
-
and not result.library_doc.keywords
|
1076
|
-
):
|
1077
|
-
self.append_diagnostics(
|
1078
|
-
range=value.range,
|
1079
|
-
message=f"Imported resource file '{value.name}' is empty.",
|
1080
|
-
severity=DiagnosticSeverity.WARNING,
|
1081
|
-
source=DIAGNOSTICS_SOURCE_NAME,
|
1082
|
-
code=Error.RESOURCE_EMPTY,
|
1083
|
-
)
|
1084
1086
|
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1087
|
+
elif isinstance(value, VariablesImport):
|
1088
|
+
if value.name is None:
|
1089
|
+
raise NameSpaceError("Variables setting requires value.")
|
1088
1090
|
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1091
|
+
result = self._get_variables_entry(
|
1092
|
+
value.name,
|
1093
|
+
value.args,
|
1094
|
+
base_dir,
|
1095
|
+
variables=variables,
|
1096
|
+
)
|
1095
1097
|
|
1096
|
-
|
1097
|
-
|
1098
|
+
result.import_range = value.range
|
1099
|
+
result.import_source = value.source
|
1098
1100
|
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
raise DiagnosticsError("Unknown import type.")
|
1101
|
+
self._import_entries[value] = result
|
1102
|
+
else:
|
1103
|
+
raise DiagnosticsError("Unknown import type.")
|
1103
1104
|
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
),
|
1126
|
-
character=0,
|
1105
|
+
if top_level and result is not None:
|
1106
|
+
if result.library_doc.source is not None and result.library_doc.errors:
|
1107
|
+
if any(err.source and Path(err.source).is_absolute() for err in result.library_doc.errors):
|
1108
|
+
self.append_diagnostics(
|
1109
|
+
range=value.range,
|
1110
|
+
message="Import definition contains errors.",
|
1111
|
+
severity=DiagnosticSeverity.ERROR,
|
1112
|
+
source=DIAGNOSTICS_SOURCE_NAME,
|
1113
|
+
related_information=[
|
1114
|
+
DiagnosticRelatedInformation(
|
1115
|
+
location=Location(
|
1116
|
+
uri=str(Uri.from_path(err.source)),
|
1117
|
+
range=Range(
|
1118
|
+
start=Position(
|
1119
|
+
line=(
|
1120
|
+
err.line_no - 1
|
1121
|
+
if err.line_no is not None
|
1122
|
+
else max(
|
1123
|
+
result.library_doc.line_no,
|
1124
|
+
0,
|
1125
|
+
)
|
1127
1126
|
),
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1127
|
+
character=0,
|
1128
|
+
),
|
1129
|
+
end=Position(
|
1130
|
+
line=(
|
1131
|
+
err.line_no - 1
|
1132
|
+
if err.line_no is not None
|
1133
|
+
else max(
|
1134
|
+
result.library_doc.line_no,
|
1135
|
+
0,
|
1136
|
+
)
|
1138
1137
|
),
|
1138
|
+
character=0,
|
1139
1139
|
),
|
1140
1140
|
),
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1141
|
+
),
|
1142
|
+
message=err.message,
|
1143
|
+
)
|
1144
|
+
for err in result.library_doc.errors
|
1145
|
+
if err.source is not None
|
1146
|
+
],
|
1147
|
+
code=Error.IMPORT_CONTAINS_ERRORS,
|
1148
|
+
)
|
1149
|
+
for err in filter(
|
1150
|
+
lambda e: e.source is None or not Path(e.source).is_absolute(),
|
1151
|
+
result.library_doc.errors,
|
1152
|
+
):
|
1153
|
+
self.append_diagnostics(
|
1154
|
+
range=value.range,
|
1155
|
+
message=err.message,
|
1156
|
+
severity=DiagnosticSeverity.ERROR,
|
1157
|
+
source=DIAGNOSTICS_SOURCE_NAME,
|
1158
|
+
code=err.type_name,
|
1159
|
+
)
|
1160
|
+
elif result.library_doc.errors is not None:
|
1161
|
+
for err in result.library_doc.errors:
|
1162
|
+
self.append_diagnostics(
|
1163
|
+
range=value.range,
|
1164
|
+
message=err.message,
|
1165
|
+
severity=DiagnosticSeverity.ERROR,
|
1166
|
+
source=DIAGNOSTICS_SOURCE_NAME,
|
1167
|
+
code=err.type_name,
|
1168
|
+
)
|
1168
1169
|
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1170
|
+
except (SystemExit, KeyboardInterrupt):
|
1171
|
+
raise
|
1172
|
+
except BaseException as e:
|
1173
|
+
if top_level:
|
1174
|
+
self.append_diagnostics(
|
1175
|
+
range=value.range,
|
1176
|
+
message=str(e),
|
1177
|
+
severity=DiagnosticSeverity.ERROR,
|
1178
|
+
source=DIAGNOSTICS_SOURCE_NAME,
|
1179
|
+
code=type(e).__qualname__,
|
1180
|
+
)
|
1181
|
+
finally:
|
1182
|
+
self._reset_global_variables()
|
1183
|
+
|
1184
|
+
return result
|
1182
1185
|
|
1183
|
-
|
1186
|
+
def _import_imports(
|
1187
|
+
self,
|
1188
|
+
imports: Iterable[Import],
|
1189
|
+
base_dir: str,
|
1190
|
+
*,
|
1191
|
+
top_level: bool = False,
|
1192
|
+
variables: Optional[Dict[str, Any]] = None,
|
1193
|
+
source: Optional[str] = None,
|
1194
|
+
parent_import: Optional[Import] = None,
|
1195
|
+
depth: int = 0,
|
1196
|
+
) -> Optional[Dict[str, Any]]:
|
1184
1197
|
|
1185
1198
|
current_time = time.monotonic()
|
1186
|
-
self._logger.debug(lambda: f"start imports for {self.document if top_level else source}")
|
1199
|
+
self._logger.debug(lambda: f"{' '*depth}start imports for {self.document if top_level else source}")
|
1187
1200
|
try:
|
1188
1201
|
for imp in imports:
|
1189
1202
|
if variables is None:
|
1190
1203
|
variables = self.get_resolvable_variables()
|
1191
1204
|
|
1192
|
-
entry
|
1205
|
+
entry = self._import(
|
1206
|
+
imp,
|
1207
|
+
variables=variables,
|
1208
|
+
base_dir=base_dir,
|
1209
|
+
top_level=top_level,
|
1210
|
+
source=source,
|
1211
|
+
parent_import=parent_import,
|
1212
|
+
)
|
1193
1213
|
|
1194
1214
|
if entry is not None:
|
1195
1215
|
if isinstance(entry, ResourceEntry):
|
@@ -1201,14 +1221,18 @@ class Namespace:
|
|
1201
1221
|
|
1202
1222
|
if already_imported_resources is None and entry.library_doc.source != self.source:
|
1203
1223
|
self._resources[entry.import_name] = entry
|
1224
|
+
if entry.variables:
|
1225
|
+
variables = self.get_resolvable_variables()
|
1226
|
+
|
1204
1227
|
try:
|
1205
|
-
self._import_imports(
|
1228
|
+
variables = self._import_imports(
|
1206
1229
|
entry.imports,
|
1207
1230
|
str(Path(entry.library_doc.source).parent),
|
1208
1231
|
top_level=False,
|
1209
1232
|
variables=variables,
|
1210
1233
|
source=entry.library_doc.source,
|
1211
1234
|
parent_import=imp if top_level else parent_import,
|
1235
|
+
depth=depth + 1,
|
1212
1236
|
)
|
1213
1237
|
except (SystemExit, KeyboardInterrupt):
|
1214
1238
|
raise
|
@@ -1221,56 +1245,59 @@ class Namespace:
|
|
1221
1245
|
source=DIAGNOSTICS_SOURCE_NAME,
|
1222
1246
|
code=type(e).__qualname__,
|
1223
1247
|
)
|
1224
|
-
|
1225
|
-
if
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
else None
|
1257
|
-
),
|
1258
|
-
code=Error.RESOURCE_ALREADY_IMPORTED,
|
1259
|
-
)
|
1248
|
+
elif top_level:
|
1249
|
+
if entry.library_doc.source == self.source:
|
1250
|
+
self.append_diagnostics(
|
1251
|
+
range=entry.import_range,
|
1252
|
+
message="Recursive resource import.",
|
1253
|
+
severity=DiagnosticSeverity.INFORMATION,
|
1254
|
+
source=DIAGNOSTICS_SOURCE_NAME,
|
1255
|
+
code=Error.RECURSIVE_IMPORT,
|
1256
|
+
)
|
1257
|
+
elif (
|
1258
|
+
already_imported_resources is not None and already_imported_resources.library_doc.source
|
1259
|
+
):
|
1260
|
+
self.append_diagnostics(
|
1261
|
+
range=entry.import_range,
|
1262
|
+
message=f"Resource {entry} already imported.",
|
1263
|
+
severity=DiagnosticSeverity.INFORMATION,
|
1264
|
+
source=DIAGNOSTICS_SOURCE_NAME,
|
1265
|
+
related_information=(
|
1266
|
+
[
|
1267
|
+
DiagnosticRelatedInformation(
|
1268
|
+
location=Location(
|
1269
|
+
uri=str(Uri.from_path(already_imported_resources.import_source)),
|
1270
|
+
range=already_imported_resources.import_range,
|
1271
|
+
),
|
1272
|
+
message="",
|
1273
|
+
)
|
1274
|
+
]
|
1275
|
+
if already_imported_resources.import_source
|
1276
|
+
else None
|
1277
|
+
),
|
1278
|
+
code=Error.RESOURCE_ALREADY_IMPORTED,
|
1279
|
+
)
|
1260
1280
|
|
1261
1281
|
elif isinstance(entry, VariablesEntry):
|
1262
|
-
already_imported_variables =
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1282
|
+
already_imported_variables = next(
|
1283
|
+
(
|
1284
|
+
e
|
1285
|
+
for e in self._variables.values()
|
1286
|
+
if e.library_doc.source == entry.library_doc.source
|
1287
|
+
and e.alias == entry.alias
|
1288
|
+
and e.args == entry.args
|
1289
|
+
),
|
1290
|
+
None,
|
1291
|
+
)
|
1269
1292
|
if (
|
1270
|
-
|
1271
|
-
and
|
1272
|
-
and
|
1293
|
+
already_imported_variables is None
|
1294
|
+
and entry.library_doc is not None
|
1295
|
+
and entry.library_doc.source_or_origin
|
1273
1296
|
):
|
1297
|
+
self._variables[entry.library_doc.source_or_origin] = entry
|
1298
|
+
if entry.variables:
|
1299
|
+
variables = self.get_resolvable_variables()
|
1300
|
+
elif top_level and already_imported_variables and already_imported_variables.library_doc.source:
|
1274
1301
|
self.append_diagnostics(
|
1275
1302
|
range=entry.import_range,
|
1276
1303
|
message=f'Variables "{entry}" already imported.',
|
@@ -1280,21 +1307,18 @@ class Namespace:
|
|
1280
1307
|
[
|
1281
1308
|
DiagnosticRelatedInformation(
|
1282
1309
|
location=Location(
|
1283
|
-
uri=str(Uri.from_path(already_imported_variables
|
1284
|
-
range=already_imported_variables
|
1310
|
+
uri=str(Uri.from_path(already_imported_variables.import_source)),
|
1311
|
+
range=already_imported_variables.import_range,
|
1285
1312
|
),
|
1286
1313
|
message="",
|
1287
1314
|
)
|
1288
1315
|
]
|
1289
|
-
if already_imported_variables
|
1316
|
+
if already_imported_variables.import_source
|
1290
1317
|
else None
|
1291
1318
|
),
|
1292
1319
|
code=Error.VARIABLES_ALREADY_IMPORTED,
|
1293
1320
|
)
|
1294
1321
|
|
1295
|
-
if entry.library_doc is not None and entry.library_doc.source_or_origin:
|
1296
|
-
self._variables[entry.library_doc.source_or_origin] = entry
|
1297
|
-
|
1298
1322
|
elif isinstance(entry, LibraryEntry):
|
1299
1323
|
if top_level and entry.name == BUILTIN_LIBRARY_NAME and entry.alias is None:
|
1300
1324
|
self.append_diagnostics(
|
@@ -1320,15 +1344,23 @@ class Namespace:
|
|
1320
1344
|
)
|
1321
1345
|
continue
|
1322
1346
|
|
1323
|
-
already_imported_library =
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1347
|
+
already_imported_library = next(
|
1348
|
+
(
|
1349
|
+
e
|
1350
|
+
for e in self._libraries.values()
|
1351
|
+
if e.library_doc.source == entry.library_doc.source
|
1352
|
+
and e.library_doc.member_name == entry.library_doc.member_name
|
1353
|
+
and e.alias == entry.alias
|
1354
|
+
and e.args == entry.args
|
1355
|
+
),
|
1356
|
+
None,
|
1357
|
+
)
|
1358
|
+
if (
|
1359
|
+
already_imported_library is None
|
1360
|
+
and (entry.alias or entry.name or entry.import_name) not in self._libraries
|
1361
|
+
):
|
1362
|
+
self._libraries[entry.alias or entry.name or entry.import_name] = entry
|
1363
|
+
elif top_level and already_imported_library and already_imported_library.library_doc.source:
|
1332
1364
|
self.append_diagnostics(
|
1333
1365
|
range=entry.import_range,
|
1334
1366
|
message=f'Library "{entry}" already imported.',
|
@@ -1338,26 +1370,26 @@ class Namespace:
|
|
1338
1370
|
[
|
1339
1371
|
DiagnosticRelatedInformation(
|
1340
1372
|
location=Location(
|
1341
|
-
uri=str(Uri.from_path(already_imported_library
|
1342
|
-
range=already_imported_library
|
1373
|
+
uri=str(Uri.from_path(already_imported_library.import_source)),
|
1374
|
+
range=already_imported_library.import_range,
|
1343
1375
|
),
|
1344
1376
|
message="",
|
1345
1377
|
)
|
1346
1378
|
]
|
1347
|
-
if already_imported_library
|
1379
|
+
if already_imported_library.import_source
|
1348
1380
|
else None
|
1349
1381
|
),
|
1350
1382
|
code=Error.LIBRARY_ALREADY_IMPORTED,
|
1351
1383
|
)
|
1352
1384
|
|
1353
|
-
if (entry.alias or entry.name or entry.import_name) not in self._libraries:
|
1354
|
-
self._libraries[entry.alias or entry.name or entry.import_name] = entry
|
1355
1385
|
finally:
|
1356
1386
|
self._logger.debug(
|
1357
|
-
lambda: "end
|
1387
|
+
lambda: f"{' '*depth}end imports for "
|
1358
1388
|
f"{self.document if top_level else source} in {time.monotonic() - current_time}s"
|
1359
1389
|
)
|
1360
1390
|
|
1391
|
+
return variables
|
1392
|
+
|
1361
1393
|
def _import_default_libraries(self, variables: Optional[Dict[str, Any]] = None) -> None:
|
1362
1394
|
def _import_lib(library: str, variables: Optional[Dict[str, Any]] = None) -> Optional[LibraryEntry]:
|
1363
1395
|
try:
|
@@ -1383,8 +1415,11 @@ class Namespace:
|
|
1383
1415
|
|
1384
1416
|
self._logger.debug(lambda: f"start import default libraries for document {self.document}")
|
1385
1417
|
try:
|
1418
|
+
if variables is None:
|
1419
|
+
variables = self.get_resolvable_variables()
|
1420
|
+
|
1386
1421
|
for library in DEFAULT_LIBRARIES:
|
1387
|
-
e = _import_lib(library, variables
|
1422
|
+
e = _import_lib(library, variables)
|
1388
1423
|
if e is not None:
|
1389
1424
|
self._libraries[e.alias or e.name or e.import_name] = e
|
1390
1425
|
finally:
|
@@ -1402,12 +1437,15 @@ class Namespace:
|
|
1402
1437
|
sentinel: Any = None,
|
1403
1438
|
variables: Optional[Dict[str, Any]] = None,
|
1404
1439
|
) -> LibraryEntry:
|
1440
|
+
if variables is None:
|
1441
|
+
variables = self.get_resolvable_variables()
|
1442
|
+
|
1405
1443
|
library_doc = self.imports_manager.get_libdoc_for_library_import(
|
1406
1444
|
name,
|
1407
1445
|
args,
|
1408
1446
|
base_dir=base_dir,
|
1409
1447
|
sentinel=None if is_default_library else sentinel,
|
1410
|
-
variables=variables
|
1448
|
+
variables=variables,
|
1411
1449
|
)
|
1412
1450
|
|
1413
1451
|
return LibraryEntry(
|
@@ -1441,14 +1479,11 @@ class Namespace:
|
|
1441
1479
|
*,
|
1442
1480
|
variables: Optional[Dict[str, Any]] = None,
|
1443
1481
|
) -> ResourceEntry:
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
) = self.imports_manager.get_namespace_and_libdoc_for_resource_import(
|
1448
|
-
name,
|
1449
|
-
base_dir,
|
1450
|
-
sentinel=self,
|
1451
|
-
variables=variables or self.get_resolvable_variables(),
|
1482
|
+
if variables is None:
|
1483
|
+
variables = self.get_resolvable_variables()
|
1484
|
+
|
1485
|
+
(namespace, library_doc) = self.imports_manager.get_namespace_and_libdoc_for_resource_import(
|
1486
|
+
name, base_dir, sentinel=self, variables=variables
|
1452
1487
|
)
|
1453
1488
|
|
1454
1489
|
return ResourceEntry(
|
@@ -1481,12 +1516,15 @@ class Namespace:
|
|
1481
1516
|
*,
|
1482
1517
|
variables: Optional[Dict[str, Any]] = None,
|
1483
1518
|
) -> VariablesEntry:
|
1519
|
+
if variables is None:
|
1520
|
+
variables = self.get_resolvable_variables()
|
1521
|
+
|
1484
1522
|
library_doc = self.imports_manager.get_libdoc_for_variables_import(
|
1485
1523
|
name,
|
1486
1524
|
args,
|
1487
1525
|
base_dir=base_dir,
|
1488
1526
|
sentinel=self,
|
1489
|
-
variables=variables
|
1527
|
+
variables=variables,
|
1490
1528
|
)
|
1491
1529
|
|
1492
1530
|
return VariablesEntry(
|
@@ -1602,6 +1640,8 @@ class Namespace:
|
|
1602
1640
|
if not self._analyzed:
|
1603
1641
|
canceled = False
|
1604
1642
|
|
1643
|
+
self.ensure_initialized()
|
1644
|
+
|
1605
1645
|
self._logger.debug(lambda: f"start analyze {self.document}")
|
1606
1646
|
start_time = time.monotonic()
|
1607
1647
|
|