@@ -68,7 +68,7 @@ func (handler *InoHandler) FromStdio(ctx context.Context, conn *jsonrpc2.Conn, r
6868 result , err = sendRequest (ctx , handler .ClangdConn , req .Method , params )
6969 }
7070 if err != nil {
71- log .Println ("From stdio: Method:" , req .Method , "Params:" , params , " Error:" , err )
71+ log .Println ("From stdio: Method:" , req .Method , "Error:" , err )
7272 return nil , err
7373 }
7474 if enableLogging {
@@ -130,6 +130,14 @@ func (handler *InoHandler) transformClangdParams(method string, raw *json.RawMes
130130 p := params .(* lsp.ReferenceParams )
131131 uri = p .TextDocument .URI
132132 err = handler .ino2cppTextDocumentPositionParams (& p .TextDocumentPositionParams )
133+ case "textDocument/formatting" :
134+ p := params .(* lsp.DocumentFormattingParams )
135+ uri = p .TextDocument .URI
136+ err = handler .ino2cppTextDocumentIdentifier (& p .TextDocument )
137+ case "textDocument/rangeFormatting" :
138+ // TODO
139+ case "textDocument/onTypeFormatting" :
140+ // TODO
133141 }
134142 return
135143}
@@ -286,6 +294,15 @@ func (handler *InoHandler) transformClangdResult(method string, uri lsp.Document
286294 for index := range * r {
287295 handler .cpp2inoDocumentHighlight (& (* r )[index ], uri )
288296 }
297+ case "textDocument/formatting" :
298+ fallthrough
299+ case "textDocument/rangeFormatting" :
300+ fallthrough
301+ case "textDocument/onTypeFormatting" :
302+ r := result .(* []lsp.TextEdit )
303+ for index := range * r {
304+ handler .cpp2inoTextEdit (& (* r )[index ], uri )
305+ }
289306 }
290307 return result
291308}
@@ -357,6 +374,13 @@ func (handler *InoHandler) cpp2inoDocumentHighlight(highlight *lsp.DocumentHighl
357374 }
358375}
359376
377+ func (handler * InoHandler ) cpp2inoTextEdit (edit * lsp.TextEdit , uri lsp.DocumentURI ) {
378+ if data , ok := handler .data [uri ]; ok {
379+ edit .Range .Start .Line = data .sourceLineMap [edit .Range .Start .Line ]
380+ edit .Range .End .Line = data .sourceLineMap [edit .Range .End .Line ]
381+ }
382+ }
383+
360384// FromClangd handles a message received from clangd.
361385func (handler * InoHandler ) FromClangd (ctx context.Context , connection * jsonrpc2.Conn , req * jsonrpc2.Request ) (interface {}, error ) {
362386 params , _ , err := handler .transformStdioParams (req .Method , req .Params )
@@ -371,7 +395,7 @@ func (handler *InoHandler) FromClangd(ctx context.Context, connection *jsonrpc2.
371395 result , err = sendRequest (ctx , handler .StdioConn , req .Method , params )
372396 }
373397 if err != nil {
374- log .Println ("From clangd: Method:" , req .Method , "Params:" , params , " Error:" , err )
398+ log .Println ("From clangd: Method:" , req .Method , "Error:" , err )
375399 return nil , err
376400 }
377401 if enableLogging {
0 commit comments