• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "src/torque/server-data.h"
6 
7 #include "src/torque/declarable.h"
8 #include "src/torque/implementation-visitor.h"
9 
10 namespace v8 {
11 namespace internal {
12 namespace torque {
13 
DEFINE_CONTEXTUAL_VARIABLE(LanguageServerData)14 DEFINE_CONTEXTUAL_VARIABLE(LanguageServerData)
15 
16 void LanguageServerData::AddDefinition(SourcePosition token,
17                                        SourcePosition definition) {
18   Get().definitions_map_[token.source].emplace_back(token, definition);
19 }
20 
FindDefinition(SourceId source,LineAndColumn pos)21 base::Optional<SourcePosition> LanguageServerData::FindDefinition(
22     SourceId source, LineAndColumn pos) {
23   if (!source.IsValid()) return base::nullopt;
24 
25   auto iter = Get().definitions_map_.find(source);
26   if (iter == Get().definitions_map_.end()) return base::nullopt;
27 
28   for (const DefinitionMapping& mapping : iter->second) {
29     SourcePosition current = mapping.first;
30     if (current.Contains(pos)) return mapping.second;
31   }
32 
33   return base::nullopt;
34 }
35 
PrepareAllDeclarableSymbols()36 void LanguageServerData::PrepareAllDeclarableSymbols() {
37   const std::vector<std::unique_ptr<Declarable>>& all_declarables =
38       global_context_->declarables_;
39 
40   for (const auto& declarable : all_declarables) {
41     // Class field accessors and implicit specializations are
42     // auto-generated and should not show up.
43     if (!declarable->IsUserDefined()) continue;
44 
45     SourceId source = declarable->Position().source;
46     symbols_map_[source].push_back(declarable.get());
47   }
48 }
49 
50 }  // namespace torque
51 }  // namespace internal
52 }  // namespace v8
53