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,63 @@
|
||||
#include <vls/features/FileOperations.hpp>
|
||||
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
using namespace vls::features::file_operations;
|
||||
using Void::Testing::expect;
|
||||
using Void::Testing::require;
|
||||
|
||||
Input input(Kind kind, std::string uri, std::string old_uri = {}) {
|
||||
return {kind, std::move(uri), std::move(old_uri)};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
VOID_TEST(FileOperations, create_and_delete_map_to_presence_and_absence) {
|
||||
const std::vector<Input> inputs{input(Kind::create, "file:///project/a.cpp"),
|
||||
input(Kind::delete_, "file:///project/b.cpp")};
|
||||
const auto result = parse(inputs);
|
||||
require(result.has_value());
|
||||
require(result->changes.size() == 2);
|
||||
expect(result->changes[0] == Change{"/project/a.cpp", false});
|
||||
expect(result->changes[1] == Change{"/project/b.cpp", true});
|
||||
}
|
||||
|
||||
VOID_TEST(FileOperations, rename_reports_the_old_path_gone_and_the_new_present) {
|
||||
const std::vector<Input> inputs{
|
||||
input(Kind::rename, "file:///project/new.cpp", "file:///project/old.cpp")};
|
||||
const auto result = parse(inputs);
|
||||
require(result.has_value());
|
||||
require(result->changes.size() == 2);
|
||||
expect(result->changes[0] == Change{"/project/old.cpp", true});
|
||||
expect(result->changes[1] == Change{"/project/new.cpp", false});
|
||||
}
|
||||
|
||||
VOID_TEST(FileOperations, non_file_uris_are_ignored_not_rejected) {
|
||||
const std::vector<Input> inputs{input(Kind::create, "untitled:Untitled-1"),
|
||||
input(Kind::create, "file:///project/a.cpp")};
|
||||
const auto result = parse(inputs);
|
||||
require(result.has_value());
|
||||
expect(result->ignored == 1);
|
||||
require(result->changes.size() == 1);
|
||||
expect(result->changes.front().path == "/project/a.cpp");
|
||||
}
|
||||
|
||||
VOID_TEST(FileOperations, invalid_uris_reject_the_notification) {
|
||||
const std::vector<Input> invalid{input(Kind::create, "")};
|
||||
expect(!parse(invalid).has_value());
|
||||
const std::vector<Input> malformed{input(Kind::create, "file://host/a.cpp")};
|
||||
expect(!parse(malformed).has_value());
|
||||
}
|
||||
|
||||
VOID_TEST(FileOperations, counts_and_paths_are_bounded) {
|
||||
const std::vector<Input> inputs{input(Kind::create, "file:///project/a.cpp"),
|
||||
input(Kind::create, "file:///project/b.cpp")};
|
||||
expect(!parse(inputs, Limits{.files = 1}).has_value());
|
||||
const std::vector<Input> one{input(Kind::create, "file:///project/a.cpp")};
|
||||
expect(!parse(one, Limits{.pathBytes = 8}).has_value());
|
||||
require(parse(one, Limits{.pathBytes = 4096}).has_value());
|
||||
}
|
||||
Reference in new issue
Block a user