Skip to content

Commit

Permalink
lsp: fix implementation of protocol.DocumentURI.Dir
Browse files Browse the repository at this point in the history
I got lost for an unreasonable amount of time trying to track down a
bug, where the working directory was being returned for an empty
DocumentURI. Whilst it might well be my naive and uninformed use of the
API, it seems safer to return an empty directory in case a DocumentURI
is also empty.

Signed-off-by: Paul Jolly <paul@myitcv.io>
Change-Id: I2fa96a6ddd302d3b8f3749f4d60c90e0dd3d50f6
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1206620
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
  • Loading branch information
myitcv committed Jan 3, 2025
1 parent 5747d91 commit 5a56848
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/golangorgx/gopls/protocol/uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ func (uri DocumentURI) Path() string {

// Dir returns the URI for the directory containing the receiver.
func (uri DocumentURI) Dir() DocumentURI {
// filepath.Dir returns "." in case passed "". So we need to special
// case a check for uri == "" in case the caller has not done that.
if uri == "" {
return ""
}
// This function could be more efficiently implemented by avoiding any call
// to Path(), but at least consolidates URI manipulation.
return URIFromPath(filepath.Dir(uri.Path()))
Expand Down

0 comments on commit 5a56848

Please sign in to comment.