Move citation module to separate crate

This commit is contained in:
Patrick Förster 2023-04-08 16:22:21 +02:00
parent f1b6388a83
commit 672e820f51
32 changed files with 85 additions and 49 deletions

View file

@ -10,7 +10,7 @@ use url::Url;
use crate::{graph, Config, Document, DocumentData, Owner};
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Workspace {
documents: FxHashSet<Document>,
config: Config,
@ -63,7 +63,11 @@ impl Workspace {
Ok(self.open(uri, text, language, owner))
}
pub fn watch(&mut self, watcher: &mut dyn notify::Watcher) {
pub fn watch(
&mut self,
watcher: &mut dyn notify::Watcher,
watched_dirs: &mut FxHashSet<PathBuf>,
) {
self.iter()
.filter(|document| document.uri.scheme() == "file")
.flat_map(|document| {
@ -73,7 +77,10 @@ impl Workspace {
})
.flatten()
.for_each(|path| {
let _ = watcher.watch(&path, notify::RecursiveMode::NonRecursive);
if !watched_dirs.contains(&path) {
let _ = watcher.watch(&path, notify::RecursiveMode::NonRecursive);
watched_dirs.insert(path);
}
});
}
@ -149,6 +156,10 @@ impl Workspace {
self.reload();
}
pub fn set_folders(&mut self, folders: Vec<PathBuf>) {
self.folders = folders;
}
pub fn reload(&mut self) {
let uris = self
.documents

View file

@ -0,0 +1,27 @@
[package]
name = "citeproc"
version = "0.0.0"
license.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
[dependencies]
chrono = { version = "0.4.24", default-features = false, features = ["std"] }
human_name = "2.0.1"
isocountry = "0.3.2"
itertools = "0.10.5"
rowan = "0.15.11"
rustc-hash = "1.1.0"
strum = { version = "0.24.1", features = ["derive"] }
syntax = { path = "../syntax" }
titlecase = "2.2.1"
unicode-normalization = "0.1.22"
url = "2.3.1"
[lib]
doctest = false
[dev-dependencies]
insta = "1.29.0"
parser = { path = "../parser" }

View file

@ -1,8 +1,8 @@
use isocountry::CountryCode;
use itertools::Itertools;
use lsp_types::Url;
use syntax::bibtex;
use titlecase::titlecase;
use url::Url;
use super::{
entry::{EntryData, EntryKind},

View file

@ -1,6 +1,6 @@
mod driver;
mod entry;
pub(crate) mod field;
pub mod field;
mod output;
use syntax::bibtex;

View file

@ -1,6 +1,5 @@
---
source: src/citation/tests.rs
assertion_line: 64
source: crates/citeproc/src/tests.rs
expression: "render_entry(r#\"\n@string{jomch = {J.~Organomet. Chem.}}\n\n@article{aksin,\n author = {Aks{\\i}n, {\\\"O}zge and T{\\\"u}rkmen, Hayati and Artok, Levent\n and {\\c{C}}etinkaya, Bekir and Ni, Chaoying and\n B{\\\"u}y{\\\"u}kg{\\\"u}ng{\\\"o}r, Orhan and {\\\"O}zkal, Erhan},\n title = {Effect of immobilization on catalytic characteristics of\n saturated {Pd-N}-heterocyclic carbenes in {Mizoroki-Heck}\n reactions},\n journaltitle = jomch,\n date = 2006,\n volume = 691,\n number = 13,\n pages = {3027-3036},\n indextitle = {Effect of immobilization on catalytic characteristics},\n}\"#)"
---
O. Aksın, H. Türkmen, L. Artok, B. Çetinkaya, C. Ni, O. Büyükgüngör, E. Özkal: "Effect of immobilization on catalytic characteristics of saturated Pd-N-heterocyclic carbenes in Mizoroki-Heck reactions". *J. Organomet. Chem.* 691.13 (2006): 3027-3036.

View file

@ -1,6 +1,5 @@
---
source: src/citation/tests.rs
assertion_line: 87
source: crates/citeproc/src/tests.rs
expression: "render_entry(r#\"\n@string{jams = {J.~Amer. Math. Soc.}}\n\n@article{bertram,\n author = {Bertram, Aaron and Wentworth, Richard},\n title = {Gromov invariants for holomorphic maps on {Riemann} surfaces},\n journaltitle = jams,\n date = 1996,\n volume = 9,\n number = 2,\n pages = {529-571},\n langid = {english},\n langidopts = {variant=american},\n shorttitle = {Gromov invariants},\n annotation = {An \\texttt{article} entry with a \\texttt{volume} and a\n \\texttt{number} field},\n}\"#)"
---
A. Bertram, R. Wentworth: "Gromov invariants for holomorphic maps on Riemann surfaces". *J. Amer. Math. Soc.* 9.2 (1996): 529-571.

View file

@ -1,6 +1,5 @@
---
source: src/citation/tests.rs
assertion_line: 138
source: crates/citeproc/src/tests.rs
expression: "render_entry(r#\"\n@article{DBLP:journals/corr/abs-2107-11903,\n author = {Michelle L. Blom and\n Jurlind Budurushi and\n Ronald L. Rivest and\n Philip B. Stark and\n Peter J. Stuckey and\n Vanessa Teague and\n Damjan Vukcevic},\n title = {Assertion-based Approaches to Auditing Complex Elections, with application\n to party-list proportional elections},\n journal = {CoRR},\n volume = {abs/2107.11903},\n year = {2021},\n url = {https://arxiv.org/abs/2107.11903},\n eprinttype = {arXiv},\n eprint = {2107.11903},\n timestamp = {Thu, 29 Jul 2021 16:14:15 +0200},\n biburl = {https://dblp.org/rec/journals/corr/abs-2107-11903.bib},\n bibsource = {dblp computer science bibliography, https://dblp.org}\n}\"#)"
---
M. Blom, J. Budurushi, R. Rivest, P. Stark, P. Stuckey, V. Teague, D. Vukcevic: "Assertion-based Approaches to Auditing Complex Elections, with application to party-list proportional elections". *CoRR* abs/2107.11903 (2021): arXiv: [2107.11903](https://arxiv.org/abs/2107.11903). URL: [https://arxiv.org/abs/2107.11903](https://arxiv.org/abs/2107.11903).

View file

@ -1,6 +1,5 @@
---
source: src/citation/tests.rs
assertion_line: 39
source: crates/citeproc/src/tests.rs
expression: "render_entry(r#\"\n@article{10.1145/331499.331504,\n author = {Jain, A. K. and Murty, M. N. and Flynn, P. J.},\n title = {Data Clustering: A Review},\n year = {1999},\n issue_date = {Sept. 1999},\n publisher = {Association for Computing Machinery},\n address = {New York, NY, USA},\n volume = {31},\n number = {3},\n issn = {0360-0300},\n url = {https://doi.org/10.1145/331499.331504},\n doi = {10.1145/331499.331504},\n journal = {ACM Comput. Surv.},\n month = {sep},\n pages = {264-323},\n numpages = {60},\n keywords = {incremental clustering, clustering applications, exploratory data analysis, cluster analysis, similarity indices, unsupervised learning}\n}\"#)"
---
A. Jain, M. Murty, P. Flynn: "Data Clustering: A Review". *ACM Comput. Surv.* 31.3 (Sep. 1999): 264-323. ISSN: 0360-0300. DOI: [10.1145/331499.331504](https://doi.org/10.1145/331499.331504). URL: [https://doi.org/10.1145/331499.331504](https://doi.org/10.1145/331499.331504).

View file

@ -1,6 +1,5 @@
---
source: src/citation/tests.rs
assertion_line: 110
source: crates/citeproc/src/tests.rs
expression: "render_entry(r#\"\n@string{jchph = {J.~Chem. Phys.}}\n\n@article{kastenholz,\n author = {Kastenholz, M. A. and H{\\\"u}nenberger, Philippe H.},\n title = {Computation of methodology\\hyphen independent ionic solvation\n free energies from molecular simulations},\n journaltitle = jchph,\n date = 2006,\n subtitle = {{I}. {The} electrostatic potential in molecular liquids},\n volume = 124,\n eid = 124106,\n doi = {10.1063/1.2172593},\n langid = {english},\n langidopts = {variant=american},\n indextitle = {Computation of ionic solvation free energies},\n annotation = {An \\texttt{article} entry with an \\texttt{eid} and a\n \\texttt{doi} field. Note that the \\textsc{doi} is transformed\n into a clickable link if \\texttt{hyperref} support has been\n enabled},\n}\n \"#)"
---
M. Kastenholz, P. Hünenberger: "Computation of methodology- independent ionic solvation free energies from molecular simulations. I. The electrostatic potential in molecular liquids". *J. Chem. Phys.* 124, 124106 (2006): DOI: [10.1063/1.2172593](https://doi.org/10.1063/1.2172593).

View file

@ -1,6 +1,5 @@
---
source: src/citation/tests.rs
assertion_line: 15
source: crates/citeproc/src/tests.rs
expression: "render_entry(r#\"\n@article{10.1145/359340.359342,\n author = {Rivest, R. L. and Shamir, A. and Adleman, L.},\n title = {A Method for Obtaining Digital Signatures and Public-Key Cryptosystems},\n year = {1978},\n issue_date = {Feb. 1978},\n publisher = {Association for Computing Machinery},\n address = {New York, NY, USA},\n volume = {21},\n number = {2},\n issn = {0001-0782},\n url = {https://doi.org/10.1145/359340.359342},\n doi = {10.1145/359340.359342},\n journal = {Commun. ACM},\n month = {feb},\n pages = {120-126},\n numpages = {7},\n}\"#)"
---
R. Rivest, A. Shamir, L. Adleman: "A Method for Obtaining Digital Signatures and Public-Key Cryptosystems". *Commun. ACM* 21.2 (Feb. 1978): 120-126. ISSN: 0001-0782. DOI: [10.1145/359340.359342](https://doi.org/10.1145/359340.359342). URL: [https://doi.org/10.1145/359340.359342](https://doi.org/10.1145/359340.359342).

View file

@ -1,6 +1,5 @@
---
source: src/citation/tests.rs
assertion_line: 165
source: crates/citeproc/src/tests.rs
expression: "render_entry(r#\"\n@book{10.5555/1177220,\n author = {Aho, Alfred V. and Lam, Monica S. and Sethi, Ravi and Ullman, Jeffrey D.},\n title = {Compilers: Principles, Techniques, and Tools (2nd Edition)},\n year = {2006},\n isbn = {0321486811},\n publisher = {Addison-Wesley Longman Publishing Co., Inc.},\n address = {USA}\n}\"#)"
---
A. Aho, M. Lam, R. Sethi, J. Ullman: "Compilers: Principles, Techniques, and Tools (2nd Edition)". Addison-Wesley Longman Publishing Co., Inc., 2006. ISBN: 0321486811.

View file

@ -1,6 +1,5 @@
---
source: src/citation/tests.rs
assertion_line: 180
source: crates/citeproc/src/tests.rs
expression: "render_entry(r#\"\n@book{averroes/bland,\n author = {Averroes},\n title = {The Epistle on the Possibility of Conjunction with the Active\n Intellect by {Ibn Rushd} with the Commentary of {Moses Narboni}},\n date = 1982,\n editor = {Bland, Kalman P.},\n translator = {Bland, Kalman P.},\n series = {Moreshet: Studies in {Jewish} History, Literature and Thought},\n number = 7,\n publisher = {Jewish Theological Seminary of America},\n location = {New York},\n keywords = {primary},\n langid = {english},\n langidopts = {variant=american},\n indextitle = {Epistle on the Possibility of Conjunction, The},\n shorttitle = {Possibility of Conjunction},\n annotation = {A \\texttt{book} entry with a \\texttt{series} and a\n \\texttt{number}. Note the concatenation of the \\texttt{editor}\n and \\texttt{translator} fields as well as the\n \\texttt{indextitle} field},\n}\"#)"
---
"The Epistle on the Possibility of Conjunction with the Active Intellect by Ibn Rushd with the Commentary of Moses Narboni". Ed. by K. Bland. Trans. by K. Bland. Moreshet: Studies in Jewish History, Literature and Thought 7. New York: Jewish Theological Seminary of America, 1982.

View file

@ -1,6 +1,5 @@
---
source: src/citation/tests.rs
assertion_line: 208
source: crates/citeproc/src/tests.rs
expression: "render_entry(r#\"\n@book{knuth:ct:a,\n author = {Knuth, Donald E.},\n title = {The {\\TeX book}},\n date = 1984,\n maintitle = {Computers \\& Typesetting},\n volume = {A},\n publisher = {Addison-Wesley},\n location = {Reading, Mass.},\n langid = {english},\n langidopts = {variant=american},\n sorttitle = {Computers & Typesetting A},\n indexsorttitle= {The TeXbook},\n indextitle = {\\protect\\TeX book, The},\n shorttitle = {\\TeX book},\n annotation = {The first volume of a five-volume book. Note the\n \\texttt{sorttitle} field. We want this\n volume to be listed after the entry referring to the entire\n five-volume set. Also note the \\texttt{indextitle} and\n \\texttt{indexsorttitle} fields. Indexing packages that don't\n generate robust index entries require some control sequences\n to be protected from expansion},\n}\n \"#)"
---
D. Knuth: "The TeX book". *Computers & Typesetting*. Vol. A. Reading, Mass.: Addison-Wesley, 1984.

View file

@ -1,6 +1,5 @@
---
source: src/citation/tests.rs
assertion_line: 313
source: crates/citeproc/src/tests.rs
expression: "render_entry(r#\"\n@collection{matuz:doody,\n editor = {Matuz, Roger},\n title = {Contemporary Literary Criticism},\n year = 1990,\n volume = 61,\n publisher = {Gale},\n location = {Detroit},\n pages = {204-208},\n langid = {english},\n langidopts = {variant=american},\n annotation = {A \\texttt{collection} entry providing the excerpt information\n for the \\texttt{doody} entry. Note the format of the\n \\texttt{pages} field},\n}\"#)"
---
"Contemporary Literary Criticism". Ed. by R. Matuz. Vol. 61. Detroit: Gale, 1990, 204-208.

View file

@ -1,6 +1,5 @@
---
source: src/citation/tests.rs
assertion_line: 290
source: crates/citeproc/src/tests.rs
expression: "render_entry(r#\"\n@inproceedings{10.1145/967900.968040,\n author = {Combi, Carlo and Pozzi, Giuseppe},\n title = {Architectures for a Temporal Workflow Management System},\n year = {2004},\n isbn = {1581138121},\n publisher = {Association for Computing Machinery},\n address = {New York, NY, USA},\n url = {https://doi.org/10.1145/967900.968040},\n doi = {10.1145/967900.968040},\n booktitle = {Proceedings of the 2004 ACM Symposium on Applied Computing},\n pages = {659-666},\n numpages = {8},\n keywords = {active DBMS, temporal DBMS, workflow management system - WfMS, temporal workflow management system},\n location = {Nicosia, Cyprus},\n series = {SAC '04}\n}\"#)"
---
C. Combi, G. Pozzi: "Architectures for a Temporal Workflow Management System". *Proceedings of the 2004 ACM Symposium on Applied Computing*. SAC '04. Nicosia, Cyprus: Association for Computing Machinery, 2004, 659-666. ISBN: 1581138121. DOI: [10.1145/967900.968040](https://doi.org/10.1145/967900.968040). URL: [https://doi.org/10.1145/967900.968040](https://doi.org/10.1145/967900.968040).

View file

@ -1,6 +1,5 @@
---
source: src/citation/tests.rs
assertion_line: 269
source: crates/citeproc/src/tests.rs
expression: "render_entry(r#\"\n@inproceedings{10.5555/1386993.1386994,\n author = {Erwin, Alva and Gopalan, Raj P. and Achuthan, N. R.},\n title = {A Bottom-up Projection Based Algorithm for Mining High Utility Itemsets},\n year = {2007},\n isbn = {9781920682651},\n publisher = {Australian Computer Society, Inc.},\n address = {AUS},\n booktitle = {Proceedings of the 2nd International Workshop on Integrating Artificial Intelligence and Data Mining - Volume 84},\n pages = {3-11},\n numpages = {9},\n keywords = {pattern growth, high utility itemset mining},\n location = {Gold Coast, Australia},\n series = {AIDM '07}\n}\"#)"
---
A. Erwin, R. Gopalan, N. Achuthan: "A Bottom-up Projection Based Algorithm for Mining High Utility Itemsets". *Proceedings of the 2nd International Workshop on Integrating Artificial Intelligence and Data Mining - Volume 84*. AIDM '07. Gold Coast, Australia: Australian Computer Society, Inc., 2007, 3-11. ISBN: 9781920682651.

View file

@ -1,6 +1,5 @@
---
source: src/citation/tests.rs
assertion_line: 238
source: crates/citeproc/src/tests.rs
expression: "render_entry(r#\"\n@string{dtv = {Deutscher Taschenbuch-Verlag}}\n\n@mvbook{nietzsche:ksa,\n author = {Nietzsche, Friedrich},\n title = {S{\\\"a}mtliche Werke},\n date = 1988,\n editor = {Colli, Giorgio and Montinari, Mazzino},\n edition = 2,\n volumes = 15,\n publisher = dtv # { and Walter de Gruyter},\n location = {M{\\\"u}nchen and Berlin and New York},\n langid = {german},\n sorttitle = {Werke-00-000},\n indexsorttitle= {Samtliche Werke},\n subtitle = {Kritische Studienausgabe},\n annotation = {The critical edition of Nietzsche's works. This is a\n \\texttt{mvbook} entry referring to a 15-volume work as a\n whole. Note the \\texttt{volumes} field and the format of the\n \\texttt{publisher} and \\texttt{location} fields in the\n database file. Also note the \\texttt{sorttitle} and\n field which is used to fine-tune the\n sorting order of the bibliography. We want this item listed\n first in the bibliography},\n}\"#)"
---
F. Nietzsche: "Sämtliche Werke. Kritische Studienausgabe". Ed. by G. Colli, M. Montinari. 2nd. München and Berlin and New York: Deutscher Taschenbuch-Verlag and Walter de Gruyter, 1988.

View file

@ -1,6 +1,5 @@
---
source: src/citation/tests.rs
assertion_line: 334
source: crates/citeproc/src/tests.rs
expression: "render_entry(r#\"\n@patent{almendro,\n author = {Almendro, Jos{\\'e} L. and Mart{\\'i}n, Jacinto and S{\\'a}nchez,\n Alberto and Nozal, Fernando},\n title = {Elektromagnetisches Signalhorn},\n number = {EU-29702195U},\n date = 1998,\n location = {countryfr and countryuk and countryde},\n langid = {german},\n annotation = {This is a \\texttt{patent} entry with a \\texttt{location}\n field. The number is given in the \\texttt{number} field. Note\n the format of the \\texttt{location} field in the database\n file. Compare \\texttt{laufenberg}, \\texttt{sorace}, and\n \\texttt{kowalik}},\n}\"#)"
---
J. Almendro, J. Martín, A. Sánchez, F. Nozal: "Elektromagnetisches Signalhorn". EU-29702195U (France and United Kingdom and Germany). 1998.

View file

@ -33,7 +33,7 @@ doctest = false
[dependencies]
anyhow = "1.0.69"
base-db = { path = "../base-db" }
chrono = { version = "0.4.23", default-features = false, features = ["std"] }
citeproc = { path = "../citeproc" }
clap = { version = "4.1.6", features = ["derive"] }
crossbeam-channel = "0.5.6"
dashmap = "5.4.0"
@ -46,7 +46,6 @@ flate2 = "1.0.25"
flume = "0.10.14"
fuzzy-matcher = { version = "0.3.7", features = ["compact"] }
human_name = { version = "2.0.1", default-features = false }
isocountry = "0.3.2"
itertools = "0.10.5"
log = "0.4.17"
lsp-server = "0.7.0"
@ -62,13 +61,11 @@ serde_json = "1.0.93"
serde_regex = "1.1.0"
serde_repr = "0.1.10"
smol_str = { version = "0.1.24", features = ["serde"] }
strum = { version = "0.24.1", features = ["derive"] }
syntax = { path = "../syntax" }
tempfile = "3.3.0"
thiserror = "1.0.38"
threadpool = "1.8.1"
titlecase = "2.2.1"
unicode-normalization = "0.1.22"
[dependencies.salsa]
git = "https://github.com/salsa-rs/salsa"

View file

@ -2,7 +2,7 @@ use lsp_types::MarkupKind;
use rowan::ast::AstNode;
use syntax::bibtex;
use crate::{citation, util::cursor::CursorContext};
use crate::util::cursor::CursorContext;
use super::HoverResult;
@ -17,7 +17,7 @@ pub(super) fn find_hover(context: &CursorContext) -> Option<HoverResult> {
let root = data.root(context.db);
let root = bibtex::Root::cast(root)?;
let entry = root.find_entry(&key)?;
citation::render(&entry)
citeproc::render(&entry)
})?;
Some(HoverResult {

View file

@ -1,8 +1,9 @@
use citeproc::field::text::TextFieldData;
use lsp_types::MarkupKind;
use rowan::ast::AstNode;
use syntax::bibtex::{self, HasName, HasValue};
use crate::{citation::field::text::TextFieldData, util::cursor::CursorContext};
use crate::util::cursor::CursorContext;
use super::HoverResult;

View file

@ -1,6 +1,5 @@
#![allow(clippy::needless_lifetimes)]
pub(crate) mod citation;
mod client;
mod config;
pub mod db;

View file

@ -22,7 +22,6 @@ use syntax::bibtex;
use threadpool::ThreadPool;
use crate::{
citation,
client::LspClient,
db::{self, discover_dependencies, Document, Owner, Workspace},
features::{
@ -544,7 +543,7 @@ impl Server {
{
item.documentation = bibtex::Root::cast(root)
.and_then(|root| root.find_entry(&key))
.and_then(|entry| citation::render(&entry))
.and_then(|entry| citeproc::render(&entry))
.map(|value| {
Documentation::MarkupContent(MarkupContent {
kind: MarkupKind::Markdown,