Completions for relative imports (., .., …) and partials #1361
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.
This PR adds completion support for relative module imports with leading dots (
.
,..
,...
) and partials (e.g.,.Sub
,..Sib
,...Gran
), for bothusing
andimport
.Today, users typing relative imports get no completions for the next module segment, and EOL positions often don’t trigger the import completion path. This PR improves the editing experience without changing resolution behavior.
This code tries to:
Base.M
does not trigger.import
completion when we detect leading dots, even if the expression under the cursor is nothing (e.g., at EOL). Guard all parent searches.import
/using
expression around the cursor; thenimport .
→ children of the current moduleimport ..
→ children of the parent moduleimport ...
→ children of the grandparent moduleimport .Sub
→ Submodule, etc.using
.Implementation details
requests/completions.jl
:_relative_dot_depth_at(doc, offset)
: robust dot-run counter._current_module_expr/_module_ancestor_expr
: walk module EXPR parents in CST._child_module_names
: list child module names by scanning the module body (or file).import_completions
if either we’re in an import/using or relative-dot depth > 0; only callget_parent_fexpr
on a safe EXPR and avoid calling it on nothing.CompletionItems
for children; fall back to existing logic for other branches.Tests
test/requests/test_relative_imports.jl
:import .
/..
/...
produce expected module child completions.Sub
,..Sib
,...Gran
) completeusing
forms mirror the same behaviorBase.M
is not treated as relativeCompatibility and performance
Notes