Serve document links for quoted includes
A bounded core resolves quoted include directives from the document directory and reports the spelling range; the server advertises documentLinkProvider and serves textDocument/documentLink from snapshots, keeping only targets that exist on disk. Angle includes are skipped because their search roots are unknown. Registered feature tests cover resolution, indentation, line counting, skipping and bounds, and the exact-capability-set assertion was updated. A real stdio session linked extra.hpp and skipped <vector> and a missing file.
This commit is contained in:
1 parent
a5b9f34c9e
commit
62d6ad01e8
13 files changed
+224
-5
No files matched your search
+1
-1
@@ -30,7 +30,7 @@ add_library(vls_protocol STATIC src/Protocol/Framing.cpp src/Protocol/Json.cpp
|
||||
src/Build/ProviderFile.cpp src/Build/CommandImport.cpp src/Build/VbsProvider.cpp
|
||||
src/Build/CompdbProvider.cpp src/DocumentSync.cpp src/WorkspaceSession.cpp src/Server.cpp
|
||||
src/semantic/Diagnostics.cpp src/semantic/SourceCatalog.cpp src/semantic/StockCompiler.cpp src/semantic/EditorDiagnostics.cpp src/semantic/Occurrences.cpp src/scheduler/Scheduler.cpp
|
||||
src/modules/ModuleGraph.cpp src/modules/ArtifactCache.cpp src/modules/GccArtifacts.cpp src/modules/ScheduledArtifacts.cpp src/index/SymbolIndex.cpp src/navigation/Navigation.cpp src/reflection/Provenance.cpp src/features/Completion.cpp src/features/IndexNavigation.cpp src/features/SignatureHelp.cpp src/features/DocumentSymbols.cpp src/features/TextStructure.cpp src/features/CodeActions.cpp src/features/SemanticTokens.cpp src/features/InlayHints.cpp src/features/FileOperations.cpp src/features/IncludeUpdate.cpp src/features/CallHierarchy.cpp src/features/CodeLens.cpp src/debug/live/LiveSession.cpp src/modules/ModuleWorkQueue.cpp src/modules/GccScan.cpp src/modules/ScanCommand.cpp)
|
||||
src/modules/ModuleGraph.cpp src/modules/ArtifactCache.cpp src/modules/GccArtifacts.cpp src/modules/ScheduledArtifacts.cpp src/index/SymbolIndex.cpp src/navigation/Navigation.cpp src/reflection/Provenance.cpp src/features/Completion.cpp src/features/IndexNavigation.cpp src/features/SignatureHelp.cpp src/features/DocumentSymbols.cpp src/features/TextStructure.cpp src/features/CodeActions.cpp src/features/SemanticTokens.cpp src/features/InlayHints.cpp src/features/FileOperations.cpp src/features/IncludeUpdate.cpp src/features/CallHierarchy.cpp src/features/CodeLens.cpp src/features/DocumentLinks.cpp src/debug/live/LiveSession.cpp src/modules/ModuleWorkQueue.cpp src/modules/GccScan.cpp src/modules/ScanCommand.cpp)
|
||||
target_include_directories(vls_protocol PUBLIC "${PROJECT_SOURCE_DIR}/include")
|
||||
target_link_libraries(vls_protocol PUBLIC Void::Data PRIVATE Void::Unicode Void::Text Void::Crypto Void::System)
|
||||
target_compile_options(vls_protocol PUBLIC -freflection PRIVATE -Wall -Wextra -Wpedantic)
|
||||
|
||||
@@ -78,6 +78,7 @@ void build(Void::Build::Project &project) {
|
||||
"src/features/IncludeUpdate.cpp",
|
||||
"src/features/CallHierarchy.cpp",
|
||||
"src/features/CodeLens.cpp",
|
||||
"src/features/DocumentLinks.cpp",
|
||||
"src/debug/live/LiveSession.cpp",
|
||||
"src/modules/ModuleWorkQueue.cpp",
|
||||
"src/modules/GccScan.cpp",
|
||||
@@ -160,7 +161,8 @@ void build(Void::Build::Project &project) {
|
||||
"tests/features/TextStructureTests.cpp", "tests/features/CodeActionsTests.cpp",
|
||||
"tests/features/SemanticTokensTests.cpp", "tests/features/InlayHintsTests.cpp",
|
||||
"tests/features/FileOperationsTests.cpp", "tests/features/IncludeUpdateTests.cpp",
|
||||
"tests/features/CallHierarchyTests.cpp", "tests/features/CodeLensTests.cpp"});
|
||||
"tests/features/CallHierarchyTests.cpp", "tests/features/CodeLensTests.cpp",
|
||||
"tests/features/DocumentLinksTests.cpp"});
|
||||
auto live_worker = project.executable("vls_live_worker_fixture");
|
||||
live_worker.cxx_standard(CxxStandard::Cxx26)
|
||||
.sources({"tests/debug/LiveWorkerFixture.cpp"})
|
||||
|
||||
@@ -23,6 +23,7 @@ missing part. Updated December 5, 2026 after semantic tokens and inlay hints.
|
||||
| textDocument/inlayHint (parameter and return types) | `vls_feature_tests`, real stdio session |
|
||||
| textDocument/codeLens + workspace/executeCommand (`vls.showReferences`) | `vls_feature_tests`, real stdio session |
|
||||
| workspace/symbol | stock occurrence corpus |
|
||||
| textDocument/documentLink (quoted includes) | `vls_feature_tests`, real stdio session |
|
||||
| workspace fileOperations (didCreate/didRename/didDelete) | `vls_feature_tests`, real stdio session |
|
||||
| workspace/willRenameFiles (include updates) | `vls_feature_tests`, real stdio session |
|
||||
| voidLanguageServer/analysisStatus, providerStatus | stdio corpora |
|
||||
|
||||
@@ -103,7 +103,7 @@ ingests occurrence facts after each analysis and the server answers
|
||||
Hash.hpp definition through it. Real persistence migrations and cross-file
|
||||
rename coverage remain open.
|
||||
|
||||
Index-backed completion (roadmap 14 first slice) is implemented: `include/vls/features/Completion.hpp`, `src/features/Completion.cpp` and registered `vls_feature_tests` cover prefix extraction, filtering with replacement ranges, label+kind deduplication, deterministic ranking and bounds. `Server.cpp` advertises `completionProvider` and answers `textDocument/completion` from the symbol index through `EditorDiagnostics::completion`; a real stdio session with the stock observer returned `fnv1a64` and `fnv1a64_update` at a real call site. Every result is marked incomplete because the index does not prove visibility. Signature help is now served from the compiler-provided occurrence signature (parameter labels and ranges, active parameter, innermost call selection) and advertised by the server. Document symbols are served from the index by path and document highlights from same-binding occurrence facts; both are advertised and were exercised over stdio with the stock observer. Selection and folding ranges are served from immutable document snapshots with registered bounded cores. Code actions now offer the compiler's own suggested fixes (quickfix) from retained published diagnostics, with SARIF fix decoding bound to the owner snapshot. Semantic tokens encode the proven call occurrences and same-file definition names, the latter with a declaration modifier, under a bounded legend. Inlay hints project parameter types from the occurrence signature at each argument start. Workspace file-operation notifications invalidate dependent index contexts and re-queue open documents. A will-rename request returns the include updates for open documents. Code lenses show index reference counts and the `vls.showReferences` command resolves them to navigation locations. Call hierarchy serves prepare and incoming calls (grouped by enclosing definition or explicitly by file) from the stock call facts. Outgoing calls are served and verified: the stock observer now reports full function extents, so nested calls are attributed to the enclosing definition. Compiler-native completion with visibility proof and deferred detail resolution remain open.
|
||||
Index-backed completion (roadmap 14 first slice) is implemented: `include/vls/features/Completion.hpp`, `src/features/Completion.cpp` and registered `vls_feature_tests` cover prefix extraction, filtering with replacement ranges, label+kind deduplication, deterministic ranking and bounds. `Server.cpp` advertises `completionProvider` and answers `textDocument/completion` from the symbol index through `EditorDiagnostics::completion`; a real stdio session with the stock observer returned `fnv1a64` and `fnv1a64_update` at a real call site. Every result is marked incomplete because the index does not prove visibility. Signature help is now served from the compiler-provided occurrence signature (parameter labels and ranges, active parameter, innermost call selection) and advertised by the server. Document symbols are served from the index by path and document highlights from same-binding occurrence facts; both are advertised and were exercised over stdio with the stock observer. Selection and folding ranges are served from immutable document snapshots with registered bounded cores. Code actions now offer the compiler's own suggested fixes (quickfix) from retained published diagnostics, with SARIF fix decoding bound to the owner snapshot. Semantic tokens encode the proven call occurrences and same-file definition names, the latter with a declaration modifier, under a bounded legend. Inlay hints project parameter types from the occurrence signature at each argument start. Workspace file-operation notifications invalidate dependent index contexts and re-queue open documents. A will-rename request returns the include updates for open documents. Document links resolve quoted includes to existing files without the compiler. Code lenses show index reference counts and the `vls.showReferences` command resolves them to navigation locations. Call hierarchy serves prepare and incoming calls (grouped by enclosing definition or explicitly by file) from the stock call facts. Outgoing calls are served and verified: the stock observer now reports full function extents, so nested calls are attributed to the enclosing definition. Compiler-native completion with visibility proof and deferred detail resolution remain open.
|
||||
|
||||
The reflection provenance representation (roadmap 12 first slice) is
|
||||
implemented as a bounded library with a registered suite: innermost-first
|
||||
|
||||
@@ -79,6 +79,25 @@ the upgraded snapshot (keeping `snapshot.prev.json`) and rewrites a legacy
|
||||
about 25-30s in a Debug build (it passed VBS at ~27s); the full CMake run then
|
||||
passed 18/18.
|
||||
|
||||
## December 5 document links for includes
|
||||
|
||||
`include/vls/features/DocumentLinks.hpp` resolves quoted include directives
|
||||
from the document's directory (angle includes are skipped because their search
|
||||
roots are unknown) and returns the spelling range per directive, with
|
||||
registered `vls_feature_tests` cases for resolution, indentation, line counting,
|
||||
skipping and bounds. `Server.cpp` advertises `documentLinkProvider` and serves
|
||||
`textDocument/documentLink` from document snapshots, keeping only targets that
|
||||
exist on disk. No compiler is involved.
|
||||
|
||||
Real stdio session on a document with `#include "extra.hpp"`,
|
||||
`#include <vector>` and `#include "missing.hpp"`:
|
||||
```
|
||||
documentLink: 1 [({'character': 10, 'line': 0}, 'extra.hpp')]
|
||||
```
|
||||
The angle include and the missing file produce no link. The exact-capability-set
|
||||
assertion in `tests/TestSupport.hpp` was updated to the fourth advertised
|
||||
capability. All 18 native suites and all 18 CMake tests passed.
|
||||
|
||||
## December 5 index schema 3 and overload-set signature help
|
||||
|
||||
`SymbolRecord` now carries the optional compiler signature and the snapshot
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::features::document_links {
|
||||
|
||||
struct Position {
|
||||
std::uint32_t line{}, character{};
|
||||
auto operator<=>(const Position &) const = default;
|
||||
};
|
||||
struct Range {
|
||||
Position start, end;
|
||||
auto operator<=>(const Range &) const = default;
|
||||
};
|
||||
|
||||
// A quoted include resolved lexically against the document's directory.
|
||||
struct Link {
|
||||
Range range; // the spelling inside the quotes
|
||||
std::string path;
|
||||
auto operator<=>(const Link &) const = default;
|
||||
};
|
||||
|
||||
struct Limits {
|
||||
std::size_t links{256};
|
||||
std::size_t pathBytes{4096};
|
||||
std::size_t scanBytes{8 * 1024 * 1024};
|
||||
};
|
||||
|
||||
// Quoted include directives in TEXT resolved from DOCUMENT_PATH's directory.
|
||||
// Angle includes are skipped because their search roots are unknown, and a
|
||||
// directive without a terminated spelling on its line is skipped. The result
|
||||
// is bounded; existence on disk is the caller's check.
|
||||
[[nodiscard]] std::vector<Link> includes(std::string_view text, std::string_view document_path,
|
||||
const Limits & = Limits{});
|
||||
|
||||
} // namespace vls::features::document_links
|
||||
@@ -2,11 +2,14 @@
|
||||
|
||||
#include <vls/DocumentSync.hpp>
|
||||
#include <vls/Json.hpp>
|
||||
#include <vls/features/DocumentLinks.hpp>
|
||||
#include <vls/semantic/EditorDiagnostics.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <condition_variable>
|
||||
#include <deque>
|
||||
#include <exception>
|
||||
#include <filesystem>
|
||||
#include <mutex>
|
||||
#include <ostream>
|
||||
#include <thread>
|
||||
@@ -305,6 +308,8 @@ DispatchResult Server::handle(std::string_view body) {
|
||||
Json{std::string{Void::LanguageServer::Documents::encoding_name(encoding)}}},
|
||||
{"textDocumentSync", Json{std::move(sync)}},
|
||||
{"workspace", Json{std::move(workspace)}}};
|
||||
capabilities.emplace("documentLinkProvider",
|
||||
Json{Json::Object{{"resolveProvider", Json{false}}}});
|
||||
if (diagnostics_) {
|
||||
capabilities.emplace("documentSymbolProvider", Json{true});
|
||||
capabilities.emplace("selectionRangeProvider", Json{true});
|
||||
@@ -441,6 +446,33 @@ DispatchResult Server::handle(std::string_view body) {
|
||||
}
|
||||
return reply(id, "result", diagnostics_->selection_ranges(*uri, selected));
|
||||
}
|
||||
if (*method == "textDocument/documentLink") {
|
||||
const auto *uri = as_string(member(member(params, "textDocument"), "uri"));
|
||||
if (!uri || !Void::LanguageServer::Documents::client_uri_key(*uri))
|
||||
return error(id, -32602, "Expected textDocument.uri");
|
||||
const auto snapshot = documents_.snapshot(*uri);
|
||||
if (!snapshot)
|
||||
return reply(id, "result", Json{Json::Array{}});
|
||||
const auto links = features::document_links::includes(
|
||||
snapshot->text, snapshot->identity.canonical_path.native());
|
||||
Json::Array result;
|
||||
for (const auto &link : links) {
|
||||
std::error_code error;
|
||||
if (!std::filesystem::exists(link.path, error))
|
||||
continue;
|
||||
const auto point = [](Void::LanguageServer::Documents::Position value) {
|
||||
return Json{
|
||||
Json::Object{{"line", Json{static_cast<std::int64_t>(value.line)}},
|
||||
{"character", Json{static_cast<std::int64_t>(value.character)}}}};
|
||||
};
|
||||
result.push_back(Json{Json::Object{
|
||||
{"range", Json{Json::Object{
|
||||
{"start", point({link.range.start.line, link.range.start.character})},
|
||||
{"end", point({link.range.end.line, link.range.end.character})}}}},
|
||||
{"target", Json{Void::LanguageServer::Documents::path_to_file_uri(link.path)}}}});
|
||||
}
|
||||
return reply(id, "result", Json{std::move(result)});
|
||||
}
|
||||
if (*method == "textDocument/codeLens") {
|
||||
if (!diagnostics_ || !diagnostics_->supports_occurrences())
|
||||
return error(id, -32601, "Method not found");
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <vls/features/DocumentLinks.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
|
||||
namespace vls::features::document_links {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
std::vector<Link> includes(std::string_view text, std::string_view document_path,
|
||||
const Limits &limits) {
|
||||
std::vector<Link> links;
|
||||
if (document_path.size() > limits.pathBytes)
|
||||
return links;
|
||||
const fs::path directory = fs::path{document_path}.parent_path();
|
||||
const auto stop = std::min(text.size(), limits.scanBytes);
|
||||
std::size_t offset{};
|
||||
std::uint32_t line_number{};
|
||||
while (offset < stop) {
|
||||
auto end = text.find('\n', offset);
|
||||
if (end == std::string_view::npos || end > stop)
|
||||
end = stop;
|
||||
auto line = text.substr(offset, end - offset);
|
||||
const auto first = line.find_first_not_of(" \t");
|
||||
if (first != std::string_view::npos) {
|
||||
line.remove_prefix(first);
|
||||
if (line.starts_with("#include")) {
|
||||
const auto rest = line.substr(8);
|
||||
const auto space = rest.find_first_not_of(" \t");
|
||||
if (space != std::string_view::npos && rest[space] == '"') {
|
||||
const auto open = offset + first + 8 + space + 1;
|
||||
const auto close = text.find('"', open);
|
||||
if (close != std::string_view::npos && close < end) {
|
||||
const auto spelling = text.substr(open, close - open);
|
||||
if (!spelling.empty() && spelling.size() <= limits.pathBytes) {
|
||||
const fs::path include{spelling};
|
||||
const auto resolved = include.is_absolute()
|
||||
? include.lexically_normal()
|
||||
: (directory / include).lexically_normal();
|
||||
const auto start = offset + first + 8 + space + 1;
|
||||
links.push_back(
|
||||
{{{line_number, static_cast<std::uint32_t>(start - offset)},
|
||||
{line_number, static_cast<std::uint32_t>(close - offset)}},
|
||||
resolved.native()});
|
||||
if (links.size() == limits.links)
|
||||
return links;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
offset = end + 1;
|
||||
++line_number;
|
||||
}
|
||||
return links;
|
||||
}
|
||||
|
||||
} // namespace vls::features::document_links
|
||||
@@ -22,7 +22,7 @@ vls_test_suite(vls_scheduler_tests scheduler/SchedulerTests.cpp)
|
||||
vls_test_suite(vls_index_tests index/SymbolIndexTests.cpp)
|
||||
vls_test_suite(vls_navigation_tests navigation/NavigationTests.cpp)
|
||||
vls_test_suite(vls_reflection_tests reflection/ProvenanceTests.cpp)
|
||||
vls_test_suite(vls_feature_tests features/CompletionTests.cpp features/IndexNavigationTests.cpp features/SignatureHelpTests.cpp features/DocumentSymbolsTests.cpp features/TextStructureTests.cpp features/CodeActionsTests.cpp features/SemanticTokensTests.cpp features/InlayHintsTests.cpp features/FileOperationsTests.cpp features/IncludeUpdateTests.cpp features/CallHierarchyTests.cpp features/CodeLensTests.cpp)
|
||||
vls_test_suite(vls_feature_tests features/CompletionTests.cpp features/IndexNavigationTests.cpp features/SignatureHelpTests.cpp features/DocumentSymbolsTests.cpp features/TextStructureTests.cpp features/CodeActionsTests.cpp features/SemanticTokensTests.cpp features/InlayHintsTests.cpp features/FileOperationsTests.cpp features/IncludeUpdateTests.cpp features/CallHierarchyTests.cpp features/CodeLensTests.cpp features/DocumentLinksTests.cpp)
|
||||
vls_test_suite(vls_live_tests debug/LiveSessionTests.cpp debug/LiveDapTests.cpp)
|
||||
target_link_libraries(vls_live_tests PRIVATE Void::System)
|
||||
add_dependencies(vls_live_tests vls_live_worker_fixture vls-dap)
|
||||
|
||||
@@ -63,7 +63,9 @@ inline void expect_sync_capabilities(const vls::Json &result,
|
||||
std::string_view encoding = "utf-16") {
|
||||
const auto &capabilities = field(result, "capabilities");
|
||||
Void::Testing::expect_eq(std::get<vls::Json::Object>(capabilities.value).size(),
|
||||
std::size_t{3});
|
||||
std::size_t{4});
|
||||
Void::Testing::expect(!std::get<bool>(
|
||||
field(field(capabilities, "documentLinkProvider"), "resolveProvider").value));
|
||||
const auto &folders = field(field(capabilities, "workspace"), "workspaceFolders");
|
||||
Void::Testing::expect(std::get<bool>(field(folders, "supported").value));
|
||||
Void::Testing::expect(std::get<bool>(field(folders, "changeNotifications").value));
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#include <vls/features/DocumentLinks.hpp>
|
||||
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
using namespace vls::features::document_links;
|
||||
using Void::Testing::expect;
|
||||
using Void::Testing::require;
|
||||
} // namespace
|
||||
|
||||
VOID_TEST(DocumentLinks, resolves_quoted_includes_from_the_document_directory) {
|
||||
const std::string text = "#pragma once\n#include \"extra.hpp\"\nint x;\n";
|
||||
const auto links = includes(text, "/project/main.cpp");
|
||||
require(links.size() == 1);
|
||||
expect(links.front().path == "/project/extra.hpp");
|
||||
expect(links.front().range.start == Position{1, 10});
|
||||
expect(links.front().range.end == Position{1, 19});
|
||||
const auto nested = includes("#include \"sub/extra.hpp\"\n", "/project/main.cpp");
|
||||
require(nested.size() == 1);
|
||||
expect(nested.front().path == "/project/sub/extra.hpp");
|
||||
}
|
||||
|
||||
VOID_TEST(DocumentLinks, skips_angle_includes_and_system_roots) {
|
||||
const std::string text = "#include <vector>\n#include \"local.hpp\"\n";
|
||||
const auto links = includes(text, "/project/main.cpp");
|
||||
require(links.size() == 1);
|
||||
expect(links.front().path == "/project/local.hpp");
|
||||
}
|
||||
|
||||
VOID_TEST(DocumentLinks, keeps_absolute_spellings) {
|
||||
const auto links = includes("#include \"/opt/inc/a.hpp\"\n", "/project/main.cpp");
|
||||
require(links.size() == 1);
|
||||
expect(links.front().path == "/opt/inc/a.hpp");
|
||||
}
|
||||
|
||||
VOID_TEST(DocumentLinks, skips_unterminated_and_indented_forms) {
|
||||
expect(includes("#include \"unterminated\n", "/project/main.cpp").empty());
|
||||
const auto indented = includes(" #include \"a.hpp\"\n", "/project/main.cpp");
|
||||
require(indented.size() == 1);
|
||||
expect(indented.front().range.start.character == 12);
|
||||
}
|
||||
|
||||
VOID_TEST(DocumentLinks, counts_lines_across_the_document) {
|
||||
const std::string text = "int a;\n\n#include \"x.hpp\"\n";
|
||||
const auto links = includes(text, "/project/main.cpp");
|
||||
require(links.size() == 1);
|
||||
expect(links.front().range.start.line == 2);
|
||||
}
|
||||
|
||||
VOID_TEST(DocumentLinks, is_bounded) {
|
||||
std::string text;
|
||||
for (int line = 0; line != 4; ++line)
|
||||
text += "#include \"a.hpp\"\n";
|
||||
expect(includes(text, "/project/main.cpp", Limits{.links = 2}).size() == 2);
|
||||
expect(includes(text, "/project/main.cpp", Limits{.scanBytes = 10}).empty());
|
||||
expect(includes(text, "/project/main.cpp", Limits{.pathBytes = 4}).empty());
|
||||
}
|
||||
Reference in new issue
Block a user