mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-07-23 12:45:04 +00:00
fix: completion in string context a bit (#351)
* fix: completion in string context a bit * fix: side effect snapshot
This commit is contained in:
parent
6967dc5a22
commit
ce8baa80b2
8 changed files with 134 additions and 3 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -4038,6 +4038,7 @@ dependencies = [
|
|||
"triomphe",
|
||||
"ttf-parser",
|
||||
"typst",
|
||||
"typst-assets",
|
||||
"typst-ts-compiler",
|
||||
"typst-ts-core",
|
||||
"unscanny",
|
||||
|
|
|
@ -57,6 +57,7 @@ once_cell.workspace = true
|
|||
insta.workspace = true
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
typst-assets = { workspace = true, features = ["fonts"] }
|
||||
typst-ts-core = { workspace = true, default-features = false, features = [
|
||||
"flat-vector",
|
||||
"vector-bbox",
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
// contains: "New Computer Modern"
|
||||
|
||||
#set text(font: ""/* range -2..0 */)
|
|
@ -0,0 +1,3 @@
|
|||
// contains: "New Computer Modern"
|
||||
|
||||
#set text(font: (""/* range -2..0 */))
|
|
@ -0,0 +1,54 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: "Completion on \"\" (52..54)"
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/modify_string.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 21,
|
||||
"label": "\"New Computer Modern\"",
|
||||
"sortText": "003",
|
||||
"textEdit": {
|
||||
"newText": "\"New Computer Modern",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 16,
|
||||
"line": 2
|
||||
},
|
||||
"start": {
|
||||
"character": 16,
|
||||
"line": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 21,
|
||||
"label": "\"New Computer Modern\"",
|
||||
"sortText": "003",
|
||||
"textEdit": {
|
||||
"newText": "New Computer Modern",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 17,
|
||||
"line": 2
|
||||
},
|
||||
"start": {
|
||||
"character": 16,
|
||||
"line": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -0,0 +1,54 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: "Completion on \"\" (53..55)"
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/modify_string_2.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 21,
|
||||
"label": "\"New Computer Modern\"",
|
||||
"sortText": "003",
|
||||
"textEdit": {
|
||||
"newText": "\"New Computer Modern",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 17,
|
||||
"line": 2
|
||||
},
|
||||
"start": {
|
||||
"character": 17,
|
||||
"line": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 21,
|
||||
"label": "\"New Computer Modern\"",
|
||||
"sortText": "003",
|
||||
"textEdit": {
|
||||
"newText": "New Computer Modern",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 18,
|
||||
"line": 2
|
||||
},
|
||||
"start": {
|
||||
"character": 18,
|
||||
"line": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -1,5 +1,6 @@
|
|||
use core::fmt;
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::{HashMap, HashSet},
|
||||
ops::Range,
|
||||
path::{Path, PathBuf},
|
||||
|
@ -105,6 +106,8 @@ pub fn run_with_sources<T>(
|
|||
};
|
||||
let mut world = TypstSystemUniverse::new(CompileOpts {
|
||||
entry: EntryOpts::new_rooted(root.as_path().into(), None),
|
||||
with_embedded_fonts: typst_assets::fonts().map(Cow::Borrowed).collect(),
|
||||
no_system_fonts: true,
|
||||
..Default::default()
|
||||
})
|
||||
.unwrap();
|
||||
|
|
|
@ -1190,9 +1190,21 @@ impl<'a, 'w> CompletionContext<'a, 'w> {
|
|||
}
|
||||
} else if at {
|
||||
apply = Some(eco_format!("at(\"{label}\")"));
|
||||
} else if label.starts_with('"') && self.after.starts_with('"') {
|
||||
if let Some(trimmed) = label.strip_suffix('"') {
|
||||
apply = Some(trimmed.into());
|
||||
} else {
|
||||
let apply_label = &mut label.as_str();
|
||||
if apply_label.ends_with('"') && self.after.starts_with('"') {
|
||||
if let Some(trimmed) = apply_label.strip_suffix('"') {
|
||||
*apply_label = trimmed;
|
||||
}
|
||||
}
|
||||
if apply_label.starts_with('"') && self.before.ends_with('"') {
|
||||
if let Some(trimmed) = apply_label.strip_prefix('"') {
|
||||
*apply_label = trimmed;
|
||||
}
|
||||
}
|
||||
|
||||
if apply_label.len() != label.len() {
|
||||
apply = Some((*apply_label).into());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue