mirror of
https://github.com/golang/go
synced 2024-11-05 14:36:11 -07:00
internal/lsp/protocol: add a compare function for span.URI
Add an additional check to handle URI comparisons. This fixes Hover on Windows. Change-Id: Ibfc816f1ec374144377a873c5b52867fafa3d7e8 Reviewed-on: https://go-review.googlesource.com/c/tools/+/172659 Run-TryBot: Rebecca Stambler <rstambler@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
183b688ac4
commit
a5870b4038
@ -40,7 +40,7 @@ func (m *ColumnMapper) Location(s span.Span) (Location, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *ColumnMapper) Range(s span.Span) (Range, error) {
|
func (m *ColumnMapper) Range(s span.Span) (Range, error) {
|
||||||
if m.URI != s.URI() {
|
if span.CompareURI(m.URI, s.URI()) != 0 {
|
||||||
return Range{}, fmt.Errorf("column mapper is for file %q instead of %q", m.URI, s.URI())
|
return Range{}, fmt.Errorf("column mapper is for file %q instead of %q", m.URI, s.URI())
|
||||||
}
|
}
|
||||||
s, err := s.WithAll(m.Converter)
|
s, err := s.WithAll(m.Converter)
|
||||||
|
@ -7,7 +7,6 @@ package span
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Span represents a source code range in standardized form.
|
// Span represents a source code range in standardized form.
|
||||||
@ -58,7 +57,7 @@ func NewPoint(line, col, offset int) Point {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Compare(a, b Span) int {
|
func Compare(a, b Span) int {
|
||||||
if r := strings.Compare(string(a.v.URI), string(b.v.URI)); r != 0 {
|
if r := CompareURI(a.URI(), b.URI()); r != 0 {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
if r := comparePoint(a.v.Start, b.v.Start); r != 0 {
|
if r := comparePoint(a.v.Start, b.v.Start); r != 0 {
|
||||||
|
@ -7,6 +7,7 @@ package span
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@ -54,6 +55,29 @@ func NewURI(s string) URI {
|
|||||||
return FileURI(s)
|
return FileURI(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CompareURI(a, b URI) int {
|
||||||
|
if a == b {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
// If we have the same URI basename, we may still have the same file URIs.
|
||||||
|
if fa, err := a.Filename(); err == nil {
|
||||||
|
if fb, err := b.Filename(); err == nil {
|
||||||
|
if filepath.Base(fa) == filepath.Base(fb) {
|
||||||
|
// Stat the files to check if they are equal.
|
||||||
|
if infoa, err := os.Stat(fa); err == nil {
|
||||||
|
if infob, err := os.Stat(fb); err == nil {
|
||||||
|
if os.SameFile(infoa, infob) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return strings.Compare(fa, fb)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return strings.Compare(string(a), string(b))
|
||||||
|
}
|
||||||
|
|
||||||
// FileURI returns a span URI for the supplied file path.
|
// FileURI returns a span URI for the supplied file path.
|
||||||
// It will always have the file scheme.
|
// It will always have the file scheme.
|
||||||
func FileURI(path string) URI {
|
func FileURI(path string) URI {
|
||||||
|
Loading…
Reference in New Issue
Block a user