tinymist_query/
document_link.rs1use crate::{SemanticRequest, analysis::get_link_exprs, prelude::*};
2
3#[derive(Debug, Clone)]
16pub struct DocumentLinkRequest {
17 pub path: PathBuf,
19}
20
21impl SemanticRequest for DocumentLinkRequest {
22 type Response = Vec<DocumentLink>;
23
24 fn request(self, ctx: &mut LocalContext) -> Option<Self::Response> {
25 let source = ctx.source_by_path(&self.path).ok()?;
26 let links = get_link_exprs(&source);
27 if links.objects.is_empty() {
28 return None;
29 }
30
31 let links = links.objects.iter().map(|obj| DocumentLink {
32 range: ctx.to_lsp_range(obj.range.clone(), &source),
33 target: obj.target.resolve(ctx),
34 tooltip: None,
35 data: None,
36 });
37 Some(links.collect())
38 }
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44 use crate::tests::*;
45
46 #[test]
47 fn test() {
48 snapshot_testing("document_link", &|ctx, path| {
49 let request = DocumentLinkRequest { path: path.clone() };
50
51 let result = request.request(ctx);
52 assert_snapshot!(JsonRepr::new_redacted(result, &REDACT_LOC));
53 });
54 }
55}