Files
Language-Server/include/vls/features/FileOperations.hpp
T
faumaray 158125ace5 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.
2026-12-05 16:03:06 +03:00

49 lines
1.3 KiB
C++

#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