@@ -135,9 +135,13 @@ func (handler *InoHandler) transformClangdParams(method string, raw *json.RawMes
135135 uri = p .TextDocument .URI
136136 err = handler .ino2cppTextDocumentIdentifier (& p .TextDocument )
137137 case "textDocument/rangeFormatting" :
138- // TODO
138+ p := params .(* lsp.DocumentRangeFormattingParams )
139+ uri = p .TextDocument .URI
140+ err = handler .ino2cppDocumentRangeFormattingParams (p )
139141 case "textDocument/onTypeFormatting" :
140- // TODO
142+ p := params .(* lsp.DocumentOnTypeFormattingParams )
143+ uri = p .TextDocument .URI
144+ err = handler .ino2cppDocumentOnTypeFormattingParams (p )
141145 }
142146 return
143147}
@@ -209,6 +213,13 @@ func (handler *InoHandler) deleteFileData(sourceURI lsp.DocumentURI) {
209213 }
210214}
211215
216+ func (handler * InoHandler ) ino2cppTextDocumentIdentifier (doc * lsp.TextDocumentIdentifier ) error {
217+ if data , ok := handler .data [doc .URI ]; ok {
218+ doc .URI = data .targetURI
219+ }
220+ return nil
221+ }
222+
212223func (handler * InoHandler ) ino2cppTextDocumentItem (doc * lsp.TextDocumentItem ) error {
213224 if strings .HasSuffix (string (doc .URI ), ".ino" ) {
214225 data , targetBytes , err := handler .createFileData (doc .URI , doc .Text )
@@ -258,9 +269,19 @@ func (handler *InoHandler) ino2cppCodeActionParams(params *lsp.CodeActionParams)
258269 return nil
259270}
260271
261- func (handler * InoHandler ) ino2cppTextDocumentIdentifier (doc * lsp.TextDocumentIdentifier ) error {
262- if data , ok := handler .data [doc .URI ]; ok {
263- doc .URI = data .targetURI
272+ func (handler * InoHandler ) ino2cppDocumentRangeFormattingParams (params * lsp.DocumentRangeFormattingParams ) error {
273+ handler .ino2cppTextDocumentIdentifier (& params .TextDocument )
274+ if data , ok := handler .data [params .TextDocument .URI ]; ok {
275+ params .Range .Start .Line = data .targetLineMap [params .Range .Start .Line ]
276+ params .Range .End .Line = data .targetLineMap [params .Range .End .Line ]
277+ }
278+ return nil
279+ }
280+
281+ func (handler * InoHandler ) ino2cppDocumentOnTypeFormattingParams (params * lsp.DocumentOnTypeFormattingParams ) error {
282+ handler .ino2cppTextDocumentIdentifier (& params .TextDocument )
283+ if data , ok := handler .data [params .TextDocument .URI ]; ok {
284+ params .Position .Line = data .targetLineMap [params .Position .Line ]
264285 }
265286 return nil
266287}
0 commit comments