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