mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-07-23 04:35:00 +00:00
dev: don't complete literal themselves (#291)
This commit is contained in:
parent
cfd94b9416
commit
c8977f0052
6 changed files with 37 additions and 5 deletions
|
@ -197,6 +197,8 @@ impl<'a, 'w> PostTypeCheckWorker<'a, 'w> {
|
||||||
log::debug!("post check paren target: {container_ty:?}::{is_before:?}");
|
log::debug!("post check paren target: {container_ty:?}::{is_before:?}");
|
||||||
|
|
||||||
let mut resp = SignatureReceiver::default();
|
let mut resp = SignatureReceiver::default();
|
||||||
|
// todo: this is legal, but it makes it sometimes complete itself.
|
||||||
|
// e.g. completing `""` on `let x = ("|")`
|
||||||
resp.bounds.lbs.push(container_ty.clone());
|
resp.bounds.lbs.push(container_ty.clone());
|
||||||
|
|
||||||
let target = ParamTarget::positional_from_before(true);
|
let target = ParamTarget::positional_from_before(true);
|
||||||
|
|
|
@ -6,7 +6,7 @@ use once_cell::sync::Lazy;
|
||||||
use regex::{Captures, Regex};
|
use regex::{Captures, Regex};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
analysis::{BuiltinTy, Ty},
|
analysis::{BuiltinTy, InsTy, Ty},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
syntax::DerefTarget,
|
syntax::DerefTarget,
|
||||||
upstream::{autocomplete, complete_path, CompletionContext},
|
upstream::{autocomplete, complete_path, CompletionContext},
|
||||||
|
@ -132,7 +132,19 @@ impl StatefulRequest for CompletionRequest {
|
||||||
let is_incomplete = false;
|
let is_incomplete = false;
|
||||||
|
|
||||||
let mut items = completion_result.or_else(|| {
|
let mut items = completion_result.or_else(|| {
|
||||||
let cc_ctx = CompletionContext::new(ctx, doc, &source, cursor, explicit)?;
|
let mut cc_ctx = CompletionContext::new(ctx, doc, &source, cursor, explicit)?;
|
||||||
|
|
||||||
|
// Exclude it self from auto completion
|
||||||
|
// e.g. `#let x = (1.);`
|
||||||
|
let self_ty = cc_ctx.leaf.cast::<ast::Expr>().and_then(|exp| {
|
||||||
|
let v = cc_ctx.ctx.mini_eval(exp)?;
|
||||||
|
Some(Ty::Value(InsTy::new(v)))
|
||||||
|
});
|
||||||
|
|
||||||
|
if let Some(self_ty) = self_ty {
|
||||||
|
cc_ctx.seen_types.insert(self_ty);
|
||||||
|
};
|
||||||
|
|
||||||
let (offset, ic, mut completions, completions_items2) = autocomplete(cc_ctx)?;
|
let (offset, ic, mut completions, completions_items2) = autocomplete(cc_ctx)?;
|
||||||
if !completions_items2.is_empty() {
|
if !completions_items2.is_empty() {
|
||||||
completion_items_rest = Some(completions_items2);
|
completion_items_rest = Some(completions_items2);
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
#let font-any = /* range after 3..4 */ ("");
|
|
@ -0,0 +1,12 @@
|
||||||
|
---
|
||||||
|
source: crates/tinymist-query/src/completion.rs
|
||||||
|
description: "Completion on \" (41..42)"
|
||||||
|
expression: "JsonRepr::new_pure(results)"
|
||||||
|
input_file: crates/tinymist-query/src/fixtures/completion/paren_string.typ
|
||||||
|
---
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"isIncomplete": false,
|
||||||
|
"items": []
|
||||||
|
}
|
||||||
|
]
|
|
@ -18,7 +18,7 @@ use unscanny::Scanner;
|
||||||
|
|
||||||
use super::{plain_docs_sentence, summarize_font_family};
|
use super::{plain_docs_sentence, summarize_font_family};
|
||||||
use crate::adt::interner::Interned;
|
use crate::adt::interner::Interned;
|
||||||
use crate::analysis::{analyze_expr, analyze_import, analyze_labels, DynLabel};
|
use crate::analysis::{analyze_expr, analyze_import, analyze_labels, DynLabel, Ty};
|
||||||
use crate::AnalysisContext;
|
use crate::AnalysisContext;
|
||||||
|
|
||||||
mod ext;
|
mod ext;
|
||||||
|
@ -964,6 +964,7 @@ pub struct CompletionContext<'a, 'w> {
|
||||||
pub completions2: Vec<lsp_types::CompletionItem>,
|
pub completions2: Vec<lsp_types::CompletionItem>,
|
||||||
pub incomplete: bool,
|
pub incomplete: bool,
|
||||||
pub seen_casts: HashSet<u128>,
|
pub seen_casts: HashSet<u128>,
|
||||||
|
pub seen_types: HashSet<Ty>,
|
||||||
pub seen_fields: HashSet<Interned<str>>,
|
pub seen_fields: HashSet<Interned<str>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -994,6 +995,7 @@ impl<'a, 'w> CompletionContext<'a, 'w> {
|
||||||
completions: vec![],
|
completions: vec![],
|
||||||
completions2: vec![],
|
completions2: vec![],
|
||||||
seen_casts: HashSet::new(),
|
seen_casts: HashSet::new(),
|
||||||
|
seen_types: HashSet::new(),
|
||||||
seen_fields: HashSet::new(),
|
seen_fields: HashSet::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -692,8 +692,10 @@ fn type_completion(
|
||||||
docs: Option<&str>,
|
docs: Option<&str>,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
// Prevent duplicate completions from appearing.
|
// Prevent duplicate completions from appearing.
|
||||||
if !ctx.seen_casts.insert(typst::util::hash128(&infer_type)) {
|
if let Some(infer_type) = infer_type {
|
||||||
return Some(());
|
if !ctx.seen_types.insert(infer_type.clone()) {
|
||||||
|
return Some(());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log::info!("type_completion: {:?}", infer_type);
|
log::info!("type_completion: {:?}", infer_type);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue