completion: Don't overwrite the following identifier (#749)

This commit is contained in:
Fangrui Song 2021-01-09 11:12:33 -08:00
parent a2d2fd8167
commit 40145807d5
4 changed files with 5 additions and 15 deletions

View File

@ -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);

View File

@ -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 =

View File

@ -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);
}

View File

@ -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.