Example #1
0
def _FormatRawComment(comment):
    """Strips leading indentation and comment markers from the comment string"""
    return textwrap.dedent('\n'.join([
        re.sub(STRIP_TRAILING_COMMENT, '',
               re.sub(STRIP_LEADING_COMMENT, '', line))
        for line in ToUnicode(comment).splitlines()
    ]))
Example #2
0
def _ConvertDetailedCompletionData(request_data, completion_data):
    name = completion_data['name']
    display_parts = completion_data['displayParts']
    signature = ''.join([part['text'] for part in display_parts])
    if name == signature:
        extra_menu_info = None
        detailed_info = []
    else:
        # Strip new lines and indentation from the signature to display it on one
        # line.
        extra_menu_info = re.sub('\s+', ' ', signature)
        detailed_info = [signature]

    docs = completion_data.get('documentation', [])
    detailed_info += [doc['text'].strip() for doc in docs if doc]
    detailed_info = '\n\n'.join(detailed_info)

    fixits = None
    if 'codeActions' in completion_data:
        location = responses.Location(request_data['line_num'],
                                      request_data['column_num'],
                                      request_data['filepath'])
        fixits = responses.BuildFixItResponse([
            responses.FixIt(
                location, _BuildFixItForChanges(request_data,
                                                action['changes']),
                action['description'])
            for action in completion_data['codeActions']
        ])

    return responses.BuildCompletionData(insertion_text=name,
                                         extra_menu_info=extra_menu_info,
                                         detailed_info=detailed_info,
                                         kind=completion_data['kind'],
                                         extra_data=fixits)
Example #3
0
def _FixLineEndings( old_buffer, new_buffer ):
  new_windows = "\r\n" in new_buffer
  old_windows = "\r\n" in old_buffer
  if new_windows != old_windows:
    if new_windows:
      new_buffer = new_buffer.replace( "\r\n", "\n" )
      new_buffer = new_buffer.replace( "\r", "\n" )
    else:
      new_buffer = re.sub( "\r(?!\n)|(?<!\r)\n", "\r\n", new_buffer )
  return new_buffer
Example #4
0
 def GetType(self, request_data):
     try:
         hover_value = self.GetHoverResponse(request_data)['value']
         # Last "paragraph" contains the signature/declaration - i.e. type info.
         type_info = hover_value.split('\n\n')[-1]
         # The first line might contain the info of enclosing scope.
         if type_info.startswith('// In'):
             comment, signature = type_info.split('\n', 1)
             type_info = signature + '; ' + comment
         # Condense multi-line function declarations into one line.
         type_info = re.sub(r'\s+', ' ', type_info)
         return responses.BuildDisplayMessageResponse(type_info)
     except language_server_completer.NoHoverInfoException:
         raise RuntimeError('Unknown type.')
Example #5
0
def _BuildCompletionExtraMenuAndDetailedInfo(request_data, entry):
    signature = _DisplayPartsToString(entry['displayParts'])
    if entry['name'] == signature:
        extra_menu_info = None
        detailed_info = []
    else:
        # Strip new lines and indentation from the signature to display it on one
        # line.
        extra_menu_info = re.sub('\\s+', ' ', signature)
        detailed_info = [signature]

    docs = entry.get('documentation', [])
    detailed_info += [doc['text'].strip() for doc in docs if doc]
    detailed_info = '\n\n'.join(detailed_info)

    return extra_menu_info, detailed_info
def _BuildCompletionExtraMenuAndDetailedInfo( request_data, entry ):
  display_parts = entry[ 'displayParts' ]
  signature = ''.join( [ part[ 'text' ] for part in display_parts ] )
  if entry[ 'name' ] == signature:
    extra_menu_info = None
    detailed_info = []
  else:
    # Strip new lines and indentation from the signature to display it on one
    # line.
    extra_menu_info = re.sub( '\\s+', ' ', signature )
    detailed_info = [ signature ]

  docs = entry.get( 'documentation', [] )
  detailed_info += [ doc[ 'text' ].strip() for doc in docs if doc ]
  detailed_info = '\n\n'.join( detailed_info )

  return extra_menu_info, detailed_info
def _ConvertDetailedCompletionData( request_data, completion_data ):
  name = completion_data[ 'name' ]
  display_parts = completion_data[ 'displayParts' ]
  signature = ''.join( [ part[ 'text' ] for part in display_parts ] )
  if name == signature:
    extra_menu_info = None
    detailed_info = []
  else:
    # Strip new lines and indentation from the signature to display it on one
    # line.
    extra_menu_info = re.sub( '\\s+', ' ', signature )
    detailed_info = [ signature ]

  docs = completion_data.get( 'documentation', [] )
  detailed_info += [ doc[ 'text' ].strip() for doc in docs if doc ]
  detailed_info = '\n\n'.join( detailed_info )

  fixits = None
  if 'codeActions' in completion_data:
    location = responses.Location( request_data[ 'line_num' ],
                                   request_data[ 'column_num' ],
                                   request_data[ 'filepath' ] )
    fixits = responses.BuildFixItResponse( [
      responses.FixIt( location,
                       _BuildFixItForChanges( request_data,
                                              action[ 'changes' ] ),
                       action[ 'description' ] )
      for action in completion_data[ 'codeActions' ]
    ] )

  return responses.BuildCompletionData(
    insertion_text  = name,
    extra_menu_info = extra_menu_info,
    detailed_info   = detailed_info,
    kind            = completion_data[ 'kind' ],
    extra_data      = fixits
  )
Example #8
0
def _FormatRawComment( comment ):
  """Strips leading indentation and comment markers from the comment string"""
  return textwrap.dedent(
    '\n'.join( [ re.sub( STRIP_TRAILING_COMMENT, '',
                 re.sub( STRIP_LEADING_COMMENT, '', line ) )
                 for line in ToUnicode( comment ).splitlines() ] ) )