mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-04 10:18:16 +00:00
feat: pass completion configs via context (#863)
This commit is contained in:
parent
ba2f1bcfb2
commit
06773da8af
6 changed files with 33 additions and 56 deletions
|
@ -145,6 +145,23 @@ impl Analysis {
|
|||
pub fn report_alloc_stats(&self) -> String {
|
||||
AllocStats::report(self)
|
||||
}
|
||||
|
||||
/// Get configured trigger suggest command.
|
||||
pub fn trigger_suggest(&self, context: bool) -> Option<&'static str> {
|
||||
(self.completion_feat.trigger_suggest && context).then_some("editor.action.triggerSuggest")
|
||||
}
|
||||
|
||||
/// Get configured trigger parameter hints command.
|
||||
pub fn trigger_parameter_hints(&self, context: bool) -> Option<&'static str> {
|
||||
(self.completion_feat.trigger_parameter_hints && context)
|
||||
.then_some("editor.action.triggerParameterHints")
|
||||
}
|
||||
|
||||
/// Get configured trigger named completion command.
|
||||
pub fn trigger_named_completion(&self, context: bool) -> Option<&'static str> {
|
||||
(self.completion_feat.trigger_named_completion && context)
|
||||
.then_some("tinymist.triggerNamedCompletion")
|
||||
}
|
||||
}
|
||||
|
||||
/// The periscope provider.
|
||||
|
|
|
@ -48,12 +48,6 @@ pub struct CompletionRequest {
|
|||
pub explicit: bool,
|
||||
/// The character that triggered the completion, if any.
|
||||
pub trigger_character: Option<char>,
|
||||
/// 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 {
|
||||
|
@ -148,9 +142,6 @@ impl StatefulRequest for CompletionRequest {
|
|||
cursor,
|
||||
explicit,
|
||||
self.trigger_character,
|
||||
self.trigger_suggest,
|
||||
self.trigger_parameter_hints,
|
||||
self.trigger_named_completion,
|
||||
)?;
|
||||
|
||||
// Exclude it self from auto completion
|
||||
|
@ -403,9 +394,6 @@ mod tests {
|
|||
position: ctx.to_lsp_pos(s, &source),
|
||||
explicit: false,
|
||||
trigger_character,
|
||||
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 {
|
||||
|
|
|
@ -810,9 +810,6 @@ pub struct CompletionContext<'a> {
|
|||
pub cursor: usize,
|
||||
pub explicit: bool,
|
||||
pub trigger_character: Option<char>,
|
||||
pub trigger_suggest: bool,
|
||||
pub trigger_parameter_hints: bool,
|
||||
pub trigger_named_completion: bool,
|
||||
pub from: usize,
|
||||
pub from_ty: Option<Ty>,
|
||||
pub completions: Vec<Completion>,
|
||||
|
@ -833,9 +830,6 @@ impl<'a> CompletionContext<'a> {
|
|||
cursor: usize,
|
||||
explicit: bool,
|
||||
trigger_character: Option<char>,
|
||||
trigger_suggest: bool,
|
||||
trigger_parameter_hints: bool,
|
||||
trigger_named_completion: bool,
|
||||
) -> Option<Self> {
|
||||
let text = source.text();
|
||||
let root = LinkedNode::new(source.root());
|
||||
|
@ -850,9 +844,6 @@ impl<'a> CompletionContext<'a> {
|
|||
leaf,
|
||||
cursor,
|
||||
trigger_character,
|
||||
trigger_suggest,
|
||||
trigger_parameter_hints,
|
||||
trigger_named_completion,
|
||||
explicit,
|
||||
from: cursor,
|
||||
from_ty: None,
|
||||
|
@ -897,8 +888,7 @@ impl<'a> CompletionContext<'a> {
|
|||
// 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
|
||||
command: (self.trigger_suggest && snippet.contains("${"))
|
||||
.then_some("editor.action.triggerSuggest"),
|
||||
command: self.ctx.analysis.trigger_suggest(snippet.contains("${")),
|
||||
..Completion::default()
|
||||
});
|
||||
}
|
||||
|
@ -1093,9 +1083,7 @@ impl<'a> CompletionContext<'a> {
|
|||
let mut command = None;
|
||||
if parens && matches!(value, Value::Func(_)) {
|
||||
if let Value::Func(func) = value {
|
||||
command = self
|
||||
.trigger_parameter_hints
|
||||
.then_some("editor.action.triggerParameterHints");
|
||||
command = self.ctx.analysis.trigger_parameter_hints(true);
|
||||
if func
|
||||
.params()
|
||||
.is_some_and(|params| params.iter().all(|param| param.name == "self"))
|
||||
|
|
|
@ -66,6 +66,13 @@ pub struct PostfixSnippet {
|
|||
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CompletionFeat {
|
||||
/// 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,
|
||||
|
||||
/// Whether to enable postfix completion.
|
||||
pub postfix: Option<bool>,
|
||||
/// Whether to enable ufcs completion.
|
||||
|
@ -325,9 +332,7 @@ impl<'a> CompletionContext<'a> {
|
|||
label_detail,
|
||||
apply: Some("".into()),
|
||||
// range: Some(range),
|
||||
command: self
|
||||
.trigger_parameter_hints
|
||||
.then_some("editor.action.triggerParameterHints"),
|
||||
command: self.ctx.analysis.trigger_parameter_hints(true),
|
||||
..Default::default()
|
||||
};
|
||||
let fn_feat = FnCompletionFeat::default().check(kind_checker.functions.iter());
|
||||
|
@ -470,9 +475,7 @@ impl<'a> CompletionContext<'a> {
|
|||
let base = Completion {
|
||||
kind: CompletionKind::Func,
|
||||
label_detail,
|
||||
command: self
|
||||
.trigger_parameter_hints
|
||||
.then_some("editor.action.triggerParameterHints"),
|
||||
command: self.ctx.analysis.trigger_parameter_hints(true),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
@ -1150,9 +1153,7 @@ fn type_completion(
|
|||
apply: Some(eco_format!("{}: ${{}}", f)),
|
||||
label_detail: p.ty.describe(),
|
||||
detail: docs.map(Into::into),
|
||||
command: ctx
|
||||
.trigger_named_completion
|
||||
.then_some("tinymist.triggerNamedCompletion"),
|
||||
command: ctx.ctx.analysis.trigger_named_completion(true),
|
||||
..Completion::default()
|
||||
});
|
||||
}
|
||||
|
|
|
@ -293,12 +293,6 @@ pub struct Config {
|
|||
pub formatter_mode: FormatterMode,
|
||||
/// Dynamic configuration for the experimental formatter.
|
||||
pub formatter_print_width: Option<u32>,
|
||||
/// 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,
|
||||
/// Whether to remove html from markup content in responses.
|
||||
pub support_html_in_markdown: bool,
|
||||
/// Tinymist's completion features.
|
||||
|
@ -374,11 +368,11 @@ impl Config {
|
|||
assign_config!(semantic_tokens := "semanticTokens"?: SemanticTokensMode);
|
||||
assign_config!(formatter_mode := "formatterMode"?: FormatterMode);
|
||||
assign_config!(formatter_print_width := "formatterPrintWidth"?: Option<u32>);
|
||||
assign_config!(trigger_suggest := "triggerSuggest"?: bool);
|
||||
assign_config!(trigger_named_completion := "triggerNamedCompletion"?: bool);
|
||||
assign_config!(trigger_parameter_hints := "triggerParameterHints"?: bool);
|
||||
assign_config!(support_html_in_markdown := "supportHtmlInMarkdown"?: bool);
|
||||
assign_config!(completion := "completion"?: CompletionFeat);
|
||||
assign_config!(completion.trigger_suggest := "triggerSuggest"?: bool);
|
||||
assign_config!(completion.trigger_named_completion := "triggerNamedCompletion"?: bool);
|
||||
assign_config!(completion.trigger_parameter_hints := "triggerParameterHints"?: bool);
|
||||
self.compile.update_by_map(update)?;
|
||||
self.compile.validate()
|
||||
}
|
||||
|
|
|
@ -771,21 +771,10 @@ impl LanguageState {
|
|||
.context
|
||||
.and_then(|c| c.trigger_character)
|
||||
.and_then(|c| c.chars().next());
|
||||
let trigger_suggest = self.config.trigger_suggest;
|
||||
let trigger_parameter_hints = self.config.trigger_parameter_hints;
|
||||
let trigger_named_completion = self.config.trigger_named_completion;
|
||||
|
||||
run_query!(
|
||||
req_id,
|
||||
self.Completion(
|
||||
path,
|
||||
position,
|
||||
explicit,
|
||||
trigger_character,
|
||||
trigger_suggest,
|
||||
trigger_parameter_hints,
|
||||
trigger_named_completion
|
||||
)
|
||||
self.Completion(path, position, explicit, trigger_character)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue