Skip to content

external_scope() should not assume file is in the workspace #1168

@DavisVaughan

Description

@DavisVaughan

pub(crate) fn external_scope(&self, file: &Url) -> ExternalScope {

Right now external_scope() assumes that file is inside the workspace.

i.e. if you open Desktop/test.R while you have a package's workspace open, it assumes you are trying to create a scope chain for a file in the package.

That is not right for a number of reasons, but in particular I noticed that all of my package's Imports were trying to be made available to test.R because of this.

I think external_scope() probably shouldn't use self.root at all, instead maybe we can discover the project type by walking the ancestors of file each time. I think this would allow:

  • Desktop/test.R to be discovered as a script because there is no package root
  • vctrs/R/file.R to still be discovered as part of a package because we find package root info

And then most importantly I'm somewhat hopeful that this can mean that if you goto definition from vctrs into an rlang function, then rlang_cache/R/file.R can be discovered as part of the rlang package rather than the vctrs workspace you might have open at the time, resulting in an entirely different set of goto definition capabilities and diagnostics, etc. Just like what you can do in rust-analyzer

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions