mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-04 02:08:17 +00:00
fix: complete import path by syntax instead of type (#968)
* fix: complete import path by syntax instead of type * test: add import package tests * fix: unused item
This commit is contained in:
parent
fee46d2123
commit
ab234634a9
7 changed files with 55 additions and 14 deletions
|
@ -285,6 +285,12 @@ impl DerefMut for LocalContext {
|
|||
}
|
||||
|
||||
impl LocalContext {
|
||||
/// Set list of packages for LSP-based completion.
|
||||
#[cfg(test)]
|
||||
pub fn test_package_list(&mut self, f: impl FnOnce() -> Vec<(PackageSpec, Option<EcoString>)>) {
|
||||
self.world.registry.test_package_list(f);
|
||||
}
|
||||
|
||||
/// Set the files for LSP-based completion.
|
||||
#[cfg(test)]
|
||||
pub fn test_completion_files(&mut self, f: impl FnOnce() -> Vec<TypstFileId>) {
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
/// contains: "@preview/example:0.1.0"
|
||||
|
||||
#import "@"/* range -1..0 */
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: "Completion on \" (50..51)"
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/import_package_path.typ
|
||||
snapshot_kind: text
|
||||
---
|
||||
[
|
||||
{
|
||||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 6,
|
||||
"label": "\"@preview/example:0.1.0\"",
|
||||
"textEdit": {
|
||||
"newText": "\"@preview/example:0.1.0",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 10,
|
||||
"line": 2
|
||||
},
|
||||
"start": {
|
||||
"character": 8,
|
||||
"line": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -24,19 +24,6 @@ pub fn deref_lvalue(mut node: LinkedNode) -> Option<LinkedNode> {
|
|||
Some(node)
|
||||
}
|
||||
|
||||
pub(crate) fn find_expr_in_import(mut node: LinkedNode) -> Option<LinkedNode> {
|
||||
while let Some(parent) = node.parent() {
|
||||
if matches!(
|
||||
parent.kind(),
|
||||
SyntaxKind::ModuleImport | SyntaxKind::ModuleInclude
|
||||
) {
|
||||
return Some(node);
|
||||
}
|
||||
node = parent.clone();
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn node_ancestors<'a, 'b>(
|
||||
node: &'b LinkedNode<'a>,
|
||||
) -> impl Iterator<Item = &'b LinkedNode<'a>> {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use core::fmt;
|
||||
use std::str::FromStr;
|
||||
use std::sync::{Arc, OnceLock};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
|
@ -7,6 +8,7 @@ use std::{
|
|||
};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use reflexo_typst::package::PackageSpec;
|
||||
use reflexo_typst::world::EntryState;
|
||||
use reflexo_typst::{CompileDriverImpl, EntryManager, EntryReader, ShadowApi};
|
||||
use serde_json::{ser::PrettyFormatter, Serializer, Value};
|
||||
|
@ -85,6 +87,12 @@ pub fn run_with_ctx<T>(
|
|||
})
|
||||
.snapshot(w);
|
||||
|
||||
ctx.test_package_list(|| {
|
||||
vec![(
|
||||
PackageSpec::from_str("@preview/example:0.1.0").unwrap(),
|
||||
Some("example package (mock).".into()),
|
||||
)]
|
||||
});
|
||||
ctx.test_completion_files(Vec::new);
|
||||
ctx.test_files(|| paths);
|
||||
f(&mut ctx, p)
|
||||
|
|
|
@ -1461,7 +1461,7 @@ pub(crate) fn complete_type(ctx: &mut CompletionContext) -> Option<()> {
|
|||
let scope = ctx.surrounding_syntax();
|
||||
|
||||
crate::log_debug_ct!("complete_type: {:?} -> ({scope:?}, {ty:#?})", ctx.leaf);
|
||||
if matches!((scope, &ty), (Regular, None)) || matches!(scope, ImportList) {
|
||||
if matches!((scope, &ty), (Regular | StringContent, None)) || matches!(scope, ImportList) {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue