Skip to content

Commit f2dea82

Browse files
committed
rope_autoimport: continue on name-defined diagnostics provided by mypy
Previously the autoimport code action did only act on diagnostics which message contained "undefined name". In my case this did not trigger at all so that the plugin failed to provide code actions. This change now additionally looks at name-defined error codes provided by mypy.
1 parent 89265cd commit f2dea82

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pylsp/plugins/rope_autoimport.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,11 @@ def pylsp_code_actions(
337337
log.debug(f"textDocument/codeAction: {document} {range} {context}")
338338
code_actions = []
339339
for diagnostic in context.get("diagnostics", []):
340-
if "undefined name" not in diagnostic.get("message", "").lower():
340+
matched_message = "undefined name" not in diagnostic.get("message", "").lower()
341+
# Provided by mypy
342+
matched_code = diagnostic.get("code", "") == "name-defined"
343+
344+
if not matched_message and not matched_code:
341345
continue
342346

343347
word = get_name_or_module(document, diagnostic)

0 commit comments

Comments
 (0)