@@ -58,7 +58,8 @@ def run(self, cmd, code):
58
58
linting in the rest of the file.
59
59
"""
60
60
self .use_cargo = self .get_view_settings ().get ('use-cargo' , False )
61
- self .use_crate_root = self .get_view_settings ().get ('use-crate-root' , False )
61
+ self .use_crate_root = self .get_view_settings ().get (
62
+ 'use-crate-root' , False )
62
63
63
64
if self .use_cargo :
64
65
current_dir = os .path .dirname (self .filename )
@@ -67,11 +68,17 @@ def run(self, cmd, code):
67
68
if self .cargo_config :
68
69
self .tempfile_suffix = '-'
69
70
70
- return util .communicate (
71
- ['cargo' , 'build' , '--manifest-path' , self .cargo_config ],
72
- code = None ,
73
- output_stream = self .error_stream ,
74
- env = self .env )
71
+ old_cwd = os .getcwd ()
72
+ os .chdir (os .path .dirname (self .cargo_config ))
73
+ try :
74
+ return util .communicate (
75
+ ['cargo' , 'build' , '--manifest-path' ,
76
+ self .cargo_config ],
77
+ code = None ,
78
+ output_stream = self .error_stream ,
79
+ env = self .env )
80
+ finally :
81
+ os .chdir (old_cwd )
75
82
76
83
if self .use_crate_root :
77
84
self .crate_root = self .locate_crate_root ()
@@ -108,6 +115,10 @@ def split_match(self, match):
108
115
When working with a crate root, the working directory is the directory of the
109
116
crate root source file.
110
117
"""
118
+ # if match:
119
+ # if os.path.basename(self.filename) != os.path.basename(match.group('file')):
120
+ # match = None
121
+
111
122
matched_file = match .group ('file' ) if match else None
112
123
113
124
if matched_file :
@@ -163,9 +174,11 @@ def locate_crate_root(self):
163
174
crate_root = self .get_view_settings ().get ('crate-root' , None )
164
175
165
176
if not crate_root :
166
- crate_root = util .find_file (os .path .dirname (self .filename ), 'main.rs' )
177
+ crate_root = util .find_file (
178
+ os .path .dirname (self .filename ), 'main.rs' )
167
179
168
180
if not crate_root :
169
- crate_root = util .find_file (os .path .dirname (self .filename ), 'lib.rs' )
181
+ crate_root = util .find_file (
182
+ os .path .dirname (self .filename ), 'lib.rs' )
170
183
171
184
return crate_root
0 commit comments