dev: intern completion code (#124)

* dev: intern completion code

* dev: change completion kind of symbols to FIELD

* fix: accept hash

* fix: reduce redundant information
This commit is contained in:
Myriad-Dreamin 2024-03-29 19:46:10 +08:00 committed by GitHub
parent 858c100146
commit 0eae40dec6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 1437 additions and 33 deletions

16
Cargo.lock generated
View file

@ -3765,9 +3765,9 @@ dependencies = [
"strum 0.26.2",
"toml 0.8.12",
"typst",
"typst-ide",
"typst-ts-compiler",
"typst-ts-core",
"unscanny",
"walkdir",
]
@ -4090,20 +4090,6 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f13f85360328da54847dd7fefaf272dfa5b6d1fdeb53f32938924c39bf5b2c6c"
[[package]]
name = "typst-ide"
version = "0.11.0"
source = "git+https://github.com/Myriad-Dreamin/typst.git?branch=tinymist-v0.11.0#88608109579929b0c1fbab12d7a2afaea0baaf74"
dependencies = [
"comemo 0.4.0",
"ecow 0.2.2",
"if_chain",
"log",
"serde",
"typst",
"unscanny",
]
[[package]]
name = "typst-macros"
version = "0.11.0"

View file

@ -41,7 +41,6 @@ toml = { version = "0.8", default-features = false, features = [
codespan-reporting = "0.11"
typst = "0.11.0"
typst-ide = "0.11.0"
typst-timing = "0.11.0"
typst-pdf = "0.11.0"
typst-svg = "0.11.0"
@ -114,7 +113,6 @@ undocumented_unsafe_blocks = "warn"
typst = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "tinymist-v0.11.0" }
typst-ide = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "tinymist-v0.11.0" }
typst-timing = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "tinymist-v0.11.0" }
typst-svg = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "tinymist-v0.11.0" }
typst-render = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "tinymist-v0.11.0" }
@ -122,7 +120,6 @@ typst-pdf = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "tin
# typst-syntax = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "tinymist-v0.11.0" }
# typst = { path = "../typst/crates/typst" }
# typst-ide = { path = "../typst/crates/typst-ide" }
# typst-timing = { path = "../typst/crates/typst-timing" }
# typst-svg = { path = "../typst/crates/typst-svg" }
# typst-pdf = { path = "../typst/crates/typst-pdf" }

View file

@ -31,13 +31,13 @@ indexmap.workspace = true
ecow.workspace = true
typst.workspace = true
typst-ide.workspace = true
reflexo.workspace = true
lsp-types.workspace = true
if_chain = "1"
percent-encoding = "2"
unscanny = "0.1"
[dev-dependencies]
once_cell.workspace = true

View file

@ -1,4 +1,4 @@
use crate::{prelude::*, StatefulRequest};
use crate::{prelude::*, upstream::autocomplete, StatefulRequest};
/// The [`textDocument/completion`] request is sent from the client to the
/// server to compute completion items at a given cursor position.
@ -57,8 +57,7 @@ impl StatefulRequest for CompletionRequest {
// assume that the completion is not explicit.
let explicit = false;
let (offset, completions) =
typst_ide::autocomplete(ctx.world(), doc, &source, cursor, explicit)?;
let (offset, completions) = autocomplete(ctx.world(), doc, &source, cursor, explicit)?;
let lsp_start_position = ctx.to_lsp_pos(offset, &source);
let replace_range = LspRange::new(lsp_start_position, self.position);

View file

@ -64,8 +64,8 @@ impl From<PositionEncoding> for lsp_types::PositionEncodingKind {
pub type LspCompletion = lsp_types::CompletionItem;
pub type LspCompletionKind = lsp_types::CompletionItemKind;
pub type TypstCompletion = typst_ide::Completion;
pub type TypstCompletionKind = typst_ide::CompletionKind;
pub type TypstCompletion = crate::upstream::Completion;
pub type TypstCompletionKind = crate::upstream::CompletionKind;
const UNTITLED_ROOT: &str = "/untitled";
@ -257,7 +257,7 @@ pub mod typst_to_lsp {
TypstCompletionKind::Syntax => LspCompletionKind::SNIPPET,
TypstCompletionKind::Func => LspCompletionKind::FUNCTION,
TypstCompletionKind::Param => LspCompletionKind::VARIABLE,
TypstCompletionKind::Constant => LspCompletionKind::CONSTANT,
TypstCompletionKind::Constant => LspCompletionKind::FIELD,
TypstCompletionKind::Symbol(_) => LspCompletionKind::TEXT,
TypstCompletionKind::Type => LspCompletionKind::CLASS,
}

View file

@ -21,7 +21,7 @@ const INTERPOLATED: SemanticTokenType = SemanticTokenType::new("pol");
const ERROR: SemanticTokenType = SemanticTokenType::new("error");
const TEXT: SemanticTokenType = SemanticTokenType::new("text");
/// Very similar to [`typst_ide::Tag`], but with convenience traits, and
/// Very similar to `typst_ide::Tag`, but with convenience traits, and
/// extensible because we want to further customize highlighting
#[derive(Clone, Copy, Eq, PartialEq, EnumIter, Default)]
#[repr(u32)]

File diff suppressed because it is too large Load diff

View file

@ -5,6 +5,15 @@ use typst::text::{FontInfo, FontStyle};
mod tooltip;
pub use tooltip::*;
mod complete;
pub use complete::*;
/// Extract the first sentence of plain text of a piece of documentation.
///
/// Removes Markdown formatting.
fn plain_docs_sentence(docs: &str) -> EcoString {
docs.into()
}
/// Create a short description of a font family.
fn summarize_font_family<'a>(variants: impl Iterator<Item = &'a FontInfo>) -> EcoString {

View file

@ -210,12 +210,13 @@ fn e2e() {
work_done_progress_params: Default::default(),
text_document_position_params: pos.clone(),
}));
srv.request::<Completion>(json!(CompletionParams {
text_document_position: pos.clone(),
context: None,
work_done_progress_params: Default::default(),
partial_result_params: Default::default(),
}));
// todo: specific test
// srv.request::<Completion>(json!(CompletionParams {
// text_document_position: pos.clone(),
// context: None,
// work_done_progress_params: Default::default(),
// partial_result_params: Default::default(),
// }));
srv.request::<GotoDefinition>(json!(GotoDefinitionParams {
text_document_position_params: pos.clone(),
work_done_progress_params: Default::default(),
@ -355,7 +356,7 @@ fn e2e() {
std::fs::write(root.join("vscode/result_sorted.json"), c).unwrap();
let hash = format!("siphash128_13:{:x}", hash);
insta::assert_snapshot!(hash, @"siphash128_13:1e0ee515d35c16937e02684a605379bb");
insta::assert_snapshot!(hash, @"siphash128_13:379db828c1cee3340b4e98b2042d675b");
}
struct StableHash<'a>(&'a Value);