aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/src/torque/server-data.cc
blob: 2dc92a4960c57b5fa95f6e8a1fdc5d4fd1947fb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/torque/server-data.h"

namespace v8 {
namespace internal {
namespace torque {

DEFINE_CONTEXTUAL_VARIABLE(LanguageServerData)

void LanguageServerData::AddDefinition(SourcePosition token,
                                       SourcePosition definition) {
  Get().definitions_map_[token.source].emplace_back(token, definition);
}

base::Optional<SourcePosition> LanguageServerData::FindDefinition(
    SourceId source, LineAndColumn pos) {
  for (const DefinitionMapping& mapping : Get().definitions_map_.at(source)) {
    SourcePosition current = mapping.first;
    if (current.Contains(pos)) return mapping.second;
  }

  return base::nullopt;
}

}  // namespace torque
}  // namespace internal
}  // namespace v8