(ctx context.Context, method string, req Request)
| 92 | } |
| 93 | |
| 94 | func defaultSendingMethodHandler(ctx context.Context, method string, req Request) (Result, error) { |
| 95 | info, ok := req.GetSession().sendingMethodInfos()[method] |
| 96 | if !ok { |
| 97 | // This can be called from user code, with an arbitrary value for method. |
| 98 | return nil, jsonrpc2.ErrNotHandled |
| 99 | } |
| 100 | params := req.GetParams() |
| 101 | if initParams, ok := params.(*InitializeParams); ok { |
| 102 | // Fix the marshaling of initialize params, to work around #607. |
| 103 | // |
| 104 | // The initialize params we produce should never be nil, nor have nil |
| 105 | // capabilities, so any panic here is a bug. |
| 106 | params = initParams.toV2() |
| 107 | } |
| 108 | // Notifications don't have results. |
| 109 | if strings.HasPrefix(method, "notifications/") { |
| 110 | return nil, req.GetSession().getConn().Notify(ctx, method, params) |
| 111 | } |
| 112 | // Create the result to unmarshal into. |
| 113 | // The concrete type of the result is the return type of the receiving function. |
| 114 | res := info.newResult() |
| 115 | if err := call(ctx, req.GetSession().getConn(), method, params, res); err != nil { |
| 116 | return nil, err |
| 117 | } |
| 118 | return res, nil |
| 119 | } |
| 120 | |
| 121 | // Helper method to avoid typed nil. |
| 122 | func orZero[T any, P *U, U any](p P) T { |
nothing calls this directly
no test coverage detected
searching dependent graphs…