File: printers.go

package info (click to toggle)
golang-golang-x-tools 1%3A0.0~git20190125.d66bd3c%2Bds-4
  • links: PTS, VCS
  • area: main
  • in suites: buster, buster-backports
  • size: 8,912 kB
  • sloc: asm: 1,394; yacc: 155; makefile: 109; sh: 108; ansic: 17; xml: 11
file content (83 lines) | stat: -rw-r--r-- 2,221 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// 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)
}

func (i CompletionItem) Format(f fmt.State, c rune) {
	fmt.Fprintf(f, "%v %v %v", i.Label, i.Detail, CompletionItemKind(i.Kind))
}

func (k CompletionItemKind) Format(f fmt.State, c rune) {
	switch k {
	case StructCompletion:
		fmt.Fprintf(f, "struct")
	case FunctionCompletion:
		fmt.Fprintf(f, "func")
	case VariableCompletion:
		fmt.Fprintf(f, "var")
	case TypeParameterCompletion:
		fmt.Fprintf(f, "type")
	case FieldCompletion:
		fmt.Fprintf(f, "field")
	case InterfaceCompletion:
		fmt.Fprintf(f, "interface")
	case ConstantCompletion:
		fmt.Fprintf(f, "const")
	case MethodCompletion:
		fmt.Fprintf(f, "method")
	case ModuleCompletion:
		fmt.Fprintf(f, "package")
	}
}