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

[WIP/RFC] Allow code actions containing an edit and a command #1760

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
27 changes: 22 additions & 5 deletions ycmd/completers/language_server/language_server_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2997,13 +2997,22 @@ def _ResolveFixit( self, request_data, fixit ):
REQUEST_TIMEOUT_COMMAND )[ 'result' ]

result = []
if 'edit' in code_action:
edit = code_action.get( 'edit' )
command = code_action.get( 'command' )
assert edit or command
if edit and command:
result.append( self.CodeActionLiteralToFixIt( request_data,
code_action ) )
self._code_action_continuation = command
result[ 0 ].keep_going = True
return responses.BuildFixItResponse( result )
if edit:
result.append( self.CodeActionLiteralToFixIt( request_data,
code_action ) )
return responses.BuildFixItResponse( result )

if 'command' in code_action:
assert not result, 'Code actions with edit and command is not supported.'
if isinstance( code_action[ 'command' ], str ):
if command:
if isinstance( command, str ):
unresolved_command_fixit = self.CommandToFixIt( request_data,
code_action )
else:
Expand All @@ -3012,7 +3021,7 @@ def _ResolveFixit( self, request_data, fixit ):
result.append( self._ResolveFixitCommand( request_data,
unresolved_command_fixit ) )

return responses.BuildFixItResponse( result )
return responses.BuildFixItResponse( result )


def _ResolveFixitCommand( self, request_data, fixit ):
Expand Down Expand Up @@ -3048,6 +3057,14 @@ def ResolveFixit( self, request_data ):
return self._ResolveFixit( request_data, request_data[ 'fixit' ] )


def NextFixIt( self, request_data ):
lsp_command = self._code_action_continuation
self._code_action_continuation = None
unresolved_command_fixit = self.CommandToFixIt( request_data, lsp_command )
fixit = self._ResolveFixitCommand( request_data, unresolved_command_fixit )
return responses.BuildFixItResponse( [ fixit ] )


def ExecuteCommand( self, request_data, args ):
if not self.ServerIsReady():
raise RuntimeError( 'Server is initializing. Please wait.' )
Expand Down
8 changes: 8 additions & 0 deletions ycmd/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ def ResolveFixit( request, response ):
return _JsonResponse( completer.ResolveFixit( request_data ), response )


@app.post( '/next_fixit' )
def NextFixit( request, response ):
request_data = RequestWrap( request.json )
completer = _GetCompleterForRequestData( request_data )

return _JsonResponse( completer.NextFixIt( request_data ), response )


@app.post( '/completions' )
def GetCompletions( request, response ):
request_data = RequestWrap( request.json )
Expand Down
6 changes: 4 additions & 2 deletions ycmd/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,13 @@ class Kind:
REFACTOR = 'refactor'


def __init__( self, location: Location, chunks, text = '', kind = None ):
def __init__( self, location: Location, chunks, text = '', kind = None, keep_going = False ):
"""location of type Location, chunks of type list<FixItChunk>"""
self.location = location
self.chunks = chunks
self.text = text
self.kind = kind
self.keep_going = keep_going


class FixItChunk:
Expand Down Expand Up @@ -334,7 +335,8 @@ def BuildFixItData( fixit ):
'chunks' : [ BuildFixitChunkData( x ) for x in fixit.chunks ],
'text': fixit.text,
'kind': fixit.kind,
'resolve': False
'resolve': False,
'keep_going': fixit.keep_going
}

if result[ 'kind' ] is None:
Expand Down
Loading