@@ -11,6 +11,7 @@ import (
1111 "fmt"
1212 "io"
1313 "log"
14+ "maps"
1415 "time"
1516
1617 "github.com/creachadair/jrpc2"
@@ -81,7 +82,7 @@ type service struct {
8182 features * Features
8283
8384 walkerCollector * walker.WalkerCollector
84- additionalHandlers map [ string ] rpch.Func
85+ additionalHandlers rpch.Map
8586
8687 singleFileMode bool
8788}
@@ -127,7 +128,7 @@ func (svc *service) Assigner() (jrpc2.Assigner, error) {
127128 var expFeatures settings.ExperimentalFeatures
128129 var validationOptions settings.ValidationOptions
129130
130- m := map [ string ] rpch.Func {
131+ m := rpch.Map {
131132 "initialize" : func (ctx context.Context , req * jrpc2.Request ) (interface {}, error ) {
132133 err := session .Initialize (req )
133134 if err != nil {
@@ -402,13 +403,9 @@ func (svc *service) Assigner() (jrpc2.Assigner, error) {
402403 }
403404
404405 // For use in tests, e.g. to test request cancellation
405- if len (svc .additionalHandlers ) > 0 {
406- for methodName , handlerFunc := range svc .additionalHandlers {
407- m [methodName ] = handlerFunc
408- }
409- }
406+ maps .Copy (m , svc .additionalHandlers )
410407
411- return convertMap ( m ) , nil
408+ return m , nil
412409}
413410
414411func (svc * service ) configureSessionDependencies (ctx context.Context , cfgOpts * settings.Options ) error {
@@ -623,18 +620,6 @@ func (svc *service) shutdown() {
623620 }
624621}
625622
626- // convertMap is a helper function allowing us to omit the jrpc2.Func
627- // signature from the method definitions
628- func convertMap (m map [string ]rpch.Func ) rpch.Map {
629- hm := make (rpch.Map , len (m ))
630-
631- for method , fun := range m {
632- hm [method ] = rpch .New (fun )
633- }
634-
635- return hm
636- }
637-
638623const requestCancelled jrpc2.Code = - 32800
639624const tracerName = "github.com/opentofu/tofu-ls/internal/langserver/handlers"
640625
0 commit comments