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

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 {