Skip to content

Commit 014c32a

Browse files
committed
Find config file and better live mode
1 parent b910675 commit 014c32a

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

pyls_mypy/plugin.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import re
2+
import tempfile
3+
import os
4+
import os.path
25
import logging
36
from mypy import api as mypy_api
47
from pyls import hookimpl
@@ -38,7 +41,7 @@ def parse_line(line, document=None):
3841
# There may be a better solution, but mypy does not provide end
3942
'end': {'line': lineno, 'character': offset + 1}
4043
},
41-
'message': msg,
44+
'message': msg.replace("]", "]"),#Prevents spyder from messign it up
4245
'severity': errno
4346
}
4447
if document:
@@ -56,24 +59,38 @@ def parse_line(line, document=None):
5659
def pyls_lint(config, workspace, document, is_saved):
5760
settings = config.plugin_settings('pyls_mypy')
5861
live_mode = settings.get('live_mode', True)
62+
path = document.path
63+
while (loc:=path.rfind("\\"))>-1:
64+
p = path[:loc+1]+"mypy.ini"
65+
if os.path.isfile(p):
66+
break
67+
else:
68+
path = path[:loc]
5969
if is_saved:
6070
args = ['--incremental',
6171
'--show-column-numbers',
62-
'--follow-imports', 'silent',
63-
'--config-file', document.path[:document.path.rfind("\\")+1]+"mypy.ini",
64-
document.path]
72+
'--follow-imports', 'silent']
6573
elif live_mode:
74+
tmpFile = tempfile.NamedTemporaryFile('w', delete=False)
75+
tmpFile.write(document.source)
76+
tmpFile.flush()
6677
args = ['--incremental',
6778
'--show-column-numbers',
6879
'--follow-imports', 'silent',
69-
'--command', document.source]
80+
'--shadow-file', document.path, tmpFile.name]
7081
else:
7182
return []
72-
83+
if loc != -1:
84+
args.append('--config-file')
85+
args.append(p)
86+
args.append(document.path)
7387
if settings.get('strict', False):
7488
args.append('--strict')
7589

7690
report, errors, _ = mypy_api.run(args)
91+
if "tmpFile" in locals():
92+
tmpFile.close()
93+
os.unlink(tmpFile.name)
7794

7895
diagnostics = []
7996
for line in report.splitlines():

0 commit comments

Comments
 (0)