pub fn generate_code_lenses(
parse_result: &dyn ParseResult,
content: &str,
versions: VersionData<'_>,
formatter: &dyn EcosystemFormatter,
uri: &Uri,
command_id: &str,
) -> Vec<CodeLens>Expand description
Zero or one lens for the document, bound to command_id.
Delegates to collect_update_all_edits for the count in the lens title — the same
call the command handler makes to produce the edits it applies, so title N == edits applied holds by construction rather than by two implementations agreeing. Returns no
lens when there is nothing to update: a permanent line-0 annotation on every
up-to-date manifest would be noise.
§Examples
use deps_core::lsp_helpers::{
generate_code_lenses, DiagnosticMessages, DiagnosticPolicy, OsvNaming, PackageNaming,
PackageRendering, RequirementResolution, SourcePolicy, VersionData,
};
use deps_core::{ConcreteVersion, PackageName, ParseResult};
use std::collections::HashMap;
struct MockFormatter;
impl PackageNaming for MockFormatter {}
impl PackageRendering for MockFormatter {
fn format_version_for_text_edit(&self, version: &ConcreteVersion) -> String {
version.to_string()
}
fn package_url(&self, name: &PackageName) -> String {
format!("https://example.com/{name}")
}
}
impl RequirementResolution for MockFormatter {}
impl DiagnosticMessages for MockFormatter {}
impl DiagnosticPolicy for MockFormatter {}
impl SourcePolicy for MockFormatter {}
impl OsvNaming for MockFormatter {}
// An empty parse result yields no outdated dependencies, so no lens is generated.
let parse_result = EmptyParseResult { uri: deps_core::test_util::test_uri("/test/Cargo.toml") };
let cached = HashMap::new();
let resolved = HashMap::new();
let lenses = generate_code_lenses(
&parse_result,
"",
VersionData::new(&cached, &resolved),
&MockFormatter,
parse_result.uri(),
"deps-lsp.updateAllOutdated",
);
assert!(lenses.is_empty());