Handle workspace file-operation notifications
The server advertises didCreate/didRename/didDelete file operations with file-scheme filters. A bounded core converts notifications into canonical filesystem changes (rename as old-gone/new-present, non-file URIs ignored, invalid URIs rejected) with registered tests, and EditorDiagnostics invalidates every dependent index context for changed or removed paths before re-queueing open documents. A real stdio session observed the index become incomplete after a deleted header, and a malformed notification left the server answering.
This commit is contained in:
1 parent
130cb57a7f
commit
158125ace5
12 files changed
+248
-12
No files matched your search
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
#include <expected>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::features::file_operations {
|
||||
|
||||
// LSP file-operation notifications.
|
||||
enum class Kind { create, rename, delete_ };
|
||||
|
||||
// One entry of a notification's `files` array. Rename carries both URIs.
|
||||
struct Input {
|
||||
Kind kind{Kind::create};
|
||||
std::string uri;
|
||||
std::string old_uri;
|
||||
};
|
||||
|
||||
// A resulting filesystem change. `gone` means the path no longer exists at
|
||||
// that identity, so dependent analysis is invalid rather than merely stale.
|
||||
struct Change {
|
||||
std::string path;
|
||||
bool gone{};
|
||||
auto operator<=>(const Change &) const = default;
|
||||
};
|
||||
|
||||
struct Limits {
|
||||
std::size_t files{4096};
|
||||
std::size_t pathBytes{4096};
|
||||
};
|
||||
|
||||
struct Result {
|
||||
std::vector<Change> changes;
|
||||
// Non-file URIs are ignored (they cannot belong to a filesystem context).
|
||||
std::size_t ignored{};
|
||||
};
|
||||
|
||||
// Converts notifications into canonical filesystem changes. A rename yields
|
||||
// the old path as gone and the new path as present. Malformed entries are
|
||||
// rejected rather than partially applied.
|
||||
[[nodiscard]] std::expected<Result, std::string> parse(std::span<const Input>,
|
||||
const Limits & = Limits{});
|
||||
|
||||
} // namespace vls::features::file_operations
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/features/FileOperations.hpp>
|
||||
#include <vls/semantic/StockCompiler.hpp>
|
||||
|
||||
#include <functional>
|
||||
@@ -16,6 +17,9 @@ class EditorDiagnostics {
|
||||
WorkspaceSession &, const Documents::DocumentStore &, Send);
|
||||
~EditorDiagnostics();
|
||||
void set_version_support(bool);
|
||||
// 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>);
|
||||
void begin_update();
|
||||
void finish_update(bool workspace_changed = false);
|
||||
void stop();
|
||||
|
||||
Reference in new issue
Block a user