Skip to content
Open
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
10 changes: 0 additions & 10 deletions crates/lsp-async-stub/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use std::marker::PhantomData;

#[async_trait(?Send)]
pub(crate) trait Handler<W: Clone> {
fn method(&self) -> &'static str;

async fn handle(
&mut self,
context: Context<W>,
Expand Down Expand Up @@ -72,10 +70,6 @@ where
F: Future<Output = Result<R::Result, rpc::Error>> + 'static,
W: Clone + 'static,
{
fn method(&self) -> &'static str {
R::METHOD
}

async fn handle(
&mut self,
context: Context<W>,
Expand Down Expand Up @@ -160,10 +154,6 @@ where
F: Future + 'static,
W: Clone + 'static,
{
fn method(&self) -> &'static str {
N::METHOD
}

async fn handle(
&mut self,
context: Context<W>,
Expand Down
2 changes: 1 addition & 1 deletion crates/taplo-cli/src/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<E: Environment> Taplo<E> {
}
}

if matches!(cmd.files.get(0).map(|it| it.as_str()), Some("-")) {
if matches!(cmd.files.first().map(|it| it.as_str()), Some("-")) {
self.lint_stdin(cmd).await
} else {
self.lint_files(cmd).await
Expand Down
2 changes: 1 addition & 1 deletion crates/taplo-cli/src/commands/toml_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<'a> TomlTestValue<'a> {
}
}

impl<'a> Serialize for TomlTestValue<'a> {
impl Serialize for TomlTestValue<'_> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
Expand Down
2 changes: 1 addition & 1 deletion crates/taplo-common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Config {
pub fn format_scopes<'s>(
&'s self,
path: &'s Path,
) -> impl Iterator<Item = (&String, taplo::formatter::OptionsIncomplete)> + Clone + 's {
) -> impl Iterator<Item = (&'s String, taplo::formatter::OptionsIncomplete)> + Clone + 's {
self.rules_for(path)
.filter_map(|rule| match (&rule.keys, &rule.options.formatting) {
(Some(keys), Some(opts)) => Some(keys.iter().map(move |k| (k, opts.clone()))),
Expand Down
6 changes: 3 additions & 3 deletions crates/taplo-common/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,21 +716,21 @@ impl NodeValidationError {
Ok(Self { keys, node, error })
}

#[must_use]
pub fn text_ranges(&self) -> Box<dyn Iterator<Item = TextRange> + '_> {
match self.error.kind {
ValidationErrorKind::AdditionalProperties { .. } => {
let include_children = false;

if self.keys.is_empty() {
return Box::new(self.node.text_ranges(include_children).into_iter());
return Box::new(self.node.text_ranges(include_children));
}

Box::new(
self.keys
.clone()
.into_iter()
.map(move |key| self.node.get(key).text_ranges(include_children))
.flatten(),
.flat_map(move |key| self.node.get(key).text_ranges(include_children)),
)
}
_ => Box::new(self.node.text_ranges(true)),
Expand Down
12 changes: 6 additions & 6 deletions crates/taplo-common/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ impl PartialEq for ArcHashValue {
#[derive(Eq)]
pub struct HashValue<'v>(pub &'v Value);

impl<'v> PartialEq for HashValue<'v> {
impl PartialEq for HashValue<'_> {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}

impl<'v> Hash for HashValue<'v> {
impl Hash for HashValue<'_> {
fn hash<H: Hasher>(&self, state: &mut H) {
match &self.0 {
Value::Null => 0.hash(state),
Expand Down Expand Up @@ -126,10 +126,10 @@ pub fn get_reqwest_client(timeout: std::time::Duration) -> Result<reqwest::Clien
#[cfg(any(feature = "native-tls", feature = "rustls-tls"))]
fn get_certs(
mut builder: reqwest::ClientBuilder,
path: std::ffi::OsString,
path: &std::ffi::OsStr,
) -> reqwest::ClientBuilder {
fn get_cert(path: &Path) -> Result<reqwest::Certificate, anyhow::Error> {
let is_der = path.extension().map_or(false, |ext| ext == "der");
let is_der = path.extension().is_some_and(|ext| ext == "der");
let buf = std::fs::read(path)?;
tracing::info!(
"Found a custom CA {}. Reading the CA...",
Expand All @@ -156,15 +156,15 @@ pub fn get_reqwest_client(timeout: std::time::Duration) -> Result<reqwest::Clien
#[cfg(not(any(feature = "native-tls", feature = "rustls-tls")))]
fn get_certs(
builder: reqwest::ClientBuilder,
path: std::ffi::OsString,
path: &std::ffi::OsStr,
) -> reqwest::ClientBuilder {
tracing::error!(?path, "Could not load certs, taplo was built without TLS");
builder
}

let mut builder = reqwest::Client::builder().timeout(timeout);
if let Some(path) = std::env::var_os("TAPLO_EXTRA_CA_CERTS") {
builder = get_certs(builder, path);
builder = get_certs(builder, &path);
}
builder.build()
}
17 changes: 5 additions & 12 deletions crates/taplo-lsp/src/handlers/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub async fn completion<E: Environment>(
|| s["type"] == "object"
|| s["type"]
.as_array()
.map_or(false, |arr| arr.iter().any(|v| v == "object"))
.is_some_and(|arr| arr.iter().any(|v| v == "object"))
})
}) {
Ok(s) => s,
Expand Down Expand Up @@ -113,8 +113,7 @@ pub async fn completion<E: Environment>(
.filter(|(full_key, _, _)| match doc.dom.path(full_key) {
Some(n) => {
node.0 == *full_key
|| n.as_table()
.map_or(false, |t| t.kind() == TableKind::Pseudo)
|| n.as_table().is_some_and(|t| t.kind() == TableKind::Pseudo)
}
None => true,
})
Expand Down Expand Up @@ -209,9 +208,7 @@ pub async fn completion<E: Environment>(
.into_iter()
// Filter out existing items.
.filter(|(full_key, _, _)| match doc.dom.path(full_key) {
Some(n) => n
.as_table()
.map_or(false, |t| t.kind() == TableKind::Pseudo),
Some(n) => n.as_table().is_some_and(|t| t.kind() == TableKind::Pseudo),
None => true,
})
.map(|(_, relative_keys, schema)| CompletionItem {
Expand Down Expand Up @@ -318,9 +315,7 @@ pub async fn completion<E: Environment>(
.into_iter()
// Filter out existing items.
.filter(|(full_key, _, _)| match doc.dom.path(full_key) {
Some(n) => n
.as_table()
.map_or(false, |t| t.kind() == TableKind::Pseudo),
Some(n) => n.as_table().is_some_and(|t| t.kind() == TableKind::Pseudo),
None => true,
})
.map(|(_, relative_keys, schema)| CompletionItem {
Expand Down Expand Up @@ -418,9 +413,7 @@ pub async fn completion<E: Environment>(
.into_iter()
// Filter out existing items.
.filter(|(full_key, _, _)| match doc.dom.path(full_key) {
Some(n) => n
.as_table()
.map_or(false, |t| t.kind() == TableKind::Pseudo),
Some(n) => n.as_table().is_some_and(|t| t.kind() == TableKind::Pseudo),
None => true,
})
.map(|(_, relative_keys, schema)| CompletionItem {
Expand Down
12 changes: 2 additions & 10 deletions crates/taplo-lsp/src/handlers/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@ pub(crate) async fn hover<E: Environment>(
s += desc;
}

let link_title = if let Some(s) = schema["title"].as_str() {
s
} else {
"..."
};
let link_title = schema["title"].as_str().unwrap_or("...");

if links_in_hover {
if let Some(link) = &ext_links.key {
Expand Down Expand Up @@ -212,11 +208,7 @@ pub(crate) async fn hover<E: Environment>(
if let Some(enum_docs) = enum_docs.get(idx).cloned().flatten() {
if links_in_hover {
let link_title =
if let Some(s) = schema["title"].as_str() {
s
} else {
"..."
};
schema["title"].as_str().unwrap_or("...");

if let Some(enum_link) =
enum_links.get(idx).and_then(Option::as_ref)
Expand Down
4 changes: 2 additions & 2 deletions crates/taplo-lsp/src/handlers/semantic_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn create_tokens(syntax: &SyntaxNode, mapper: &Mapper) -> Vec<SemanticToken>
.parent()
.and_then(|p| p.next_sibling())
.and_then(|t| t.first_child())
.map_or(false, |t| t.kind() == INLINE_TABLE);
.is_some_and(|t| t.kind() == INLINE_TABLE);

if is_table_key {
builder.add_token(&token, TokenType::TomlTableKey, &[]);
Expand All @@ -98,7 +98,7 @@ pub fn create_tokens(syntax: &SyntaxNode, mapper: &Mapper) -> Vec<SemanticToken>
.parent()
.and_then(|p| p.next_sibling())
.and_then(|t| t.first_child())
.map_or(false, |t| t.kind() == ARRAY);
.is_some_and(|t| t.kind() == ARRAY);

if is_array_key {
builder.add_token(&token, TokenType::TomlArrayKey, &[]);
Expand Down
27 changes: 9 additions & 18 deletions crates/taplo-lsp/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,10 @@ impl Query {
pub fn header_key(&self) -> Option<SyntaxNode> {
match (&self.before, &self.after) {
(Some(before), _) => {
let Some(header_syntax) = before
let header_syntax = before
.syntax
.parent_ancestors()
.find(|s| matches!(s.kind(), TABLE_ARRAY_HEADER | TABLE_HEADER))
else {
return None;
};
.find(|s| matches!(s.kind(), TABLE_ARRAY_HEADER | TABLE_HEADER))?;

header_syntax.descendants().find(|n| n.kind() == KEY)
}
Expand All @@ -188,13 +185,10 @@ impl Query {
None => return None,
};

let Some(keys) = syntax
let keys = syntax
.parent_ancestors()
.find(|n| n.kind() == ENTRY)
.and_then(|entry| entry.children().find(|c| c.kind() == KEY))
else {
return None;
};
.and_then(|entry| entry.children().find(|c| c.kind() == KEY))?;

Some(keys)
}
Expand All @@ -206,13 +200,10 @@ impl Query {
None => return None,
};

let Some(value) = syntax
let value = syntax
.parent_ancestors()
.find(|n| n.kind() == ENTRY)
.and_then(|entry| entry.children().find(|c| c.kind() == VALUE))
else {
return None;
};
.and_then(|entry| entry.children().find(|c| c.kind() == VALUE))?;

Some(value)
}
Expand Down Expand Up @@ -294,7 +285,7 @@ impl Query {
#[must_use]
pub fn in_entry_keys(&self) -> bool {
self.entry_key()
.map_or(false, |k| k.text_range().contains(self.offset))
.is_some_and(|k| k.text_range().contains(self.offset))
}

#[must_use]
Expand All @@ -318,7 +309,7 @@ impl Query {
let in_value = self
.entry_value()
// We are inside the value even if the cursor is right after it.
.map_or(false, |k| k.text_range().contains_inclusive(self.offset));
.is_some_and(|k| k.text_range().contains_inclusive(self.offset));

if in_value {
return true;
Expand All @@ -341,7 +332,7 @@ impl Query {

#[must_use]
pub fn is_single_quote_value(&self) -> bool {
self.entry_value().map_or(false, |v| {
self.entry_value().is_some_and(|v| {
v.descendants_with_tokens()
.any(|t| matches!(t.kind(), STRING_LITERAL | MULTI_LINE_STRING_LITERAL))
})
Expand Down
24 changes: 2 additions & 22 deletions crates/taplo-wasm/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,7 @@ impl AsyncRead for JsAsyncRead {
}
};

let promise = match Promise::try_from(ret) {
Ok(p) => p,
Err(err) => {
return Poll::Ready(Err(io::Error::new(
io::ErrorKind::Other,
format!("{:?}", err),
)));
}
};

self.fut = Some(JsFuture::from(promise));
self.fut = Some(JsFuture::from(Promise::from(ret)));
}

if let Some(fut) = self.fut.as_mut() {
Expand Down Expand Up @@ -113,17 +103,7 @@ impl AsyncWrite for JsAsyncWrite {
}
};

let promise = match Promise::try_from(ret) {
Ok(p) => p,
Err(err) => {
return Poll::Ready(Err(io::Error::new(
io::ErrorKind::Other,
format!("{:?}", err),
)));
}
};

self.fut = Some(JsFuture::from(promise));
self.fut = Some(JsFuture::from(Promise::from(ret)));
}

if let Some(fut) = self.fut.as_mut() {
Expand Down
4 changes: 3 additions & 1 deletion crates/taplo-wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Silence errors produced by the #[wasm_bindgen] macro.
#![allow(unexpected_cfgs)]

use environment::WasmEnvironment;
use serde::Serialize;
use std::path::Path;
Expand Down Expand Up @@ -213,7 +216,6 @@ pub async fn run_cli(env: JsValue, args: JsValue) -> Result<(), JsError> {
#[cfg(feature = "lsp")]
#[wasm_bindgen]
pub fn create_lsp(env: JsValue, lsp_interface: JsValue) -> lsp::TaploWasmLsp {
use taplo_common::environment::Environment;
use taplo_common::log::setup_stderr_logging;

let env = WasmEnvironment::from(env);
Expand Down
4 changes: 2 additions & 2 deletions crates/taplo/src/dom/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ impl Index for String {
}
}

impl<'a, T> Sealed for &'a T where T: ?Sized + Sealed {}
impl<'a, T> Index for &'a T
impl<T> Sealed for &T where T: ?Sized + Sealed {}
impl<T> Index for &T
where
T: ?Sized + Index,
{
Expand Down
2 changes: 1 addition & 1 deletion crates/taplo/src/dom/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl Node {
&self,
keys: Keys,
include_children: bool,
) -> Result<impl Iterator<Item = (Keys, Node)> + ExactSizeIterator, Error> {
) -> Result<impl ExactSizeIterator<Item = (Keys, Node)>, Error> {
let mut all = self.flat_iter_impl();

let mut err: Option<Error> = None;
Expand Down
12 changes: 6 additions & 6 deletions crates/taplo/src/dom/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ pub enum Error {
Dom(#[from] dom::error::Error),
}

fn std_range(range: TextRange) -> Range<usize> {
let start: usize = u32::from(range.start()) as usize;
let end: usize = u32::from(range.end()) as usize;
start..end
}

#[cfg(test)]
mod tests {
use super::Rewrite;
Expand Down Expand Up @@ -192,9 +198,3 @@ mod tests {
assert_eq!(expected_toml, patches.to_string());
}
}

fn std_range(range: TextRange) -> Range<usize> {
let start: usize = u32::from(range.start()) as usize;
let end: usize = u32::from(range.end()) as usize;
start..end
}
Loading
Loading