@@ -146,6 +146,10 @@ func (handler *InoHandler) transformClangdParams(method string, raw *json.RawMes
146
146
p := params .(* lsp.DocumentSymbolParams )
147
147
uri = p .TextDocument .URI
148
148
err = handler .ino2cppTextDocumentIdentifier (& p .TextDocument )
149
+ case "textDocument/rename" :
150
+ p := params .(* lsp.RenameParams )
151
+ uri = p .TextDocument .URI
152
+ err = handler .ino2cppRenameParams (p )
149
153
}
150
154
return
151
155
}
@@ -290,6 +294,14 @@ func (handler *InoHandler) ino2cppDocumentOnTypeFormattingParams(params *lsp.Doc
290
294
return nil
291
295
}
292
296
297
+ func (handler * InoHandler ) ino2cppRenameParams (params * lsp.RenameParams ) error {
298
+ handler .ino2cppTextDocumentIdentifier (& params .TextDocument )
299
+ if data , ok := handler .data [params .TextDocument .URI ]; ok {
300
+ params .Position .Line = data .targetLineMap [params .Position .Line ]
301
+ }
302
+ return nil
303
+ }
304
+
293
305
func (handler * InoHandler ) transformClangdResult (method string , uri lsp.DocumentURI , result interface {}) interface {} {
294
306
switch method {
295
307
case "textDocument/completion" :
@@ -330,7 +342,10 @@ func (handler *InoHandler) transformClangdResult(method string, uri lsp.Document
330
342
}
331
343
case "textDocument/documentSymbol" :
332
344
r := result .(* []DocumentSymbol )
333
- handler .cpp2inoDocumentSymbol (r , uri )
345
+ result = handler .cpp2inoDocumentSymbols (* r , uri )
346
+ case "textDocument/rename" :
347
+ r := result .(* lsp.WorkspaceEdit )
348
+ result = handler .cpp2inoWorkspaceEdit (r )
334
349
}
335
350
return result
336
351
}
@@ -348,8 +363,19 @@ func (handler *InoHandler) cpp2inoCompletionList(list *lsp.CompletionList, uri l
348
363
}
349
364
350
365
func (handler * InoHandler ) cpp2inoCodeAction (codeAction * CodeAction , uri lsp.DocumentURI ) {
366
+ codeAction .Edit = handler .cpp2inoWorkspaceEdit (codeAction .Edit )
367
+ if data , ok := handler .data [uri ]; ok {
368
+ for index := range codeAction .Diagnostics {
369
+ r := & codeAction .Diagnostics [index ].Range
370
+ r .Start .Line = data .sourceLineMap [r .Start .Line ]
371
+ r .End .Line = data .sourceLineMap [r .End .Line ]
372
+ }
373
+ }
374
+ }
375
+
376
+ func (handler * InoHandler ) cpp2inoWorkspaceEdit (origEdit * lsp.WorkspaceEdit ) * lsp.WorkspaceEdit {
351
377
newEdit := lsp.WorkspaceEdit {Changes : make (map [string ][]lsp.TextEdit )}
352
- for uri , edit := range codeAction . Edit .Changes {
378
+ for uri , edit := range origEdit .Changes {
353
379
if data , ok := handler .data [lsp .DocumentURI (uri )]; ok {
354
380
newValue := make ([]lsp.TextEdit , len (edit ))
355
381
for index := range edit {
@@ -367,14 +393,7 @@ func (handler *InoHandler) cpp2inoCodeAction(codeAction *CodeAction, uri lsp.Doc
367
393
newEdit .Changes [uri ] = edit
368
394
}
369
395
}
370
- codeAction .Edit = & newEdit
371
- if data , ok := handler .data [uri ]; ok {
372
- for index := range codeAction .Diagnostics {
373
- r := & codeAction .Diagnostics [index ].Range
374
- r .Start .Line = data .sourceLineMap [r .Start .Line ]
375
- r .End .Line = data .sourceLineMap [r .End .Line ]
376
- }
377
- }
396
+ return & newEdit
378
397
}
379
398
380
399
func (handler * InoHandler ) cpp2inoHover (hover * Hover , uri lsp.DocumentURI ) {
@@ -409,29 +428,34 @@ func (handler *InoHandler) cpp2inoTextEdit(edit *lsp.TextEdit, uri lsp.DocumentU
409
428
}
410
429
}
411
430
412
- func (handler * InoHandler ) cpp2inoDocumentSymbol (symbols * []DocumentSymbol , uri lsp.DocumentURI ) {
413
- if data , ok := handler .data [uri ]; ok {
414
- for i := 0 ; i < len (* symbols ); {
415
- symbol := & (* symbols )[i ]
416
- symbol .Range .Start .Line = data .sourceLineMap [symbol .Range .Start .Line ]
417
- symbol .Range .End .Line = data .sourceLineMap [symbol .Range .End .Line ]
431
+ func (handler * InoHandler ) cpp2inoDocumentSymbols (origSymbols []DocumentSymbol , uri lsp.DocumentURI ) []DocumentSymbol {
432
+ data , ok := handler .data [uri ]
433
+ if ! ok || len (origSymbols ) == 0 {
434
+ return origSymbols
435
+ }
436
+ newSymbols := make ([]DocumentSymbol , len (origSymbols ))
437
+ j := 0
438
+ for i := 0 ; i < len (origSymbols ); i ++ {
439
+ symbol := & origSymbols [i ]
440
+ symbol .Range .Start .Line = data .sourceLineMap [symbol .Range .Start .Line ]
441
+ symbol .Range .End .Line = data .sourceLineMap [symbol .Range .End .Line ]
442
+
443
+ duplicate := false
444
+ for k := 0 ; k < j ; k ++ {
445
+ if symbol .Name == newSymbols [k ].Name && symbol .Range .Start .Line == newSymbols [k ].Range .Start .Line {
446
+ duplicate = true
447
+ break
448
+ }
449
+ }
450
+ if ! duplicate {
418
451
symbol .SelectionRange .Start .Line = data .sourceLineMap [symbol .SelectionRange .Start .Line ]
419
452
symbol .SelectionRange .End .Line = data .sourceLineMap [symbol .SelectionRange .End .Line ]
420
-
421
- duplicate := false
422
- for j := 0 ; j < i ; j ++ {
423
- if symbol .Name == (* symbols )[j ].Name && symbol .Range .Start .Line == (* symbols )[j ].Range .Start .Line {
424
- duplicate = true
425
- break
426
- }
427
- }
428
- if duplicate {
429
- * symbols = (* symbols )[:i + copy ((* symbols )[i :], (* symbols )[i + 1 :])]
430
- } else {
431
- i ++
432
- }
453
+ symbol .Children = handler .cpp2inoDocumentSymbols (symbol .Children , uri )
454
+ newSymbols [j ] = * symbol
455
+ j ++
433
456
}
434
457
}
458
+ return newSymbols [:j ]
435
459
}
436
460
437
461
// FromClangd handles a message received from clangd.
0 commit comments