mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-03 09:52:27 +00:00
dev: run completion snapshots with filtering (#230)
This commit is contained in:
parent
97043b9789
commit
10fad2ecde
21 changed files with 187 additions and 11006 deletions
|
@ -215,7 +215,7 @@ mod matcher_tests {
|
|||
#[cfg(test)]
|
||||
mod document_tests {
|
||||
|
||||
use crate::syntax::find_document_before;
|
||||
use crate::syntax::find_docs_before;
|
||||
use crate::tests::*;
|
||||
|
||||
#[test]
|
||||
|
@ -227,7 +227,7 @@ mod document_tests {
|
|||
.to_typst_pos(find_test_position(&source), &source)
|
||||
.unwrap();
|
||||
|
||||
let result = find_document_before(&source, pos);
|
||||
let result = find_docs_before(&source, pos);
|
||||
let result = result.as_deref().unwrap_or("<nil>");
|
||||
|
||||
assert_snapshot!(result);
|
||||
|
|
|
@ -200,11 +200,13 @@ impl StatefulRequest for CompletionRequest {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::HashSet;
|
||||
|
||||
use insta::with_settings;
|
||||
use lsp_types::CompletionItem;
|
||||
|
||||
use super::*;
|
||||
use crate::tests::*;
|
||||
use crate::{syntax::find_module_level_docs, tests::*};
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
|
@ -213,6 +215,52 @@ mod tests {
|
|||
let rng = find_test_range(&source);
|
||||
let text = source.text()[rng.clone()].to_string();
|
||||
|
||||
let docs = find_module_level_docs(&source).unwrap_or_default();
|
||||
let properties = get_test_properties(&docs);
|
||||
let mut includes = HashSet::new();
|
||||
let mut excludes = HashSet::new();
|
||||
|
||||
for kk in properties.get("contains").iter().flat_map(|v| v.split(',')) {
|
||||
// split first char
|
||||
let (kind, item) = kk.split_at(1);
|
||||
if kind == "+" {
|
||||
includes.insert(item.trim());
|
||||
} else if kind == "-" {
|
||||
excludes.insert(item.trim());
|
||||
} else {
|
||||
includes.insert(kk.trim());
|
||||
}
|
||||
}
|
||||
let get_items = |items: Vec<CompletionItem>| {
|
||||
let mut res: Vec<_> = items
|
||||
.into_iter()
|
||||
.map(|item| CompletionItem {
|
||||
label: item.label,
|
||||
sort_text: item.sort_text,
|
||||
kind: item.kind,
|
||||
text_edit: item.text_edit,
|
||||
..Default::default()
|
||||
})
|
||||
.filter(|item| {
|
||||
if includes.is_empty() {
|
||||
return true;
|
||||
}
|
||||
if !excludes.is_empty() && excludes.contains(item.label.as_str()) {
|
||||
panic!("{item:?} was excluded in {excludes:?}");
|
||||
}
|
||||
includes.contains(item.label.as_str())
|
||||
})
|
||||
.collect();
|
||||
|
||||
res.sort_by(|a, b| {
|
||||
a.sort_text
|
||||
.as_ref()
|
||||
.cmp(&b.sort_text.as_ref())
|
||||
.then_with(|| a.label.cmp(&b.label))
|
||||
});
|
||||
res
|
||||
};
|
||||
|
||||
let mut results = vec![];
|
||||
for s in rng.clone() {
|
||||
let request = CompletionRequest {
|
||||
|
@ -225,48 +273,11 @@ mod tests {
|
|||
match resp {
|
||||
CompletionResponse::List(l) => CompletionResponse::List(CompletionList {
|
||||
is_incomplete: l.is_incomplete,
|
||||
items: {
|
||||
let mut res: Vec<_> = l
|
||||
.items
|
||||
.into_iter()
|
||||
.map(|item| CompletionItem {
|
||||
label: item.label,
|
||||
sort_text: item.sort_text,
|
||||
kind: item.kind,
|
||||
text_edit: item.text_edit,
|
||||
..Default::default()
|
||||
})
|
||||
.collect();
|
||||
|
||||
res.sort_by(|a, b| {
|
||||
a.sort_text
|
||||
.as_ref()
|
||||
.cmp(&b.sort_text.as_ref())
|
||||
.then_with(|| a.label.cmp(&b.label))
|
||||
});
|
||||
res
|
||||
},
|
||||
}),
|
||||
CompletionResponse::Array(items) => CompletionResponse::Array({
|
||||
let mut res: Vec<_> = items
|
||||
.into_iter()
|
||||
.map(|item| CompletionItem {
|
||||
label: item.label,
|
||||
sort_text: item.sort_text,
|
||||
kind: item.kind,
|
||||
text_edit: item.text_edit,
|
||||
..Default::default()
|
||||
})
|
||||
.collect();
|
||||
|
||||
res.sort_by(|a, b| {
|
||||
a.sort_text
|
||||
.as_ref()
|
||||
.cmp(&b.sort_text.as_ref())
|
||||
.then_with(|| a.label.cmp(&b.label))
|
||||
});
|
||||
res
|
||||
items: get_items(l.items),
|
||||
}),
|
||||
CompletionResponse::Array(items) => {
|
||||
CompletionResponse::Array(get_items(items))
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// contains: aa,aab,aac,aabc
|
||||
|
||||
#let aa() = 1;
|
||||
#let aab() = 1;
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
// contains: caption
|
||||
|
||||
#figure.where(/* range 0..1 */)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// contains: content,authors,font,class
|
||||
|
||||
#let tmpl(content, authors: (), font: none, class: "article") = {
|
||||
if class != "article" and class != "letter" {
|
||||
panic("")
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// contains: content,authors,font,class
|
||||
|
||||
#let tmpl(content, authors: (), font: none, class: "article") = {
|
||||
if class != "article" and class != "letter" {
|
||||
panic("")
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// contains: aa,aab,aac,aabc
|
||||
|
||||
#let aa(aab, aac, aabc) ={
|
||||
aac(/* range -2..0 */);
|
||||
#let aa(aab, aac, aabc) = {
|
||||
aac(/* range -2..0 */)
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// contains: content,authors,font,class
|
||||
|
||||
#let tmpl(content, authors: (), font: none, class: "article") = {
|
||||
if class != "article" and class != "letter" {
|
||||
panic("")
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// contains: aa,aac
|
||||
|
||||
#let aa = 1;
|
||||
#let aa() = 1;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// contains: aa,aab,aac,aabc
|
||||
|
||||
#let aa() = 1;
|
||||
#let aab = 1;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on c( (68..70)
|
||||
description: Completion on c( (98..100)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/base.typ
|
||||
---
|
||||
|
@ -16,45 +16,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/base.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
"line": 7
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aa.where",
|
||||
"textEdit": {
|
||||
"newText": "aa.where(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aa.with",
|
||||
"textEdit": {
|
||||
"newText": "aa.with(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
"line": 7
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,45 +33,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/base.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
"line": 7
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aab.where",
|
||||
"textEdit": {
|
||||
"newText": "aab.where(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aab.with",
|
||||
"textEdit": {
|
||||
"newText": "aab.with(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
"line": 7
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -118,45 +50,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/base.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
"line": 7
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aabc.where",
|
||||
"textEdit": {
|
||||
"newText": "aabc.where(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aabc.with",
|
||||
"textEdit": {
|
||||
"newText": "aabc.with(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
"line": 7
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -169,215 +67,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/base.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
"line": 7
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aac.where",
|
||||
"textEdit": {
|
||||
"newText": "aac.where(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aac.with",
|
||||
"textEdit": {
|
||||
"newText": "aac.with(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 21,
|
||||
"label": "aqua",
|
||||
"textEdit": {
|
||||
"newText": "aqua",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 7,
|
||||
"label": "array",
|
||||
"textEdit": {
|
||||
"newText": "array",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 15,
|
||||
"label": "array literal",
|
||||
"textEdit": {
|
||||
"newText": "(${1:1, 2, 3})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 15,
|
||||
"label": "dictionary literal",
|
||||
"textEdit": {
|
||||
"newText": "(${1:a: 1, b: 2})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 15,
|
||||
"label": "import package",
|
||||
"textEdit": {
|
||||
"newText": "import \"@${1:}\": ${2:items}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 15,
|
||||
"label": "include (package)",
|
||||
"textEdit": {
|
||||
"newText": "include \"@${1:}\"",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "metadata",
|
||||
"textEdit": {
|
||||
"newText": "metadata(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "pagebreak",
|
||||
"textEdit": {
|
||||
"newText": "pagebreak(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "parbreak",
|
||||
"textEdit": {
|
||||
"newText": "parbreak()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "smallcaps",
|
||||
"textEdit": {
|
||||
"newText": "smallcaps(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
"line": 7
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -395,45 +89,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/base.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
"line": 7
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aabc.where",
|
||||
"textEdit": {
|
||||
"newText": "aabc.where(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aabc.with",
|
||||
"textEdit": {
|
||||
"newText": "aabc.with(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
"line": 7
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -446,45 +106,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/base.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
"line": 7
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aac.where",
|
||||
"textEdit": {
|
||||
"newText": "aac.where(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aac.with",
|
||||
"textEdit": {
|
||||
"newText": "aac.with(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
"line": 7
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on / (319..320)
|
||||
description: Completion on / (364..365)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/func_args2.typ
|
||||
---
|
||||
|
@ -17,11 +17,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/func_args2.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 18,
|
||||
"line": 14
|
||||
"line": 16
|
||||
},
|
||||
"start": {
|
||||
"character": 18,
|
||||
"line": 14
|
||||
"line": 16
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,11 +35,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/func_args2.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 18,
|
||||
"line": 14
|
||||
"line": 16
|
||||
},
|
||||
"start": {
|
||||
"character": 18,
|
||||
"line": 14
|
||||
"line": 16
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on c( (31..33)
|
||||
description: Completion on c( (62..64)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/func_params.typ
|
||||
---
|
||||
|
@ -16,45 +16,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/func_params.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 5,
|
||||
"line": 1
|
||||
"line": 3
|
||||
},
|
||||
"start": {
|
||||
"character": 2,
|
||||
"line": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aa.where",
|
||||
"textEdit": {
|
||||
"newText": "aa.where(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 5,
|
||||
"line": 1
|
||||
},
|
||||
"start": {
|
||||
"character": 2,
|
||||
"line": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aa.with",
|
||||
"textEdit": {
|
||||
"newText": "aa.with(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 5,
|
||||
"line": 1
|
||||
},
|
||||
"start": {
|
||||
"character": 2,
|
||||
"line": 1
|
||||
"line": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,11 +33,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/func_params.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 5,
|
||||
"line": 1
|
||||
"line": 3
|
||||
},
|
||||
"start": {
|
||||
"character": 2,
|
||||
"line": 1
|
||||
"line": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,11 +50,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/func_params.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 5,
|
||||
"line": 1
|
||||
"line": 3
|
||||
},
|
||||
"start": {
|
||||
"character": 2,
|
||||
"line": 1
|
||||
"line": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,181 +67,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/func_params.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 5,
|
||||
"line": 1
|
||||
"line": 3
|
||||
},
|
||||
"start": {
|
||||
"character": 2,
|
||||
"line": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 21,
|
||||
"label": "aqua",
|
||||
"textEdit": {
|
||||
"newText": "aqua",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 5,
|
||||
"line": 1
|
||||
},
|
||||
"start": {
|
||||
"character": 2,
|
||||
"line": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 7,
|
||||
"label": "array",
|
||||
"textEdit": {
|
||||
"newText": "array",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 5,
|
||||
"line": 1
|
||||
},
|
||||
"start": {
|
||||
"character": 2,
|
||||
"line": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 15,
|
||||
"label": "array literal",
|
||||
"textEdit": {
|
||||
"newText": "(${1:1, 2, 3})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 5,
|
||||
"line": 1
|
||||
},
|
||||
"start": {
|
||||
"character": 2,
|
||||
"line": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 15,
|
||||
"label": "dictionary literal",
|
||||
"textEdit": {
|
||||
"newText": "(${1:a: 1, b: 2})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 5,
|
||||
"line": 1
|
||||
},
|
||||
"start": {
|
||||
"character": 2,
|
||||
"line": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 15,
|
||||
"label": "import package",
|
||||
"textEdit": {
|
||||
"newText": "import \"@${1:}\": ${2:items}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 5,
|
||||
"line": 1
|
||||
},
|
||||
"start": {
|
||||
"character": 2,
|
||||
"line": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 15,
|
||||
"label": "include (package)",
|
||||
"textEdit": {
|
||||
"newText": "include \"@${1:}\"",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 5,
|
||||
"line": 1
|
||||
},
|
||||
"start": {
|
||||
"character": 2,
|
||||
"line": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "metadata",
|
||||
"textEdit": {
|
||||
"newText": "metadata(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 5,
|
||||
"line": 1
|
||||
},
|
||||
"start": {
|
||||
"character": 2,
|
||||
"line": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "pagebreak",
|
||||
"textEdit": {
|
||||
"newText": "pagebreak(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 5,
|
||||
"line": 1
|
||||
},
|
||||
"start": {
|
||||
"character": 2,
|
||||
"line": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "parbreak",
|
||||
"textEdit": {
|
||||
"newText": "parbreak()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 5,
|
||||
"line": 1
|
||||
},
|
||||
"start": {
|
||||
"character": 2,
|
||||
"line": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "smallcaps",
|
||||
"textEdit": {
|
||||
"newText": "smallcaps(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 5,
|
||||
"line": 1
|
||||
},
|
||||
"start": {
|
||||
"character": 2,
|
||||
"line": 1
|
||||
"line": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -293,11 +89,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/func_params.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 5,
|
||||
"line": 1
|
||||
"line": 3
|
||||
},
|
||||
"start": {
|
||||
"character": 2,
|
||||
"line": 1
|
||||
"line": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -310,11 +106,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/func_params.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 5,
|
||||
"line": 1
|
||||
"line": 3
|
||||
},
|
||||
"start": {
|
||||
"character": 2,
|
||||
"line": 1
|
||||
"line": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on c( (48..50)
|
||||
description: Completion on c( (69..71)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/item_shadow.typ
|
||||
---
|
||||
|
@ -16,45 +16,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/item_shadow.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
"line": 6
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aa.where",
|
||||
"textEdit": {
|
||||
"newText": "aa.where(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aa.with",
|
||||
"textEdit": {
|
||||
"newText": "aa.with(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
"line": 6
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,215 +33,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/item_shadow.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
"line": 6
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aac.where",
|
||||
"textEdit": {
|
||||
"newText": "aac.where(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aac.with",
|
||||
"textEdit": {
|
||||
"newText": "aac.with(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 21,
|
||||
"label": "aqua",
|
||||
"textEdit": {
|
||||
"newText": "aqua",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 7,
|
||||
"label": "array",
|
||||
"textEdit": {
|
||||
"newText": "array",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 15,
|
||||
"label": "array literal",
|
||||
"textEdit": {
|
||||
"newText": "(${1:1, 2, 3})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 15,
|
||||
"label": "dictionary literal",
|
||||
"textEdit": {
|
||||
"newText": "(${1:a: 1, b: 2})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 15,
|
||||
"label": "import package",
|
||||
"textEdit": {
|
||||
"newText": "import \"@${1:}\": ${2:items}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 15,
|
||||
"label": "include (package)",
|
||||
"textEdit": {
|
||||
"newText": "include \"@${1:}\"",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "metadata",
|
||||
"textEdit": {
|
||||
"newText": "metadata(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "pagebreak",
|
||||
"textEdit": {
|
||||
"newText": "pagebreak(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "parbreak",
|
||||
"textEdit": {
|
||||
"newText": "parbreak()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "smallcaps",
|
||||
"textEdit": {
|
||||
"newText": "smallcaps(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
"line": 6
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -293,45 +55,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/item_shadow.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
"line": 6
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aac.where",
|
||||
"textEdit": {
|
||||
"newText": "aac.where(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aac.with",
|
||||
"textEdit": {
|
||||
"newText": "aac.with(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 4
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 4
|
||||
"line": 6
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on c( (64..66)
|
||||
description: Completion on c( (94..96)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/let.typ
|
||||
---
|
||||
|
@ -16,45 +16,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/let.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
"line": 7
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aa.where",
|
||||
"textEdit": {
|
||||
"newText": "aa.where(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aa.with",
|
||||
"textEdit": {
|
||||
"newText": "aa.with(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
"line": 7
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,11 +33,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/let.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
"line": 7
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
"line": 7
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,11 +50,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/let.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
"line": 7
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
"line": 7
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,215 +67,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/let.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
"line": 7
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aac.where",
|
||||
"textEdit": {
|
||||
"newText": "aac.where(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aac.with",
|
||||
"textEdit": {
|
||||
"newText": "aac.with(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 21,
|
||||
"label": "aqua",
|
||||
"textEdit": {
|
||||
"newText": "aqua",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 7,
|
||||
"label": "array",
|
||||
"textEdit": {
|
||||
"newText": "array",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 15,
|
||||
"label": "array literal",
|
||||
"textEdit": {
|
||||
"newText": "(${1:1, 2, 3})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 15,
|
||||
"label": "dictionary literal",
|
||||
"textEdit": {
|
||||
"newText": "(${1:a: 1, b: 2})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 15,
|
||||
"label": "import package",
|
||||
"textEdit": {
|
||||
"newText": "import \"@${1:}\": ${2:items}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 15,
|
||||
"label": "include (package)",
|
||||
"textEdit": {
|
||||
"newText": "include \"@${1:}\"",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "metadata",
|
||||
"textEdit": {
|
||||
"newText": "metadata(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "pagebreak",
|
||||
"textEdit": {
|
||||
"newText": "pagebreak(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "parbreak",
|
||||
"textEdit": {
|
||||
"newText": "parbreak()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "smallcaps",
|
||||
"textEdit": {
|
||||
"newText": "smallcaps(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
"line": 7
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -327,11 +89,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/let.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
"line": 7
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
"line": 7
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -344,45 +106,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/let.typ
|
|||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
"line": 7
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aac.where",
|
||||
"textEdit": {
|
||||
"newText": "aac.where(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aac.with",
|
||||
"textEdit": {
|
||||
"newText": "aac.with(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 5
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 5
|
||||
"line": 7
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
|||
analysis::{analyze_dyn_signature, find_definition, DefinitionLink, Signature},
|
||||
jump_from_cursor,
|
||||
prelude::*,
|
||||
syntax::{find_document_before, get_deref_target, LexicalKind, LexicalVarKind},
|
||||
syntax::{find_docs_before, get_deref_target, LexicalKind, LexicalVarKind},
|
||||
upstream::{expr_tooltip, tooltip, Tooltip},
|
||||
LspHoverContents, StatefulRequest,
|
||||
};
|
||||
|
@ -266,7 +266,7 @@ impl DocTooltip {
|
|||
let (fid, def_range) = lnk.def_at.clone()?;
|
||||
|
||||
let src = ctx.source_by_id(fid).ok()?;
|
||||
find_document_before(&src, def_range.start)
|
||||
find_docs_before(&src, def_range.start)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,13 +3,17 @@ use std::ops::Range;
|
|||
use crate::prelude::*;
|
||||
use crate::syntax::get_def_target;
|
||||
|
||||
fn extract_document_between(node: &LinkedNode, rng: Range<usize>) -> Option<String> {
|
||||
fn extract_document_between(
|
||||
node: &LinkedNode,
|
||||
rng: Range<usize>,
|
||||
first_group: bool,
|
||||
) -> Option<String> {
|
||||
// collect all comments before the definition
|
||||
let mut comments = vec![];
|
||||
|
||||
let mut newline_count = 0;
|
||||
let nodes = node.parent()?.children();
|
||||
for n in nodes {
|
||||
let nodes = node.children();
|
||||
'scan_comments: for n in nodes {
|
||||
let offset = n.offset();
|
||||
if !rng.contains(&offset) {
|
||||
continue;
|
||||
|
@ -26,11 +30,17 @@ fn extract_document_between(node: &LinkedNode, rng: Range<usize>) -> Option<Stri
|
|||
newline_count += 1;
|
||||
}
|
||||
if newline_count > 1 {
|
||||
if first_group {
|
||||
break 'scan_comments;
|
||||
}
|
||||
comments.clear();
|
||||
}
|
||||
}
|
||||
SyntaxKind::Parbreak => {
|
||||
newline_count = 2;
|
||||
if first_group {
|
||||
break 'scan_comments;
|
||||
}
|
||||
comments.clear();
|
||||
}
|
||||
SyntaxKind::LineComment => {
|
||||
|
@ -75,14 +85,14 @@ fn extract_document_between(node: &LinkedNode, rng: Range<usize>) -> Option<Stri
|
|||
Some(docs)
|
||||
}
|
||||
|
||||
pub fn find_document_before(src: &Source, cursor: usize) -> Option<String> {
|
||||
pub fn find_docs_before(src: &Source, cursor: usize) -> Option<String> {
|
||||
log::debug!("finding docs at: {id:?}, {cursor}", id = src.id());
|
||||
|
||||
let root = LinkedNode::new(src.root());
|
||||
let leaf = root.leaf_at(cursor)?;
|
||||
let def_target = get_def_target(leaf.clone())?;
|
||||
log::debug!("found docs target: {:?}", def_target.node().kind());
|
||||
// todo: import
|
||||
// todo: import node
|
||||
let target = def_target.node().clone();
|
||||
let mut node = target.clone();
|
||||
while let Some(prev) = node.prev_sibling() {
|
||||
|
@ -98,12 +108,27 @@ pub fn find_document_before(src: &Source, cursor: usize) -> Option<String> {
|
|||
return None;
|
||||
}
|
||||
|
||||
return extract_document_between(&node, start..end);
|
||||
return extract_document_between(node.parent()?, start..end, false);
|
||||
}
|
||||
|
||||
if node.parent()?.range() == root.range() && node.prev_sibling().is_none() {
|
||||
return extract_document_between(&node, root.offset()..node.range().start);
|
||||
return extract_document_between(node.parent()?, root.offset()..node.range().start, false);
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn find_module_level_docs(src: &Source) -> Option<String> {
|
||||
log::debug!("finding docs at: {id:?}", id = src.id());
|
||||
|
||||
let root = LinkedNode::new(src.root());
|
||||
for n in root.children() {
|
||||
if n.kind().is_trivia() {
|
||||
continue;
|
||||
}
|
||||
|
||||
return extract_document_between(&root, 0..n.offset(), true);
|
||||
}
|
||||
|
||||
extract_document_between(&root, 0..src.text().len(), true)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use core::fmt;
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
collections::{HashMap, HashSet},
|
||||
ops::Range,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
@ -86,6 +86,17 @@ pub fn snapshot_testing(name: &str, f: &impl Fn(&mut AnalysisContext, PathBuf))
|
|||
});
|
||||
}
|
||||
|
||||
pub fn get_test_properties(s: &str) -> HashMap<&'_ str, &'_ str> {
|
||||
let mut props = HashMap::new();
|
||||
for line in s.lines() {
|
||||
let mut line = line.splitn(2, ':');
|
||||
let key = line.next().unwrap().trim();
|
||||
let value = line.next().unwrap().trim();
|
||||
props.insert(key, value);
|
||||
}
|
||||
props
|
||||
}
|
||||
|
||||
pub fn run_with_sources<T>(source: &str, f: impl FnOnce(&mut TypstSystemWorld, PathBuf) -> T) -> T {
|
||||
let root = if cfg!(windows) {
|
||||
PathBuf::from("C:\\")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue