Skip to content

Commit

Permalink
cmake_minimum_required 3.8; clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Nov 10, 2019
1 parent 20e0beb commit e3133be
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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/)
Expand Down
11 changes: 5 additions & 6 deletions src/messages/textDocument_completion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ void MessageHandler::textDocument_completion(CompletionParam &param,
ReplyOnce &reply) {
static CompleteConsumerCache<std::vector<CompletionItem>> 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;
}
Expand All @@ -449,9 +449,8 @@ void MessageHandler::textDocument_completion(CompletionParam &param,
// 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;
Expand Down Expand Up @@ -487,7 +486,7 @@ void MessageHandler::textDocument_completion(CompletionParam &param,
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);
Expand Down
12 changes: 8 additions & 4 deletions src/messages/textDocument_signatureHelp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
12 changes: 5 additions & 7 deletions src/working_files.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,21 +336,19 @@ std::optional<int> 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);
}

Expand Down
14 changes: 4 additions & 10 deletions src/working_files.hh
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,10 @@ struct WorkingFile {
// Also resolves |column| if not NULL.
std::optional<int> 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.
Expand Down

0 comments on commit e3133be

Please sign in to comment.