Skip to content

Commit

Permalink
Handle code actions which affect other buffers (#359)
Browse files Browse the repository at this point in the history
When a code action results in a new file, open the file in a new buffer populated with the the new content.
  • Loading branch information
tlo-johnson authored and nickspoons committed Apr 22, 2018
1 parent 297cdd9 commit d9ea240
Showing 1 changed file with 20 additions and 4 deletions.
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

0 comments on commit d9ea240

Please sign in to comment.