@@ -260,15 +260,11 @@ func (handler *InoHandler) exit() {
260
260
os .Exit (1 )
261
261
}
262
262
263
- func newPathFromURI (uri lsp.DocumentURI ) * paths.Path {
264
- return paths .New (uriToPath (uri ))
265
- }
266
-
267
263
func (handler * InoHandler ) initializeWorkbench (ctx context.Context , params * lsp.InitializeParams ) error {
268
264
rootURI := params .RootURI
269
265
log .Printf ("--> initializeWorkbench(%s)\n " , rootURI )
270
266
271
- handler .sketchRoot = newPathFromURI ( rootURI )
267
+ handler .sketchRoot = rootURI . AsPath ( )
272
268
handler .sketchName = handler .sketchRoot .Base ()
273
269
if buildPath , err := generateBuildEnvironment (handler .sketchRoot , handler .config .SelectedBoard .Fqbn ); err == nil {
274
270
handler .buildPath = buildPath
@@ -298,7 +294,7 @@ func (handler *InoHandler) initializeWorkbench(ctx context.Context, params *lsp.
298
294
handler .ClangdConn = jsonrpc2 .NewConn (context .Background (), clangdStream , clangdHandler )
299
295
300
296
params .RootPath = handler .buildSketchRoot .String ()
301
- params .RootURI = pathToURI (handler .buildSketchRoot . String () )
297
+ params .RootURI = lsp . NewDocumenteURIFromPath (handler .buildSketchRoot )
302
298
return nil
303
299
}
304
300
@@ -353,7 +349,7 @@ func (handler *InoHandler) didOpen(ctx context.Context, params *lsp.DidOpenTextD
353
349
log .Printf ("--> didOpen(%s)" , doc .URI )
354
350
355
351
// If we are tracking a .ino...
356
- if newPathFromURI ( doc .URI ).Ext () == ".ino" {
352
+ if doc .URI . AsPath ( ).Ext () == ".ino" {
357
353
handler .sketchTrackedFilesCount ++
358
354
log .Printf (" increasing .ino tracked files count: %d" , handler .sketchTrackedFilesCount )
359
355
@@ -362,7 +358,7 @@ func (handler *InoHandler) didOpen(ctx context.Context, params *lsp.DidOpenTextD
362
358
sketchCpp , err := handler .buildSketchCpp .ReadFile ()
363
359
newParam := & lsp.DidOpenTextDocumentParams {
364
360
TextDocument : lsp.TextDocumentItem {
365
- URI : pathToURI (handler .buildSketchCpp . String () ),
361
+ URI : lsp . NewDocumenteURIFromPath (handler .buildSketchCpp ),
366
362
Text : string (sketchCpp ),
367
363
LanguageID : "cpp" ,
368
364
Version : 1 ,
@@ -388,11 +384,11 @@ func (handler *InoHandler) updateFileData(ctx context.Context, data *FileData, c
388
384
return err
389
385
}
390
386
}
391
- targetBytes , err := updateCpp ([]byte (newSourceText ), uriToPath ( data .sourceURI ), handler .config .SelectedBoard .Fqbn , false , uriToPath ( data .targetURI ))
387
+ targetBytes , err := updateCpp ([]byte (newSourceText ), data .sourceURI . Unbox ( ), handler .config .SelectedBoard .Fqbn , false , data .targetURI . Unbox ( ))
392
388
if err != nil {
393
389
if rang == nil {
394
390
// Fallback: use the source text unchanged
395
- targetBytes , err = copyIno2Cpp (newSourceText , uriToPath ( data .targetURI ))
391
+ targetBytes , err = copyIno2Cpp (newSourceText , data .targetURI . Unbox ( ))
396
392
if err != nil {
397
393
return err
398
394
}
@@ -473,7 +469,7 @@ func (handler *InoHandler) sketchToBuildPathTextDocumentIdentifier(doc *lsp.Text
473
469
// another/path/source.cpp -> unchanged
474
470
475
471
// Convert sketch path to build path
476
- docFile := newPathFromURI ( doc .URI )
472
+ docFile := doc .URI . AsPath ( )
477
473
newDocFile := docFile
478
474
479
475
if docFile .Ext () == ".ino" {
@@ -490,7 +486,7 @@ func (handler *InoHandler) sketchToBuildPathTextDocumentIdentifier(doc *lsp.Text
490
486
newDocFile = handler .buildSketchRoot .JoinPath (rel )
491
487
}
492
488
log .Printf (" URI: '%s' -> '%s'" , docFile , newDocFile )
493
- doc .URI = pathToURI ( newDocFile . String () )
489
+ doc .URI = lsp . NewDocumenteURIFromPath ( newDocFile )
494
490
return nil
495
491
}
496
492
@@ -841,7 +837,7 @@ func (handler *InoHandler) FromClangd(ctx context.Context, connection *jsonrpc2.
841
837
log .Printf (" > %d:%d - %v: %s" , diag .Range .Start .Line , diag .Range .Start .Character , diag .Severity , diag .Code )
842
838
}
843
839
844
- if newPathFromURI ( p .URI ).EquivalentTo (handler .buildSketchCpp ) {
840
+ if p .URI . AsPath ( ).EquivalentTo (handler .buildSketchCpp ) {
845
841
// we should transform back N diagnostics of sketch.cpp.ino into
846
842
// their .ino counter parts (that may span over multiple files...)
847
843
@@ -860,7 +856,7 @@ func (handler *InoHandler) FromClangd(ctx context.Context, connection *jsonrpc2.
860
856
// Push back to IDE the converted diagnostics
861
857
for filename , inoDiags := range convertedDiagnostics {
862
858
msg := lsp.PublishDiagnosticsParams {
863
- URI : pathToURI (filename ),
859
+ URI : lsp . NewDocumentURI (filename ),
864
860
Diagnostics : inoDiags ,
865
861
}
866
862
if enableLogging {
@@ -936,3 +932,7 @@ func (handler *InoHandler) showMessage(ctx context.Context, msgType lsp.MessageT
936
932
}
937
933
handler .StdioConn .Notify (ctx , "window/showMessage" , & params )
938
934
}
935
+
936
+ func unknownURI (uri lsp.DocumentURI ) error {
937
+ return errors .New ("Document is not available: " + string (uri ))
938
+ }
0 commit comments