| 1 |
// Copyright 2018 The Go Authors. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
package protocol |
| 16 |
|
| 17 |
import ( |
| 18 |
"fmt" |
| 19 |
) |
| 20 |
|
| 21 |
var ( |
| 22 |
namesTextDocumentSyncKind [int(Incremental) + 1]string |
| 23 |
namesInitializeError [int(UnknownProtocolVersion) + 1]string |
| 24 |
namesMessageType [int(Log) + 1]string |
| 25 |
namesFileChangeType [int(Deleted) + 1]string |
| 26 |
namesWatchKind [int(WatchDelete) + 1]string |
| 27 |
namesCompletionTriggerKind [int(TriggerForIncompleteCompletions) + 1]string |
| 28 |
namesDiagnosticSeverity [int(SeverityHint) + 1]string |
| 29 |
namesDiagnosticTag [int(Unnecessary) + 1]string |
| 30 |
namesCompletionItemKind [int(TypeParameterCompletion) + 1]string |
| 31 |
namesInsertTextFormat [int(SnippetTextFormat) + 1]string |
| 32 |
namesDocumentHighlightKind [int(Write) + 1]string |
| 33 |
namesSymbolKind [int(TypeParameter) + 1]string |
| 34 |
namesTextDocumentSaveReason [int(FocusOut) + 1]string |
| 35 |
) |
| 36 |
|
| 37 |
func init() { |
| 38 |
namesTextDocumentSyncKind[int(None)] = "None" |
| 39 |
namesTextDocumentSyncKind[int(Full)] = "Full" |
| 40 |
namesTextDocumentSyncKind[int(Incremental)] = "Incremental" |
| 41 |
|
| 42 |
namesInitializeError[int(UnknownProtocolVersion)] = "UnknownProtocolVersion" |
| 43 |
|
| 44 |
namesMessageType[int(Error)] = "Error" |
| 45 |
namesMessageType[int(Warning)] = "Warning" |
| 46 |
namesMessageType[int(Info)] = "Info" |
| 47 |
namesMessageType[int(Log)] = "Log" |
| 48 |
|
| 49 |
namesFileChangeType[int(Created)] = "Created" |
| 50 |
namesFileChangeType[int(Changed)] = "Changed" |
| 51 |
namesFileChangeType[int(Deleted)] = "Deleted" |
| 52 |
|
| 53 |
namesWatchKind[int(WatchCreate)] = "WatchCreate" |
| 54 |
namesWatchKind[int(WatchChange)] = "WatchChange" |
| 55 |
namesWatchKind[int(WatchDelete)] = "WatchDelete" |
| 56 |
|
| 57 |
namesCompletionTriggerKind[int(Invoked)] = "Invoked" |
| 58 |
namesCompletionTriggerKind[int(TriggerCharacter)] = "TriggerCharacter" |
| 59 |
namesCompletionTriggerKind[int(TriggerForIncompleteCompletions)] = "TriggerForIncompleteCompletions" |
| 60 |
|
| 61 |
namesDiagnosticSeverity[int(SeverityError)] = "Error" |
| 62 |
namesDiagnosticSeverity[int(SeverityWarning)] = "Warning" |
| 63 |
namesDiagnosticSeverity[int(SeverityInformation)] = "Information" |
| 64 |
namesDiagnosticSeverity[int(SeverityHint)] = "Hint" |
| 65 |
|
| 66 |
namesDiagnosticTag[int(Unnecessary)] = "Unnecessary" |
| 67 |
|
| 68 |
namesCompletionItemKind[int(TextCompletion)] = "text" |
| 69 |
namesCompletionItemKind[int(MethodCompletion)] = "method" |
| 70 |
namesCompletionItemKind[int(FunctionCompletion)] = "func" |
| 71 |
namesCompletionItemKind[int(ConstructorCompletion)] = "constructor" |
| 72 |
namesCompletionItemKind[int(FieldCompletion)] = "field" |
| 73 |
namesCompletionItemKind[int(VariableCompletion)] = "var" |
| 74 |
namesCompletionItemKind[int(ClassCompletion)] = "type" |
| 75 |
namesCompletionItemKind[int(InterfaceCompletion)] = "interface" |
| 76 |
namesCompletionItemKind[int(ModuleCompletion)] = "package" |
| 77 |
namesCompletionItemKind[int(PropertyCompletion)] = "property" |
| 78 |
namesCompletionItemKind[int(UnitCompletion)] = "unit" |
| 79 |
namesCompletionItemKind[int(ValueCompletion)] = "value" |
| 80 |
namesCompletionItemKind[int(EnumCompletion)] = "enum" |
| 81 |
namesCompletionItemKind[int(KeywordCompletion)] = "keyword" |
| 82 |
namesCompletionItemKind[int(SnippetCompletion)] = "snippet" |
| 83 |
namesCompletionItemKind[int(ColorCompletion)] = "color" |
| 84 |
namesCompletionItemKind[int(FileCompletion)] = "file" |
| 85 |
namesCompletionItemKind[int(ReferenceCompletion)] = "reference" |
| 86 |
namesCompletionItemKind[int(FolderCompletion)] = "folder" |
| 87 |
namesCompletionItemKind[int(EnumMemberCompletion)] = "enumMember" |
| 88 |
namesCompletionItemKind[int(ConstantCompletion)] = "const" |
| 89 |
namesCompletionItemKind[int(StructCompletion)] = "struct" |
| 90 |
namesCompletionItemKind[int(EventCompletion)] = "event" |
| 91 |
namesCompletionItemKind[int(OperatorCompletion)] = "operator" |
| 92 |
namesCompletionItemKind[int(TypeParameterCompletion)] = "typeParam" |
| 93 |
|
| 94 |
namesInsertTextFormat[int(PlainTextTextFormat)] = "PlainText" |
| 95 |
namesInsertTextFormat[int(SnippetTextFormat)] = "Snippet" |
| 96 |
|
| 97 |
namesDocumentHighlightKind[int(Text)] = "Text" |
| 98 |
namesDocumentHighlightKind[int(Read)] = "Read" |
| 99 |
namesDocumentHighlightKind[int(Write)] = "Write" |
| 100 |
|
| 101 |
namesSymbolKind[int(File)] = "File" |
| 102 |
namesSymbolKind[int(Module)] = "Module" |
| 103 |
namesSymbolKind[int(Namespace)] = "Namespace" |
| 104 |
namesSymbolKind[int(Package)] = "Package" |
| 105 |
namesSymbolKind[int(Class)] = "Class" |
| 106 |
namesSymbolKind[int(Method)] = "Method" |
| 107 |
namesSymbolKind[int(Property)] = "Property" |
| 108 |
namesSymbolKind[int(Field)] = "Field" |
| 109 |
namesSymbolKind[int(Constructor)] = "Constructor" |
| 110 |
namesSymbolKind[int(Enum)] = "Enum" |
| 111 |
namesSymbolKind[int(Interface)] = "Interface" |
| 112 |
namesSymbolKind[int(Function)] = "Function" |
| 113 |
namesSymbolKind[int(Variable)] = "Variable" |
| 114 |
namesSymbolKind[int(Constant)] = "Constant" |
| 115 |
namesSymbolKind[int(String)] = "String" |
| 116 |
namesSymbolKind[int(Number)] = "Number" |
| 117 |
namesSymbolKind[int(Boolean)] = "Boolean" |
| 118 |
namesSymbolKind[int(Array)] = "Array" |
| 119 |
namesSymbolKind[int(Object)] = "Object" |
| 120 |
namesSymbolKind[int(Key)] = "Key" |
| 121 |
namesSymbolKind[int(Null)] = "Null" |
| 122 |
namesSymbolKind[int(EnumMember)] = "EnumMember" |
| 123 |
namesSymbolKind[int(Struct)] = "Struct" |
| 124 |
namesSymbolKind[int(Event)] = "Event" |
| 125 |
namesSymbolKind[int(Operator)] = "Operator" |
| 126 |
namesSymbolKind[int(TypeParameter)] = "TypeParameter" |
| 127 |
|
| 128 |
namesTextDocumentSaveReason[int(Manual)] = "Manual" |
| 129 |
namesTextDocumentSaveReason[int(AfterDelay)] = "AfterDelay" |
| 130 |
namesTextDocumentSaveReason[int(FocusOut)] = "FocusOut" |
| 131 |
} |
| 132 |
|
| 133 |
func formatEnum(f fmt.State, c rune, i int, names []string, unknown string) { |
| 134 |
s := "" |
| 135 |
if i >= 0 && i < len(names) { |
| 136 |
s = names[i] |
| 137 |
} |
| 138 |
if s != "" { |
| 139 |
fmt.Fprint(f, s) |
| 140 |
} else { |
| 141 |
fmt.Fprintf(f, "%s(%d)", unknown, i) |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
func parseEnum(s string, names []string) int { |
| 146 |
for i, name := range names { |
| 147 |
if s == name { |
| 148 |
return i |
| 149 |
} |
| 150 |
} |
| 151 |
return 0 |
| 152 |
} |
| 153 |
|
| 154 |
func (e TextDocumentSyncKind) Format(f fmt.State, c rune) { |
| 155 |
formatEnum(f, c, int(e), namesTextDocumentSyncKind[:], "TextDocumentSyncKind") |
| 156 |
} |
| 157 |
|
| 158 |
func ParseTextDocumentSyncKind(s string) TextDocumentSyncKind { |
| 159 |
return TextDocumentSyncKind(parseEnum(s, namesTextDocumentSyncKind[:])) |
| 160 |
} |
| 161 |
|
| 162 |
func (e InitializeError) Format(f fmt.State, c rune) { |
| 163 |
formatEnum(f, c, int(e), namesInitializeError[:], "InitializeError") |
| 164 |
} |
| 165 |
|
| 166 |
func ParseInitializeError(s string) InitializeError { |
| 167 |
return InitializeError(parseEnum(s, namesInitializeError[:])) |
| 168 |
} |
| 169 |
|
| 170 |
func (e MessageType) Format(f fmt.State, c rune) { |
| 171 |
formatEnum(f, c, int(e), namesMessageType[:], "MessageType") |
| 172 |
} |
| 173 |
|
| 174 |
func ParseMessageType(s string) MessageType { |
| 175 |
return MessageType(parseEnum(s, namesMessageType[:])) |
| 176 |
} |
| 177 |
|
| 178 |
func (e FileChangeType) Format(f fmt.State, c rune) { |
| 179 |
formatEnum(f, c, int(e), namesFileChangeType[:], "FileChangeType") |
| 180 |
} |
| 181 |
|
| 182 |
func ParseFileChangeType(s string) FileChangeType { |
| 183 |
return FileChangeType(parseEnum(s, namesFileChangeType[:])) |
| 184 |
} |
| 185 |
|
| 186 |
func (e WatchKind) Format(f fmt.State, c rune) { |
| 187 |
formatEnum(f, c, int(e), namesWatchKind[:], "WatchKind") |
| 188 |
} |
| 189 |
|
| 190 |
func ParseWatchKind(s string) WatchKind { |
| 191 |
return WatchKind(parseEnum(s, namesWatchKind[:])) |
| 192 |
} |
| 193 |
|
| 194 |
func (e CompletionTriggerKind) Format(f fmt.State, c rune) { |
| 195 |
formatEnum(f, c, int(e), namesCompletionTriggerKind[:], "CompletionTriggerKind") |
| 196 |
} |
| 197 |
|
| 198 |
func ParseCompletionTriggerKind(s string) CompletionTriggerKind { |
| 199 |
return CompletionTriggerKind(parseEnum(s, namesCompletionTriggerKind[:])) |
| 200 |
} |
| 201 |
|
| 202 |
func (e DiagnosticSeverity) Format(f fmt.State, c rune) { |
| 203 |
formatEnum(f, c, int(e), namesDiagnosticSeverity[:], "DiagnosticSeverity") |
| 204 |
} |
| 205 |
|
| 206 |
func ParseDiagnosticSeverity(s string) DiagnosticSeverity { |
| 207 |
return DiagnosticSeverity(parseEnum(s, namesDiagnosticSeverity[:])) |
| 208 |
} |
| 209 |
|
| 210 |
func (e DiagnosticTag) Format(f fmt.State, c rune) { |
| 211 |
formatEnum(f, c, int(e), namesDiagnosticTag[:], "DiagnosticTag") |
| 212 |
} |
| 213 |
|
| 214 |
func ParseDiagnosticTag(s string) DiagnosticTag { |
| 215 |
return DiagnosticTag(parseEnum(s, namesDiagnosticTag[:])) |
| 216 |
} |
| 217 |
|
| 218 |
func (e CompletionItemKind) Format(f fmt.State, c rune) { |
| 219 |
formatEnum(f, c, int(e), namesCompletionItemKind[:], "CompletionItemKind") |
| 220 |
} |
| 221 |
|
| 222 |
func ParseCompletionItemKind(s string) CompletionItemKind { |
| 223 |
return CompletionItemKind(parseEnum(s, namesCompletionItemKind[:])) |
| 224 |
} |
| 225 |
|
| 226 |
func (e InsertTextFormat) Format(f fmt.State, c rune) { |
| 227 |
formatEnum(f, c, int(e), namesInsertTextFormat[:], "InsertTextFormat") |
| 228 |
} |
| 229 |
|
| 230 |
func ParseInsertTextFormat(s string) InsertTextFormat { |
| 231 |
return InsertTextFormat(parseEnum(s, namesInsertTextFormat[:])) |
| 232 |
} |
| 233 |
|
| 234 |
func (e DocumentHighlightKind) Format(f fmt.State, c rune) { |
| 235 |
formatEnum(f, c, int(e), namesDocumentHighlightKind[:], "DocumentHighlightKind") |
| 236 |
} |
| 237 |
|
| 238 |
func ParseDocumentHighlightKind(s string) DocumentHighlightKind { |
| 239 |
return DocumentHighlightKind(parseEnum(s, namesDocumentHighlightKind[:])) |
| 240 |
} |
| 241 |
|
| 242 |
func (e SymbolKind) Format(f fmt.State, c rune) { |
| 243 |
formatEnum(f, c, int(e), namesSymbolKind[:], "SymbolKind") |
| 244 |
} |
| 245 |
|
| 246 |
func ParseSymbolKind(s string) SymbolKind { |
| 247 |
return SymbolKind(parseEnum(s, namesSymbolKind[:])) |
| 248 |
} |
| 249 |
|
| 250 |
func (e TextDocumentSaveReason) Format(f fmt.State, c rune) { |
| 251 |
formatEnum(f, c, int(e), namesTextDocumentSaveReason[:], "TextDocumentSaveReason") |
| 252 |
} |
| 253 |
|
| 254 |
func ParseTextDocumentSaveReason(s string) TextDocumentSaveReason { |
| 255 |
return TextDocumentSaveReason(parseEnum(s, namesTextDocumentSaveReason[:])) |
| 256 |
} |