дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +02:00
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]>
41 рядки
1.9 KiB
Rust
41 рядки
1.9 KiB
Rust
use openidea_plugin::Position;
|
|
use openidea_plugin::mock::MockHost;
|
|
use openidea_plugin::providers::{CompletionItem, CompletionKind, CompletionList, Document, Providers};
|
|
|
|
/// GORM-style dynamic finders: each step depends on what has been typed, so the list is incomplete.
|
|
struct Finders;
|
|
impl Providers for Finders {
|
|
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();
|
|
let typed = &line[line.rfind('.').map_or(0, |i| i + 1)..at.character as usize];
|
|
let items = ["Title", "Author"]
|
|
.iter()
|
|
.map(|p| CompletionItem::new(&format!("{typed}{p}"), CompletionKind::Method))
|
|
.collect();
|
|
CompletionList { items, incomplete: true }
|
|
}
|
|
}
|
|
|
|
/// A provider written before API 1.16: only `completion`.
|
|
struct Keywords;
|
|
impl Providers for Keywords {
|
|
fn completion(&mut self, _: &Document, _: Position, _: Option<&str>) -> Vec<CompletionItem> {
|
|
vec![CompletionItem::new("where", CompletionKind::Keyword)]
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn completion_lists_carry_the_incomplete_flag_and_default_to_completion() {
|
|
let mock = MockHost::install();
|
|
assert_eq!(mock.completion_list(&mut Finders, Position::new(0, 0), None), None, "no editor");
|
|
mock.open_editor("/p/Book.groovy", "groovy", "Book.findByTitleAnd", &[]);
|
|
let list = mock.completion_list(&mut Finders, Position::new(0, 19), None).unwrap();
|
|
assert!(list.incomplete);
|
|
let labels: Vec<_> = list.items.iter().map(|i| i.label.as_str()).collect();
|
|
assert_eq!(labels, ["findByTitleAndTitle", "findByTitleAndAuthor"]);
|
|
|
|
let list = mock.completion_list(&mut Keywords, Position::new(0, 19), None).unwrap();
|
|
assert_eq!(list, CompletionList::from(vec![CompletionItem::new("where", CompletionKind::Keyword)]));
|
|
assert!(!list.incomplete);
|
|
}
|