Файли
openidea/crates/ide-plugin/tests/fixtures/completion-list/src/lib.rs
T
Alexis ad81ff442e feat(plugins): let completion providers mark their list incomplete (#5643)
A plugin's completion was asked once when the popup opened; the editor then only filtered that list, so completions built from what is typed could not be offered. A new optional export, completion-list-provider, returns the items with an incomplete flag and is called instead of providers.completion for that plugin. While the user types on in the same word, only the plugins that marked their list incomplete are asked again; the language server's list and the other plugins' items from the first request are kept. A new word, a trigger character or an incomplete server list asks everyone, as before.

API 1.15 shipped with v0.1.51, so this starts API 1.16: wit/ and the SDK copy move to @1.16.0 with ENGINE_VERSION and API_VERSION, and the checked-in components are rebuilt.

Closes #4970

Co-authored-by: Rhombicdodecahedron <[email protected]>
2026-11-24 23:04:40 +08:00

39 рядки
1.6 KiB
Rust

//! API 1.16 fixture for the optional `completion-list-provider` export: GORM-style
//! dynamic finders, built from what has been typed after the `.`, so the list is
//! marked incomplete.
use openidea_plugin::providers::{CompletionItem, CompletionKind, CompletionList, Document, Providers};
use openidea_plugin::{Error, Invocation, Plugin, Position, register_plugin};
#[derive(Default)]
struct Fixture;
impl Plugin for Fixture {
fn run_command(&mut self, id: &str, _: &Invocation, _: Option<&str>) -> Result<Option<String>, Error> {
Err(Error::NotFound(id.into()))
}
}
impl Providers for Fixture {
/// Not called once `completion_list` is exported.
fn completion(&mut self, _: &Document, _: Position, _: Option<&str>) -> Vec<CompletionItem> {
vec![CompletionItem::new("legacy", CompletionKind::Text)]
}
fn completion_list(&mut self, doc: &Document, at: Position, _: Option<&str>) -> CompletionList {
let line = doc.text.lines().nth(at.line as usize).unwrap_or_default();
// ASCII test documents: the UTF-16 column is the byte offset.
let head = &line[..(at.character as usize).min(line.len())];
let Some(dot) = head.rfind('.') else {
return vec![CompletionItem::new("findBy", CompletionKind::Method)].into();
};
let typed = &head[dot + 1..];
let items = ["Title", "Author"]
.iter()
.map(|p| CompletionItem::new(&format!("{typed}{p}"), CompletionKind::Method))
.collect();
CompletionList { items, incomplete: true }
}
}
register_plugin!(Fixture, providers, completion_list);