Line data Source code
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_SERVER_DATA_H_
6 : #define V8_TORQUE_SERVER_DATA_H_
7 :
8 : #include <map>
9 : #include <vector>
10 :
11 : #include "src/base/macros.h"
12 : #include "src/base/optional.h"
13 : #include "src/torque/source-positions.h"
14 :
15 : namespace v8 {
16 : namespace internal {
17 : namespace torque {
18 :
19 : // The definition of the token in the first element, can be found at the second.
20 : using DefinitionMapping = std::pair<SourcePosition, SourcePosition>;
21 : // TODO(szuend): Support overlapping source positions when we start adding them.
22 : using Definitions = std::vector<DefinitionMapping>;
23 : using DefinitionsMap = std::map<SourceId, Definitions>;
24 :
25 : // This contextual class holds all the necessary data to answer incoming
26 : // LSP requests. It is reset for each compilation step and all information
27 : // is calculated eagerly during compilation.
28 9 : class LanguageServerData : public ContextualClass<LanguageServerData> {
29 : public:
30 : LanguageServerData() = default;
31 :
32 : V8_EXPORT_PRIVATE static void AddDefinition(SourcePosition token,
33 : SourcePosition definition);
34 :
35 : V8_EXPORT_PRIVATE static base::Optional<SourcePosition> FindDefinition(
36 : SourceId source, LineAndColumn pos);
37 :
38 : private:
39 : DefinitionsMap definitions_map_;
40 : };
41 :
42 : } // namespace torque
43 : } // namespace internal
44 : } // namespace v8
45 :
46 : #endif // V8_TORQUE_SERVER_DATA_H_
|