Skip to content

Conversation

@blami
Copy link

@blami blami commented Sep 21, 2025

This change allows to provide callback function to custom requests.

Builds on #640 to accommodate scenarios where response is needed from server but cannot be handled by custom handler (as there's no method field).

@blami
Copy link
Author

blami commented Sep 21, 2025

I was wondering if it would be any useful to have also sync and async variant of RequestCustom (e.g. RequestCustomAsync). With these two virtually any missing/niche functionality can be done as custom request.

I was also thinking of providing noop g:LspRequestCustomReply (basically same as WorkspaceExecuteReply except scope) that can be used if caller does not care about response.

Let me know what do you think and I can make those changes.

Copy link
Contributor

@jclsn jclsn left a comment

Choose a reason for hiding this comment

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

Afaik a funcref needs to exist. For every call without a callback, you would have to create and empty function to pass as argument. So I think it would be better to have a separate function for this. Not a 100% sure though.

This change adds g:LspRequestCustomCb with additional callback function
parameter. Original g:LspRequestCustom calls to it with
WorkspaceExecuteReply as callback function for backwards compatibility.
@blami
Copy link
Author

blami commented Sep 30, 2025

@jclsn Thanks for review, I agree with you. I like approach with *Cb() callback variant. Also I changed the non-callback to just call callback variant providing original WorkspaceExecuteReply so that if logic ever changes fix will be in single place.

The only other option I can think of is to have variadic argument and check for emptyness but that feels too fragile and obscure to me.

Let me know what do you think now.

@jclsn
Copy link
Contributor

jclsn commented Sep 30, 2025

Looks good to me, but in the end @yegappan needs to approve.

@blami blami changed the title feat: Add callback parameter to LspRequestCustom feat: Add custom callback variant of LspRequestCustom Sep 30, 2025
# Request: any
# Params: any
# Cbfunc: callback function
def g:LspRequestCustomCb(name: string, msg: string, params: any, Cbfunc: func): void
Copy link
Owner

Choose a reason for hiding this comment

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

Can you update the help text with some details about how to use this new function?

Copy link
Author

Choose a reason for hiding this comment

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

@yegappan @jclsn Sure I can. I actually did bit of investigation and learning and feel in my specific usecase this should not be needed and it is language server for which I do this being wrong and anything that edits workspace should be really code action and not custom request.

Anyway I think there's still some use for this and g:LspRequestCustom. As I got more familiar with codebase I now think that rather than making both these g: it would be actually better to export in lsp.vim as in case of other functions that are used by commands.

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