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

Completions for macros in #[macro_use(...)] of extern crate/mod declaration #15657

Closed
Veykril opened this issue Sep 23, 2023 · 2 comments · Fixed by #16137
Closed

Completions for macros in #[macro_use(...)] of extern crate/mod declaration #15657

Veykril opened this issue Sep 23, 2023 · 2 comments · Fixed by #16137
Labels
A-completion autocompletion C-feature Category: feature request E-has-instructions Issue has some instructions and pointers to code to get started

Comments

@Veykril
Copy link
Member

Veykril commented Sep 23, 2023

#[macro_use($0)]
extern crate foo;

we should be completing the exported macros of the foo crate here.
Likewise for modules

#[macro_use($0)]
mod foo;
#[macro_use($0)]
mod bar { ... }
@Veykril Veykril added A-completion autocompletion C-feature Category: feature request labels Sep 23, 2023
@Veykril Veykril self-assigned this Oct 6, 2023
@Veykril
Copy link
Member Author

Veykril commented Oct 10, 2023

We'll have to add a new arm to the match here

match path.text().as_str() {
"repr" => repr::complete_repr(acc, ctx, tt),
"feature" => {
lint::complete_lint(acc, ctx, colon_prefix, &parse_tt_as_comma_sep_paths(tt)?, FEATURES)
}
"allow" | "warn" | "deny" | "forbid" => {
let existing_lints = parse_tt_as_comma_sep_paths(tt)?;
let lints: Vec<Lint> = CLIPPY_LINT_GROUPS
.iter()
.map(|g| &g.lint)
.chain(DEFAULT_LINTS)
.chain(CLIPPY_LINTS)
.chain(RUSTDOC_LINTS)
.cloned()
.collect();
lint::complete_lint(acc, ctx, colon_prefix, &existing_lints, &lints);
}
"cfg" => cfg::complete_cfg(acc, ctx),
_ => (),
}

and create a corresponding submodule in crates/ide-completion/src/completions/attribute/macro_use.rs.

Then we'll need to figure out what the attribute we are completing in is actually attached to. For that we need to add a new field here

/// Set if we are currently completing in an unexpanded attribute, this usually implies a builtin attribute like `allow($0)`
UnexpandedAttrTT {
colon_prefix: bool,
fake_attribute_under_caret: Option<ast::Attr>,
},
of type ModuleDef and populate it here appropriately
CompletionAnalysis::UnexpandedAttrTT {
fake_attribute_under_caret: fake_ident_token
.parent_ancestors()
.find_map(ast::Attr::cast),
colon_prefix,
}

Then in the newly created completions module we'll have to check if the definition the attribute is attached to is a module or extern crate and fetch the exported macros for that from there.

@Veykril Veykril added the E-has-instructions Issue has some instructions and pointers to code to get started label Oct 10, 2023
@Veykril Veykril removed their assignment Oct 16, 2023
@unexge
Copy link
Contributor

unexge commented Nov 29, 2023

Seems like arguments to #[macro_use] are not allowed for modules. This fails:

#[macro_use(foo)] // <- error: arguments to `macro_use` are not allowed here
mod inner {
    macro_rules! foo {
        () => {};
    }
}

fn main() {}

We should just autocomplete if #[macro_use] is applied to extern crate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion autocompletion C-feature Category: feature request E-has-instructions Issue has some instructions and pointers to code to get started
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants