manateelazycat / lsp-bridge

A blazingly fast LSP client for Emacs
GNU General Public License v3.0
1.42k stars 205 forks source link

Auto-import broken for duplicate names #826

Closed runekaagaard closed 8 months ago

runekaagaard commented 8 months ago

When using pyright lsp server to auto-import a name that exists in multiple files only the last candidate is shown. This is due to the "detail" key of the response always being "Auto-import" and thus the candidate key being "MyThing_Auto-import" for all the candidates.

This little change in the process_response method in completion.py works for me:

import hashlib

if self.file_action.enable_auto_import:
    candidate["additionalTextEdits"] = item.get("additionalTextEdits", [])
    key += "_".join(
        hashlib.md5(x["newText"].encode('utf-8')).hexdigest()
        for x in candidate["additionalTextEdits"])
    candidate["key"] = key
manateelazycat commented 8 months ago

can you send test code to me?

runekaagaard commented 8 months ago

Sure, you can try to import the symbol MyThing in the file d.py from this repo:

https://github.com/runekaagaard/lspb-example

It should show MyThing from a.py, b.py and c.py.

manateelazycat commented 8 months ago

How to operate? Can you tell me the steps to reproduce?

runekaagaard commented 8 months ago

Sure, go to d.py and type MyThing on an empty line. I only shows the completion for one of a, b or c but should show all three.

manateelazycat commented 8 months ago

I typed MyThing, but there was no completion menu. Can you share your lsp-bridge configuration?

runekaagaard commented 8 months ago

Hmmm, that's very standard. You are probably missing pyright?

pip install pyright
# or
npm install -g pyright
manateelazycat commented 8 months ago

截图 2024-01-12 20-26-22 截图 2024-01-12 20-26-30

I guess because lsp-bridge-python-multi-lsp-server "pyright-background-analysis_ruff" ?

Which python lsp server did you use?

runekaagaard commented 8 months ago

I use pyright and have no special configuration related to that, LSPB picks it up automatically.

manateelazycat commented 8 months ago

Can you send a PR ? I'm happy merge it if logic is okay.

runekaagaard commented 8 months ago

https://github.com/manateelazycat/lsp-bridge/pull/829