@@ -1488,6 +1488,25 @@ func (ls *INOLanguageServer) cpp2inoWorkspaceEdit(logger jsonrpc.FunctionLogger,
1488
1488
1489
1489
func (ls * INOLanguageServer ) cpp2inoTextEdit (logger jsonrpc.FunctionLogger , cppURI lsp.DocumentURI , cppEdit lsp.TextEdit ) (lsp.DocumentURI , lsp.TextEdit , bool , error ) {
1490
1490
inoURI , inoRange , inPreprocessed , err := ls .clang2IdeRangeAndDocumentURI (logger , cppURI , cppEdit .Range )
1491
+
1492
+ if err != nil {
1493
+ if strings .HasPrefix (cppEdit .NewText , "\n " ) && cppEdit .Range .Start .Line < cppEdit .Range .End .Line {
1494
+ // Special case: the text-edit may start from the very end of a not-ino section and fallthrough
1495
+ // in the .ino section with a '\n...' at the beginning of the replacement text.
1496
+ nextLine := lsp.Position {Line : cppEdit .Range .Start .Line + 1 , Character : 0 }
1497
+ startOffset , err1 := textedits .GetOffset (ls .sketchMapper .CppText .Text , cppEdit .Range .Start )
1498
+ nextOffset , err2 := textedits .GetOffset (ls .sketchMapper .CppText .Text , nextLine )
1499
+ if err1 == nil && err2 == nil && startOffset + 1 == nextOffset {
1500
+ // In this can we can generate an equivalent text-edit that fits entirely in the .ino section
1501
+ // by removing the redundant '\n' and by offsetting the start location to the beginning of the
1502
+ // next line.
1503
+ cppEdit .Range .Start = nextLine
1504
+ cppEdit .NewText = cppEdit .NewText [1 :]
1505
+ return ls .cpp2inoTextEdit (logger , cppURI , cppEdit )
1506
+ }
1507
+ }
1508
+ }
1509
+
1491
1510
inoEdit := cppEdit
1492
1511
inoEdit .Range = inoRange
1493
1512
return inoURI , inoEdit , inPreprocessed , err
0 commit comments