1 /**
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <vector>
17 #include "services/services.h"
18 #include "services/utilities.h"
19 #include "internal_api.h"
20 #include "public/public.h"
21
22 namespace ark::es2panda::lsp {
GetImplementationLocationAtPosition(es2panda_Context * context,int position)23 std::vector<Location> GetImplementationLocationAtPosition(es2panda_Context *context, int position)
24 {
25 auto ctx = reinterpret_cast<public_lib::Context *>(context);
26 auto options = reinterpret_cast<public_lib::Context *>(context)->config->options;
27 auto sourceFiles = options->ArkTSConfig()->Files();
28 std::vector<Location> locations;
29
30 if (options->GetExtension() != ScriptExtension::ETS) {
31 return locations;
32 }
33
34 // NOTE: Currently Ozerovs implementation returns single implementation location.
35 // So this section should be updated after the implementation of vector returning
36 // function.
37
38 auto implementationList = ArenaVector<ir::AstNode *>(ctx->allocator->Adapter());
39 auto declInfo = GetDefinitionAtPositionImpl(context, (size_t)position);
40 auto implementation = declInfo.first;
41 if (implementation != nullptr && IsValidImplementation(implementation)) {
42 implementationList.push_back(implementation);
43 }
44
45 for (auto &node : implementationList) {
46 Position sPos(node->Range().start.line, node->Range().start.index);
47 Position ePos(node->Range().end.line, node->Range().end.index);
48
49 // NOTE: It should be implementations sourcefilename but at the moment this should suffice
50 locations.emplace_back(Location(ctx->sourceFileName, Range(sPos, ePos)));
51 }
52
53 return locations;
54 }
55
56 } // namespace ark::es2panda::lsp
57