mirror of
https://github.com/tombi-toml/tombi.git
synced 2025-08-04 18:48:10 +00:00
feat: add tombi-version-sort crates.
This commit is contained in:
parent
f1523ea651
commit
e1d29bfa57
10 changed files with 28 additions and 13 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -3027,6 +3027,7 @@ dependencies = [
|
|||
"tombi-text",
|
||||
"tombi-toml-version",
|
||||
"tombi-validator",
|
||||
"tombi-version-sort",
|
||||
"tombi-x-keyword",
|
||||
"tracing",
|
||||
]
|
||||
|
@ -3524,6 +3525,13 @@ dependencies = [
|
|||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tombi-version-sort"
|
||||
version = "0.0.0-dev"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tombi-x-keyword"
|
||||
version = "0.0.0-dev"
|
||||
|
|
|
@ -82,6 +82,7 @@ tombi-toml-text = { path = "crates/tombi-toml-text" }
|
|||
tombi-toml-version = { path = "crates/tombi-toml-version" }
|
||||
tombi-url = { path = "crates/tombi-url" }
|
||||
tombi-validator = { path = "crates/tombi-validator" }
|
||||
tombi-version-sort = { path = "crates/tombi-version-sort" }
|
||||
tombi-x-keyword = { path = "crates/tombi-x-keyword" }
|
||||
tower-lsp = { version = "0.20.0" }
|
||||
tracing = { version = "0.1.41" }
|
||||
|
|
|
@ -22,5 +22,6 @@ tombi-syntax.workspace = true
|
|||
tombi-text.workspace = true
|
||||
tombi-toml-version.workspace = true
|
||||
tombi-validator.workspace = true
|
||||
tombi-version-sort.workspace = true
|
||||
tombi-x-keyword.workspace = true
|
||||
tracing.workspace = true
|
||||
|
|
|
@ -402,7 +402,8 @@ impl SortableValues {
|
|||
pub fn sorted_version(self) -> Vec<(tombi_ast::Value, tombi_ast::Comma)> {
|
||||
match self {
|
||||
Self::String(mut sortable_values) => {
|
||||
sortable_values.sort_by(|(a, _, _), (b, _, _)| tombi_x_keyword::version_sort(a, b));
|
||||
sortable_values
|
||||
.sort_by(|(a, _, _), (b, _, _)| tombi_version_sort::version_sort(a, b));
|
||||
sortable_values
|
||||
.into_iter()
|
||||
.map(|(_, value, comma)| (value, comma))
|
||||
|
|
|
@ -3,7 +3,7 @@ use itertools::Itertools;
|
|||
use tombi_ast::AstNode;
|
||||
use tombi_schema_store::{SchemaContext, TableSchema};
|
||||
use tombi_syntax::SyntaxElement;
|
||||
use tombi_x_keyword::version_sort;
|
||||
use tombi_version_sort::version_sort;
|
||||
use tombi_x_keyword::TableKeysOrder;
|
||||
|
||||
pub async fn inline_table_keys_order<'a>(
|
||||
|
|
|
@ -164,7 +164,7 @@ where
|
|||
(
|
||||
SchemaAccessor::Key(a_key),
|
||||
SchemaAccessor::Key(b_key),
|
||||
) => tombi_x_keyword::version_sort(a_key, b_key),
|
||||
) => tombi_version_sort::version_sort(a_key, b_key),
|
||||
_ => unreachable!(
|
||||
"Unexpected accessor type in table keys order sorting"
|
||||
),
|
||||
|
|
10
crates/tombi-version-sort/Cargo.toml
Normal file
10
crates/tombi-version-sort/Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "tombi-version-sort"
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
repository.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
itertools.workspace = true
|
4
crates/tombi-version-sort/README.md
Normal file
4
crates/tombi-version-sort/README.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
# tombi-version-sort
|
||||
|
||||
This is a copy of the rustfmt version sort implementation.
|
||||
For detailed specification, see https://doc.rust-lang.org/nightly/style-guide/index.html#sorting.
|
|
@ -1,7 +1,3 @@
|
|||
mod version_sort;
|
||||
|
||||
pub use version_sort::version_sort;
|
||||
|
||||
pub const X_TOMBI_TOML_VERSION: &str = "x-tombi-toml-version";
|
||||
pub const X_TOMBI_ARRAY_VALUES_ORDER: &str = "x-tombi-array-values-order";
|
||||
pub const X_TOMBI_TABLE_KEYS_ORDER: &str = "x-tombi-table-keys-order";
|
||||
|
@ -13,9 +9,6 @@ pub const X_TOMBI_TABLE_KEYS_ORDER: &str = "x-tombi-table-keys-order";
|
|||
pub enum ArrayValuesOrder {
|
||||
Ascending,
|
||||
Descending,
|
||||
// Version Sorting
|
||||
//
|
||||
// See: https://doc.rust-lang.org/nightly/style-guide/index.html#sorting
|
||||
VersionSort,
|
||||
}
|
||||
|
||||
|
@ -50,9 +43,6 @@ pub enum TableKeysOrder {
|
|||
Ascending,
|
||||
Descending,
|
||||
Schema,
|
||||
// Version Sorting
|
||||
//
|
||||
// See: https://doc.rust-lang.org/nightly/style-guide/index.html#sorting
|
||||
VersionSort,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue