• 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 TODO_COMMENTS_H
17 #define TODO_COMMENTS_H
18 
19 #include <cstddef>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 #include "cancellation_token.h"
24 #include "public/es2panda_lib.h"
25 
26 namespace ark::es2panda::lsp {
27 struct TodoCommentDescriptor {
28 private:
29     std::string text_;
30     int priority_;
31 
32 public:
TodoCommentDescriptorTodoCommentDescriptor33     TodoCommentDescriptor(std::string text, int priority) : text_(std::move(text)), priority_(priority) {}
34 
GetTextTodoCommentDescriptor35     std::string GetText() const
36     {
37         return text_;
38     }
39 
GetPriorityTodoCommentDescriptor40     int GetPriority() const
41     {
42         return priority_;
43     }
44 };
45 
46 struct TodoComment {
47 private:
48     TodoCommentDescriptor commentDescriptor_;
49     std::string message_;
50     size_t position_;
51 
52 public:
TodoCommentTodoComment53     TodoComment(TodoCommentDescriptor descriptor, std::string message, size_t position)
54         : commentDescriptor_(std::move(descriptor)), message_(std::move(message)), position_(position)
55     {
56     }
57 
GetCommentDescriptorTodoComment58     TodoCommentDescriptor GetCommentDescriptor() const
59     {
60         return commentDescriptor_;
61     }
62 
GetMessageTodoComment63     std::string GetMessage() const
64     {
65         return message_;
66     }
67 
GetPositionTodoComment68     int GetPosition() const
69     {
70         return position_;
71     }
72 };
73 
74 struct TodoMatchContext {
75     es2panda_Context *context;
76     const std::vector<ark::es2panda::lsp::TodoCommentDescriptor> &descriptors;
77     size_t lineStart;
78     const std::string *line;
79     std::string_view fileContents;
80     std::vector<ark::es2panda::lsp::TodoComment> &result;
81 };
82 
83 std::vector<ark::es2panda::lsp::TodoComment> GetTodoCommentsImpl(
84     es2panda_Context *context, std::vector<ark::es2panda::lsp::TodoCommentDescriptor> &descriptors,
85     CancellationToken *cancellationToken);
86 
87 }  // namespace ark::es2panda::lsp
88 
89 #endif