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
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::features::include_update {
|
||||
|
||||
// One edit as byte offsets into the document text. The caller converts them to
|
||||
// negotiated LSP positions with the document snapshot.
|
||||
struct Edit {
|
||||
std::size_t start{}, end{};
|
||||
std::string replacement;
|
||||
auto operator<=>(const Edit &) const = default;
|
||||
};
|
||||
|
||||
struct Limits {
|
||||
std::size_t edits{256};
|
||||
std::size_t pathBytes{4096};
|
||||
std::size_t scanBytes{8 * 1024 * 1024};
|
||||
};
|
||||
|
||||
// Edits for every quoted include directive in TEXT that resolves from the
|
||||
// document's directory to OLD_PATH, replacing the spelling with NEW_PATH
|
||||
// relative to that directory (or absolute when it was absolute). Angle
|
||||
// includes are never touched because their search roots are unknown.
|
||||
[[nodiscard]] std::vector<Edit> include_edits(std::string_view text, std::string_view document_path,
|
||||
std::string_view old_path, std::string_view new_path,
|
||||
const Limits & = Limits{});
|
||||
|
||||
} // namespace vls::features::include_update
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/features/FileOperations.hpp>
|
||||
#include <vls/features/IncludeUpdate.hpp>
|
||||
#include <vls/semantic/StockCompiler.hpp>
|
||||
|
||||
#include <functional>
|
||||
@@ -20,6 +21,13 @@ class EditorDiagnostics {
|
||||
// Filesystem changes from workspace file-operation notifications. Paths
|
||||
// that changed or disappeared invalidate every dependent analysis context.
|
||||
void files_changed(std::span<const features::file_operations::Change>);
|
||||
struct RenamedFile {
|
||||
std::string old_path, new_path;
|
||||
};
|
||||
// Workspace edit updating quoted includes in open documents that resolve
|
||||
// to a renamed path. Null when nothing would change.
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json
|
||||
renamed_files(std::span<const RenamedFile>) const;
|
||||
void begin_update();
|
||||
void finish_update(bool workspace_changed = false);
|
||||
void stop();
|
||||
|
||||
Reference in new issue
Block a user