forked from unshare/hybris-integration-intellij-idea-plugin
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#925 | Added code completion for Editor wrapping types
- Loading branch information
Showing
8 changed files
with
261 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<!-- | ||
~ This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA. | ||
~ Copyright (C) 2019-2023 EPAM Systems <[email protected]> and contributors | ||
~ This file is part of "SAP Commerce Developers Toolset" plugin for IntelliJ IDEA. | ||
~ Copyright (C) 2019-2024 EPAM Systems <[email protected]> and contributors | ||
~ | ||
~ This program is free software: you can redistribute it and/or modify | ||
~ it under the terms of the GNU Lesser General Public License as | ||
|
@@ -66,9 +66,6 @@ | |
|
||
<completion.contributor language="ImpEx" implementationClass="com.intellij.idea.plugin.hybris.impex.completion.ImpexCompletionContributor"/> | ||
|
||
<projectService serviceInterface="com.intellij.idea.plugin.hybris.system.type.codeInsight.completion.TSCompletionService" | ||
serviceImplementation="com.intellij.idea.plugin.hybris.system.type.codeInsight.completion.impl.DefaultTSCompletionService"/> | ||
|
||
<!-- ####################################################################################################### --> | ||
|
||
<highlightUsagesHandlerFactory | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA. | ||
* Copyright (C) 2019-2023 EPAM Systems <[email protected]> and contributors | ||
* This file is part of "SAP Commerce Developers Toolset" plugin for IntelliJ IDEA. | ||
* Copyright (C) 2019-2024 EPAM Systems <[email protected]> and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
|
@@ -23,6 +23,8 @@ import com.intellij.codeInsight.completion.CompletionResultSet | |
import com.intellij.codeInsight.completion.PrioritizedLookupElement | ||
import com.intellij.idea.plugin.hybris.codeInsight.completion.provider.ItemTypeCodeCompletionProvider | ||
import com.intellij.idea.plugin.hybris.common.HybrisConstants | ||
import com.intellij.idea.plugin.hybris.system.cockpitng.codeInsight.lookup.CngLookupElementFactory | ||
import com.intellij.idea.plugin.hybris.system.cockpitng.meta.CngWrappingType | ||
import com.intellij.idea.plugin.hybris.system.cockpitng.model.config.Config | ||
import com.intellij.idea.plugin.hybris.system.cockpitng.model.config.Context | ||
import com.intellij.idea.plugin.hybris.system.type.codeInsight.lookup.TSLookupElementFactory | ||
|
@@ -59,7 +61,7 @@ class CngItemTypeCodeCompletionProvider : ItemTypeCodeCompletionProvider() { | |
?: return super.addCompletions(parameters, context, result) | ||
val tag = currentAttribute.parentOfType<XmlTag>() | ||
?.takeIf { it.localName == Config.CONTEXT } | ||
?: return super.addCompletions(parameters, context, result) | ||
?: return addTypeCompletions(parameters, context, result) | ||
|
||
val metaModelAccess = TSMetaModelAccess.getInstance(element.project) | ||
val currentAttributeName = currentAttribute.localName | ||
|
@@ -77,6 +79,18 @@ class CngItemTypeCodeCompletionProvider : ItemTypeCodeCompletionProvider() { | |
addContextSpecificCompletions(currentAttributeName, anotherAttributeValue, result, boostedItems, allItems) | ||
} | ||
|
||
private fun addTypeCompletions( | ||
parameters: CompletionParameters, | ||
context: ProcessingContext, | ||
result: CompletionResultSet | ||
) { | ||
super.addCompletions(parameters, context, result) | ||
|
||
CngWrappingType.entries | ||
.map { CngLookupElementFactory.buildWrappingType(it.type, it.presentation, it.tail) } | ||
.forEach { result.addElement(it) } | ||
} | ||
|
||
private fun addContextSpecificCompletions( | ||
currentAttributeName: String, | ||
anotherAttributeValue: TSGlobalMetaClassifier<out DomElement>, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA. | ||
* Copyright (C) 2019-2023 EPAM Systems <[email protected]> and contributors | ||
* This file is part of "SAP Commerce Developers Toolset" plugin for IntelliJ IDEA. | ||
* Copyright (C) 2019-2024 EPAM Systems <[email protected]> and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
|
@@ -18,7 +18,11 @@ | |
|
||
package com.intellij.idea.plugin.hybris.system.cockpitng.codeInsight.lookup | ||
|
||
import com.intellij.codeInsight.completion.InsertionContext | ||
import com.intellij.codeInsight.completion.PrioritizedLookupElement | ||
import com.intellij.codeInsight.lookup.LookupElement | ||
import com.intellij.codeInsight.lookup.LookupElementBuilder | ||
import com.intellij.idea.plugin.hybris.codeInsight.completion.AutoPopupInsertHandler | ||
import com.intellij.idea.plugin.hybris.common.utils.HybrisIcons | ||
import com.intellij.idea.plugin.hybris.system.cockpitng.meta.model.* | ||
import com.intellij.psi.xml.XmlTag | ||
|
@@ -58,4 +62,20 @@ object CngLookupElementFactory { | |
fun buildInitializeProperty(property: String) = LookupElementBuilder.create(property) | ||
.withIcon(HybrisIcons.COCKPIT_NG_INITIALIZE_PROPERTY) | ||
|
||
fun buildWrappingType(lookupString: String, presentableText: String, tailText: String? = null) = PrioritizedLookupElement.withGrouping( | ||
PrioritizedLookupElement.withPriority( | ||
LookupElementBuilder.create(lookupString) | ||
.withPresentableText(presentableText) | ||
.withTailText(tailText?.let { " ($it)" }, true) | ||
.withTypeText(lookupString, true) | ||
.withIcon(HybrisIcons.TYPE_OBJECT) | ||
.withInsertHandler( | ||
object : AutoPopupInsertHandler() { | ||
override fun handle(context: InsertionContext, item: LookupElement) { | ||
val cursorOffset = context.editor.caretModel.offset | ||
context.editor.caretModel.moveToOffset(cursorOffset - 1) | ||
} | ||
} | ||
), 2.0 | ||
), 1) | ||
} |
37 changes: 37 additions & 0 deletions
37
src/com/intellij/idea/plugin/hybris/system/cockpitng/meta/CngWrappingType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* This file is part of "SAP Commerce Developers Toolset" plugin for IntelliJ IDEA. | ||
* Copyright (C) 2019-2024 EPAM Systems <[email protected]> and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.intellij.idea.plugin.hybris.system.cockpitng.meta | ||
|
||
enum class CngWrappingType(val presentation: String, val type: String, val tail: String? = null) { | ||
RANGE("Range", "Range()"), | ||
LOCALIZED("Localized", "Localized()"), | ||
LOCALIZED_SIMPLE("Localized Simple", "LocalizedSimple()"), | ||
LIST("List", "List()"), | ||
REFERENCE("Reference", "Reference()"), | ||
FIXED_VALUES_REFERENCE("Fixed Values Reference", "FixedValuesReference()"), | ||
MULTI_REFERENCE_COLLECTION("Multi Reference", "MultiReference-COLLECTION()", "collection"), | ||
MULTI_REFERENCE_LIST("Multi Reference", "MultiReference-LIST()", "list"), | ||
MULTI_REFERENCE_SET("Multi Reference", "MultiReference-SET()", "set"), | ||
EXTENDED_MULTI_REFERENCE_COLLECTION("Extended Multi Reference", "ExtendedMultiReference-COLLECTION()", "collection"), | ||
EXTENDED_MULTI_REFERENCE_LIST("Extended Multi Reference", "ExtendedMultiReference-LIST()", "list"), | ||
EXTENDED_MULTI_REFERENCE_SET("Extended Multi Reference", "ExtendedMultiReference-SET()", "set"), | ||
ENUM_MULTI_REFERENCE_COLLECTION("Enum Multi Reference", "EnumMultiReference-COLLECTION()", "collection"), | ||
ENUM_MULTI_REFERENCE_LIST("Enum Multi Reference", "EnumMultiReference-LIST()", "list"), | ||
ENUM_MULTI_REFERENCE_SET("Enum Multi Reference", "EnumMultiReference-SET()", "set"), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA. | ||
* Copyright (C) 2019 EPAM Systems <[email protected]> | ||
* This file is part of "SAP Commerce Developers Toolset" plugin for IntelliJ IDEA. | ||
* Copyright (C) 2019-2024 EPAM Systems <[email protected]> and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
|
@@ -37,8 +37,6 @@ import com.intellij.psi.ResolveResult | |
import com.intellij.psi.util.* | ||
|
||
/** | ||
* https://help.sap.com/docs/SAP_COMMERCE/5c9ea0c629214e42b727bf08800d8dfa/8b59d395866910149db8889c5087a5ef.html?locale=en-US&q=ExtendedMultiReference | ||
* | ||
* see, standard-editors-spring.xml | ||
*/ | ||
open class CngTSItemReference(element: PsiElement) : TSReferenceBase<PsiElement>(element), PsiPolyVariantReference, HighlightedReference { | ||
|
@@ -96,13 +94,23 @@ open class CngTSItemReference(element: PsiElement) : TSReferenceBase<PsiElement> | |
.toTypedArray() | ||
|
||
private val regexes = arrayOf( | ||
// https://help.sap.com/docs/SAP_COMMERCE_CLOUD_PUBLIC_CLOUD/9b5366ff6eb34df5be29881ff55f97d2/8bad5c918669101499c8d4802cd12214.html | ||
"^Range\\((.*)\\)\$".toRegex(), | ||
// https://help.sap.com/docs/SAP_COMMERCE_CLOUD_PUBLIC_CLOUD/9b5366ff6eb34df5be29881ff55f97d2/8c0606208669101480e1b95aa5146259.html | ||
"^Localized\\((.*)\\)\$".toRegex(), | ||
// https://help.sap.com/docs/SAP_COMMERCE_CLOUD_PUBLIC_CLOUD/9b5366ff6eb34df5be29881ff55f97d2/8c062ff286691014b2618f676f8099fe.html | ||
"^LocalizedSimple\\((.*)\\)\$".toRegex(), | ||
// https://help.sap.com/docs/SAP_COMMERCE_CLOUD_PUBLIC_CLOUD/9b5366ff6eb34df5be29881ff55f97d2/8bac73cc866910148c4bcba41953b0ed.html | ||
"^List\\((.*)\\)\$".toRegex(), | ||
// https://help.sap.com/docs/SAP_COMMERCE_CLOUD_PUBLIC_CLOUD/9b5366ff6eb34df5be29881ff55f97d2/8bad8ae286691014bf4ab06b9b99d7c6.html | ||
"^Reference\\((.*)\\)\$".toRegex(), | ||
// https://help.sap.com/docs/SAP_COMMERCE_CLOUD_PUBLIC_CLOUD/9b5366ff6eb34df5be29881ff55f97d2/f7ce138967d0470aaeae5c7e01e1c162.html | ||
"^FixedValuesReference\\((.*)\\)\$".toRegex(), | ||
// https://help.sap.com/docs/SAP_COMMERCE_CLOUD_PUBLIC_CLOUD/9b5366ff6eb34df5be29881ff55f97d2/8bad002786691014924ba694583a1368.html | ||
"^MultiReference-(COLLECTION|LIST|SET)\\((.*)\\)\$".toRegex(), | ||
// https://help.sap.com/docs/SAP_COMMERCE_CLOUD_PUBLIC_CLOUD/9b5366ff6eb34df5be29881ff55f97d2/8bab997f86691014852cfbeabd21a5c8.html | ||
"^ExtendedMultiReference-(COLLECTION|LIST|SET)\\((.*)\\)\$".toRegex(), | ||
// https://help.sap.com/docs/SAP_COMMERCE_CLOUD_PUBLIC_CLOUD/9b5366ff6eb34df5be29881ff55f97d2/8bab6c4486691014a3899cab8989d996.html | ||
"^EnumMultiReference-(COLLECTION|LIST|SET)\\((.*)\\)\$".toRegex(), | ||
) | ||
} | ||
|
Oops, something went wrong.