Fix vscode complaining about overlapping text edits for rename

This commit is contained in:
Jacob Dufault 2017-04-20 23:56:42 -07:00
parent 1fcefb5262
commit bdd433abd4
4 changed files with 11 additions and 3 deletions

View File

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

View File

@ -205,8 +205,6 @@ struct IndexedTypeDef {
std::vector<IndexTypeId> 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<IndexVarId> instantiations;
// Every usage, useful for things like renames.

View File

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

View File

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