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

automatic imports stopped working #61

Open
the-drunk-coder opened this issue Oct 24, 2024 · 16 comments
Open

automatic imports stopped working #61

the-drunk-coder opened this issue Oct 24, 2024 · 16 comments

Comments

@the-drunk-coder
Copy link

Hi,

I've been using rustic mode for a while now, but today I noticed that automated imports stopped working.

That is, when starting to type a type name, the options show up, but if I hit "return" or "tab", nothing happens, when in the past the required type would be added automatically.

Not sure whether that's a rustic issue, but maybe someone can point me in the right direction?

Best,
N

@Erk-
Copy link

Erk- commented Oct 24, 2024

Which lsp backend do you use?

@the-drunk-coder
Copy link
Author

rust-analyzer

@xitep
Copy link

xitep commented Oct 24, 2024

just want to confirm that i've observed same issue on my side as well; invoking lsp-execute-code-action (bound to C-c C-c a) is something i've been using as a workaround so far; but it's very inconvenient :/

using rust-analyzer (tagged as 2024-10-21 in the rust-analyzer repo; i'm not sure but it's about two / three weeks back that i started seeing it suddenly happening.)

@Erk-
Copy link

Erk- commented Oct 25, 2024

rust-analyzer

Ah sorry I meant which LSP client is used inside of emacs, lsp-mode or eglot, or something else?

@the-drunk-coder
Copy link
Author

I'm using lsp-mode

@the-drunk-coder
Copy link
Author

btw, not sure whether that helps but I observed some other problems as well that make the overall experience way less smooth that it was just a couple of weeks ago ... summarized them here:

https://users.rust-lang.org/t/recent-problems-with-emacs-rustic

@Erk-
Copy link

Erk- commented Oct 25, 2024

Could you try to log the communication between lsp-mode and rust-analyzer as described here? https://emacs-lsp.github.io/lsp-mode/page/troubleshooting/#log-client-server-json

Then it should be possible to figure out if it happens because of lsp-mode or something else.

@the-drunk-coder
Copy link
Author

@Erk- what would I be looking out for ?

@psibi
Copy link
Member

psibi commented Oct 25, 2024

One of the techniques which I use to debug this kind of issue is follow this:

  • Try editing the same Rust project using Vscode using the same version of Rust-analyzer
  • See if you are able able to reprduce it. If you are able to reproduce it, this is likely a rust-analyzer issue.
  • If you are not able to reproduce it, get the logs based on the above link which @Erk- put.
  • Get also the logs for VSCode and compare them to see why they differ.

@Erk-
Copy link

Erk- commented Oct 25, 2024

The request/response which inserts the imports is completionItem/resolve which is the one you want to look for.

@the-drunk-coder
Copy link
Author

@Erk-

the items look like this:

[Trace - 03:28:31 PM] Sending request 'completionItem/resolve - (168)'.
Params: {
  "label": "HashMap (use std::collections::HashMap)",
  "kind": 22,
  "deprecated": null,
  "sortText": "80000000",
  "filterText": "HashMap",
  "textEdit": {
    "newText": "HashMap",
    "insert": {
      "start": {
        "line": 6,
        "character": 15
      },
      "end": {
        "line": 6,
        "character": 19
      }
    },
    "replace": {
      "start": {
        "line": 6,
        "character": 15
      },
      "end": {
        "line": 6,
        "character": 19
      }
    }
  },
  "additionalTextEdits": [],
  "data": {
    "position": {
      "textDocument": {
        "uri": "file:///[...].rs"
      },
      "position": {
        "line": 6,
        "character": 19
      }
    },
    "imports": [
      {
        "full_import_path": "std::collections::HashMap",
        "imported_name": "HashMap"
      }
    ],
    "version": 34,
    "trigger_character": null
  }
}

@Erk-
Copy link

Erk- commented Oct 25, 2024

@the-drunk-coder Does rust-analyzer not send a response back?

@CeleritasCelery
Copy link
Contributor

Also, make sure that lsp-rust-analyzer-completion-auto-import-enable and lsp-completion-enable-additional-text-edit are both t.

@the-drunk-coder
Copy link
Author

Also, make sure that lsp-rust-analyzer-completion-auto-import-enable and lsp-completion-enable-additional-text-edit are both t.

Added them to my .emacs but that doesn't change anything ...

@the-drunk-coder
Copy link
Author

the-drunk-coder commented Oct 25, 2024

@the-drunk-coder Does rust-analyzer not send a response back?

yes, they look like this:

[Trace - 04:44:35 PM] Received response 'completionItem/resolve - (162)' in 289ms.
Result: {
  "label": "HashSet (use std::collections::HashSet)",
  "kind": 22,
  "sortText": "80000000",
  "filterText": "HashSet",
  "textEdit": {
    "newText": "HashSet",
    "insert": {
      "start": {
        "line": 48,
        "character": 10
      },
      "end": {
        "line": 48,
        "character": 15
      }
    },
    "replace": {
      "start": {
        "line": 48,
        "character": 10
      },
      "end": {
        "line": 48,
        "character": 15
      }
    }
  },
  "additionalTextEdits": []
}

(it's from a subsequent attempt, not the same one as above)

But it's strange that all the info needed (additional imports, etc) already seems to be present in the request ..

@psibi
Copy link
Member

psibi commented Nov 6, 2024

Looks like an upstream issue: rust-lang/rust-analyzer#18363

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants