@@ -243,6 +243,18 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
243
243
cppURI = p .TextDocument .URI
244
244
log .Printf (" --> formatting(%s)" , p .TextDocument .URI )
245
245
246
+ case * lsp.DocumentRangeFormattingParams :
247
+ // Method: "textDocument/rangeFormatting"
248
+ log .Printf ("--> %s(%s:%s)" , req .Method , p .TextDocument .URI , p .Range )
249
+ inoURI = p .TextDocument .URI
250
+ if cppParams , e := handler .ino2cppDocumentRangeFormattingParams (p ); e == nil {
251
+ params = cppParams
252
+ cppURI = cppParams .TextDocument .URI
253
+ log .Printf (" --> %s(%s:%s)" , req .Method , cppParams .TextDocument .URI , cppParams .Range )
254
+ } else {
255
+ err = e
256
+ }
257
+
246
258
case * lsp.TextDocumentPositionParams :
247
259
// Method: "textDocument/signatureHelp"
248
260
// Method: "textDocument/definition"
@@ -282,11 +294,6 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
282
294
return nil , nil
283
295
inoURI = p .TextDocument .URI
284
296
_ , err = handler .ino2cppTextDocumentPositionParams (& p .TextDocumentPositionParams )
285
- case * lsp.DocumentRangeFormattingParams : // "textDocument/rangeFormatting":
286
- log .Printf ("--X " + req .Method )
287
- return nil , nil
288
- inoURI = p .TextDocument .URI
289
- err = handler .ino2cppDocumentRangeFormattingParams (p )
290
297
case * lsp.DocumentOnTypeFormattingParams : // "textDocument/onTypeFormatting":
291
298
log .Printf ("--X " + req .Method )
292
299
return nil , nil
@@ -778,14 +785,30 @@ func (handler *InoHandler) ino2cppTextDocumentPositionParams(inoParams *lsp.Text
778
785
}, nil
779
786
}
780
787
781
- func (handler * InoHandler ) ino2cppDocumentRangeFormattingParams (params * lsp.DocumentRangeFormattingParams ) error {
782
- panic ("not implemented" )
783
- // handler.sketchToBuildPathTextDocumentIdentifier(¶ms.TextDocument)
784
- // if data, ok := handler.data[params.TextDocument.URI]; ok {
785
- // params.Range = data.sourceMap.InoToCppLSPRange(data.sourceURI, params.Range)
786
- // return nil
787
- // }
788
- return unknownURI (params .TextDocument .URI )
788
+ func (handler * InoHandler ) ino2cppRange (inoURI lsp.DocumentURI , inoRange lsp.Range ) (lsp.DocumentURI , lsp.Range , error ) {
789
+ cppURI , err := handler .ino2cppDocumentURI (inoURI )
790
+ if err != nil {
791
+ return "" , lsp.Range {}, err
792
+ }
793
+ if cppURI .AsPath ().EquivalentTo (handler .buildSketchCpp ) {
794
+ cppRange := handler .sketchMapper .InoToCppLSPRange (inoURI , inoRange )
795
+ return cppURI , cppRange , nil
796
+ }
797
+ return cppURI , inoRange , nil
798
+ }
799
+
800
+ func (handler * InoHandler ) ino2cppDocumentRangeFormattingParams (inoParams * lsp.DocumentRangeFormattingParams ) (* lsp.DocumentRangeFormattingParams , error ) {
801
+ cppTextDocument , err := handler .ino2cppTextDocumentIdentifier (inoParams .TextDocument )
802
+ if err != nil {
803
+ return nil , err
804
+ }
805
+
806
+ _ , cppRange , err := handler .ino2cppRange (inoParams .TextDocument .URI , inoParams .Range )
807
+ return & lsp.DocumentRangeFormattingParams {
808
+ TextDocument : cppTextDocument ,
809
+ Range : cppRange ,
810
+ Options : inoParams .Options ,
811
+ }, err
789
812
}
790
813
791
814
func (handler * InoHandler ) ino2cppDocumentOnTypeFormattingParams (params * lsp.DocumentOnTypeFormattingParams ) error {
0 commit comments