Skip to content

Commit

Permalink
chore: run cargo clippy to fix warnings
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Jan 3, 2024
1 parent b82e786 commit cec5a95
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 27 deletions.
14 changes: 6 additions & 8 deletions kclvm/tools/src/LSP/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub(crate) fn completion(
label: name,
detail: Some(ty.ty_str()),
documentation: sema_info.doc.clone(),
kind: type_to_item_kind(&ty),
kind: type_to_item_kind(ty),
insert_text: None,
});
}
Expand Down Expand Up @@ -248,9 +248,9 @@ fn completion_dot(
kclvm_sema::ty::TypeKind::Schema(_) => {
Some(KCLCompletionItemKind::SchemaAttr)
}
_ => type_to_item_kind(&attr_ty),
_ => type_to_item_kind(attr_ty),
},
None => type_to_item_kind(&attr_ty),
None => type_to_item_kind(attr_ty),
};
let documentation = match &sema_info.doc {
Some(doc) => {
Expand Down Expand Up @@ -615,12 +615,10 @@ fn ty_complete_label(ty: &Type, module: Option<&ModuleInfo>) -> Vec<String> {
"{}{}{}",
if schema.pkgpath.is_empty() || schema.pkgpath == MAIN_PKG {
"".to_string()
} else if let Some(m) = module {
format!("{}.", pkg_real_name(&schema.pkgpath, m))
} else {
if let Some(m) = module {
format!("{}.", pkg_real_name(&schema.pkgpath, m))
} else {
format!("{}.", schema.pkgpath.split('.').last().unwrap())
}
format!("{}.", schema.pkgpath.split('.').last().unwrap())
},
schema.name,
"{}"
Expand Down
1 change: 1 addition & 0 deletions kclvm/tools/src/LSP/src/document_symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ fn symbol_to_document_symbol(symbol: &KCLSymbol) -> Option<DocumentSymbol> {
let kind = symbol_kind_to_document_symbol_kind(kind);
let detail = sema_info.ty.clone().map(|ty| ty.ty_str());

#[allow(deprecated)]
Some(DocumentSymbol {
name,
kind,
Expand Down
8 changes: 3 additions & 5 deletions kclvm/tools/src/LSP/src/find_refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ pub(crate) fn find_refs_from_def<F: Fn(String) -> Result<(), anyhow::Error>>(
for (_, word_index) in &mut *word_index_map.write() {
if let Some(mut locs) = word_index.get(name.as_str()).cloned() {
if locs.len() >= 20 {
let _ = logger(format!(
"Found more than 20 matched symbols, only the first 20 will be processed"
));
let _ = logger("Found more than 20 matched symbols, only the first 20 will be processed".to_string());
locs = locs[0..20].to_vec();
}

Expand Down Expand Up @@ -109,14 +107,14 @@ pub(crate) fn find_refs_from_def<F: Fn(String) -> Result<(), anyhow::Error>>(
Err(err) => {
let _ = logger(format!(
"{file_path} compilation failed: {}",
err.to_string()
err
));
false
}
}
}
Err(err) => {
let _ = logger(format!("compilation failed: {}", err.to_string()));
let _ = logger(format!("compilation failed: {}", err));
false
}
}
Expand Down
12 changes: 6 additions & 6 deletions kclvm/tools/src/LSP/src/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ where
if let Some(symbol_ref) = find_def_with_gs(&kcl_pos, &gs, true) {
if let Some(symbol_def) = gs.get_symbols().get_symbol(symbol_ref) {
if symbol_def.get_range() == range {
refs.push(loc.clone())
refs.push(loc)
}
}
}
Expand Down Expand Up @@ -400,7 +400,7 @@ where
mod tests {
use kclvm_ast::ast;
use kclvm_error::diagnostic;
use lsp_types::{Location, Position, Range, TextEdit, Url};
use lsp_types::{Position, Range, TextEdit};
use maplit::hashmap;
use parking_lot::RwLock;
use std::fs;
Expand Down Expand Up @@ -509,7 +509,7 @@ e = a["abc"]

#[test]
fn test_select_symbol() {
let (root, _, person_path, server_path, config_path, vfs) = prepare_vfs();
let (root, _, person_path, server_path, _config_path, vfs) = prepare_vfs();
let pkg_root = root.as_path().to_str().unwrap().to_string();

if let Some((name, range)) = select_symbol(
Expand Down Expand Up @@ -689,7 +689,7 @@ e = a["abc"]

let vfs: Arc<RwLock<Vfs>> = Arc::new(RwLock::new(Default::default()));
for path in vec![base_path, main_path] {
let content = fs::read_to_string(path.clone()).unwrap();
let content = fs::read_to_string(path).unwrap();
vfs.write().set_file_contents(
VfsPath::new_virtual_path(path.to_string()),
Some(content.into_bytes()),
Expand Down Expand Up @@ -884,8 +884,8 @@ a = base.Person {
root.to_str().unwrap(),
"base:Person",
hashmap! {
base_path_string.clone() => base_source_code.clone().to_string(),
main_path_string.clone() => main_source_code.clone().to_string(),
base_path_string.clone() => base_source_code.to_string(),
main_path_string.clone() => main_source_code.to_string(),
},
"NewPerson".to_string(),
)
Expand Down
2 changes: 1 addition & 1 deletion kclvm/tools/src/LSP/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ pub(crate) fn handle_document_symbol(
}
Ok(res)
}
Err(_) => return Ok(None),
Err(_) => Ok(None),
}
}

Expand Down
8 changes: 4 additions & 4 deletions kclvm/tools/src/LSP/src/semantic_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ mod tests {
.iter()
.map(|token| {
(
token.delta_line as u32,
token.delta_start as u32,
token.length as u32,
token.token_type as u32,
token.delta_line,
token.delta_start,
token.length,
token.token_type,
)
})
.collect();
Expand Down
8 changes: 5 additions & 3 deletions kclvm/tools/src/LSP/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ pub(crate) fn get_real_path_from_external(
real_path
}

#[allow(unused)]
pub(crate) fn build_word_index_for_source_codes(
source_codes: HashMap<String, String>,
prune: bool,
Expand Down Expand Up @@ -792,9 +793,10 @@ pub(crate) fn build_word_index(
build_word_index_for_file_paths(&files, prune)
}

pub struct VirtualLocation {
pub filepath: String,
pub range: Range,
#[allow(unused)]
pub(crate) struct VirtualLocation {
pub(crate) filepath: String,
pub(crate) range: Range,
}

pub(crate) fn build_word_index_for_file_content_with_vfs(
Expand Down

0 comments on commit cec5a95

Please sign in to comment.