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

rust-analyzer and generated code #12167

Closed
axbannaz opened this issue May 5, 2022 · 16 comments
Closed

rust-analyzer and generated code #12167

axbannaz opened this issue May 5, 2022 · 16 comments
Labels
C-support Category: support questions

Comments

@axbannaz
Copy link

axbannaz commented May 5, 2022

Hi,
Does the rust-analyzer support indexing the FFI generated code to C/C++ world? if it dose not, would it be possible to have it support it?
Thanks

@bjorn3
Copy link
Member

bjorn3 commented May 5, 2022

There is no difference between FFI generated code and other generated code. If the generated code is part of the source or created by a build script, rust-analyzer should support it just fine.

@axbannaz
Copy link
Author

axbannaz commented May 6, 2022

I can give an example of a project that I am looking at https://github.com/temporalio/sdk-core.git. looking at bridge-ffi/src/lib.rs file and trying to find definition of CreateWorkerRequest referenced at bridge-ffi/src/lib.rs:225
it is not able to find it. no definition found for 'CreateWorkerRequest'
Do I need to set an extra option? does it work out of the box?

I am using the latest version of rust-analyzer v0.2.1040 and vscode 1.67.0

VS code options set for rust-analyzer

    "rust-analyzer.assist.importPrefix": "crate",
    "rust-analyzer.callInfo.full": true,
    "rust-analyzer.cargo.runBuildScripts": false,
    "rust-analyzer.checkOnSave.enable": true,
    "rust-analyzer.hoverActions.enable": true,
    "rust-analyzer.hoverActions.debug": true,
    "rust-analyzer.hoverActions.gotoTypeDef": true,
    "rust-analyzer.hoverActions.implementations": true,
    "rust-analyzer.hoverActions.references": true,
    "rust-analyzer.hoverActions.run": true,
    "rust-analyzer.lens.enable": true,
    "rust-analyzer.lens.enumVariantReferences": true,
    "rust-analyzer.lens.debug": true,
    "rust-analyzer.lens.implementations": true,
    "rust-analyzer.lens.methodReferences": true,
    "rust-analyzer.lens.references": true,
    "rust-analyzer.lens.run": true,
    "rust-analyzer.procMacro.enable": false,
    "rust-analyzer.notifications.cargoTomlNotFound": true,
    "rust-analyzer.trace.server": "verbose",
    "rust-analyzer.trace.extension": true,
    "rust-analyzer.workspace.symbol.search.scope": "workspace_and_dependencies",
    "rust-analyzer.workspace.symbol.search.kind": "all_symbols",

@bjorn3
Copy link
Member

bjorn3 commented May 6, 2022

Can you go to https://github.com/temporalio/sdk-core/blob/79bc52c03917e6ad03d9d3692da2f65f8b9c9ca0/sdk-core-protos/src/lib.rs#L26 and see if it shows any errors? I believe this macro creates CreateWorkerRequest. By the way tonic handles RPC, not FFI.

@axbannaz
Copy link
Author

axbannaz commented May 6, 2022

Ah you are right.. CreateWorkerRequest is part of the sdk-core-protos crate. project build just fine. with regards for rust-analyzer, not sure where to check for errors..
grepping through the project, the generated code containing CreateWorkerRequest is in target/debug/build/temporal-sdk-core-protos-ffe87ea728c1ba6c/out/coresdk.bridge.rs after build was done.

@axbannaz axbannaz changed the title rust-analyzer and FFI code rust-analyzer and generated code May 6, 2022
@flodiebold flodiebold added the C-support Category: support questions label May 6, 2022
@flodiebold
Copy link
Member

flodiebold commented May 6, 2022

You need to enable rust-analyzer.cargo.runBuildScripts. (Also, I would recommend not turning off rust-analyzer.procMacro.enable either.)

@axbannaz
Copy link
Author

axbannaz commented May 6, 2022

Thanks, That resolved the Go to Definition issue.. however it takes me to where macro is used to include the generated code..
is there a way to go to the generated code not the macro call?

@flodiebold
Copy link
Member

That's #3767.

@axbannaz
Copy link
Author

axbannaz commented May 6, 2022

Thanks..
neither rust-analyzer.cargoFeatures.loadOutDirsFromCheck nor rust-analyzer.cargo.loadOutDirsFromCheck seem to work. their entries in settings.json are grayed out and no effect after adding them.

@bjorn3
Copy link
Member

bjorn3 commented May 6, 2022

You need rust-analyzer.cargo.runBuildScripts to be true. rust-analyzer.cargo.loadOutDirsFromCheck was the old name for it I believe.

@axbannaz
Copy link
Author

axbannaz commented May 6, 2022

That is what have been running with as per your suggestion.. however the "Go to definition" goes to the macro not the generated code.
a note.. when I hover on the CreateWorkerRequest I do see the correct info.. it is just not jumping to it.

temporal_sdk_core_protos::coresdk::bridge
pub struct CreateWorkerRequest
0 implementations

Current config

    "rust-analyzer.assist.importPrefix": "crate",
    "rust-analyzer.callInfo.full": true,
    "rust-analyzer.cargo.runBuildScripts": true,
    "rust-analyzer.checkOnSave.enable": true,
    "rust-analyzer.hoverActions.enable": true,
    "rust-analyzer.hoverActions.debug": true,
    "rust-analyzer.hoverActions.gotoTypeDef": true,
    "rust-analyzer.hoverActions.implementations": true,
    "rust-analyzer.hoverActions.references": true,
    "rust-analyzer.hoverActions.run": true,
    "rust-analyzer.lens.enable": true,
    "rust-analyzer.lens.enumVariantReferences": true,
    "rust-analyzer.lens.debug": true,
    "rust-analyzer.lens.implementations": true,
    "rust-analyzer.lens.methodReferences": true,
    "rust-analyzer.lens.references": true,
    "rust-analyzer.lens.run": true,
    "rust-analyzer.procMacro.enable": true,
    "rust-analyzer.notifications.cargoTomlNotFound": true,
    "rust-analyzer.trace.server": "verbose",
    "rust-analyzer.trace.extension": true,
    "rust-analyzer.workspace.symbol.search.scope": "workspace_and_dependencies",
    "rust-analyzer.workspace.symbol.search.kind": "all_symbols",

@bjorn3
Copy link
Member

bjorn3 commented May 6, 2022

As @flodiebold already mentioned that is #3767

@axbannaz
Copy link
Author

axbannaz commented May 6, 2022

I am sorry, I may be missing something.. but, I am getting two settings from #3767
"rust-analyzer.cargoFeatures.loadOutDirsFromCheck": true
and
"rust-analyzer.cargo.loadOutDirsFromCheck": true
neither one seem to work as expected. as I mentioned above.

@bjorn3
Copy link
Member

bjorn3 commented May 6, 2022

Those are the old names of rust-analyzer.cargo.runBuildScripts. #3767 is an issue that goto definition is not supported for include!() in rust-analyzer. There is no setting you can toggle to allow it, rust-analyzer is simply missing support for it.

@axbannaz
Copy link
Author

axbannaz commented May 6, 2022

Ah, I see. do you foresee adding support for it?

@bjorn3
Copy link
Member

bjorn3 commented May 7, 2022

It will probably be added at some point, but I don't know how hard that would be.

@flodiebold
Copy link
Member

Let's close this since that problem is already tracked elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-support Category: support questions
Projects
None yet
Development

No branches or pull requests

3 participants