mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-07-19 18:55:01 +00:00
feat: client-side control to whether issue completion callback (#744)
* feat: client-side control to whether issue completion callback * fix: bad changes
This commit is contained in:
parent
5dd1226cdc
commit
9c87fe2fb4
8 changed files with 87 additions and 15 deletions
|
@ -45,6 +45,12 @@ pub struct CompletionRequest {
|
|||
pub position: LspPosition,
|
||||
/// Whether the completion is triggered explicitly.
|
||||
pub explicit: bool,
|
||||
/// Whether to trigger suggest completion, a.k.a. auto-completion.
|
||||
pub trigger_suggest: bool,
|
||||
/// Whether to trigger named parameter completion.
|
||||
pub trigger_named_completion: bool,
|
||||
/// Whether to trigger parameter hint, a.k.a. signature help.
|
||||
pub trigger_parameter_hints: bool,
|
||||
}
|
||||
|
||||
impl StatefulRequest for CompletionRequest {
|
||||
|
@ -131,7 +137,16 @@ impl StatefulRequest for CompletionRequest {
|
|||
let is_incomplete = false;
|
||||
|
||||
let mut items = completion_result.or_else(|| {
|
||||
let mut cc_ctx = CompletionContext::new(ctx, doc, &source, cursor, explicit)?;
|
||||
let mut cc_ctx = CompletionContext::new(
|
||||
ctx,
|
||||
doc,
|
||||
&source,
|
||||
cursor,
|
||||
explicit,
|
||||
self.trigger_suggest,
|
||||
self.trigger_parameter_hints,
|
||||
self.trigger_named_completion,
|
||||
)?;
|
||||
|
||||
// Exclude it self from auto completion
|
||||
// e.g. `#let x = (1.);`
|
||||
|
@ -372,6 +387,9 @@ mod tests {
|
|||
path: ctx.path_for_id(id).unwrap(),
|
||||
position: ctx.to_lsp_pos(s, &source),
|
||||
explicit: false,
|
||||
trigger_suggest: true,
|
||||
trigger_parameter_hints: true,
|
||||
trigger_named_completion: true,
|
||||
};
|
||||
results.push(request.request(ctx, doc.clone()).map(|resp| match resp {
|
||||
CompletionResponse::List(l) => CompletionResponse::List(CompletionList {
|
||||
|
|
|
@ -959,6 +959,9 @@ pub struct CompletionContext<'a, 'b> {
|
|||
pub leaf: LinkedNode<'a>,
|
||||
pub cursor: usize,
|
||||
pub explicit: bool,
|
||||
pub trigger_suggest: bool,
|
||||
pub trigger_parameter_hints: bool,
|
||||
pub trigger_named_completion: bool,
|
||||
pub from: usize,
|
||||
pub completions: Vec<Completion>,
|
||||
pub completions2: Vec<lsp_types::CompletionItem>,
|
||||
|
@ -970,12 +973,16 @@ pub struct CompletionContext<'a, 'b> {
|
|||
|
||||
impl<'a, 'w> CompletionContext<'a, 'w> {
|
||||
/// Create a new autocompletion context.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
ctx: &'a mut AnalysisContext<'w>,
|
||||
document: Option<&'a Document>,
|
||||
source: &'a Source,
|
||||
cursor: usize,
|
||||
explicit: bool,
|
||||
trigger_suggest: bool,
|
||||
trigger_parameter_hints: bool,
|
||||
trigger_named_completion: bool,
|
||||
) -> Option<Self> {
|
||||
let text = source.text();
|
||||
let root = LinkedNode::new(source.root());
|
||||
|
@ -989,6 +996,9 @@ impl<'a, 'w> CompletionContext<'a, 'w> {
|
|||
root,
|
||||
leaf,
|
||||
cursor,
|
||||
trigger_suggest,
|
||||
trigger_parameter_hints,
|
||||
trigger_named_completion,
|
||||
explicit,
|
||||
from: cursor,
|
||||
incomplete: true,
|
||||
|
@ -1032,10 +1042,7 @@ impl<'a, 'w> CompletionContext<'a, 'w> {
|
|||
// VS Code doesn't do that... Auto triggering suggestion only happens on typing (word
|
||||
// starts or trigger characters). However, you can use editor.action.triggerSuggest as
|
||||
// command on a suggestion to "manually" retrigger suggest after inserting one
|
||||
//
|
||||
// todo: only vscode and neovim (0.9.1) support this
|
||||
command: snippet
|
||||
.contains("${")
|
||||
command: (self.trigger_suggest && snippet.contains("${"))
|
||||
.then_some("editor.action.triggerSuggest"),
|
||||
..Completion::default()
|
||||
});
|
||||
|
@ -1231,7 +1238,9 @@ impl<'a, 'w> CompletionContext<'a, 'w> {
|
|||
let mut command = None;
|
||||
if parens && matches!(value, Value::Func(_)) {
|
||||
if let Value::Func(func) = value {
|
||||
command = Some("editor.action.triggerParameterHints");
|
||||
command = self
|
||||
.trigger_parameter_hints
|
||||
.then_some("editor.action.triggerParameterHints");
|
||||
if func
|
||||
.params()
|
||||
.is_some_and(|params| params.iter().all(|param| param.name == "self"))
|
||||
|
|
|
@ -308,8 +308,9 @@ impl<'a, 'w> CompletionContext<'a, 'w> {
|
|||
let base = Completion {
|
||||
kind: kind.clone(),
|
||||
label_detail: ty_detail,
|
||||
// todo: only vscode and neovim (0.9.1) support this
|
||||
command: Some("editor.action.triggerParameterHints"),
|
||||
command: self
|
||||
.trigger_parameter_hints
|
||||
.then_some("editor.action.triggerParameterHints"),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
@ -648,7 +649,9 @@ pub fn param_completions<'a>(
|
|||
apply: Some(eco_format!("{}: ${{}}", param.name)),
|
||||
detail: docs(),
|
||||
label_detail: None,
|
||||
command: Some("tinymist.triggerNamedCompletion"),
|
||||
command: ctx
|
||||
.trigger_named_completion
|
||||
.then_some("tinymist.triggerNamedCompletion"),
|
||||
..Completion::default()
|
||||
};
|
||||
match param.ty {
|
||||
|
@ -734,7 +737,9 @@ fn type_completion(
|
|||
label: f.into(),
|
||||
apply: Some(eco_format!("{}: ${{}}", f)),
|
||||
detail: docs.map(Into::into),
|
||||
command: Some("tinymist.triggerNamedCompletion"),
|
||||
command: ctx
|
||||
.trigger_named_completion
|
||||
.then_some("tinymist.triggerNamedCompletion"),
|
||||
..Completion::default()
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue