void CompletionData::ExtractDataFromChunk( CXCompletionString completion_string, size_t chunk_num, bool &saw_left_paren, bool &saw_function_params, bool &saw_placeholder ) { CXCompletionChunkKind kind = clang_getCompletionChunkKind( completion_string, chunk_num ); if ( IsMainCompletionTextInfo( kind ) ) { if ( kind == CXCompletionChunk_LeftParen ) { saw_left_paren = true; } else if ( saw_left_paren && !saw_function_params && kind != CXCompletionChunk_RightParen && kind != CXCompletionChunk_Informative ) { saw_function_params = true; everything_except_return_type_.append( " " ); } else if ( saw_function_params && kind == CXCompletionChunk_RightParen ) { everything_except_return_type_.append( " " ); } if ( kind == CXCompletionChunk_Optional ) { everything_except_return_type_.append( OptionalChunkToString( completion_string, chunk_num ) ); } else { everything_except_return_type_.append( ChunkToString( completion_string, chunk_num ) ); } } switch ( kind ) { case CXCompletionChunk_ResultType: return_type_ = ChunkToString( completion_string, chunk_num ); break; case CXCompletionChunk_Placeholder: saw_placeholder = true; break; case CXCompletionChunk_TypedText: case CXCompletionChunk_Text: // need to add paren to insert string // when implementing inherited methods or declared methods in objc. case CXCompletionChunk_LeftParen: case CXCompletionChunk_RightParen: case CXCompletionChunk_HorizontalSpace: if ( !saw_placeholder ) { original_string_ += ChunkToString( completion_string, chunk_num ); } break; default: break; } }
std::string CompletionData::OptionalChunkToString( CXCompletionString completion_string, size_t chunk_num ) { std::string final_string; if ( !completion_string ) return final_string; CXCompletionString optional_completion_string = clang_getCompletionChunkCompletionString( completion_string, chunk_num ); if ( !optional_completion_string ) return final_string; size_t optional_num_chunks = clang_getNumCompletionChunks( optional_completion_string ); for ( size_t j = 0; j < optional_num_chunks; ++j ) { CXCompletionChunkKind kind = clang_getCompletionChunkKind( optional_completion_string, j ); if ( kind == CXCompletionChunk_Optional ) { final_string.append( OptionalChunkToString( optional_completion_string, j ) ); } else if ( kind == CXCompletionChunk_Placeholder ) { final_string.append( "[" + ChunkToString( optional_completion_string, j ) + "]" ); } else if ( kind == CXCompletionChunk_CurrentParameter ) { current_arg_ = "[" + ChunkToString( optional_completion_string, j ) + "]"; final_string.append( "☞ " + current_arg_ ); } else { final_string.append( ChunkToString( optional_completion_string, j ) ); } } return final_string; }
void CompletionData::ExtractDataFromChunk( CXCompletionString completion_string, uint chunk_num, bool &saw_left_paren, bool &saw_function_params ) { CXCompletionChunkKind kind = clang_getCompletionChunkKind( completion_string, chunk_num ); if ( IsMainCompletionTextInfo( kind ) ) { if ( kind == CXCompletionChunk_LeftParen ) { saw_left_paren = true; } else if ( saw_left_paren && !saw_function_params && kind != CXCompletionChunk_RightParen && kind != CXCompletionChunk_Informative ) { saw_function_params = true; everything_except_return_type_.append( " " ); } else if ( saw_function_params && kind == CXCompletionChunk_RightParen ) { everything_except_return_type_.append( " " ); } if ( kind == CXCompletionChunk_Optional ) { everything_except_return_type_.append( OptionalChunkToString( completion_string, chunk_num ) ); } else { everything_except_return_type_.append( ChunkToString( completion_string, chunk_num ) ); } } if ( kind == CXCompletionChunk_ResultType ) return_type_ = ChunkToString( completion_string, chunk_num ); if ( kind == CXCompletionChunk_TypedText ) original_string_ = ChunkToString( completion_string, chunk_num ); }