1
0
mirror of https://github.com/golang/go synced 2024-11-18 23:44:43 -07:00
go/internal/lsp/source/enums.go
Rebecca Stambler 04840ef8f3 internal/lsp: switch to using protocol positions for document symbols
Change-Id: I8e550b753328b8e536bff3bb61b4ff4486fcd4f9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/193722
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-09-06 18:11:17 +00:00

69 lines
1.9 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.
package source
import (
"fmt"
)
var (
namesDiagnosticSeverity [int(SeverityError) + 1]string
namesCompletionItemKind [int(PackageCompletionItem) + 1]string
)
func init() {
namesDiagnosticSeverity[SeverityWarning] = "Warning"
namesDiagnosticSeverity[SeverityError] = "Error"
namesCompletionItemKind[Unknown] = "Unknown"
namesCompletionItemKind[InterfaceCompletionItem] = "interface"
namesCompletionItemKind[StructCompletionItem] = "struct"
namesCompletionItemKind[TypeCompletionItem] = "type"
namesCompletionItemKind[ConstantCompletionItem] = "const"
namesCompletionItemKind[FieldCompletionItem] = "field"
namesCompletionItemKind[ParameterCompletionItem] = "parameter"
namesCompletionItemKind[VariableCompletionItem] = "var"
namesCompletionItemKind[FunctionCompletionItem] = "func"
namesCompletionItemKind[MethodCompletionItem] = "method"
namesCompletionItemKind[PackageCompletionItem] = "package"
}
func formatEnum(f fmt.State, c rune, i int, names []string, unknown string) {
s := ""
if i >= 0 && i < len(names) {
s = names[i]
}
if s != "" {
fmt.Fprint(f, s)
} else {
fmt.Fprintf(f, "%s(%d)", unknown, i)
}
}
func parseEnum(s string, names []string) int {
for i, name := range names {
if s == name {
return i
}
}
return 0
}
func (e DiagnosticSeverity) Format(f fmt.State, c rune) {
formatEnum(f, c, int(e), namesDiagnosticSeverity[:], "DiagnosticSeverity")
}
func ParseDiagnosticSeverity(s string) DiagnosticSeverity {
return DiagnosticSeverity(parseEnum(s, namesDiagnosticSeverity[:]))
}
func (e CompletionItemKind) Format(f fmt.State, c rune) {
formatEnum(f, c, int(e), namesCompletionItemKind[:], "CompletionItemKind")
}
func ParseCompletionItemKind(s string) CompletionItemKind {
return CompletionItemKind(parseEnum(s, namesCompletionItemKind[:]))
}