From e3133bea90652c8d8905cba687654aef4eb9e818 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 13 Dec 2018 20:58:13 -0800 Subject: [PATCH] cmake_minimum_required 3.8; clean up --- CMakeLists.txt | 2 +- src/messages/textDocument_completion.cc | 11 +++++------ src/messages/textDocument_signatureHelp.cc | 12 ++++++++---- src/working_files.cc | 12 +++++------- src/working_files.hh | 14 ++++---------- 5 files changed, 23 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 01f49968..bf39ebfd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.8) project(ccls LANGUAGES CXX) list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/) diff --git a/src/messages/textDocument_completion.cc b/src/messages/textDocument_completion.cc index 13621d00..3f6fa3fb 100644 --- a/src/messages/textDocument_completion.cc +++ b/src/messages/textDocument_completion.cc @@ -438,8 +438,8 @@ void MessageHandler::textDocument_completion(CompletionParam ¶m, ReplyOnce &reply) { static CompleteConsumerCache> cache; std::string path = param.textDocument.uri.GetPath(); - WorkingFile *file = wfiles->GetFile(path); - if (!file) { + WorkingFile *wf = wfiles->GetFile(path); + if (!wf) { reply.NotReady(true); return; } @@ -449,9 +449,8 @@ void MessageHandler::textDocument_completion(CompletionParam ¶m, // It shouldn't be possible, but sometimes vscode will send queries out // of order, ie, we get completion request before buffer content update. std::string buffer_line; - if (param.position.line >= 0 && - param.position.line < file->buffer_lines.size()) - buffer_line = file->buffer_lines[param.position.line]; + if (param.position.line >= 0 && param.position.line < wf->buffer_lines.size()) + buffer_line = wf->buffer_lines[param.position.line]; clang::CodeCompleteOptions CCOpts; CCOpts.IncludeBriefComments = true; @@ -487,7 +486,7 @@ void MessageHandler::textDocument_completion(CompletionParam ¶m, std::string filter; Position end_pos = param.position; Position begin_pos = - file->FindStableCompletionSource(param.position, &filter, &end_pos); + wf->GetCompletionPosition(param.position, &filter, &end_pos); #if LLVM_VERSION_MAJOR < 8 ParseIncludeLineResult preprocess = ParseIncludeLine(buffer_line); diff --git a/src/messages/textDocument_signatureHelp.cc b/src/messages/textDocument_signatureHelp.cc index 240aada3..dcb11427 100644 --- a/src/messages/textDocument_signatureHelp.cc +++ b/src/messages/textDocument_signatureHelp.cc @@ -143,11 +143,15 @@ void MessageHandler::textDocument_signatureHelp( std::string path = param.textDocument.uri.GetPath(); Position begin_pos = param.position; - if (WorkingFile *file = wfiles->GetFile(path)) { - std::string completion_text; + WorkingFile *wf = wfiles->GetFile(path); + if (!wf) { + reply.NotReady(true); + return; + } + { + std::string filter; Position end_pos = param.position; - begin_pos = file->FindStableCompletionSource(param.position, - &completion_text, &end_pos); + begin_pos = wf->GetCompletionPosition(param.position, &filter, &end_pos); } SemaManager::OnComplete callback = diff --git a/src/working_files.cc b/src/working_files.cc index 37d76c0c..771a208b 100644 --- a/src/working_files.cc +++ b/src/working_files.cc @@ -336,21 +336,19 @@ std::optional WorkingFile::GetIndexPosFromBufferPos(int line, int *column, index_lines, is_end); } -Position -WorkingFile::FindStableCompletionSource(Position position, - std::string *existing_completion, - Position *replace_end_pos) const { - int start = GetOffsetForPosition(position, buffer_content); +Position WorkingFile::GetCompletionPosition(Position pos, std::string *filter, + Position *replace_end_pos) const { + int start = GetOffsetForPosition(pos, buffer_content); int i = start; while (i > 0 && isIdentifierBody(buffer_content[i - 1])) --i; - *replace_end_pos = position; + *replace_end_pos = pos; for (int i = start; i < buffer_content.size() && isIdentifierBody(buffer_content[i]); i++) replace_end_pos->character++; - *existing_completion = buffer_content.substr(i, start - i); + *filter = buffer_content.substr(i, start - i); return GetPositionForOffset(buffer_content, i); } diff --git a/src/working_files.hh b/src/working_files.hh index 00f21371..322c81b9 100644 --- a/src/working_files.hh +++ b/src/working_files.hh @@ -50,16 +50,10 @@ struct WorkingFile { // Also resolves |column| if not NULL. std::optional GetIndexPosFromBufferPos(int line, int *column, bool is_end); - // Returns a relatively stable completion position (it jumps back until there - // is a non-alphanumeric character). - // - // The out param |is_global_completion| is set to true if this looks like a - // global completion. - // The out param |existing_completion| is set to any existing completion - // content the user has entered. - Position FindStableCompletionSource(Position position, - std::string *existing_completion, - Position *replace_end_pos) const; + // Returns the stable completion position (it jumps back until there is a + // non-alphanumeric character). + Position GetCompletionPosition(Position pos, std::string *filter, + Position *replace_end_pos) const; private: // Compute index_to_buffer and buffer_to_index.