Serve parameter inlay hints from occurrence signatures
A bounded core finds top-level argument starts (nested brackets, literals and comments aware) and projects parameter-type hints from the compiler signature, filtered to the requested range. The server advertises inlayHintProvider and serves textDocument/inlayHint through EditorDiagnostics. Registered tests cover splitting, filtering, short signatures and bounds; a real stdio session returned the std::string_view hint for the fnv1a64 argument. Refresh the parity matrix.
This commit is contained in:
1 parent
12a71ff692
commit
130cb57a7f
12 files changed
+360
-10
No files matched your search
@@ -4,6 +4,7 @@
|
||||
#include <vls/features/Completion.hpp>
|
||||
#include <vls/features/DocumentSymbols.hpp>
|
||||
#include <vls/features/IndexNavigation.hpp>
|
||||
#include <vls/features/InlayHints.hpp>
|
||||
#include <vls/features/SemanticTokens.hpp>
|
||||
#include <vls/features/SignatureHelp.hpp>
|
||||
#include <vls/features/TextStructure.hpp>
|
||||
@@ -1199,6 +1200,59 @@ Json EditorDiagnostics::semantic_tokens(std::string_view uri) const {
|
||||
return Json{Json::Object{{"data", Json{std::move(data)}}}};
|
||||
}
|
||||
|
||||
Json EditorDiagnostics::inlay_hints(std::string_view uri, Documents::Range range) const {
|
||||
auto &s = *state_;
|
||||
auto key = Documents::client_uri_key(uri);
|
||||
std::shared_ptr<const Receipt> receipt;
|
||||
std::shared_ptr<const std::vector<Occurrence>> facts;
|
||||
{
|
||||
std::lock_guard lock{s.mutex};
|
||||
const auto i = key ? s.entries.find(*key) : s.entries.end();
|
||||
if (i == s.entries.end())
|
||||
return Json{Json::Array{}};
|
||||
receipt = i->second.receipt;
|
||||
facts = i->second.occurrences;
|
||||
}
|
||||
if (!receipt || !facts || !s.valid(*receipt))
|
||||
return Json{Json::Array{}};
|
||||
const Documents::DocumentSnapshot *snapshot = nullptr;
|
||||
for (const auto &entry : receipt->capture->entries())
|
||||
if (entry.snapshot && entry.snapshot->identity.canonical_uri == *key) {
|
||||
snapshot = entry.snapshot.get();
|
||||
break;
|
||||
}
|
||||
if (!snapshot)
|
||||
return Json{Json::Array{}};
|
||||
std::vector<features::inlay_hints::Hint> hints;
|
||||
const features::inlay_hints::Range requested{{range.start.line, range.start.character},
|
||||
{range.end.line, range.end.character}};
|
||||
for (const auto &occurrence : *facts) {
|
||||
if (occurrence.use_file.get() != snapshot || occurrence.signature.empty())
|
||||
continue;
|
||||
const auto use = snapshot->range_to_offsets(occurrence.use);
|
||||
if (!use)
|
||||
continue;
|
||||
const std::vector<std::string> signatures{occurrence.signature};
|
||||
const auto produced = features::inlay_hints::parameter_hints(signatures, snapshot->text,
|
||||
use->second, requested);
|
||||
hints.insert(hints.end(), produced.begin(), produced.end());
|
||||
}
|
||||
std::ranges::sort(hints);
|
||||
const auto unique = std::ranges::unique(hints);
|
||||
hints.erase(unique.begin(), unique.end());
|
||||
Json::Array result;
|
||||
for (const auto &hint : hints) {
|
||||
if (result.size() == 256)
|
||||
break;
|
||||
result.push_back(
|
||||
Json{Json::Object{{"position", position({hint.position.line, hint.position.character})},
|
||||
{"label", Json{hint.label}},
|
||||
{"kind", Json{static_cast<std::int64_t>(hint.kind)}},
|
||||
{"paddingRight", Json{hint.padding_right}}}});
|
||||
}
|
||||
return Json{std::move(result)};
|
||||
}
|
||||
|
||||
void EditorDiagnostics::set_transactional_rename(bool supported) {
|
||||
std::lock_guard lock{state_->mutex};
|
||||
state_->transactional_rename = supported;
|
||||
|
||||
Reference in new issue
Block a user