Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle code actions requiring a separate file than the current buffer #359

Merged
merged 4 commits into from
Apr 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions python/OmniSharp.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,21 @@ def getCodeActions(mode, version='v1'):
return []

def runCodeAction(mode, action, version='v1'):
def __applyChange(changeDefinition):
filename = formatPathForClient(changeDefinition['FileName'])
openFile(filename, 1, 1)
if __isBufferChange(changeDefinition):
setBufferText(changeDefinition['Buffer'])
elif __isNewFile(changeDefinition):
for change in changeDefinition['Changes']:
setBufferText(change['NewText'])

def __isBufferChange(changeDefinition):
return 'Buffer' in changeDefinition and changeDefinition['Buffer'] != None

def __isNewFile(changeDefinition):
return 'Changes' in changeDefinition and changeDefinition['Changes'] != None

parameters = codeActionParameters(mode, version)
if version == 'v1':
parameters['codeaction'] = action
Expand All @@ -159,10 +174,11 @@ def runCodeAction(mode, action, version='v1'):
res = getResponse('/v2/runcodeaction', parameters)
js = json.loads(res)
if 'Changes' in js:
for c in js['Changes']:
if 'ModificationType' in c and c['ModificationType'] == 0 and 'Buffer' in c:
setBufferText(c['Buffer'])
return True
vim.command("let cursor_position = getcurpos()")
for changeDefinition in js['Changes']:
__applyChange(changeDefinition)
vim.command("call setpos('.', cursor_position)")
return True
return False

def codeActionParameters(mode, version='v1'):
Expand Down