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

Can't access client from server methods #37

Open
dan1994 opened this issue Sep 1, 2022 · 1 comment
Open

Can't access client from server methods #37

dan1994 opened this issue Sep 1, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@dan1994
Copy link

dan1994 commented Sep 1, 2022

I've just started fiddling around with this package, and this is also my first venture into LSPs.
If I understand correctly, in order to send diagnostics about a file in response to a message (e.g. textDocument/didOpen), I need to access the client created by protocol.NewServer.
I see that the client is embedded into the context, but the key used to embed it is private and there appears to be no method to extract it from the context (as opposed to the logger which has LoggerFromContext in context.go).
Am I missing anything?

@a-h
Copy link
Contributor

a-h commented Jul 4, 2024

I think you're right, just an oversight.

Adding a function to context.go is all that's required to make it usable from the server.

// ClientFromContext extracts Client from context.
func ClientFromContext(ctx context.Context) Client {
	client, ok := ctx.Value(ctxClient).(Client)
	if !ok {
		return nil
	}
	return client
}

@zchee zchee added the bug Something isn't working label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

3 participants