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 <string_view>
17 #include "refactors/convert_template.h"
18 #include "refactor_provider.h"
19 #include "internal_api.h"
20
21 namespace ark::es2panda::lsp {
22
ConvertTemplateRefactor()23 ConvertTemplateRefactor::ConvertTemplateRefactor()
24 {
25 AddKind(std::string(TO_NAMED_TEMPLATE_ACTION.kind));
26 }
27
GetAvailableActions(const RefactorContext & refContext) const28 ApplicableRefactorInfo ConvertTemplateRefactor::GetAvailableActions(const RefactorContext &refContext) const
29 {
30 es2panda_Context *context = refContext.context;
31 size_t position = refContext.span.pos;
32
33 ApplicableRefactorInfo res;
34
35 if (!IsKind(refContext.kind)) {
36 return res;
37 }
38 auto node = GetTouchingToken(context, position, false);
39 if (node == nullptr) {
40 return res;
41 }
42
43 if (node != nullptr && node->Parent() != nullptr &&
44 (node->Parent()->IsExpression() && node->Parent()->IsBinaryExpression())) {
45 res.name = refactor_name::CONVERT_TEMPLATE_REFACTOR_NAME;
46 res.description = refactor_description::CONVERT_TEMPLATE_REFACTOR_DESC;
47 res.action.kind = std::string(TO_NAMED_TEMPLATE_ACTION.kind);
48 res.action.name = std::string(TO_NAMED_TEMPLATE_ACTION.name);
49 res.action.description = std::string(TO_NAMED_TEMPLATE_ACTION.description);
50 }
51
52 return res;
53 }
54
GetEditsForAction(const RefactorContext & context,const std::string & actionName) const55 std::unique_ptr<RefactorEditInfo> ConvertTemplateRefactor::GetEditsForAction(const RefactorContext &context,
56 const std::string &actionName) const
57 {
58 (void)context;
59 (void)actionName;
60 return std::make_unique<RefactorEditInfo>();
61 }
62 // NOLINTNEXTLINE(fuchsia-statically-constructed-objects, cert-err58-cpp)
63 AutoRefactorRegister<ConvertTemplateRefactor> g_convertTemplateRefactorRegister("ConvertTemplateRefactor");
64
65 } // namespace ark::es2panda::lsp
66