Skip to content

Commit 9516c6f

Browse files
committed
factor out todos
1 parent 1171089 commit 9516c6f

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

internal/lsp/server.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,16 +496,18 @@ var handlers = sync.OnceValue(func() handlerMap {
496496
registerLanguageServiceDocumentRequestHandler(handlers, lsproto.TextDocumentDefinitionInfo, (*Server).handleDefinition)
497497
registerLanguageServiceDocumentRequestHandler(handlers, lsproto.TextDocumentTypeDefinitionInfo, (*Server).handleTypeDefinition)
498498
registerLanguageServiceDocumentRequestHandler(handlers, lsproto.TextDocumentCompletionInfo, (*Server).handleCompletion)
499-
registerLanguageServiceDocumentRequestHandler(handlers, lsproto.TextDocumentReferencesInfo, (*Server).handleReferences)
500499
registerLanguageServiceDocumentRequestHandler(handlers, lsproto.TextDocumentImplementationInfo, (*Server).handleImplementations)
501500
registerLanguageServiceDocumentRequestHandler(handlers, lsproto.TextDocumentSignatureHelpInfo, (*Server).handleSignatureHelp)
502501
registerLanguageServiceDocumentRequestHandler(handlers, lsproto.TextDocumentFormattingInfo, (*Server).handleDocumentFormat)
503502
registerLanguageServiceDocumentRequestHandler(handlers, lsproto.TextDocumentRangeFormattingInfo, (*Server).handleDocumentRangeFormat)
504503
registerLanguageServiceDocumentRequestHandler(handlers, lsproto.TextDocumentOnTypeFormattingInfo, (*Server).handleDocumentOnTypeFormat)
505504
registerLanguageServiceDocumentRequestHandler(handlers, lsproto.TextDocumentDocumentSymbolInfo, (*Server).handleDocumentSymbol)
506-
registerLanguageServiceDocumentRequestHandler(handlers, lsproto.TextDocumentRenameInfo, (*Server).handleRename)
507505
registerLanguageServiceDocumentRequestHandler(handlers, lsproto.TextDocumentDocumentHighlightInfo, (*Server).handleDocumentHighlight)
508506
registerLanguageServiceDocumentRequestHandler(handlers, lsproto.TextDocumentSelectionRangeInfo, (*Server).handleSelectionRange)
507+
508+
registerMultiProjectDocumentRequestHandler(handlers, lsproto.TextDocumentReferencesInfo, (*Server).handleReferences)
509+
registerMultiProjectDocumentRequestHandler(handlers, lsproto.TextDocumentRenameInfo, (*Server).handleRename)
510+
509511
registerRequestHandler(handlers, lsproto.WorkspaceSymbolInfo, (*Server).handleWorkspaceSymbol)
510512
registerRequestHandler(handlers, lsproto.CompletionItemResolveInfo, (*Server).handleCompletionItemResolve)
511513

@@ -581,6 +583,32 @@ func registerLanguageServiceDocumentRequestHandler[Req lsproto.HasTextDocumentUR
581583
}
582584
}
583585

586+
func registerMultiProjectDocumentRequestHandler[Req lsproto.HasTextDocumentURI, Resp any](handlers handlerMap, info lsproto.RequestInfo[Req, Resp], fn func(*Server, context.Context, *ls.LanguageService, Req) (Resp, error)) {
587+
handlers[info.Method] = func(s *Server, ctx context.Context, req *lsproto.RequestMessage) error {
588+
var params Req
589+
// Ignore empty params.
590+
if req.Params != nil {
591+
params = req.Params.(Req)
592+
}
593+
// !!! sheetal: multiple projects that contain the file through symlinks
594+
// !!! multiple projects that contain the file directly
595+
ls, err := s.session.GetLanguageService(ctx, params.TextDocumentURI())
596+
if err != nil {
597+
return err
598+
}
599+
defer s.recover(req)
600+
resp, err := fn(s, ctx, ls, params)
601+
if err != nil {
602+
return err
603+
}
604+
if ctx.Err() != nil {
605+
return ctx.Err()
606+
}
607+
s.sendResult(req.ID, resp)
608+
return nil
609+
}
610+
}
611+
584612
func (s *Server) recover(req *lsproto.RequestMessage) {
585613
if r := recover(); r != nil {
586614
stack := debug.Stack()
@@ -922,6 +950,7 @@ func (s *Server) handleWorkspaceSymbol(ctx context.Context, params *lsproto.Work
922950
defer release()
923951
defer s.recover(reqMsg)
924952
programs := core.Map(snapshot.ProjectCollection.Projects(), (*project.Project).GetProgram)
953+
// !!! sheetal: additional projects that can be loaded but were delayed
925954
return ls.ProvideWorkspaceSymbols(ctx, programs, snapshot.Converters(), params.Query)
926955
}
927956

0 commit comments

Comments
 (0)