Skip to content

Commit 8242066

Browse files
committed
separate action generation logic: fix linting problem
1 parent 4ae20c8 commit 8242066

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

pyls/plugins/importmagic_lint.py

+25-19
Original file line numberDiff line numberDiff line change
@@ -129,28 +129,34 @@ def pyls_code_actions(config, document, context):
129129
# These tend to be terrible
130130
continue
131131

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+
151134
return actions
152135

153136

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+
154160
@hookimpl
155161
def pyls_execute_command(workspace, command, arguments):
156162
if command != ADD_IMPORT_COMMAND:

0 commit comments

Comments
 (0)