• 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 #ifndef NAVIGATE_TO_H
17 #define NAVIGATE_TO_H
18 
19 #include <string>
20 #include <cctype>
21 #include <string_view>
22 #include <vector>
23 #include "es2panda.h"
24 #include "ir/astNode.h"
25 #include <regex>
26 
27 namespace ark::es2panda::lsp {
28 
29 enum class MatchKind { EXACT, PREFIX, SUBSTRING, CAMELCASE, NONE };
30 
31 struct TextSpan {
32     size_t start;
33     size_t length;
34 };
35 
36 struct NavigateToItem {
37     std::string name;
38     std::string_view kind;
39     MatchKind matchKind = MatchKind::NONE;
40     bool isCaseSensitive = false;
41     std::string fileName;
42     std::string containerName;
43     std::string_view containerKind;
44 };
45 
46 class PatternMatcher {
47 public:
48     PatternMatcher(const std::string &pattern, bool isCaseSensitive);
49 
50     bool IsPatternValid() const;
51     bool MatchesExact(const std::string &candidate) const;
52     bool MatchesPrefix(const std::string &candidate) const;
53     bool MatchesSubstring(const std::string &candidate) const;
54 
55 private:
56     std::string pattern_;
57     std::optional<std::regex> regexPattern_;
58     bool isCaseSensitive_;
59 };
60 
61 std::vector<NavigateToItem> GetNavigateToItems(es2panda_Context *context,
62                                                const std::vector<ark::es2panda::SourceFile> &srcFiles,
63                                                size_t maxResultCount, const std::string &searchValue,
64                                                bool isCaseSensitive);
65 
66 ir::AstNode *GetContainerNodes(ir::AstNode *node);
67 std::vector<NavigateToItem> GetItemsFromNamedDeclaration(const SourceFile &file, const PatternMatcher &matcher);
68 
69 }  // namespace ark::es2panda::lsp
70 
71 #endif