mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-07-24 13:13:43 +00:00
feat: consider context free requests
This commit is contained in:
parent
85cc29f884
commit
788792f202
5 changed files with 83 additions and 26 deletions
|
@ -11,11 +11,9 @@ pub struct DocumentSymbolRequest {
|
|||
impl DocumentSymbolRequest {
|
||||
pub fn request(
|
||||
self,
|
||||
world: &TypstSystemWorld,
|
||||
source: Source,
|
||||
position_encoding: PositionEncoding,
|
||||
) -> Option<DocumentSymbolResponse> {
|
||||
let source = get_suitable_source_in_workspace(world, &self.path).ok()?;
|
||||
|
||||
let symbols = get_lexical_hierarchy(source.clone(), LexicalScopeKind::Symbol)?;
|
||||
|
||||
let symbols = filter_document_symbols(&symbols, &source, position_encoding);
|
||||
|
@ -74,8 +72,11 @@ mod tests {
|
|||
}
|
||||
"#,
|
||||
|world, path| {
|
||||
let request = DocumentSymbolRequest { path };
|
||||
let result = request.request(world, PositionEncoding::Utf16);
|
||||
let request = DocumentSymbolRequest { path: path.clone() };
|
||||
|
||||
let source = get_suitable_source_in_workspace(world, &path).unwrap();
|
||||
|
||||
let result = request.request(source, PositionEncoding::Utf16);
|
||||
assert_snapshot!(JsonRepr::new_redacted(result.unwrap(), &REDACT_LOC), @r###"
|
||||
[
|
||||
{
|
||||
|
|
|
@ -12,13 +12,11 @@ pub struct FoldingRangeRequest {
|
|||
impl FoldingRangeRequest {
|
||||
pub fn request(
|
||||
self,
|
||||
world: &TypstSystemWorld,
|
||||
source: Source,
|
||||
position_encoding: PositionEncoding,
|
||||
) -> Option<Vec<FoldingRange>> {
|
||||
let line_folding_only = self.line_folding_only;
|
||||
|
||||
let source = get_suitable_source_in_workspace(world, &self.path).ok()?;
|
||||
|
||||
let symbols = get_lexical_hierarchy(source.clone(), LexicalScopeKind::Block)?;
|
||||
|
||||
let mut results = vec![];
|
||||
|
@ -123,10 +121,13 @@ mod tests {
|
|||
fn test_folding_range_request() {
|
||||
run_with_source("#let a = 1;", |world, path| {
|
||||
let request = FoldingRangeRequest {
|
||||
path,
|
||||
path: path.clone(),
|
||||
line_folding_only: true,
|
||||
};
|
||||
let result = request.request(world, PositionEncoding::Utf16);
|
||||
|
||||
let source = get_suitable_source_in_workspace(world, &path).unwrap();
|
||||
|
||||
let result = request.request(source, PositionEncoding::Utf16);
|
||||
assert_snapshot!(JsonRepr::new_pure(result.unwrap()), @"[]");
|
||||
});
|
||||
let t = r#"#let a = {
|
||||
|
@ -136,10 +137,13 @@ mod tests {
|
|||
}"#;
|
||||
run_with_source(t, |world, path| {
|
||||
let request = FoldingRangeRequest {
|
||||
path,
|
||||
path: path.clone(),
|
||||
line_folding_only: true,
|
||||
};
|
||||
let result = request.request(world, PositionEncoding::Utf16);
|
||||
|
||||
let source = get_suitable_source_in_workspace(world, &path).unwrap();
|
||||
|
||||
let result = request.request(source, PositionEncoding::Utf16);
|
||||
assert_snapshot!(JsonRepr::new_pure(result.unwrap()), @r###"
|
||||
[
|
||||
{
|
||||
|
|
|
@ -42,6 +42,14 @@ mod polymorphic {
|
|||
pub path: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum FoldRequestFeature {
|
||||
PinnedFirst,
|
||||
Unique,
|
||||
Mergable,
|
||||
ContextFreeUnique,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum CompilerQueryRequest {
|
||||
OnSaveExport(OnSaveExportRequest),
|
||||
|
@ -57,7 +65,26 @@ mod polymorphic {
|
|||
FoldingRange(FoldingRangeRequest),
|
||||
SelectionRange(SelectionRangeRequest),
|
||||
}
|
||||
|
||||
impl CompilerQueryRequest {
|
||||
pub fn fold_feature(&self) -> FoldRequestFeature {
|
||||
use FoldRequestFeature::*;
|
||||
match self {
|
||||
CompilerQueryRequest::OnSaveExport(..) => Mergable,
|
||||
CompilerQueryRequest::Hover(..) => PinnedFirst,
|
||||
CompilerQueryRequest::GotoDefinition(..) => PinnedFirst,
|
||||
CompilerQueryRequest::InlayHint(..) => Unique,
|
||||
CompilerQueryRequest::Completion(..) => Mergable,
|
||||
CompilerQueryRequest::SignatureHelp(..) => PinnedFirst,
|
||||
CompilerQueryRequest::DocumentSymbol(..) => ContextFreeUnique,
|
||||
CompilerQueryRequest::Symbol(..) => Mergable,
|
||||
CompilerQueryRequest::SemanticTokensFull(..) => ContextFreeUnique,
|
||||
CompilerQueryRequest::SemanticTokensDelta(..) => ContextFreeUnique,
|
||||
CompilerQueryRequest::FoldingRange(..) => ContextFreeUnique,
|
||||
CompilerQueryRequest::SelectionRange(..) => ContextFreeUnique,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn associated_path(&self) -> Option<&Path> {
|
||||
Some(match self {
|
||||
CompilerQueryRequest::OnSaveExport(req) => &req.path,
|
||||
|
|
|
@ -9,11 +9,9 @@ pub struct SelectionRangeRequest {
|
|||
impl SelectionRangeRequest {
|
||||
pub fn request(
|
||||
self,
|
||||
world: &TypstSystemWorld,
|
||||
source: Source,
|
||||
position_encoding: PositionEncoding,
|
||||
) -> Option<Vec<SelectionRange>> {
|
||||
let source = get_suitable_source_in_workspace(world, &self.path).ok()?;
|
||||
|
||||
let mut ranges = Vec::new();
|
||||
for position in self.positions {
|
||||
let typst_offset =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue