mirror of
https://github.com/golang/go
synced 2024-11-19 07:04:43 -07:00
1aef897494
It is impossible to reconstruct a line and column correctly from export data, so we have to attempt to find open and process the file in order to guess what the original pos was when we have one that originated in export data. This occurs in any time in go to definition when the target is not in the same pacakge as the source. Change-Id: Ib2ee404d4f1c39d8bd7f1fbc2096d8d6cbeed6f8 Reviewed-on: https://go-review.googlesource.com/c/150044 Reviewed-by: Rebecca Stambler <rstambler@golang.org>
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// This file contains formatting functions for types that
|
|
// are commonly printed in debugging information.
|
|
// They are separated from their types and gathered here as
|
|
// they are hand written and not generated from the spec.
|
|
// They should not be relied on for programmatic use (their
|
|
// results should never be parsed for instance) but are meant
|
|
// for temporary debugging and error messages.
|
|
|
|
package protocol
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func (p Position) Format(f fmt.State, c rune) {
|
|
fmt.Fprintf(f, "%d", int(p.Line)+1)
|
|
if p.Character >= 0 {
|
|
fmt.Fprintf(f, ":%d", int(p.Character)+1)
|
|
}
|
|
}
|
|
|
|
func (r Range) Format(f fmt.State, c rune) {
|
|
switch {
|
|
case r.Start == r.End || r.End.Line < 0:
|
|
fmt.Fprintf(f, "%v", r.Start)
|
|
case r.End.Line == r.Start.Line:
|
|
fmt.Fprintf(f, "%v¦%d", r.Start, int(r.End.Character)+1)
|
|
default:
|
|
fmt.Fprintf(f, "%v¦%v", r.Start, r.End)
|
|
}
|
|
}
|
|
|
|
func (l Location) Format(f fmt.State, c rune) {
|
|
fmt.Fprintf(f, "%s:%v", l.URI, l.Range)
|
|
}
|
|
|
|
func (s DiagnosticSeverity) Format(f fmt.State, c rune) {
|
|
switch s {
|
|
case SeverityError:
|
|
fmt.Fprint(f, "Error")
|
|
case SeverityWarning:
|
|
fmt.Fprint(f, "Warning")
|
|
case SeverityInformation:
|
|
fmt.Fprint(f, "Information")
|
|
case SeverityHint:
|
|
fmt.Fprint(f, "Hint")
|
|
}
|
|
}
|
|
|
|
func (d Diagnostic) Format(f fmt.State, c rune) {
|
|
fmt.Fprintf(f, "%v:%v from %v at %v: %v", d.Severity, d.Code, d.Source, d.Range, d.Message)
|
|
}
|