diff --git a/src/command_line.cc b/src/command_line.cc index fe906ffa..c9811f10 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -678,7 +678,11 @@ lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db, WorkingFiles* working_file lsTextEdit edit; edit.range = ls_location->range; edit.newText = new_text; - path_to_edit[location.path].edits.push_back(edit); + + // vscode complains if we submit overlapping text edits. + auto& edits = path_to_edit[location.path].edits; + if (std::find(edits.begin(), edits.end(), edit) == edits.end()) + edits.push_back(edit); } diff --git a/src/indexer.h b/src/indexer.h index 03d0ca44..65348422 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -205,8 +205,6 @@ struct IndexedTypeDef { std::vector derived; // Declared variables of this type. - // TODO: this needs a lot more work and lots of tests. - // TODO: add instantiation on ctor / dtor, do not add instantiation if type is ptr std::vector instantiations; // Every usage, useful for things like renames. diff --git a/src/language_server_api.cc b/src/language_server_api.cc index 70497a86..39a18772 100644 --- a/src/language_server_api.cc +++ b/src/language_server_api.cc @@ -197,6 +197,10 @@ bool lsLocation::operator==(const lsLocation& other) const { return uri == other.uri && range == other.range; } +bool lsTextEdit::operator==(const lsTextEdit& that) { + return range == that.range && newText == that.newText; +} + void Reflect(Reader& reader, lsInitializeParams::lsTrace& value) { std::string v = reader.GetString(); if (v == "off") diff --git a/src/language_server_api.h b/src/language_server_api.h index 7e63cd99..367f6cbc 100644 --- a/src/language_server_api.h +++ b/src/language_server_api.h @@ -506,6 +506,8 @@ struct lsTextEdit { // The string to be inserted. For delete operations use an // empty string. std::string newText; + + bool operator==(const lsTextEdit& that); }; MAKE_REFLECT_STRUCT(lsTextEdit, range, newText);