Repository: denoland/deno
File: cli/lsp/documents.rs (Rust)

Code before:
      .insert(module.specifier.clone(), module.clone());
    Some(module)
  }

  fn remove_expired(&self) {
    // IMPORTANT: Maintain this order based on weak ref relations.
    self.open.write().remove_expired();
    self.server.write().remove_expired();
    self.by_specifier.write().remove_expired();
  }
}

#[derive(Debug, Default, Clone)]
pub struct DocumentModules {
  pub documents: Documents,
  config: Arc<Config>,
  compiler_options_resolver: Arc<LspCompilerOptionsResolver>,
  resolver: Arc<LspResolver>,
  cache: Arc<LspCache>,
  workspace_files: Arc<IndexSet<PathBuf>>,
  dep_info_by_scope: once_cell::sync::OnceCell<Arc<DepInfoByScope>>,
  modules_unscoped: Arc<WeakDocumentModuleMap>,
  modules_by_scope: Arc<BTreeMap<Arc<Url>, Arc<WeakDocumentModuleMap>>>,
  #[allow(clippy::type_complexity)]
  assigned_scopes:
    Arc<DashMap<Arc<Uri>, (Option<Arc<Url>>, CompilerOptionsKey)>>,
}

impl DocumentModules {
  pub fn update_config(
    &mut self,
    config: &Config,
    compiler_options_resolver: &Arc<LspCompilerOptionsResolver>,
    resolver: &Arc<LspResolver>,
    cache: &LspCache,
    workspace_files: &Arc<IndexSet<PathBuf>>,
  ) {
    self.config = Arc::new(config.clone());
    self.compiler_options_resolver = compiler_options_resolver.clone();
    self.cache = Arc::new(cache.clone());
    self.resolver = resolver.clone();
    self.workspace_files = workspace_files.clone();
    self.modules_unscoped = Default::default();
    self.modules_by_scope = Arc::new(
      self
        .config
        .tree
        .data_by_scope()
        .keys()
        .map(|s| (s.clone(), Default::default()))
        .collect(),

Review comment (performance):
I agree with `type_complexity` lint here - I don't understand what this is storing and a wrapper struct would be helpful here.

Code after:
      .insert(module.specifier.clone(), module.clone());
    Some(module)
  }

  fn remove_expired(&self) {
    // IMPORTANT: Maintain this order based on weak ref relations.
    self.open.write().remove_expired();
    self.server.write().remove_expired();
    self.by_specifier.write().remove_expired();
  }
}

type ScopeInfo = (Option<Arc<Url>>, CompilerOptionsKey);

#[derive(Debug, Default, Clone)]
pub struct DocumentModules {
  pub documents: Documents,
  config: Arc<Config>,
  compiler_options_resolver: Arc<LspCompilerOptionsResolver>,
  resolver: Arc<LspResolver>,
  cache: Arc<LspCache>,
  workspace_files: Arc<IndexSet<PathBuf>>,
  dep_info_by_scope: once_cell::sync::OnceCell<Arc<DepInfoByScope>>,
  modules_unscoped: Arc<WeakDocumentModuleMap>,
  modules_by_scope: Arc<BTreeMap<Arc<Url>, Arc<WeakDocumentModuleMap>>>,
  assigned_scopes: Arc<DashMap<Arc<Uri>, ScopeInfo>>,
}

impl DocumentModules {
  pub fn update_config(
    &mut self,
    config: &Config,
    compiler_options_resolver: &Arc<LspCompilerOptionsResolver>,
    resolver: &Arc<LspResolver>,
    cache: &LspCache,
    workspace_files: &Arc<IndexSet<PathBuf>>,
  ) {
    self.config = Arc::new(config.clone());
    self.compiler_options_resolver = compiler_options_resolver.clone();
    self.cache = Arc::new(cache.clone());
    self.resolver = resolver.clone();
    self.workspace_files = workspace_files.clone();
    self.modules_unscoped = Default::default();
    self.modules_by_scope = Arc::new(
      self
        .config
        .tree
        .data_by_scope()
        .keys()
        .map(|s| (s.clone(), Default::default()))
        .collect(),