дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
Plugin API 1.21 adds the optional completion-resolve-provider export: completion returns items with an opaque data token, and resolve is called when the user focuses one. As with LSP completionItem/resolve, the resolved detail, documentation and additional edits are filled in while the label and what the item inserts stay as listed. Plugins without the export keep the existing completion providers. Includes the SDK trait and registration, a fixture plugin with a host integration test, rebuilt plugin components and README notes. Co-authored-by: RuyimgByCN <[email protected]>
40 рядки
1.6 KiB
Rust
40 рядки
1.6 KiB
Rust
use openidea_plugin::providers::{CompletionItem, CompletionKind, Document};
|
|
use openidea_plugin::{CompletionResolveProvider, Error, Position, ResolvableCompletionItem, ResolvableCompletionList};
|
|
|
|
struct Demo;
|
|
|
|
impl CompletionResolveProvider for Demo {
|
|
fn completion(&mut self, _: &Document, _: Position, _: Option<&str>) -> ResolvableCompletionList {
|
|
ResolvableCompletionList {
|
|
items: vec![ResolvableCompletionItem {
|
|
item: CompletionItem::new("selectUser", CompletionKind::Method),
|
|
data: Some("mapper.xml#selectUser".into()),
|
|
}],
|
|
incomplete: false,
|
|
}
|
|
}
|
|
|
|
fn resolve(&mut self, _: &Document, mut entry: ResolvableCompletionItem) -> Result<CompletionItem, Error> {
|
|
entry.item.detail = entry.data;
|
|
entry.item.documentation = Some("Lazy SQL preview".into());
|
|
Ok(entry.item)
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn completion_resolve_trait_preserves_data_and_resolves_lazily() {
|
|
let mut demo = Demo;
|
|
let doc = Document {
|
|
path: "/proj/UserMapper.java".into(),
|
|
language: "java".into(),
|
|
version: 1,
|
|
text: "interface UserMapper {}".into(),
|
|
};
|
|
let list = demo.completion(&doc, Position::new(0, 0), None);
|
|
assert_eq!(list.items.len(), 1);
|
|
assert_eq!(list.items[0].data.as_deref(), Some("mapper.xml#selectUser"));
|
|
let resolved = demo.resolve(&doc, list.items.into_iter().next().unwrap()).unwrap();
|
|
assert_eq!(resolved.detail.as_deref(), Some("mapper.xml#selectUser"));
|
|
assert_eq!(resolved.documentation.as_deref(), Some("Lazy SQL preview"));
|
|
}
|