Skip to content

Commit

Permalink
chore: enable clippy unused_async rule (denoland#22834)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Mar 12, 2024
1 parent c38c14f commit ad6b00a
Show file tree
Hide file tree
Showing 38 changed files with 433 additions and 430 deletions.
13 changes: 5 additions & 8 deletions cli/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,17 @@ impl CliFactoryBuilder {
}
}

pub async fn build_from_flags(
self,
flags: Flags,
) -> Result<CliFactory, AnyError> {
pub fn build_from_flags(self, flags: Flags) -> Result<CliFactory, AnyError> {
Ok(self.build_from_cli_options(Arc::new(CliOptions::from_flags(flags)?)))
}

pub async fn build_from_flags_for_watcher(
pub fn build_from_flags_for_watcher(
mut self,
flags: Flags,
watcher_communicator: Arc<WatcherCommunicator>,
) -> Result<CliFactory, AnyError> {
self.watcher_communicator = Some(watcher_communicator);
self.build_from_flags(flags).await
self.build_from_flags(flags)
}

pub fn build_from_cli_options(self, options: Arc<CliOptions>) -> CliFactory {
Expand Down Expand Up @@ -190,8 +187,8 @@ pub struct CliFactory {
}

impl CliFactory {
pub async fn from_flags(flags: Flags) -> Result<Self, AnyError> {
CliFactoryBuilder::new().build_from_flags(flags).await
pub fn from_flags(flags: Flags) -> Result<Self, AnyError> {
CliFactoryBuilder::new().build_from_flags(flags)
}

pub fn from_cli_options(options: Arc<CliOptions>) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion cli/lsp/code_lens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ pub fn collect_test(
}

/// Return tsc navigation tree code lenses.
pub async fn collect_tsc(
pub fn collect_tsc(
specifier: &ModuleSpecifier,
code_lens_settings: &CodeLensSettings,
line_index: Arc<LineIndex>,
Expand Down
48 changes: 20 additions & 28 deletions cli/lsp/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ impl Inner {
})
}

pub async fn update_cache(&mut self) -> Result<(), AnyError> {
pub fn update_cache(&mut self) -> Result<(), AnyError> {
let mark = self.performance.mark("lsp.update_cache");
self.performance.measure(mark);
let maybe_cache = &self.config.workspace_settings().cache;
Expand Down Expand Up @@ -816,23 +816,17 @@ impl Inner {
None
};
if self.maybe_global_cache_path != maybe_global_cache_path {
self
.set_new_global_cache_path(maybe_global_cache_path)
.await?;
self.set_new_global_cache_path(maybe_global_cache_path)?;
}
Ok(())
}

async fn recreate_http_client_and_dependents(
&mut self,
) -> Result<(), AnyError> {
self
.set_new_global_cache_path(self.maybe_global_cache_path.clone())
.await
fn recreate_http_client_and_dependents(&mut self) -> Result<(), AnyError> {
self.set_new_global_cache_path(self.maybe_global_cache_path.clone())
}

/// Recreates the http client and all dependent structs.
async fn set_new_global_cache_path(
fn set_new_global_cache_path(
&mut self,
new_cache_path: Option<PathBuf>,
) -> Result<(), AnyError> {
Expand Down Expand Up @@ -1025,21 +1019,21 @@ impl Inner {

async fn update_registries(&mut self) -> Result<(), AnyError> {
let mark = self.performance.mark("lsp.update_registries");
self.recreate_http_client_and_dependents().await?;
self.recreate_http_client_and_dependents()?;
let workspace_settings = self.config.workspace_settings();
for (registry, enabled) in workspace_settings.suggest.imports.hosts.iter() {
if *enabled {
lsp_log!("Enabling import suggestions for: {}", registry);
self.module_registries.enable(registry).await?;
} else {
self.module_registries.disable(registry).await?;
self.module_registries.disable(registry)?;
}
}
self.performance.measure(mark);
Ok(())
}

async fn update_config_file(&mut self) -> Result<(), AnyError> {
fn update_config_file(&mut self) -> Result<(), AnyError> {
self.config.clear_config_file();
self.fmt_options = FmtOptions::new_with_base(self.initial_cwd.clone());
self.lint_options = LintOptions::new_with_base(self.initial_cwd.clone());
Expand All @@ -1064,7 +1058,7 @@ impl Inner {
self.config.set_config_file(config_file);
self.lint_options = lint_options;
self.fmt_options = fmt_options;
self.recreate_http_client_and_dependents().await?;
self.recreate_http_client_and_dependents()?;
if let Some(config_file) = self.config.maybe_config_file() {
if let Ok((compiler_options, _)) = config_file.to_compiler_options() {
if let Some(compiler_options_obj) = compiler_options.as_object() {
Expand Down Expand Up @@ -1278,11 +1272,11 @@ impl Inner {

self.update_debug_flag();
// Check to see if we need to change the cache path
if let Err(err) = self.update_cache().await {
if let Err(err) = self.update_cache() {
lsp_warn!("Error updating cache: {:#}", err);
self.client.show_message(MessageType::WARNING, err);
}
if let Err(err) = self.update_config_file().await {
if let Err(err) = self.update_config_file() {
lsp_warn!("Error updating config file: {:#}", err);
self.client.show_message(MessageType::WARNING, err);
}
Expand Down Expand Up @@ -1349,11 +1343,11 @@ impl Inner {
self.refresh_npm_specifiers().await;
}

async fn shutdown(&self) -> LspResult<()> {
fn shutdown(&self) -> LspResult<()> {
Ok(())
}

async fn did_open(
fn did_open(
&mut self,
specifier: &ModuleSpecifier,
params: DidOpenTextDocumentParams,
Expand Down Expand Up @@ -1475,15 +1469,15 @@ impl Inner {
};

self.update_debug_flag();
if let Err(err) = self.update_cache().await {
if let Err(err) = self.update_cache() {
lsp_warn!("Error updating cache: {:#}", err);
self.client.show_message(MessageType::WARNING, err);
}
if let Err(err) = self.update_registries().await {
lsp_warn!("Error updating registries: {:#}", err);
self.client.show_message(MessageType::WARNING, err);
}
if let Err(err) = self.update_config_file().await {
if let Err(err) = self.update_config_file() {
lsp_warn!("Error updating config file: {:#}", err);
self.client.show_message(MessageType::WARNING, err);
}
Expand Down Expand Up @@ -1601,7 +1595,7 @@ impl Inner {
files_to_check.insert(url.clone());
}
// Update config.
if let Err(err) = self.update_config_file().await {
if let Err(err) = self.update_config_file() {
lsp_warn!("Error updating config file: {:#}", err);
self.client.show_message(MessageType::WARNING, err);
}
Expand Down Expand Up @@ -2246,7 +2240,7 @@ impl Inner {
)),
)
.await?;
code_action.edit = refactor_edit_info.to_workspace_edit(self).await?;
code_action.edit = refactor_edit_info.to_workspace_edit(self)?;
code_action
} else {
// The code action doesn't need to be resolved
Expand Down Expand Up @@ -2314,7 +2308,6 @@ impl Inner {
line_index,
&navigation_tree,
)
.await
.map_err(|err| {
error!(
"Error getting ts code lenses for \"{:#}\": {:#}",
Expand Down Expand Up @@ -2483,7 +2476,7 @@ impl Inner {
.await?;

if let Some(definition) = maybe_definition {
let results = definition.to_definition(line_index, self).await;
let results = definition.to_definition(line_index, self);
self.performance.measure(mark);
Ok(results)
} else {
Expand Down Expand Up @@ -2978,7 +2971,6 @@ impl Inner {
let rename_locations = tsc::RenameLocations { locations };
let workspace_edits = rename_locations
.into_workspace_edit(&params.new_name, self)
.await
.map_err(|err| {
error!("Failed to get workspace edits: {:#}", err);
LspError::internal_error()
Expand Down Expand Up @@ -3426,7 +3418,7 @@ impl tower_lsp::LanguageServer for LanguageServer {

async fn shutdown(&self) -> LspResult<()> {
self.1.cancel();
self.0.write().await.shutdown().await
self.0.write().await.shutdown()
}

async fn did_open(&self, params: DidOpenTextDocumentParams) {
Expand All @@ -3441,7 +3433,7 @@ impl tower_lsp::LanguageServer for LanguageServer {
let specifier = inner
.url_map
.normalize_url(&params.text_document.uri, LspUrlKind::File);
let document = inner.did_open(&specifier, params).await;
let document = inner.did_open(&specifier, params);
if document.is_diagnosable() {
inner.refresh_npm_specifiers().await;
let specifiers = inner.documents.dependents(&specifier);
Expand Down
2 changes: 1 addition & 1 deletion cli/lsp/registries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ impl ModuleRegistry {
}

/// Disable a registry, removing its configuration, if any, from memory.
pub async fn disable(&mut self, origin: &str) -> Result<(), AnyError> {
pub fn disable(&mut self, origin: &str) -> Result<(), AnyError> {
let origin = base_url(&Url::parse(origin)?);
self.origins.remove(&origin);
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion cli/lsp/testing/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl TestRun {
let args = self.get_args();
lsp_log!("Executing test run with arguments: {}", args.join(" "));
let flags = flags_from_vec(args.into_iter().map(String::from).collect())?;
let factory = CliFactory::from_flags(flags).await?;
let factory = CliFactory::from_flags(flags)?;
// Various test files should not share the same permissions in terms of
// `PermissionsContainer` - otherwise granting/revoking permissions in one
// file would have impact on other files, which is undesirable.
Expand Down
6 changes: 3 additions & 3 deletions cli/lsp/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2106,7 +2106,7 @@ pub struct RenameLocations {
}

impl RenameLocations {
pub async fn into_workspace_edit(
pub fn into_workspace_edit(
self,
new_name: &str,
language_server: &language_server::Inner,
Expand Down Expand Up @@ -2226,7 +2226,7 @@ impl DefinitionInfoAndBoundSpan {
Ok(())
}

pub async fn to_definition(
pub fn to_definition(
&self,
line_index: Arc<LineIndex>,
language_server: &language_server::Inner,
Expand Down Expand Up @@ -2609,7 +2609,7 @@ impl RefactorEditInfo {
Ok(())
}

pub async fn to_workspace_edit(
pub fn to_workspace_edit(
&self,
language_server: &language_server::Inner,
) -> LspResult<Option<lsp::WorkspaceEdit>> {
Expand Down
10 changes: 7 additions & 3 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async fn run_subcommand(flags: Flags) -> Result<i32, AnyError> {
tools::run::eval_command(flags, eval_flags).await
}),
DenoSubcommand::Cache(cache_flags) => spawn_subcommand(async move {
let factory = CliFactory::from_flags(flags).await?;
let factory = CliFactory::from_flags(flags)?;
let module_load_preparer = factory.module_load_preparer().await?;
let emitter = factory.emitter()?;
let graph_container = factory.graph_container();
Expand All @@ -119,7 +119,7 @@ async fn run_subcommand(flags: Flags) -> Result<i32, AnyError> {
emitter.cache_module_emits(&graph_container.graph())
}),
DenoSubcommand::Check(check_flags) => spawn_subcommand(async move {
let factory = CliFactory::from_flags(flags).await?;
let factory = CliFactory::from_flags(flags)?;
let module_load_preparer = factory.module_load_preparer().await?;
module_load_preparer
.load_and_type_check_files(&check_flags.files)
Expand All @@ -137,7 +137,11 @@ async fn run_subcommand(flags: Flags) -> Result<i32, AnyError> {
)
}
DenoSubcommand::Init(init_flags) => {
spawn_subcommand(async { tools::init::init_project(init_flags).await })
spawn_subcommand(async {
// make compiler happy since init_project is sync
tokio::task::yield_now().await;
tools::init::init_project(init_flags)
})
}
DenoSubcommand::Info(info_flags) => {
spawn_subcommand(async { tools::info::info(flags, info_flags).await })
Expand Down
3 changes: 1 addition & 2 deletions cli/tools/bench/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,7 @@ pub async fn run_benchmarks_with_watch(
let bench_flags = bench_flags.clone();
Ok(async move {
let factory = CliFactoryBuilder::new()
.build_from_flags_for_watcher(flags, watcher_communicator.clone())
.await?;
.build_from_flags_for_watcher(flags, watcher_communicator.clone())?;
let cli_options = factory.cli_options();
let bench_options = cli_options.resolve_bench_options(bench_flags)?;

Expand Down
9 changes: 5 additions & 4 deletions cli/tools/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ pub async fn bundle(
move |flags, watcher_communicator, _changed_paths| {
let bundle_flags = bundle_flags.clone();
Ok(async move {
let factory = CliFactoryBuilder::new()
.build_from_flags_for_watcher(flags, watcher_communicator.clone())
.await?;
let factory = CliFactoryBuilder::new().build_from_flags_for_watcher(
flags,
watcher_communicator.clone(),
)?;
let cli_options = factory.cli_options();
let _ = watcher_communicator.watch_paths(cli_options.watch_paths());
bundle_action(factory, &bundle_flags).await?;
Expand All @@ -48,7 +49,7 @@ pub async fn bundle(
)
.await?;
} else {
let factory = CliFactory::from_flags(flags).await?;
let factory = CliFactory::from_flags(flags)?;
bundle_action(factory, &bundle_flags).await?;
}

Expand Down
2 changes: 1 addition & 1 deletion cli/tools/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub async fn compile(
flags: Flags,
compile_flags: CompileFlags,
) -> Result<(), AnyError> {
let factory = CliFactory::from_flags(flags).await?;
let factory = CliFactory::from_flags(flags)?;
let cli_options = factory.cli_options();
let module_graph_creator = factory.module_graph_creator().await?;
let parsed_source_cache = factory.parsed_source_cache();
Expand Down
2 changes: 1 addition & 1 deletion cli/tools/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ pub async fn cover_files(
return Err(generic_error("No matching coverage profiles found"));
}

let factory = CliFactory::from_flags(flags).await?;
let factory = CliFactory::from_flags(flags)?;
let npm_resolver = factory.npm_resolver().await?;
let file_fetcher = factory.file_fetcher()?;
let cli_options = factory.cli_options();
Expand Down
7 changes: 2 additions & 5 deletions cli/tools/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use deno_config::glob::PathOrPatternSet;
use deno_core::anyhow::bail;
use deno_core::anyhow::Context;
use deno_core::error::AnyError;
use deno_core::futures::FutureExt;
use deno_doc as doc;
use deno_graph::GraphKind;
use deno_graph::ModuleAnalyzer;
Expand Down Expand Up @@ -73,7 +72,7 @@ async fn generate_doc_nodes_for_builtin_types(
}

pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> {
let factory = CliFactory::from_flags(flags).await?;
let factory = CliFactory::from_flags(flags)?;
let cli_options = factory.cli_options();
let module_info_cache = factory.module_info_cache()?;
let parsed_source_cache = factory.parsed_source_cache();
Expand Down Expand Up @@ -156,8 +155,6 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> {
};

generate_docs_directory(&doc_nodes_by_url, html_options, deno_ns)
.boxed_local()
.await
} else {
let modules_len = doc_nodes_by_url.len();
let doc_nodes =
Expand Down Expand Up @@ -224,7 +221,7 @@ impl deno_doc::html::HrefResolver for DocResolver {
}
}

async fn generate_docs_directory(
fn generate_docs_directory(
doc_nodes_by_url: &IndexMap<ModuleSpecifier, Vec<doc::DocNode>>,
html_options: &DocHtmlFlag,
deno_ns: std::collections::HashSet<Vec<String>>,
Expand Down
Loading

0 comments on commit ad6b00a

Please sign in to comment.