v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
message.h
Go to the documentation of this file.
1// Copyright 2019 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_TORQUE_LS_MESSAGE_H_
6#define V8_TORQUE_LS_MESSAGE_H_
7
8#include "src/base/logging.h"
12
13namespace v8 {
14namespace internal {
15namespace torque {
16namespace ls {
17
18// Base class for Messages and Objects that are backed by either a
19// JsonValue or a reference to a JsonObject.
20// Helper methods are used by macros to implement typed accessors.
22 public:
23 template <class T>
24 T GetObject(const std::string& property) {
25 return T(GetObjectProperty(property));
26 }
27
28 bool HasProperty(const std::string& property) const {
29 return object().count(property) > 0;
30 }
31
32 void SetNull(const std::string& property) {
34 }
35
36 bool IsNull(const std::string& property) const {
37 return HasProperty(property) &&
38 object().at(property).tag == JsonValue::IS_NULL;
39 }
40
41 protected:
42 virtual const JsonObject& object() const = 0;
43 virtual JsonObject& object() = 0;
44
45 JsonObject& GetObjectProperty(const std::string& property) {
46 if (!object()[property].IsObject()) {
48 }
49 return object()[property].ToObject();
50 }
51
52 JsonArray& GetArrayProperty(const std::string& property) {
53 if (!object()[property].IsArray()) {
55 }
56 return object()[property].ToArray();
57 }
58
59 JsonObject& AddObjectElementToArrayProperty(const std::string& property) {
60 JsonArray& array = GetArrayProperty(property);
61 array.push_back(JsonValue::From(JsonObject{}));
62
63 return array.back().ToObject();
64 }
65};
66
67// Base class for Requests, Responses and Notifications.
68// In contrast to "BaseObject", a Message owns the backing JsonValue of the
69// whole object tree; i.e. value_ serves as root.
70class Message : public BaseJsonAccessor {
71 public:
74 set_jsonrpc("2.0");
75 }
76 explicit Message(JsonValue value) : value_(std::move(value)) {
78 }
79
81
83
84 protected:
85 const JsonObject& object() const override { return value_.ToObject(); }
86 JsonObject& object() override { return value_.ToObject(); }
87
88 private:
90};
91
92// Base class for complex type that might be part of a Message.
93// Instead of creating theses directly, use the accessors on the
94// root Message or a parent object.
96 public:
97 explicit NestedJsonAccessor(JsonObject& object) : object_(object) {}
98
99 const JsonObject& object() const override { return object_; }
100 JsonObject& object() override { return object_; }
101
102 private:
104};
105
107 public:
109
111 JSON_STRING_ACCESSORS(message)
112};
113
115 public:
117
118 JSON_INT_ACCESSORS(processId)
119 JSON_STRING_ACCESSORS(rootPath)
120 JSON_STRING_ACCESSORS(rootUri)
122};
123
125 public:
127
128 // TODO(szuend): Implement read accessor for string
129 // arrays. "files" is managed directly.
130};
131
133 public:
135
136 JSON_STRING_ACCESSORS(globPattern)
138
146};
147
154
156 public:
158
161};
162
169
171 public:
173
174 JSON_BOOL_ACCESSORS(includeText)
175};
176
178 public:
180
181 JSON_BOOL_ACCESSORS(openClose)
182 JSON_INT_ACCESSORS(change)
183 JSON_BOOL_ACCESSORS(willSave)
184 JSON_BOOL_ACCESSORS(willSaveWaitUntil)
186};
187
189 public:
191
193 JSON_BOOL_ACCESSORS(definitionProvider)
194 JSON_BOOL_ACCESSORS(documentSymbolProvider)
195};
196
203
212
219
227
235
237 public:
239
242
244 set_uri(SourceFileMap::AbsolutePath(position.source));
245 range().start().set_line(position.start.line);
246 range().start().set_character(position.start.column);
247 range().end().set_line(position.end.line);
248 range().end().set_character(position.end.column);
249 }
250};
251
258
266
268 public:
270
277
279 JSON_INT_ACCESSORS(severity)
281 JSON_STRING_ACCESSORS(message)
282};
283
291
305
312
322
323template <class T>
324class Request : public Message {
325 public:
326 explicit Request(JsonValue value) : Message(std::move(value)) {}
328
331 JSON_OBJECT_ACCESSORS(T, params)
332};
340
341template <class T>
342class Response : public Message {
343 public:
344 explicit Response(JsonValue value) : Message(std::move(value)) {}
346
350};
353
354// Same as "Response" but the result is T[] instead of T.
355template <class T>
366
367} // namespace ls
368} // namespace torque
369} // namespace internal
370} // namespace v8
371
372#endif // V8_TORQUE_LS_MESSAGE_H_
#define T
Builtins::Kind kind
Definition builtins.cc:40
static std::string AbsolutePath(SourceId file)
bool HasProperty(const std::string &property) const
Definition message.h:28
bool IsNull(const std::string &property) const
Definition message.h:36
void SetNull(const std::string &property)
Definition message.h:32
virtual const JsonObject & object() const =0
JsonArray & GetArrayProperty(const std::string &property)
Definition message.h:52
JsonObject & AddObjectElementToArrayProperty(const std::string &property)
Definition message.h:59
JsonObject & GetObjectProperty(const std::string &property)
Definition message.h:45
T GetObject(const std::string &property)
Definition message.h:24
void SetTo(SourcePosition position)
Definition message.h:243
const JsonObject & object() const override
Definition message.h:85
JsonObject & object() override
Definition message.h:86
const JsonObject & object() const override
Definition message.h:99
int start
int end
const std::string property
ZoneVector< RpoNumber > & result
int position
Definition liveedit.cc:290
#define JSON_ARRAY_OBJECT_ACCESSORS(type, name)
#define JSON_BOOL_ACCESSORS(name)
#define JSON_INT_ACCESSORS(name)
#define JSON_STRING_ACCESSORS(name)
#define JSON_DYNAMIC_OBJECT_ACCESSORS(name)
#define JSON_OBJECT_ACCESSORS(type, name)
STL namespace.
std::map< std::string, JsonValue > JsonObject
Definition json.h:22
std::vector< JsonValue > JsonArray
Definition json.h:23
BUILTIN_FP_CALL BUILTIN_FP_CALL BUILTIN_FP_CALL BUILTIN_FP_CALL BUILTIN_FP_CALL BUILTIN_FP_CALL BUILTIN_FP_CALL BUILTIN_FP_CALL BUILTIN_FP_CALL BUILTIN_FP_CALL int character
V8_INLINE constexpr bool IsObject(TaggedImpl< kRefType, StorageType > obj)
Definition objects.h:661
#define CHECK(condition)
Definition logging.h:124
enum v8::internal::torque::ls::JsonValue::@156 tag
static JsonValue From(double number)
Definition json.h:37
static JsonValue JsonNull()
Definition json.h:72
const JsonObject & ToObject() const
Definition json.h:97
Symbol method