Skip to content

Conversation

@bennyyip
Copy link
Contributor

@bennyyip bennyyip commented Jan 20, 2025

This feature is for lsp server with custom locations request(e.g. ccls). It's similar to CocLocations in coc.nvim.

Example config for ccls

# not call
nmap <buffer> <localleader>f <scriptcmd>g:LspFindLocations('ccls', false, "textDocument/references", {"excludeRole": 32})<cr>
# macro
nmap <buffer> <localleader>M <scriptcmd>g:LspFindLocations('ccls', false, "textDocument/references", {"role": 64})<cr>
# read
nmap <buffer> <localleader>r <scriptcmd>g:LspFindLocations('ccls', false, "textDocument/references", {"role": 8})<cr>
# write
nmap <buffer> <localleader>w <scriptcmd>g:LspFindLocations('ccls', false, "textDocument/references", {"role": 16})<cr>
# x (xref)
# bases of up to 3 levels
nmap <buffer> <localleader>b <scriptcmd>g:LspFindLocations('ccls', false, "$ccls/inheritance", {})<cr>
nmap <buffer> <localleader>B <scriptcmd>g:LspFindLocations('ccls', false, "$ccls/inheritance", {"levels": 3})<cr>
# derived of up to 3 levels
nmap <buffer> <localleader>d <scriptcmd>g:LspFindLocations('ccls', false, "$ccls/inheritance", {"derived": v:true})<cr>
# derived of up to 3 levels
nmap <buffer> <localleader>D <scriptcmd>g:LspFindLocations('ccls', false, "$ccls/inheritance", {"derived": v:true, "levels": 3})<cr>
# caller
nmap <buffer> <localleader>c <scriptcmd>g:LspFindLocations('ccls', false, "$ccls/call")<cr>
# callee
nmap <buffer> <localleader>C <scriptcmd>g:LspFindLocations('ccls', false, "$ccls/call", {"callee": v:true})<cr>
# member
nmap <buffer> <localleader>m <scriptcmd>g:LspFindLocations('ccls', false, "$ccls/member")<cr>

Copy link
Contributor

@Shane-XB-Qian Shane-XB-Qian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try the instr in 'lsp-cfg-customRequestHandlers', maybe that is your need.

@Shane-XB-Qian
Copy link
Contributor

or if you just want to ignore some custom, then refer #386

@bennyyip
Copy link
Contributor Author

bennyyip commented Jan 20, 2025

@Shane-XB-Qian I want to use custom locations, not to ignore them.
If a lsp server supports custom locations, it probably supports references.

Can we specify a lsp server by name? For example, g:FindLocations('ccls', false, "$ccls/member")

@Shane-XB-Qian
Copy link
Contributor

yes, you can customized add your request handler too, please check that example:

		vim9script
		g:LspAddServer([{
			filetype: ['javascript', 'typescript'],
			path: '/usr/local/bin/typescript-language-server',
			args: ['--stdio'],
			customNotificationHandlers: {
				'$/typescriptVersion': (lspserver, reply) => {
					echom printf("TypeScript Version = %s",
						reply.params.version)
				}
			}
		}])

in doc, or if not fit, then maybe need to refine this custom filter code.

@bennyyip
Copy link
Contributor Author

lsp-custom-commands is about handling command from server to client.
This PR is about sending command from client to server.

@bennyyip
Copy link
Contributor Author

bennyyip commented Jan 20, 2025

Since custom command is only available in certain lsp server, I added buf.CurbufGetServerByName to specify it.

@Shane-XB-Qian
Copy link
Contributor

Shane-XB-Qian commented Jan 20, 2025 via email

@bennyyip
Copy link
Contributor Author

CreateRequest() just constructs a request, and I don't think it's for end-user. This PR sends msg to server using lspserver.rpc().

@Shane-XB-Qian
Copy link
Contributor

yes, i mean if like to support this feat, maybe began to use this CreateRequest() to constructs request.
normally the req to server were some fixed msg which defined in lsp spec,
as for custom, i have no such demand, and felt rare needing, let's see if yeggapa have some comment.

@yegappan yegappan merged commit 74718e5 into yegappan:main Jan 21, 2025
2 checks passed
Copy link
Contributor

@Shane-XB-Qian Shane-XB-Qian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yegappan accepted your PR, though maybe some tiny flaw, but not a big deal, it's ok.
//similar like others PR i reviewed here today, you maybe can refine it in the future..


# Result: Location[] | null
if reply->empty() || reply.result->empty()
util.WarnMsg('No references found')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to your example in the OP, looks your custom msg were not all for references, but do location related things, so:

  1. the description here and next symbol.ShowLocations looks not accurate?
  2. for now so-called 'custom request' actually only for 'location' related things.

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

Successfully merging this pull request may close these issues.

3 participants