• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "lsp/include/api.h"
17 #include "internal_api.h"
18 #include "references.h"
19 #include "ir/astNode.h"
20 #include "find_safe_delete_location.h"
21 
22 namespace ark::es2panda::lsp {
23 
FindSafeDeleteLocationImpl(es2panda_Context * ctx,const std::tuple<std::string,std::string> & declInfo)24 std::vector<SafeDeleteLocation> FindSafeDeleteLocationImpl(es2panda_Context *ctx,
25                                                            const std::tuple<std::string, std::string> &declInfo)
26 {
27     std::vector<SafeDeleteLocation> locations;
28     if (std::get<0>(declInfo).empty() || std::get<1>(declInfo).empty()) {
29         return locations;
30     }
31 
32     std::unordered_set<std::string> seen;
33     auto references = GetReferencesAtPositionImpl(ctx, declInfo);
34 
35     locations.reserve(references.referenceInfos.size());
36     for (const auto &ref : references.referenceInfos) {
37         std::string key = ref.fileName + ":" + std::to_string(ref.start) + ":" + std::to_string(ref.length);
38         if (seen.insert(key).second) {
39             SafeDeleteLocation loc;
40             loc.uri = ref.fileName;
41             loc.start = ref.start;
42             loc.length = ref.length;
43             locations.push_back(loc);
44         }
45     }
46 
47     return locations;
48 }
49 
50 }  // namespace ark::es2panda::lsp
51