1
1
import re
2
+ import tempfile
3
+ import os
4
+ import os .path
2
5
import logging
3
6
from mypy import api as mypy_api
4
7
from pyls import hookimpl
@@ -38,7 +41,7 @@ def parse_line(line, document=None):
38
41
# There may be a better solution, but mypy does not provide end
39
42
'end' : {'line' : lineno , 'character' : offset + 1 }
40
43
},
41
- 'message' : msg ,
44
+ 'message' : msg . replace ( "]" , "]" ), #Prevents spyder from messign it up
42
45
'severity' : errno
43
46
}
44
47
if document :
@@ -56,24 +59,38 @@ def parse_line(line, document=None):
56
59
def pyls_lint (config , workspace , document , is_saved ):
57
60
settings = config .plugin_settings ('pyls_mypy' )
58
61
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 ]
59
69
if is_saved :
60
70
args = ['--incremental' ,
61
71
'--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' ]
65
73
elif live_mode :
74
+ tmpFile = tempfile .NamedTemporaryFile ('w' , delete = False )
75
+ tmpFile .write (document .source )
76
+ tmpFile .flush ()
66
77
args = ['--incremental' ,
67
78
'--show-column-numbers' ,
68
79
'--follow-imports' , 'silent' ,
69
- '--command ' , document .source ]
80
+ '--shadow-file ' , document .path , tmpFile . name ]
70
81
else :
71
82
return []
72
-
83
+ if loc != - 1 :
84
+ args .append ('--config-file' )
85
+ args .append (p )
86
+ args .append (document .path )
73
87
if settings .get ('strict' , False ):
74
88
args .append ('--strict' )
75
89
76
90
report , errors , _ = mypy_api .run (args )
91
+ if "tmpFile" in locals ():
92
+ tmpFile .close ()
93
+ os .unlink (tmpFile .name )
77
94
78
95
diagnostics = []
79
96
for line in report .splitlines ():
0 commit comments