@@ -77,10 +77,11 @@ type BuildHandler struct {
77
77
findPkg map [findPkgKey ]* findPkgValue
78
78
langserver.HandlerCommon
79
79
* langserver.HandlerShared
80
- init * lspext.InitializeParams // set by "initialize" request
81
- rootImportPath string // root import path of the workspace (e.g., "github.com/foo/bar")
82
- cachingClient * http.Client // http.Client with a cache backed by an in-memory LRU cache
83
- closers []io.Closer // values to dispose of when Close() is called
80
+ init * lspext.InitializeParams // set by "initialize" request
81
+ originalRootURI * url.URL // derived from InitializeParams.OriginalRootURI
82
+ rootImportPath string // root import path of the workspace (e.g., "github.com/foo/bar")
83
+ cachingClient * http.Client // http.Client with a cache backed by an in-memory LRU cache
84
+ closers []io.Closer // values to dispose of when Close() is called
84
85
// Whether URIs in the same workspace begin with:
85
86
// - `file://` (true)
86
87
// - `git://` (false)
@@ -101,6 +102,11 @@ func (h *BuildHandler) reset(init *lspext.InitializeParams, conn *jsonrpc2.Conn,
101
102
return err
102
103
}
103
104
h .init = init
105
+ var err error
106
+ h .originalRootURI , err = url .Parse (string (h .init .OriginalRootURI ))
107
+ if h .init .OriginalRootURI == "" || err != nil {
108
+ h .originalRootURI = nil
109
+ }
104
110
// 100 MiB cache, no age-based eviction
105
111
h .cachingClient = & http.Client {Transport : httpcache .NewTransport (lrucache .New (100 * 1024 * 1024 , 0 ))}
106
112
h .depURLMutex = newKeyMutex ()
@@ -360,11 +366,10 @@ func (h *BuildHandler) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *jso
360
366
if err != nil {
361
367
return uri
362
368
}
363
- originalRootURI , err := url .Parse (string (h .init .OriginalRootURI ))
364
- if err != nil {
369
+ if h .originalRootURI == nil {
365
370
return uri
366
371
}
367
- if currentURL .Hostname () == originalRootURI .Hostname () && currentURL .RawPath == originalRootURI .RawPath {
372
+ if currentURL .Hostname () == h . originalRootURI .Hostname () && currentURL .RawPath == h . originalRootURI .RawPath {
368
373
path = currentURL .Fragment
369
374
} else {
370
375
return uri // refers to a resource outside of this workspace
@@ -520,10 +525,10 @@ func (h *BuildHandler) rewriteURIFromLangServer(uri lsp.DocumentURI) (lsp.Docume
520
525
// analyzing).
521
526
return lsp .DocumentURI ("file:///" + fileInGoStdlib ), nil
522
527
}
523
- newURI , err := url .Parse (string (h .init .OriginalRootURI ))
524
- if err != nil {
528
+ if h .originalRootURI == nil {
525
529
return uri , nil
526
530
}
531
+ newURI , _ := url .Parse (h .originalRootURI .String ())
527
532
newURI .Fragment = fileInGoStdlib
528
533
return lsp .DocumentURI (newURI .String ()), nil
529
534
}
@@ -536,10 +541,10 @@ func (h *BuildHandler) rewriteURIFromLangServer(uri lsp.DocumentURI) (lsp.Docume
536
541
pathInThisWorkspace := util .PathTrimPrefix (u .Path , h .RootFSPath )
537
542
return lsp .DocumentURI ("file:///" + pathInThisWorkspace ), nil
538
543
}
539
- newURI , err := url .Parse (string (h .init .OriginalRootURI ))
540
- if err != nil {
544
+ if h .originalRootURI == nil {
541
545
return uri , nil
542
546
}
547
+ newURI , _ := url .Parse (h .originalRootURI .String ())
543
548
newURI .Fragment = util .PathTrimPrefix (u .Path , h .RootFSPath )
544
549
return lsp .DocumentURI (newURI .String ()), nil
545
550
}
0 commit comments