@@ -210,30 +210,24 @@ func (handler *InoHandler) transformParamsToClangd(ctx context.Context, method s
210210 return
211211}
212212
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 )
215216 targetPath , targetBytes , err := generateCpp ([]byte (sourceText ), sourcePath , handler .config .SelectedBoard .Fqbn )
216217 if err != nil {
217218 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
226220 }
227221
228222 targetURI := pathToURI (targetPath )
229223 data := & FileData {
230224 sourceText ,
231- sourceURI ,
225+ inoSourceURI ,
232226 targetURI ,
233227 sourcemapper .CreateInoMapper (bytes .NewReader (targetBytes )),
234228 version ,
235229 }
236- handler .data [sourceURI ] = data
230+ handler .data [inoSourceURI ] = data
237231 handler .data [targetURI ] = data
238232 return data , targetBytes , nil
239233}
@@ -263,7 +257,7 @@ func (handler *InoHandler) updateFileData(ctx context.Context, data *FileData, c
263257 // Fallback: try to apply a multi-line update
264258 data .sourceText = newSourceText
265259 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 )
267261 return nil
268262 }
269263 }
@@ -282,7 +276,7 @@ func (handler *InoHandler) updateFileData(ctx context.Context, data *FileData, c
282276 }
283277 data .sourceMap .Update (0 , rang .Start .Line , change .Text )
284278
285- * rang = data .sourceMap .InoToCppRange ( * rang )
279+ * rang = data .sourceMap .InoToCppLSPRange ( data . sourceURI , * rang )
286280 }
287281 return nil
288282}
@@ -368,7 +362,7 @@ func (handler *InoHandler) ino2cppDidChangeTextDocumentParams(ctx context.Contex
368362func (handler * InoHandler ) ino2cppTextDocumentPositionParams (params * lsp.TextDocumentPositionParams ) error {
369363 handler .ino2cppTextDocumentIdentifier (& params .TextDocument )
370364 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 )
372366 params .Position .Line = targetLine
373367 return nil
374368 }
@@ -378,10 +372,10 @@ func (handler *InoHandler) ino2cppTextDocumentPositionParams(params *lsp.TextDoc
378372func (handler * InoHandler ) ino2cppCodeActionParams (params * lsp.CodeActionParams ) error {
379373 handler .ino2cppTextDocumentIdentifier (& params .TextDocument )
380374 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 )
382376 for index := range params .Context .Diagnostics {
383377 r := & params .Context .Diagnostics [index ].Range
384- * r = data .sourceMap .InoToCppRange ( * r )
378+ * r = data .sourceMap .InoToCppLSPRange ( data . sourceURI , * r )
385379 }
386380 return nil
387381 }
@@ -391,7 +385,7 @@ func (handler *InoHandler) ino2cppCodeActionParams(params *lsp.CodeActionParams)
391385func (handler * InoHandler ) ino2cppDocumentRangeFormattingParams (params * lsp.DocumentRangeFormattingParams ) error {
392386 handler .ino2cppTextDocumentIdentifier (& params .TextDocument )
393387 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 )
395389 return nil
396390 }
397391 return unknownURI (params .TextDocument .URI )
@@ -400,7 +394,7 @@ func (handler *InoHandler) ino2cppDocumentRangeFormattingParams(params *lsp.Docu
400394func (handler * InoHandler ) ino2cppDocumentOnTypeFormattingParams (params * lsp.DocumentOnTypeFormattingParams ) error {
401395 handler .ino2cppTextDocumentIdentifier (& params .TextDocument )
402396 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 )
404398 return nil
405399 }
406400 return unknownURI (params .TextDocument .URI )
@@ -409,7 +403,7 @@ func (handler *InoHandler) ino2cppDocumentOnTypeFormattingParams(params *lsp.Doc
409403func (handler * InoHandler ) ino2cppRenameParams (params * lsp.RenameParams ) error {
410404 handler .ino2cppTextDocumentIdentifier (& params .TextDocument )
411405 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 )
413407 return nil
414408 }
415409 return unknownURI (params .TextDocument .URI )
@@ -443,7 +437,7 @@ func (handler *InoHandler) ino2cppWorkspaceEdit(origEdit *lsp.WorkspaceEdit) *ls
443437 for index := range edit {
444438 newValue [index ] = lsp.TextEdit {
445439 NewText : edit [index ].NewText ,
446- Range : data .sourceMap .InoToCppRange ( edit [index ].Range ),
440+ Range : data .sourceMap .InoToCppLSPRange ( data . sourceURI , edit [index ].Range ),
447441 }
448442 }
449443 newEdit .Changes [string (data .targetURI )] = newValue
@@ -537,7 +531,7 @@ func (handler *InoHandler) cpp2inoCompletionList(list *lsp.CompletionList, uri l
537531 for _ , item := range list .Items {
538532 if ! strings .HasPrefix (item .InsertText , "_" ) {
539533 if item .TextEdit != nil {
540- item .TextEdit .Range = data .sourceMap .CppToInoRange (item .TextEdit .Range )
534+ _ , item .TextEdit .Range = data .sourceMap .CppToInoRange (item .TextEdit .Range )
541535 }
542536 newItems = append (newItems , item )
543537 }
@@ -550,7 +544,7 @@ func (handler *InoHandler) cpp2inoCodeAction(codeAction *CodeAction, uri lsp.Doc
550544 codeAction .Edit = handler .cpp2inoWorkspaceEdit (codeAction .Edit )
551545 if data , ok := handler .data [uri ]; ok {
552546 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 )
554548 }
555549 }
556550}
@@ -570,9 +564,10 @@ func (handler *InoHandler) cpp2inoWorkspaceEdit(origEdit *lsp.WorkspaceEdit) *ls
570564 if data , ok := handler .data [lsp .DocumentURI (uri )]; ok {
571565 newValue := make ([]lsp.TextEdit , len (edit ))
572566 for index := range edit {
567+ _ , newRange := data .sourceMap .CppToInoRange (edit [index ].Range )
573568 newValue [index ] = lsp.TextEdit {
574569 NewText : edit [index ].NewText ,
575- Range : data . sourceMap . CppToInoRange ( edit [ index ]. Range ) ,
570+ Range : newRange ,
576571 }
577572 }
578573 newEdit .Changes [string (data .sourceURI )] = newValue
@@ -587,27 +582,27 @@ func (handler *InoHandler) cpp2inoHover(hover *Hover, uri lsp.DocumentURI) {
587582 if data , ok := handler .data [uri ]; ok {
588583 r := hover .Range
589584 if r != nil {
590- * r = data .sourceMap .CppToInoRange (* r )
585+ _ , * r = data .sourceMap .CppToInoRange (* r )
591586 }
592587 }
593588}
594589
595590func (handler * InoHandler ) cpp2inoLocation (location * lsp.Location ) {
596591 if data , ok := handler .data [location .URI ]; ok {
597592 location .URI = data .sourceURI
598- location .Range = data .sourceMap .CppToInoRange (location .Range )
593+ _ , location .Range = data .sourceMap .CppToInoRange (location .Range )
599594 }
600595}
601596
602597func (handler * InoHandler ) cpp2inoDocumentHighlight (highlight * lsp.DocumentHighlight , uri lsp.DocumentURI ) {
603598 if data , ok := handler .data [uri ]; ok {
604- highlight .Range = data .sourceMap .CppToInoRange (highlight .Range )
599+ _ , highlight .Range = data .sourceMap .CppToInoRange (highlight .Range )
605600 }
606601}
607602
608603func (handler * InoHandler ) cpp2inoTextEdit (edit * lsp.TextEdit , uri lsp.DocumentURI ) {
609604 if data , ok := handler .data [uri ]; ok {
610- edit .Range = data .sourceMap .CppToInoRange (edit .Range )
605+ _ , edit .Range = data .sourceMap .CppToInoRange (edit .Range )
611606 }
612607}
613608
@@ -620,7 +615,7 @@ func (handler *InoHandler) cpp2inoDocumentSymbols(origSymbols []DocumentSymbol,
620615 symbolIdx := make (map [string ]* DocumentSymbol )
621616 for i := 0 ; i < len (origSymbols ); i ++ {
622617 symbol := & origSymbols [i ]
623- symbol .Range = data .sourceMap .CppToInoRange (symbol .Range )
618+ _ , symbol .Range = data .sourceMap .CppToInoRange (symbol .Range )
624619
625620 duplicate := false
626621 other , duplicate := symbolIdx [symbol .Name ]
@@ -633,7 +628,7 @@ func (handler *InoHandler) cpp2inoDocumentSymbols(origSymbols []DocumentSymbol,
633628 }
634629 }
635630
636- symbol .SelectionRange = data .sourceMap .CppToInoRange (symbol .SelectionRange )
631+ _ , symbol .SelectionRange = data .sourceMap .CppToInoRange (symbol .SelectionRange )
637632 symbol .Children = handler .cpp2inoDocumentSymbols (symbol .Children , uri )
638633 symbolIdx [symbol .Name ] = symbol
639634 }
@@ -722,9 +717,9 @@ func (handler *InoHandler) cpp2inoPublishDiagnosticsParams(params *lsp.PublishDi
722717 newDiagnostics := make ([]lsp.Diagnostic , 0 , len (params .Diagnostics ))
723718 for index := range params .Diagnostics {
724719 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 {
726721 r .Start .Line = startLine
727- r .End .Line = data .sourceMap .CppToInoLine (r .End .Line )
722+ _ , r .End .Line = data .sourceMap .CppToInoLine (r .End .Line )
728723 newDiagnostics = append (newDiagnostics , params .Diagnostics [index ])
729724 }
730725 }
0 commit comments