mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-07-24 13:13:43 +00:00
feat: forward const config
This commit is contained in:
parent
d49085338f
commit
0c7e67ed9a
12 changed files with 125 additions and 211 deletions
|
@ -4,7 +4,6 @@ use crate::prelude::*;
|
|||
pub struct CompletionRequest {
|
||||
pub path: PathBuf,
|
||||
pub position: LspPosition,
|
||||
pub position_encoding: PositionEncoding,
|
||||
pub explicit: bool,
|
||||
}
|
||||
|
||||
|
@ -12,16 +11,16 @@ pub fn completion(
|
|||
world: &TypstSystemWorld,
|
||||
doc: Option<Arc<TypstDocument>>,
|
||||
req: CompletionRequest,
|
||||
position_encoding: PositionEncoding,
|
||||
) -> Option<CompletionResponse> {
|
||||
let source = get_suitable_source_in_workspace(world, &req.path).ok()?;
|
||||
let typst_offset =
|
||||
lsp_to_typst::position_to_offset(req.position, req.position_encoding, &source);
|
||||
let typst_offset = lsp_to_typst::position_to_offset(req.position, position_encoding, &source);
|
||||
|
||||
let (typst_start_offset, completions) =
|
||||
typst_ide::autocomplete(world, doc.as_deref(), &source, typst_offset, req.explicit)?;
|
||||
|
||||
let lsp_start_position =
|
||||
typst_to_lsp::offset_to_position(typst_start_offset, req.position_encoding, &source);
|
||||
typst_to_lsp::offset_to_position(typst_start_offset, position_encoding, &source);
|
||||
let replace_range = LspRawRange::new(lsp_start_position, req.position);
|
||||
Some(typst_to_lsp::completions(&completions, replace_range).into())
|
||||
}
|
||||
|
|
|
@ -3,17 +3,17 @@ use crate::prelude::*;
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct DocumentSymbolRequest {
|
||||
pub path: PathBuf,
|
||||
pub position_encoding: PositionEncoding,
|
||||
}
|
||||
|
||||
pub fn document_symbol(
|
||||
world: &TypstSystemWorld,
|
||||
req: DocumentSymbolRequest,
|
||||
position_encoding: PositionEncoding,
|
||||
) -> Option<DocumentSymbolResponse> {
|
||||
let source = get_suitable_source_in_workspace(world, &req.path).ok()?;
|
||||
|
||||
let uri = Url::from_file_path(req.path).unwrap();
|
||||
let symbols = get_document_symbols(source, uri, req.position_encoding);
|
||||
let symbols = get_document_symbols(source, uri, position_encoding);
|
||||
|
||||
symbols.map(DocumentSymbolResponse::Flat)
|
||||
}
|
||||
|
|
|
@ -4,22 +4,21 @@ use crate::prelude::*;
|
|||
pub struct HoverRequest {
|
||||
pub path: PathBuf,
|
||||
pub position: LspPosition,
|
||||
pub position_encoding: PositionEncoding,
|
||||
}
|
||||
|
||||
pub fn hover(
|
||||
world: &TypstSystemWorld,
|
||||
doc: Option<Arc<TypstDocument>>,
|
||||
req: HoverRequest,
|
||||
position_encoding: PositionEncoding,
|
||||
) -> Option<Hover> {
|
||||
let source = get_suitable_source_in_workspace(world, &req.path).ok()?;
|
||||
let typst_offset =
|
||||
lsp_to_typst::position_to_offset(req.position, req.position_encoding, &source);
|
||||
let typst_offset = lsp_to_typst::position_to_offset(req.position, position_encoding, &source);
|
||||
|
||||
let typst_tooltip = typst_ide::tooltip(world, doc.as_deref(), &source, typst_offset)?;
|
||||
|
||||
let ast_node = LinkedNode::new(source.root()).leaf_at(typst_offset)?;
|
||||
let range = typst_to_lsp::range(ast_node.range(), &source, req.position_encoding);
|
||||
let range = typst_to_lsp::range(ast_node.range(), &source, position_encoding);
|
||||
|
||||
Some(Hover {
|
||||
contents: typst_to_lsp::tooltip(&typst_tooltip),
|
||||
|
|
|
@ -4,22 +4,21 @@ use crate::prelude::*;
|
|||
pub struct SelectionRangeRequest {
|
||||
pub path: PathBuf,
|
||||
pub positions: Vec<LspPosition>,
|
||||
pub position_encoding: PositionEncoding,
|
||||
}
|
||||
|
||||
pub fn selection_range(
|
||||
world: &TypstSystemWorld,
|
||||
req: SelectionRangeRequest,
|
||||
position_encoding: PositionEncoding,
|
||||
) -> Option<Vec<SelectionRange>> {
|
||||
let source = get_suitable_source_in_workspace(world, &req.path).ok()?;
|
||||
|
||||
let mut ranges = Vec::new();
|
||||
for position in req.positions {
|
||||
let typst_offset =
|
||||
lsp_to_typst::position_to_offset(position, req.position_encoding, &source);
|
||||
let typst_offset = lsp_to_typst::position_to_offset(position, position_encoding, &source);
|
||||
let tree = LinkedNode::new(source.root());
|
||||
let leaf = tree.leaf_at(typst_offset)?;
|
||||
ranges.push(range_for_node(&source, req.position_encoding, &leaf));
|
||||
ranges.push(range_for_node(&source, position_encoding, &leaf));
|
||||
}
|
||||
|
||||
Some(ranges)
|
||||
|
|
|
@ -15,7 +15,7 @@ use self::modifier_set::ModifierSet;
|
|||
use self::token_encode::encode_tokens;
|
||||
use self::typst_tokens::{Modifier, TokenType};
|
||||
|
||||
pub use self::delta::CacheInner as TokenCacheInner;
|
||||
use self::delta::CacheInner as TokenCacheInner;
|
||||
|
||||
mod delta;
|
||||
mod modifier_set;
|
||||
|
|
|
@ -4,18 +4,18 @@ use crate::{prelude::*, SemanticTokenCache};
|
|||
pub struct SemanticTokensDeltaRequest {
|
||||
pub path: PathBuf,
|
||||
pub previous_result_id: String,
|
||||
pub position_encoding: PositionEncoding,
|
||||
}
|
||||
|
||||
pub fn semantic_tokens_delta(
|
||||
cache: &SemanticTokenCache,
|
||||
source: Source,
|
||||
req: SemanticTokensDeltaRequest,
|
||||
position_encoding: PositionEncoding,
|
||||
) -> Option<SemanticTokensFullDeltaResult> {
|
||||
let (tokens, result_id) = cache.try_semantic_tokens_delta_from_result_id(
|
||||
&source,
|
||||
&req.previous_result_id,
|
||||
req.position_encoding,
|
||||
position_encoding,
|
||||
);
|
||||
|
||||
match tokens {
|
||||
|
|
|
@ -3,15 +3,15 @@ use crate::{prelude::*, SemanticTokenCache};
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct SemanticTokensFullRequest {
|
||||
pub path: PathBuf,
|
||||
pub position_encoding: PositionEncoding,
|
||||
}
|
||||
|
||||
pub fn semantic_tokens_full(
|
||||
cache: &SemanticTokenCache,
|
||||
source: Source,
|
||||
req: SemanticTokensFullRequest,
|
||||
_req: SemanticTokensFullRequest,
|
||||
position_encoding: PositionEncoding,
|
||||
) -> Option<SemanticTokensResult> {
|
||||
let (tokens, result_id) = cache.get_semantic_tokens_full(&source, req.position_encoding);
|
||||
let (tokens, result_id) = cache.get_semantic_tokens_full(&source, position_encoding);
|
||||
|
||||
Some(
|
||||
SemanticTokens {
|
||||
|
|
|
@ -4,16 +4,12 @@ use crate::prelude::*;
|
|||
pub struct SignatureHelpRequest {
|
||||
pub path: PathBuf,
|
||||
pub position: LspPosition,
|
||||
pub position_encoding: PositionEncoding,
|
||||
}
|
||||
|
||||
pub fn signature_help(
|
||||
world: &TypstSystemWorld,
|
||||
SignatureHelpRequest {
|
||||
path,
|
||||
position,
|
||||
position_encoding,
|
||||
}: SignatureHelpRequest,
|
||||
SignatureHelpRequest { path, position }: SignatureHelpRequest,
|
||||
position_encoding: PositionEncoding,
|
||||
) -> Option<SignatureHelp> {
|
||||
let source = get_suitable_source_in_workspace(world, &path).ok()?;
|
||||
let typst_offset = lsp_to_typst::position_to_offset(position, position_encoding, &source);
|
||||
|
|
|
@ -6,15 +6,12 @@ use crate::prelude::*;
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct SymbolRequest {
|
||||
pub pattern: Option<String>,
|
||||
pub position_encoding: PositionEncoding,
|
||||
}
|
||||
|
||||
pub fn symbol(
|
||||
world: &TypstSystemWorld,
|
||||
SymbolRequest {
|
||||
pattern,
|
||||
position_encoding,
|
||||
}: SymbolRequest,
|
||||
SymbolRequest { pattern }: SymbolRequest,
|
||||
position_encoding: PositionEncoding,
|
||||
) -> Option<Vec<SymbolInformation>> {
|
||||
// todo: expose source
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue