@@ -260,15 +260,11 @@ func (handler *InoHandler) exit() {
260260 os .Exit (1 )
261261}
262262
263- func newPathFromURI (uri lsp.DocumentURI ) * paths.Path {
264- return paths .New (uriToPath (uri ))
265- }
266-
267263func (handler * InoHandler ) initializeWorkbench (ctx context.Context , params * lsp.InitializeParams ) error {
268264 rootURI := params .RootURI
269265 log .Printf ("--> initializeWorkbench(%s)\n " , rootURI )
270266
271- handler .sketchRoot = newPathFromURI ( rootURI )
267+ handler .sketchRoot = rootURI . AsPath ( )
272268 handler .sketchName = handler .sketchRoot .Base ()
273269 if buildPath , err := generateBuildEnvironment (handler .sketchRoot , handler .config .SelectedBoard .Fqbn ); err == nil {
274270 handler .buildPath = buildPath
@@ -298,7 +294,7 @@ func (handler *InoHandler) initializeWorkbench(ctx context.Context, params *lsp.
298294 handler .ClangdConn = jsonrpc2 .NewConn (context .Background (), clangdStream , clangdHandler )
299295
300296 params .RootPath = handler .buildSketchRoot .String ()
301- params .RootURI = pathToURI (handler .buildSketchRoot . String () )
297+ params .RootURI = lsp . NewDocumenteURIFromPath (handler .buildSketchRoot )
302298 return nil
303299}
304300
@@ -353,7 +349,7 @@ func (handler *InoHandler) didOpen(ctx context.Context, params *lsp.DidOpenTextD
353349 log .Printf ("--> didOpen(%s)" , doc .URI )
354350
355351 // If we are tracking a .ino...
356- if newPathFromURI ( doc .URI ).Ext () == ".ino" {
352+ if doc .URI . AsPath ( ).Ext () == ".ino" {
357353 handler .sketchTrackedFilesCount ++
358354 log .Printf (" increasing .ino tracked files count: %d" , handler .sketchTrackedFilesCount )
359355
@@ -362,7 +358,7 @@ func (handler *InoHandler) didOpen(ctx context.Context, params *lsp.DidOpenTextD
362358 sketchCpp , err := handler .buildSketchCpp .ReadFile ()
363359 newParam := & lsp.DidOpenTextDocumentParams {
364360 TextDocument : lsp.TextDocumentItem {
365- URI : pathToURI (handler .buildSketchCpp . String () ),
361+ URI : lsp . NewDocumenteURIFromPath (handler .buildSketchCpp ),
366362 Text : string (sketchCpp ),
367363 LanguageID : "cpp" ,
368364 Version : 1 ,
@@ -388,11 +384,11 @@ func (handler *InoHandler) updateFileData(ctx context.Context, data *FileData, c
388384 return err
389385 }
390386 }
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 ( ))
392388 if err != nil {
393389 if rang == nil {
394390 // Fallback: use the source text unchanged
395- targetBytes , err = copyIno2Cpp (newSourceText , uriToPath ( data .targetURI ))
391+ targetBytes , err = copyIno2Cpp (newSourceText , data .targetURI . Unbox ( ))
396392 if err != nil {
397393 return err
398394 }
@@ -473,7 +469,7 @@ func (handler *InoHandler) sketchToBuildPathTextDocumentIdentifier(doc *lsp.Text
473469 // another/path/source.cpp -> unchanged
474470
475471 // Convert sketch path to build path
476- docFile := newPathFromURI ( doc .URI )
472+ docFile := doc .URI . AsPath ( )
477473 newDocFile := docFile
478474
479475 if docFile .Ext () == ".ino" {
@@ -490,7 +486,7 @@ func (handler *InoHandler) sketchToBuildPathTextDocumentIdentifier(doc *lsp.Text
490486 newDocFile = handler .buildSketchRoot .JoinPath (rel )
491487 }
492488 log .Printf (" URI: '%s' -> '%s'" , docFile , newDocFile )
493- doc .URI = pathToURI ( newDocFile . String () )
489+ doc .URI = lsp . NewDocumenteURIFromPath ( newDocFile )
494490 return nil
495491}
496492
@@ -841,7 +837,7 @@ func (handler *InoHandler) FromClangd(ctx context.Context, connection *jsonrpc2.
841837 log .Printf (" > %d:%d - %v: %s" , diag .Range .Start .Line , diag .Range .Start .Character , diag .Severity , diag .Code )
842838 }
843839
844- if newPathFromURI ( p .URI ).EquivalentTo (handler .buildSketchCpp ) {
840+ if p .URI . AsPath ( ).EquivalentTo (handler .buildSketchCpp ) {
845841 // we should transform back N diagnostics of sketch.cpp.ino into
846842 // their .ino counter parts (that may span over multiple files...)
847843
@@ -860,7 +856,7 @@ func (handler *InoHandler) FromClangd(ctx context.Context, connection *jsonrpc2.
860856 // Push back to IDE the converted diagnostics
861857 for filename , inoDiags := range convertedDiagnostics {
862858 msg := lsp.PublishDiagnosticsParams {
863- URI : pathToURI (filename ),
859+ URI : lsp . NewDocumentURI (filename ),
864860 Diagnostics : inoDiags ,
865861 }
866862 if enableLogging {
@@ -936,3 +932,7 @@ func (handler *InoHandler) showMessage(ctx context.Context, msgType lsp.MessageT
936932 }
937933 handler .StdioConn .Notify (ctx , "window/showMessage" , & params )
938934}
935+
936+ func unknownURI (uri lsp.DocumentURI ) error {
937+ return errors .New ("Document is not available: " + string (uri ))
938+ }
0 commit comments