multilspy icon indicating copy to clipboard operation
multilspy copied to clipboard

Searching for symbols directly

Open prabhuteja12 opened this issue 1 year ago • 2 comments

Hello,

Thank you for the great code!

I was wondering if there is a way to search for a symbol directly instead of pointing to file and line number where that symbol is mentioned.

For eg: Currently

lsp.request_definition("myfile.py", 10, 2)

searches for the symbol (say something called SymbolName) that is mentioned in the 11th line, and 3rd character. I would like to check if something like lsp.request_definition("SymbolName") is possible.

Thank you! Edit:

LSP specification seems to do something for this: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_symbol

prabhuteja12 avatar Jan 02 '25 13:01 prabhuteja12

I hacked together a small solution to suit my needs by adding the following method to the LanguageServer class.

 async def workspace_symbol(
        self, symbol: str
    ) -> Union[List[SymbolInformation], List[WorkspaceSymbol], None]:
        response = await self.server.send.workspace_symbol(
            params=WorkspaceSymbolParams(query=symbol)
        )
        return response

prabhuteja12 avatar Jan 02 '25 14:01 prabhuteja12

Hi @prabhuteja12, great find and implementation. Could you please contribute a PR about the same?

I would just request to include a test using this function in at least one of the languages (hopefully your target usecase). Please let me know if I can help in any way!

LakshyAAAgrawal avatar Jan 26 '25 06:01 LakshyAAAgrawal