Update includes when files are renamed
The server advertises willRename and answers workspace/willRenameFiles with a WorkspaceEdit. A bounded core resolves quoted includes against the document directory and replaces only the spelling (relative stays relative, absolute stays absolute, angle includes untouched), with registered tests. EditorDiagnostics converts the byte edits to negotiated positions for every open overlay; a real stdio session returned the extra.hpp -> renamed.hpp edit.
This commit is contained in:
1 parent
158125ace5
commit
b0b48d961c
12 files changed
+277
-5
No files matched your search
@@ -708,6 +708,38 @@ void EditorDiagnostics::files_changed(std::span<const features::file_operations:
|
||||
}
|
||||
}
|
||||
|
||||
Json EditorDiagnostics::renamed_files(std::span<const RenamedFile> renames) const {
|
||||
auto &s = *state_;
|
||||
Json::Object changes;
|
||||
for (const auto &overlay : s.documents.list_overlays()) {
|
||||
if (!overlay || !overlay->identity.is_file_uri)
|
||||
continue;
|
||||
for (const auto &rename : renames) {
|
||||
const auto edits = features::include_update::include_edits(
|
||||
overlay->text, overlay->identity.canonical_path.native(), rename.old_path,
|
||||
rename.new_path);
|
||||
if (edits.empty())
|
||||
continue;
|
||||
auto &list = changes[overlay->identity.display_uri];
|
||||
if (!std::holds_alternative<Json::Array>(list.value))
|
||||
list = Json{Json::Array{}};
|
||||
auto &array = std::get<Json::Array>(list.value);
|
||||
for (const auto &edit : edits) {
|
||||
const auto start = overlay->offset_to_position(edit.start);
|
||||
const auto end = overlay->offset_to_position(edit.end);
|
||||
if (!start || !end)
|
||||
continue;
|
||||
array.push_back(
|
||||
Json{Json::Object{{"range", range_json(Documents::Range{*start, *end})},
|
||||
{"newText", Json{edit.replacement}}}});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (changes.empty())
|
||||
return Json{nullptr};
|
||||
return Json{Json::Object{{"changes", Json{std::move(changes)}}}};
|
||||
}
|
||||
|
||||
void EditorDiagnostics::finish_update(bool workspace_changed) {
|
||||
auto &s = *state_;
|
||||
auto overlays = s.documents.list_overlays();
|
||||
|
||||
Reference in new issue
Block a user