Skip to content

Commit

Permalink
completion: Don't overwrite the following identifier (MaskRay#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Jan 9, 2021
1 parent a2d2fd8 commit 4014580
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/messages/textDocument_completion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,8 @@ void MessageHandler::textDocument_completion(CompletionParam &param,
}

std::string filter;
Position end_pos;
Position begin_pos =
wf->getCompletionPosition(param.position, &filter, &end_pos);
Position end_pos = param.position;
Position begin_pos = wf->getCompletionPosition(param.position, &filter);

#if LLVM_VERSION_MAJOR < 8
ParseIncludeLineResult preprocess = ParseIncludeLine(buffer_line);
Expand Down
3 changes: 1 addition & 2 deletions src/messages/textDocument_signatureHelp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ void MessageHandler::textDocument_signatureHelp(
buffer_line = wf->buffer_lines[param.position.line];
{
std::string filter;
Position end_pos;
begin_pos = wf->getCompletionPosition(param.position, &filter, &end_pos);
begin_pos = wf->getCompletionPosition(param.position, &filter);
}

SemaManager::OnComplete callback =
Expand Down
9 changes: 1 addition & 8 deletions src/working_files.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,18 +339,11 @@ std::optional<int> WorkingFile::getIndexPosFromBufferPos(int line, int *column,
index_lines, is_end);
}

Position WorkingFile::getCompletionPosition(Position pos, std::string *filter,
Position *replace_end_pos) const {
Position WorkingFile::getCompletionPosition(Position pos, std::string *filter) const {
int start = getOffsetForPosition(pos, buffer_content);
int i = start;
while (i > 0 && isIdentifierBody(buffer_content[i - 1]))
--i;

*replace_end_pos = pos;
for (int i = start;
i < buffer_content.size() && isIdentifierBody(buffer_content[i]); i++)
replace_end_pos->character++;

*filter = buffer_content.substr(i, start - i);
return getPositionForOffset(buffer_content, i);
}
Expand Down
3 changes: 1 addition & 2 deletions src/working_files.hh
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ struct WorkingFile {
bool is_end);
// 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;
Position getCompletionPosition(Position pos, std::string *filter) const;

private:
// Compute index_to_buffer and buffer_to_index.
Expand Down

0 comments on commit 4014580

Please sign in to comment.