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

Complete exported macros in #[macro_use($0)] #16137

Merged
merged 3 commits into from Dec 22, 2023

Conversation

unexge
Copy link
Contributor

@unexge unexge commented Dec 16, 2023

Closes #15657.

Originally added a test case for incomplete input:

#[test]
fn completes_incomplete_syntax() {
    check(
        r#"
//- /dep.rs crate:dep
#[macro_export]
macro_rules! foo {
    () => {};
}

//- /main.rs crate:main deps:dep
#[macro_use($0
extern crate dep;
"#,
        expect![[r#"
                ma foo
            "#]],
    )
}

but couldn't make it pass and removed it 😅 Our current recovering logic doesn't work for token trees and for this code:

#[macro_use(
extern crate lazy_static;

fn main() {}

we ended up with this syntax tree:

SOURCE_FILE@0..53
  ATTR@0..52
    POUND@0..1 "#"
    L_BRACK@1..2 "["
    META@2..52
      PATH@2..11
        PATH_SEGMENT@2..11
          NAME_REF@2..11
            IDENT@2..11 "macro_use"
      TOKEN_TREE@11..52
        L_PAREN@11..12 "("
        WHITESPACE@12..13 "\n"
        EXTERN_KW@13..19 "extern"
        WHITESPACE@19..20 " "
        CRATE_KW@20..25 "crate"
        WHITESPACE@25..26 " "
        IDENT@26..37 "lazy_static"
        SEMICOLON@37..38 ";"
        WHITESPACE@38..40 "\n\n"
        FN_KW@40..42 "fn"
        WHITESPACE@42..43 " "
        IDENT@43..47 "main"
        TOKEN_TREE@47..49
          L_PAREN@47..48 "("
          R_PAREN@48..49 ")"
        WHITESPACE@49..50 " "
        TOKEN_TREE@50..52
          L_CURLY@50..51 "{"
          R_CURLY@51..52 "}"
  WHITESPACE@52..53 "\n"

Maybe we can try to parse the token tree in crates/ide-completion/src/context/analysis.rs but I'm not sure what's the best way forward.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 16, 2023
if let Some(tt) = ast::TokenTree::cast(parent.clone()) {
if let Some(x) = try_lookup_include_path(sema, tt, token.clone(), file_id) {
return Some(vec![x]);
}

if let Some(x) = try_lookup_macro_def_in_macro_use(sema, token.clone()) {
Copy link
Member

Choose a reason for hiding this comment

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

Fine to do now, but ideally this would be done the same way we handle derives, by giving macro_use a dummy expansion we can map into. #11929

@Veykril
Copy link
Member

Veykril commented Dec 22, 2023

Thanks!
@bors r+

@bors
Copy link
Collaborator

bors commented Dec 22, 2023

📌 Commit 3b8801c has been approved by Veykril

It is now in the queue for this repository.

@Veykril
Copy link
Member

Veykril commented Dec 22, 2023

Our current recovering logic doesn't work for token trees

There is not much we can do there, since a token tree ends at its closing delimiter.

@bors
Copy link
Collaborator

bors commented Dec 22, 2023

⌛ Testing commit 3b8801c with merge 23a1280...

@bors
Copy link
Collaborator

bors commented Dec 22, 2023

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing 23a1280 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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