Add support for source() directive in symbol resolution#1157
Open
lionel- wants to merge 10 commits intooak/namespacefrom
Open
Add support for source() directive in symbol resolution#1157lionel- wants to merge 10 commits intooak/namespacefrom
source() directive in symbol resolution#1157lionel- wants to merge 10 commits intooak/namespacefrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Branched from #1154
Closes #1148
Progress towards posit-dev/positron#11112
Adds support for
source()directives in scripts, allowing for cross-file symbol resolution. Like in RStudio, sourced files are resolved from the workspace directory. Effects on the LSP:source()call.library()andrequire()calls are also made available after thesource()call.For now this only affects goto-definition, but should later also affect diagnostics such as unused symbols.
Both
source()andlibrary()are allowed in lazy nested scopes such as function bodies. In that case the side effects are available inside that scope (and nested children), but not outside, even though the effects are global. That's because outside that scope, code can't make assumptions about the availability of the symbols.With a
helpers.Rfile containing:We have at top-level:
In nested scopes:
At top-level, it doesn't matter whether
localis true or false, the sourced definitions overwrite any local ones. We have a newDefinitionKind::Sourcedvariant for these definitions:In nested scopes, if
local = FALSE, the sourced definitions are made available via cross-file directives instead, that are only used for unbound symbols. This allows proper resolution of local symbols:If
localis true, sourced definitions are instead added to the local scope.