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

Broken IDE intellisense for input, frame modules and others. #375

Closed
kevzettler opened this issue May 8, 2023 · 11 comments
Closed

Broken IDE intellisense for input, frame modules and others. #375

kevzettler opened this issue May 8, 2023 · 11 comments
Labels
bug Something isn't working

Comments

@kevzettler
Copy link
Contributor

I'm working on some input handling features and have some Ambient code like:

   let mut cursor_lock = input::CursorLockGuard::new(true);
    ambient_api::messages::Frame::subscribe(move |_| {
        let (delta, input) = input::get_delta();

I wanted to learn more about input::get_delta and messages::Frame However my IDE cannot look up any definitions,implementations, or declarations for these modules. I have tried in both emacs, and vscode There are gifs below.

in emacs:

emacs

And in Vscode

vscode

Is this a greater configuration issue on my machine? If this is expected behavior this is very unfortunate developer experience. Seems to break expected conventions and very cumbersome to have to go look at Ambient source code directly.

@philpax philpax added the bug Something isn't working label May 9, 2023
@philpax
Copy link
Contributor

philpax commented May 9, 2023

This is definitely not intentional; it's an issue with rust-analyzer not being able to handle the attribute proc macros. If you comment out the #[main] attribute, your intellisense will work properly.

I'll see if I can chat to the rust-analyzer folk about why this is happening, and what we can do to prevent it.


I haven't been able to reproduce this consistently - do you have an example you can share?

@kevzettler
Copy link
Contributor Author

yes I do see the #[main] macro highlighted with:

server.rs 51 1 error unresolved-proc-macro proc macro `main` not expanded: no proc macro dylib present (lsp)

@philpax this is currently happening in my public project at:
https://github.com/kevzettler/ambient-test-project

@philpax
Copy link
Contributor

philpax commented May 9, 2023

Cheers, I'll have a look soon!

I notice that you have a direct dependency on ambient_api:

ambient_api = { path = "/Users/kevzettler/code/Ambient/guest/rust/api" }

Do you still see the same issue if you switch to using ambient_api = "0.2.1"?

@kevzettler
Copy link
Contributor Author

kevzettler commented May 9, 2023

@philpax I just switched to ambient_api = "0.2.1" and did cargo update

/Users/kevzettler/code/ambient-test-project
kevzettler@kevs-mbp-3 ambient-test-project % cargo update
    Updating crates.io index
      Adding ambient_api v0.2.1
      Adding ambient_api_core v0.2.1
      Adding ambient_api_macros v0.2.1
      Adding ambient_cb v0.2.1
      Adding ambient_color v0.2.1
      Adding ambient_editor_derive v0.2.1
      Adding ambient_element v0.2.1
      Adding ambient_element_component v0.2.1
      Adding ambient_friendly_id v0.2.1
      Adding ambient_guest_bridge v0.2.1
      Adding ambient_math v0.2.1
      Adding ambient_project v0.2.1
      Adding ambient_project_macro_common v0.2.1
      Adding ambient_project_rt v0.2.1
      Adding ambient_schema v0.2.1
      Adding ambient_shared_types v0.2.1
      Adding ambient_time v0.2.1
      Adding ambient_ui v0.2.1
    Updating libc v0.2.143 -> v0.2.144
    Updating quote v1.0.26 -> v1.0.27

Unfortunately, The issue still happens

@philpax
Copy link
Contributor

philpax commented May 9, 2023

Cheers, will look into it!

@philpax
Copy link
Contributor

philpax commented May 11, 2023

Had some time to look at it, and realised what the issue was.

The proc-macro is only built if R-A sees a binary using it; however, because the client and the server binaries both have required-features, R-A doesn't consider them, and doesn't end up building the proc macro.

To fix this, you need to tell your IDE/R-A to treat the environment as having those features enabled, so that it will attempt to build the binaries and the corresponding proc macro. We have this set up by default for new projects, but it's something that needs to be added to existing projects.

To do this for VSCode (sorry, not sure what it is for emacs), create .vscode/settings.json in your project directory:

{
  "rust-analyzer.cargo.features": ["client", "server"]
}

Sorry about this - we should have called this out in the changelog!

Let me know if that fixes the issue.

@kevzettler
Copy link
Contributor Author

ok thanks that was the issue. Found an emacs implementation at:
emacs-lsp/lsp-mode#3375

@philpax
Copy link
Contributor

philpax commented May 12, 2023

Can you detail what settings you used for emacs? I'll add both VSCode and Emacs to the known pitfalls docs

@kevzettler
Copy link
Contributor Author

ok I just had to revisit this after some updates and the I had to set the following variables for lsp-mode in emacs

  (setq lsp-rust-analyzer-cargo-target "wasm32-wasi"
        lsp-rust-analyzer-cargo-watch-args ["--features" "client server"]
        lsp-rust-features ["client" "server"])

@kevzettler
Copy link
Contributor Author

Furthermore you can add a .dir-locals.el file to your project directory that emacs will pick up and load settings for. Similiar to the .vscode/settings.json The contents of that file in my project are:

((rustic-mode . ((eval . (setq-local lsp-rust-analyzer-cargo-target "wasm32-wasi"))
                 (eval . (setq-local lsp-rust-analyzer-cargo-watch-args ["--features" "client server"]))
                 (eval . (setq-local lsp-rust-features ["client" "server"])))))

@FredrikNoren
Copy link
Contributor

@kevzettler Would you mind adding this to https://ambientrun.github.io/Ambient/user/setting_up_ide.html ? We should create a section for emacs there

kevzettler added a commit to kevzettler/Ambient that referenced this issue Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants