@@ -129,28 +129,34 @@ def pyls_code_actions(config, document, context):
129
129
# These tend to be terrible
130
130
continue
131
131
132
- # Generate the patch we would need to apply
133
- imports = importmagic .Imports (index , document .source )
134
- if variable :
135
- imports .add_import_from (module , variable )
136
- else :
137
- imports .add_import (module )
138
- start_line , end_line , text = imports .get_update ()
139
-
140
- actions .append ({
141
- 'title' : _command_title (variable , module ),
142
- 'command' : ADD_IMPORT_COMMAND ,
143
- 'arguments' : [{
144
- 'uri' : document .uri ,
145
- 'version' : document .version ,
146
- 'startLine' : start_line ,
147
- 'endLine' : end_line ,
148
- 'newText' : text
149
- }]
150
- })
132
+ actions .append (generate_add_action (document .source , index , module , variable ))
133
+
151
134
return actions
152
135
153
136
137
+ def generate_add_action (document , index , module , variable ):
138
+ # Generate the patch we would need to apply
139
+ imports = importmagic .Imports (index , document .source )
140
+ if variable :
141
+ imports .add_import_from (module , variable )
142
+ else :
143
+ imports .add_import (module )
144
+ start_line , end_line , text = imports .get_update ()
145
+
146
+ action = {
147
+ 'title' : _command_title (variable , module ),
148
+ 'command' : ADD_IMPORT_COMMAND ,
149
+ 'arguments' : [{
150
+ 'uri' : document .uri ,
151
+ 'version' : document .version ,
152
+ 'startLine' : start_line ,
153
+ 'endLine' : end_line ,
154
+ 'newText' : text
155
+ }]
156
+ }
157
+ return action
158
+
159
+
154
160
@hookimpl
155
161
def pyls_execute_command (workspace , command , arguments ):
156
162
if command != ADD_IMPORT_COMMAND :
0 commit comments