Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refine label types to remove hacking citation filter #603

Merged
merged 5 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions crates/tinymist-query/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl StatefulRequest for CompletionRequest {
let ty_chk = ctx.type_check(source.clone());
if let Some(ty_chk) = ty_chk {
let ty = ty_chk.type_of_span(cano_expr.span());
log::debug!("check string ty: {:?}", ty);
log::debug!("check string ty: {ty:?}");
if let Some(Ty::Builtin(BuiltinTy::Path(path_filter))) = ty {
completion_result =
complete_path(ctx, Some(cano_expr), &source, cursor, &path_filter);
Expand Down Expand Up @@ -371,17 +371,12 @@ mod tests {
position: ctx.to_lsp_pos(s, &source),
explicit: false,
};
results.push(request.request(ctx, doc.clone()).map(|resp| {
// CompletionResponse::Array(items)
match resp {
CompletionResponse::List(l) => CompletionResponse::List(CompletionList {
is_incomplete: l.is_incomplete,
items: get_items(l.items),
}),
CompletionResponse::Array(items) => {
CompletionResponse::Array(get_items(items))
}
}
results.push(request.request(ctx, doc.clone()).map(|resp| match resp {
CompletionResponse::List(l) => CompletionResponse::List(CompletionList {
is_incomplete: l.is_incomplete,
items: get_items(l.items),
}),
CompletionResponse::Array(items) => CompletionResponse::Array(get_items(items)),
}));
}
with_settings!({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// path: references.bib
@article{Russell:1908,
Author = {Bertand Russell},
Journal = {American Journal of Mathematics},
Pages = {222--262},
Title = {Mathematical logic based on the theory of types},
Volume = 30,
Year = 1908}
@article{Rus,
Author = {Bertand Russell},
Journal = {American Journal of Mathematics},
Pages = {222--262},
Title = {Mathematical logic based on the theory of types},
Volume = 30,
Year = 1908}

-----

// contains:Russell:1908,Mathematical logic based on the theory of types
// compile:true

#set heading(numbering: "1.1")

#let cite_prose(labl) = cite(labl)
#let cite_prose_different_name(labl) = cite(labl)

#bibliography("references.bib")

#cite_prose(<Rus> /* range -2..-1 */)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// path: references.bib
@article{Russell:1908,
Author = {Bertand Russell},
Journal = {American Journal of Mathematics},
Pages = {222--262},
Title = {Mathematical logic based on the theory of types},
Volume = 30,
Year = 1908}
@article{Rus,
Author = {Bertand Russell},
Journal = {American Journal of Mathematics},
Pages = {222--262},
Title = {Mathematical logic based on the theory of types},
Volume = 30,
Year = 1908}

-----
// contains:Russell:1908,Mathematical logic based on the theory of types
// compile:true

#set heading(numbering: "1.1")

#let cite_prose(labl) = cite(labl)
#let cite_prose_different_name(labl) = cite(labl)

#bibliography("references.bib")

#cite_prose_different_name(<Rus> /* range -2..-1 */)
17 changes: 17 additions & 0 deletions crates/tinymist-query/src/fixtures/completion/cite_heading.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// path: references.bib
@article{t,}

-----

// contains:form,test
// compile:true

#set heading(numbering: "1.1")

#let cite_prose(labl) = cite(labl)

= H <test>

#cite_prose(<t> /* range -3..-2 */)

#bibliography("references.bib")
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// contains:test
// compile:true

#set heading(numbering: "1.1")

= H <t>

== H2 <test>

aba aba

#<t> /* range -3..-2 */
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// contains:test
// compile:true

#set heading(numbering: "1.1")

= H <t>

== H2 <test>

aba aba

@t /* range -2..-1 */
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
source: crates/tinymist-query/src/completion.rs
description: Completion on > (262..263)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/bug_cite_function_infer.typ
---
[
{
"isIncomplete": false,
"items": [
{
"kind": 21,
"label": "Mathematical logic based on the theory of types",
"labelDetails": {
"description": "Russell:1908"
},
"sortText": "000",
"textEdit": {
"newText": "<Russell:1908",
"range": {
"end": {
"character": 16,
"line": 10
},
"start": {
"character": 16,
"line": 10
}
}
}
},
{
"kind": 21,
"label": "Mathematical logic based on the theory of types",
"labelDetails": {
"description": "Rus"
},
"sortText": "001",
"textEdit": {
"newText": "<Rus",
"range": {
"end": {
"character": 16,
"line": 10
},
"start": {
"character": 16,
"line": 10
}
}
}
},
{
"kind": 18,
"label": "Russell:1908",
"labelDetails": {
"description": "Mathematical logic based on the theory of types"
},
"sortText": "003",
"textEdit": {
"newText": "<Russell:1908",
"range": {
"end": {
"character": 16,
"line": 10
},
"start": {
"character": 16,
"line": 10
}
}
}
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
source: crates/tinymist-query/src/completion.rs
description: Completion on > (272..273)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/bug_cite_function_infer2.typ
---
[
{
"isIncomplete": false,
"items": [
{
"kind": 21,
"label": "Mathematical logic based on the theory of types",
"labelDetails": {
"description": "Russell:1908"
},
"sortText": "000",
"textEdit": {
"newText": "<Russell:1908",
"range": {
"end": {
"character": 31,
"line": 10
},
"start": {
"character": 31,
"line": 10
}
}
}
},
{
"kind": 21,
"label": "Mathematical logic based on the theory of types",
"labelDetails": {
"description": "Rus"
},
"sortText": "001",
"textEdit": {
"newText": "<Rus",
"range": {
"end": {
"character": 31,
"line": 10
},
"start": {
"character": 31,
"line": 10
}
}
}
},
{
"kind": 18,
"label": "Russell:1908",
"labelDetails": {
"description": "Mathematical logic based on the theory of types"
},
"sortText": "003",
"textEdit": {
"newText": "<Russell:1908",
"range": {
"end": {
"character": 31,
"line": 10
},
"start": {
"character": 31,
"line": 10
}
}
}
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: crates/tinymist-query/src/completion.rs
description: Completion on t (132..133)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/cite_heading.typ
---
[
{
"isIncomplete": false,
"items": []
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
source: crates/tinymist-query/src/completion.rs
description: Completion on t (100..101)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/complete_purely_label.typ
---
[
{
"isIncomplete": false,
"items": [
{
"kind": 18,
"label": "test",
"labelDetails": {
"description": "H2"
},
"textEdit": {
"newText": "test>",
"range": {
"end": {
"character": 2,
"line": 11
},
"start": {
"character": 2,
"line": 11
}
}
}
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
source: crates/tinymist-query/src/completion.rs
description: Completion on t (99..100)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/complete_purely_ref.typ
---
[
{
"isIncomplete": false,
"items": [
{
"kind": 18,
"label": "test",
"labelDetails": {
"description": "H2"
},
"textEdit": {
"newText": "test",
"range": {
"end": {
"character": 1,
"line": 11
},
"start": {
"character": 1,
"line": 11
}
}
}
}
]
}
]
Loading
Loading