Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Apr 1, 2021
1 parent 0dc1702 commit 0c9f4a7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 38 deletions.
32 changes: 14 additions & 18 deletions cli/lsp/path_to_regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,14 @@ fn lexer(s: &str) -> Result<Vec<LexToken>, AnyError> {
}
Some(':') => {
let mut name = String::new();
loop {
if let Some(c) = chars.peek() {
if (*c >= '0' && *c <= '9')
|| (*c >= 'A' && *c <= 'Z')
|| (*c >= 'a' && *c <= 'z')
|| *c == '_'
{
let ch = chars.next().unwrap();
name.push(ch);
} else {
break;
}
while let Some(c) = chars.peek() {
if (*c >= '0' && *c <= '9')
|| (*c >= 'A' && *c <= 'Z')
|| (*c >= 'a' && *c <= 'z')
|| *c == '_'
{
let ch = chars.next().unwrap();
name.push(ch);
} else {
break;
}
Expand Down Expand Up @@ -451,7 +447,7 @@ pub fn parse(
key += 1;
default
},
|s| StringOrNumber::String(s),
StringOrNumber::String,
);
let prefix = if prefix.is_empty() {
None
Expand Down Expand Up @@ -501,7 +497,7 @@ pub fn parse(
StringOrNumber::String("".to_string())
}
},
|s| StringOrNumber::String(s),
StringOrNumber::String,
);
let pattern = if maybe_name.is_some() && maybe_pattern.is_none() {
default_pattern.clone()
Expand Down Expand Up @@ -617,12 +613,12 @@ pub fn tokens_to_regex(
if has_ends_with {
route.push_str(&format!(r"(?={})", ends_with));
} else {
route.push_str("$");
route.push('$');
}
} else {
let is_end_deliminated = match maybe_end_token {
Some(Token::String(s)) => {
if let Some(c) = s.clone().pop() {
Some(Token::String(mut s)) => {
if let Some(c) = s.pop() {
delimiter.contains(c)
} else {
false
Expand Down Expand Up @@ -693,7 +689,7 @@ impl Compiler {

Self {
matches,
tokens: tokens.iter().cloned().collect(),
tokens: tokens.to_vec(),
validate,
}
}
Expand Down
37 changes: 17 additions & 20 deletions cli/lsp/registries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,8 @@ fn get_completion_endpoint(
Token::Key(k) if k.name == *key => Some(k),
_ => None,
});
url_str = url_str.replace(
&format!("${{{}}}", name),
&value.to_string(maybe_key.clone()),
);
url_str =
url_str.replace(&format!("${{{}}}", name), &value.to_string(maybe_key));
url_str = url_str.replace(
&format!("${{{{{}}}}}", name),
&percent_encoding::percent_encode(
Expand Down Expand Up @@ -174,21 +172,18 @@ fn validate_config(config: &RegistryConfigurationJson) -> Result<(), AnyError> {
}
for registry in &config.registries {
let (_, keys) = string_to_regex(&registry.schema, None)?;
let key_names: HashSet<String> = keys.map_or_else(
|| HashSet::new(),
|keys| {
keys
.iter()
.filter_map(|k| {
if let StringOrNumber::String(s) = &k.name {
Some(s.clone())
} else {
None
}
})
.collect()
},
);
let key_names: HashSet<String> = keys.map_or_else(HashSet::new, |keys| {
keys
.iter()
.filter_map(|k| {
if let StringOrNumber::String(s) = &k.name {
Some(s.clone())
} else {
None
}
})
.collect()
});
let mut variable_names = HashSet::<String>::new();
for variable in &registry.variables {
variable_names.insert(variable.key.clone());
Expand Down Expand Up @@ -292,6 +287,8 @@ impl ModuleRegistry {

pub async fn enable(&mut self, origin: &str) -> Result<(), AnyError> {
let origin = base_url(&Url::parse(origin)?)?;
#[allow(clippy::map_entry)]
// we can't use entry().or_insert_with() because we can't use async closures
if !self.origins.contains_key(&origin) {
let configs = self.fetch_config(&origin).await?;
self.origins.insert(origin, configs);
Expand Down Expand Up @@ -513,7 +510,7 @@ impl ModuleRegistry {
new_text: origin.clone(),
}));
Some(lsp::CompletionItem {
label: origin.clone(),
label: origin,
kind: Some(lsp::CompletionItemKind::Folder),
detail: Some("(registry)".to_string()),
sort_text: Some("1".to_string()),
Expand Down

0 comments on commit 0c9f4a7

Please sign in to comment.