parent
b2e58f7207
commit
c23d036426
@ -1,3 +1,4 @@
|
|||||||
|
use std::cmp::Reverse;
|
||||||
use std::collections::{BTreeSet, HashSet};
|
use std::collections::{BTreeSet, HashSet};
|
||||||
|
|
||||||
use ecow::{eco_format, EcoString};
|
use ecow::{eco_format, EcoString};
|
||||||
@ -424,10 +425,12 @@ fn complete_imports(ctx: &mut CompletionContext) -> bool {
|
|||||||
Some(SyntaxKind::ModuleImport | SyntaxKind::ModuleInclude)
|
Some(SyntaxKind::ModuleImport | SyntaxKind::ModuleInclude)
|
||||||
);
|
);
|
||||||
if let Some(ast::Expr::Str(str)) = ctx.leaf.cast();
|
if let Some(ast::Expr::Str(str)) = ctx.leaf.cast();
|
||||||
if str.get().starts_with('@');
|
let value = str.get();
|
||||||
|
if value.starts_with('@');
|
||||||
then {
|
then {
|
||||||
|
let all_versions = value.contains(':');
|
||||||
ctx.from = ctx.leaf.offset();
|
ctx.from = ctx.leaf.offset();
|
||||||
ctx.package_completions();
|
ctx.package_completions(all_versions);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1003,8 +1006,13 @@ impl<'a> CompletionContext<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Add completions for all available packages.
|
/// Add completions for all available packages.
|
||||||
fn package_completions(&mut self) {
|
fn package_completions(&mut self, all_versions: bool) {
|
||||||
for (package, description) in self.world.packages() {
|
let mut packages: Vec<_> = self.world.packages().iter().collect();
|
||||||
|
packages.sort_by_key(|(spec, _)| (&spec.name, Reverse(spec.version)));
|
||||||
|
if !all_versions {
|
||||||
|
packages.dedup_by_key(|(spec, _)| &spec.name);
|
||||||
|
}
|
||||||
|
for (package, description) in packages {
|
||||||
self.value_completion(
|
self.value_completion(
|
||||||
None,
|
None,
|
||||||
&Value::Str(format_str!("{package}")),
|
&Value::Str(format_str!("{package}")),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user