Skip to content

Commit

Permalink
separate action generation logic: fix linting problem
Browse files Browse the repository at this point in the history
  • Loading branch information
youben11 committed Oct 29, 2019
1 parent 4ae20c8 commit 8242066
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions pyls/plugins/importmagic_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,28 +129,34 @@ def pyls_code_actions(config, document, context):
# These tend to be terrible
continue

# Generate the patch we would need to apply
imports = importmagic.Imports(index, document.source)
if variable:
imports.add_import_from(module, variable)
else:
imports.add_import(module)
start_line, end_line, text = imports.get_update()

actions.append({
'title': _command_title(variable, module),
'command': ADD_IMPORT_COMMAND,
'arguments': [{
'uri': document.uri,
'version': document.version,
'startLine': start_line,
'endLine': end_line,
'newText': text
}]
})
actions.append(generate_add_action(document.source, index, module, variable))

return actions


def generate_add_action(document, index, module, variable):
# Generate the patch we would need to apply
imports = importmagic.Imports(index, document.source)
if variable:
imports.add_import_from(module, variable)
else:
imports.add_import(module)
start_line, end_line, text = imports.get_update()

action = {
'title': _command_title(variable, module),
'command': ADD_IMPORT_COMMAND,
'arguments': [{
'uri': document.uri,
'version': document.version,
'startLine': start_line,
'endLine': end_line,
'newText': text
}]
}
return action


@hookimpl
def pyls_execute_command(workspace, command, arguments):
if command != ADD_IMPORT_COMMAND:
Expand Down

0 comments on commit 8242066

Please sign in to comment.