Skip to content

Commit 914791e

Browse files
authored
Error in handlers if init handshake hasn't happened (#1747)
1 parent 865ec14 commit 914791e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

internal/lsp/server.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,10 @@ var handlers = sync.OnceValue(func() handlerMap {
468468

469469
func registerNotificationHandler[Req any](handlers handlerMap, info lsproto.NotificationInfo[Req], fn func(*Server, context.Context, Req) error) {
470470
handlers[info.Method] = func(s *Server, ctx context.Context, req *lsproto.RequestMessage) error {
471+
if s.session == nil && req.Method != lsproto.MethodInitialized {
472+
return lsproto.ErrServerNotInitialized
473+
}
474+
471475
var params Req
472476
// Ignore empty params; all generated params are either pointers or any.
473477
if req.Params != nil {
@@ -486,6 +490,10 @@ func registerRequestHandler[Req, Resp any](
486490
fn func(*Server, context.Context, Req, *lsproto.RequestMessage) (Resp, error),
487491
) {
488492
handlers[info.Method] = func(s *Server, ctx context.Context, req *lsproto.RequestMessage) error {
493+
if s.session == nil && req.Method != lsproto.MethodInitialize {
494+
return lsproto.ErrServerNotInitialized
495+
}
496+
489497
var params Req
490498
// Ignore empty params.
491499
if req.Params != nil {

0 commit comments

Comments
 (0)