Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lsp): move sloppy import resolution from loader to resolver #23751

Merged
merged 8 commits into from
May 9, 2024
Prev Previous commit
Next Next commit
reduce some clones
  • Loading branch information
dsherret committed May 9, 2024
commit d572ea5571deb353c0e8103cc9a9cabbbec173ca
22 changes: 11 additions & 11 deletions cli/lsp/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ impl LspResolver {
Ok(())
}

pub fn as_graph_resolver<'a>(
&self,
pub fn as_graph_resolver<'a, 'b>(
&'a self,
// this really only needs a HashSet<ModuleSpecifier>, but it's provided
// the entire HashMap to avoid cloning all the time
open_docs: &'a HashMap<ModuleSpecifier, Arc<Document>>,
) -> LspGraphResolver<'a> {
open_docs: &'b HashMap<ModuleSpecifier, Arc<Document>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was thinking about this more this morning and realized that we should just not bother passing the open documents here. In places like vscode, the file will always exist on the file system if it's open (unlike our test server), so we can just consult that for simplicity.

) -> LspGraphResolver<'a, 'b> {
LspGraphResolver {
resolver: self.graph_resolver.clone(),
cache: self.cache.clone(),
resolver: &self.graph_resolver,
cache: self.cache.as_ref(),
unstable_sloppy_imports: self.unstable_sloppy_imports,
open_docs,
}
Expand Down Expand Up @@ -333,14 +333,14 @@ impl LspResolver {
}

#[derive(Debug)]
pub struct LspGraphResolver<'a> {
cache: Arc<dyn HttpCache>,
resolver: Arc<CliGraphResolver>,
open_docs: &'a HashMap<ModuleSpecifier, Arc<Document>>,
pub struct LspGraphResolver<'a, 'b> {
cache: &'a dyn HttpCache,
resolver: &'a CliGraphResolver,
open_docs: &'b HashMap<ModuleSpecifier, Arc<Document>>,
unstable_sloppy_imports: bool,
}

impl<'a> Resolver for LspGraphResolver<'a> {
impl<'a, 'b> Resolver for LspGraphResolver<'a, 'b> {
fn default_jsx_import_source(&self) -> Option<String> {
self.resolver.default_jsx_import_source()
}
Expand Down
Loading