Skip to content

Commit 5902ba6

Browse files
committed
added rangeFormatting
1 parent b3f97b9 commit 5902ba6

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

Diff for: handler/handler.go

+36-13
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,18 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
243243
cppURI = p.TextDocument.URI
244244
log.Printf(" --> formatting(%s)", p.TextDocument.URI)
245245

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+
246258
case *lsp.TextDocumentPositionParams:
247259
// Method: "textDocument/signatureHelp"
248260
// Method: "textDocument/definition"
@@ -282,11 +294,6 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
282294
return nil, nil
283295
inoURI = p.TextDocument.URI
284296
_, 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)
290297
case *lsp.DocumentOnTypeFormattingParams: // "textDocument/onTypeFormatting":
291298
log.Printf("--X " + req.Method)
292299
return nil, nil
@@ -778,14 +785,30 @@ func (handler *InoHandler) ino2cppTextDocumentPositionParams(inoParams *lsp.Text
778785
}, nil
779786
}
780787

781-
func (handler *InoHandler) ino2cppDocumentRangeFormattingParams(params *lsp.DocumentRangeFormattingParams) error {
782-
panic("not implemented")
783-
// handler.sketchToBuildPathTextDocumentIdentifier(&params.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
789812
}
790813

791814
func (handler *InoHandler) ino2cppDocumentOnTypeFormattingParams(params *lsp.DocumentOnTypeFormattingParams) error {

0 commit comments

Comments
 (0)