@@ -210,30 +210,24 @@ func (handler *InoHandler) transformParamsToClangd(ctx context.Context, method s
210
210
return
211
211
}
212
212
213
- func (handler * InoHandler ) createFileData (ctx context.Context , sourceURI lsp.DocumentURI , sourceText string , version int ) (* FileData , []byte , error ) {
214
- sourcePath := uriToPath (sourceURI )
213
+ func (handler * InoHandler ) createFileData (ctx context.Context , inoSourceURI lsp.DocumentURI , sourceText string , version int ) (* FileData , []byte , error ) {
214
+ log .Println ("InoHandler: createFileData(" , inoSourceURI , sourceText , version )
215
+ sourcePath := uriToPath (inoSourceURI )
215
216
targetPath , targetBytes , err := generateCpp ([]byte (sourceText ), sourcePath , handler .config .SelectedBoard .Fqbn )
216
217
if err != nil {
217
218
err = handler .handleError (ctx , err )
218
- if len (targetPath ) == 0 {
219
- return nil , nil , err
220
- }
221
- // Fallback: use the source text unchanged
222
- targetBytes , err = copyIno2Cpp (sourceText , targetPath )
223
- if err != nil {
224
- return nil , nil , err
225
- }
219
+ return nil , nil , err
226
220
}
227
221
228
222
targetURI := pathToURI (targetPath )
229
223
data := & FileData {
230
224
sourceText ,
231
- sourceURI ,
225
+ inoSourceURI ,
232
226
targetURI ,
233
227
sourcemapper .CreateInoMapper (bytes .NewReader (targetBytes )),
234
228
version ,
235
229
}
236
- handler .data [sourceURI ] = data
230
+ handler .data [inoSourceURI ] = data
237
231
handler .data [targetURI ] = data
238
232
return data , targetBytes , nil
239
233
}
@@ -263,7 +257,7 @@ func (handler *InoHandler) updateFileData(ctx context.Context, data *FileData, c
263
257
// Fallback: try to apply a multi-line update
264
258
data .sourceText = newSourceText
265
259
data .sourceMap .Update (rang .End .Line - rang .Start .Line , rang .Start .Line , change .Text )
266
- * rang = data .sourceMap .InoToCppRange ( * rang )
260
+ * rang = data .sourceMap .InoToCppLSPRange ( data . sourceURI , * rang )
267
261
return nil
268
262
}
269
263
}
@@ -282,7 +276,7 @@ func (handler *InoHandler) updateFileData(ctx context.Context, data *FileData, c
282
276
}
283
277
data .sourceMap .Update (0 , rang .Start .Line , change .Text )
284
278
285
- * rang = data .sourceMap .InoToCppRange ( * rang )
279
+ * rang = data .sourceMap .InoToCppLSPRange ( data . sourceURI , * rang )
286
280
}
287
281
return nil
288
282
}
@@ -368,7 +362,7 @@ func (handler *InoHandler) ino2cppDidChangeTextDocumentParams(ctx context.Contex
368
362
func (handler * InoHandler ) ino2cppTextDocumentPositionParams (params * lsp.TextDocumentPositionParams ) error {
369
363
handler .ino2cppTextDocumentIdentifier (& params .TextDocument )
370
364
if data , ok := handler .data [params .TextDocument .URI ]; ok {
371
- targetLine := data .sourceMap .InoToCppLine (params .Position .Line )
365
+ targetLine := data .sourceMap .InoToCppLine (data . sourceURI , params .Position .Line )
372
366
params .Position .Line = targetLine
373
367
return nil
374
368
}
@@ -378,10 +372,10 @@ func (handler *InoHandler) ino2cppTextDocumentPositionParams(params *lsp.TextDoc
378
372
func (handler * InoHandler ) ino2cppCodeActionParams (params * lsp.CodeActionParams ) error {
379
373
handler .ino2cppTextDocumentIdentifier (& params .TextDocument )
380
374
if data , ok := handler .data [params .TextDocument .URI ]; ok {
381
- params .Range = data .sourceMap .InoToCppRange ( params .Range )
375
+ params .Range = data .sourceMap .InoToCppLSPRange ( data . sourceURI , params .Range )
382
376
for index := range params .Context .Diagnostics {
383
377
r := & params .Context .Diagnostics [index ].Range
384
- * r = data .sourceMap .InoToCppRange ( * r )
378
+ * r = data .sourceMap .InoToCppLSPRange ( data . sourceURI , * r )
385
379
}
386
380
return nil
387
381
}
@@ -391,7 +385,7 @@ func (handler *InoHandler) ino2cppCodeActionParams(params *lsp.CodeActionParams)
391
385
func (handler * InoHandler ) ino2cppDocumentRangeFormattingParams (params * lsp.DocumentRangeFormattingParams ) error {
392
386
handler .ino2cppTextDocumentIdentifier (& params .TextDocument )
393
387
if data , ok := handler .data [params .TextDocument .URI ]; ok {
394
- params .Range = data .sourceMap .InoToCppRange ( params .Range )
388
+ params .Range = data .sourceMap .InoToCppLSPRange ( data . sourceURI , params .Range )
395
389
return nil
396
390
}
397
391
return unknownURI (params .TextDocument .URI )
@@ -400,7 +394,7 @@ func (handler *InoHandler) ino2cppDocumentRangeFormattingParams(params *lsp.Docu
400
394
func (handler * InoHandler ) ino2cppDocumentOnTypeFormattingParams (params * lsp.DocumentOnTypeFormattingParams ) error {
401
395
handler .ino2cppTextDocumentIdentifier (& params .TextDocument )
402
396
if data , ok := handler .data [params .TextDocument .URI ]; ok {
403
- params .Position .Line = data .sourceMap .InoToCppLine (params .Position .Line )
397
+ params .Position .Line = data .sourceMap .InoToCppLine (data . sourceURI , params .Position .Line )
404
398
return nil
405
399
}
406
400
return unknownURI (params .TextDocument .URI )
@@ -409,7 +403,7 @@ func (handler *InoHandler) ino2cppDocumentOnTypeFormattingParams(params *lsp.Doc
409
403
func (handler * InoHandler ) ino2cppRenameParams (params * lsp.RenameParams ) error {
410
404
handler .ino2cppTextDocumentIdentifier (& params .TextDocument )
411
405
if data , ok := handler .data [params .TextDocument .URI ]; ok {
412
- params .Position .Line = data .sourceMap .InoToCppLine (params .Position .Line )
406
+ params .Position .Line = data .sourceMap .InoToCppLine (data . sourceURI , params .Position .Line )
413
407
return nil
414
408
}
415
409
return unknownURI (params .TextDocument .URI )
@@ -443,7 +437,7 @@ func (handler *InoHandler) ino2cppWorkspaceEdit(origEdit *lsp.WorkspaceEdit) *ls
443
437
for index := range edit {
444
438
newValue [index ] = lsp.TextEdit {
445
439
NewText : edit [index ].NewText ,
446
- Range : data .sourceMap .InoToCppRange ( edit [index ].Range ),
440
+ Range : data .sourceMap .InoToCppLSPRange ( data . sourceURI , edit [index ].Range ),
447
441
}
448
442
}
449
443
newEdit .Changes [string (data .targetURI )] = newValue
@@ -537,7 +531,7 @@ func (handler *InoHandler) cpp2inoCompletionList(list *lsp.CompletionList, uri l
537
531
for _ , item := range list .Items {
538
532
if ! strings .HasPrefix (item .InsertText , "_" ) {
539
533
if item .TextEdit != nil {
540
- item .TextEdit .Range = data .sourceMap .CppToInoRange (item .TextEdit .Range )
534
+ _ , item .TextEdit .Range = data .sourceMap .CppToInoRange (item .TextEdit .Range )
541
535
}
542
536
newItems = append (newItems , item )
543
537
}
@@ -550,7 +544,7 @@ func (handler *InoHandler) cpp2inoCodeAction(codeAction *CodeAction, uri lsp.Doc
550
544
codeAction .Edit = handler .cpp2inoWorkspaceEdit (codeAction .Edit )
551
545
if data , ok := handler .data [uri ]; ok {
552
546
for index := range codeAction .Diagnostics {
553
- codeAction .Diagnostics [index ].Range = data .sourceMap .CppToInoRange (codeAction .Diagnostics [index ].Range )
547
+ _ , codeAction .Diagnostics [index ].Range = data .sourceMap .CppToInoRange (codeAction .Diagnostics [index ].Range )
554
548
}
555
549
}
556
550
}
@@ -570,9 +564,10 @@ func (handler *InoHandler) cpp2inoWorkspaceEdit(origEdit *lsp.WorkspaceEdit) *ls
570
564
if data , ok := handler .data [lsp .DocumentURI (uri )]; ok {
571
565
newValue := make ([]lsp.TextEdit , len (edit ))
572
566
for index := range edit {
567
+ _ , newRange := data .sourceMap .CppToInoRange (edit [index ].Range )
573
568
newValue [index ] = lsp.TextEdit {
574
569
NewText : edit [index ].NewText ,
575
- Range : data . sourceMap . CppToInoRange ( edit [ index ]. Range ) ,
570
+ Range : newRange ,
576
571
}
577
572
}
578
573
newEdit .Changes [string (data .sourceURI )] = newValue
@@ -587,27 +582,27 @@ func (handler *InoHandler) cpp2inoHover(hover *Hover, uri lsp.DocumentURI) {
587
582
if data , ok := handler .data [uri ]; ok {
588
583
r := hover .Range
589
584
if r != nil {
590
- * r = data .sourceMap .CppToInoRange (* r )
585
+ _ , * r = data .sourceMap .CppToInoRange (* r )
591
586
}
592
587
}
593
588
}
594
589
595
590
func (handler * InoHandler ) cpp2inoLocation (location * lsp.Location ) {
596
591
if data , ok := handler .data [location .URI ]; ok {
597
592
location .URI = data .sourceURI
598
- location .Range = data .sourceMap .CppToInoRange (location .Range )
593
+ _ , location .Range = data .sourceMap .CppToInoRange (location .Range )
599
594
}
600
595
}
601
596
602
597
func (handler * InoHandler ) cpp2inoDocumentHighlight (highlight * lsp.DocumentHighlight , uri lsp.DocumentURI ) {
603
598
if data , ok := handler .data [uri ]; ok {
604
- highlight .Range = data .sourceMap .CppToInoRange (highlight .Range )
599
+ _ , highlight .Range = data .sourceMap .CppToInoRange (highlight .Range )
605
600
}
606
601
}
607
602
608
603
func (handler * InoHandler ) cpp2inoTextEdit (edit * lsp.TextEdit , uri lsp.DocumentURI ) {
609
604
if data , ok := handler .data [uri ]; ok {
610
- edit .Range = data .sourceMap .CppToInoRange (edit .Range )
605
+ _ , edit .Range = data .sourceMap .CppToInoRange (edit .Range )
611
606
}
612
607
}
613
608
@@ -620,7 +615,7 @@ func (handler *InoHandler) cpp2inoDocumentSymbols(origSymbols []DocumentSymbol,
620
615
symbolIdx := make (map [string ]* DocumentSymbol )
621
616
for i := 0 ; i < len (origSymbols ); i ++ {
622
617
symbol := & origSymbols [i ]
623
- symbol .Range = data .sourceMap .CppToInoRange (symbol .Range )
618
+ _ , symbol .Range = data .sourceMap .CppToInoRange (symbol .Range )
624
619
625
620
duplicate := false
626
621
other , duplicate := symbolIdx [symbol .Name ]
@@ -633,7 +628,7 @@ func (handler *InoHandler) cpp2inoDocumentSymbols(origSymbols []DocumentSymbol,
633
628
}
634
629
}
635
630
636
- symbol .SelectionRange = data .sourceMap .CppToInoRange (symbol .SelectionRange )
631
+ _ , symbol .SelectionRange = data .sourceMap .CppToInoRange (symbol .SelectionRange )
637
632
symbol .Children = handler .cpp2inoDocumentSymbols (symbol .Children , uri )
638
633
symbolIdx [symbol .Name ] = symbol
639
634
}
@@ -722,9 +717,9 @@ func (handler *InoHandler) cpp2inoPublishDiagnosticsParams(params *lsp.PublishDi
722
717
newDiagnostics := make ([]lsp.Diagnostic , 0 , len (params .Diagnostics ))
723
718
for index := range params .Diagnostics {
724
719
r := & params .Diagnostics [index ].Range
725
- if startLine , ok := data .sourceMap .CppToInoLineOk (r .Start .Line ); ok {
720
+ if _ , startLine , ok := data .sourceMap .CppToInoLineOk (r .Start .Line ); ok {
726
721
r .Start .Line = startLine
727
- r .End .Line = data .sourceMap .CppToInoLine (r .End .Line )
722
+ _ , r .End .Line = data .sourceMap .CppToInoLine (r .End .Line )
728
723
newDiagnostics = append (newDiagnostics , params .Diagnostics [index ])
729
724
}
730
725
}
0 commit comments