Skip to content

Commit

Permalink
#11 Autocomplete for NamedIntegerConstants
Browse files Browse the repository at this point in the history
  • Loading branch information
satran004 committed Mar 18, 2021
1 parent c710177 commit dfa785c
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ public TEALCompletionContributor() {
AssetParamsGetCompletionProvider.PATTERN,
new AssetParamsGetCompletionProvider());

//Named integer constants
extend(CompletionType.BASIC,
NamedIntegerConstantsCompletionProvider.PATTERN,
new NamedIntegerConstantsCompletionProvider());

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ public final class TEALKeywords {
public final static LookupElement PRAGMA_LINE = new TEALKeywordElement("#pragma version 2").getLookupElement();

public final static String TXN_FIELDS = "txn_fields";
public final static String TYPE_ENUM_MAPPING = "type_enum_mapping";
public final static String TYPE_ENUM_MAPPING = "typeenum_constants";
public final static String GLOBAL_FIELDS = "global_fields";
public final static String ASSET_HOLDING_GET_FIELDS = "asset_holding_get_fields";
public final static String ASSET_PARAMS_GET_FIELDS = "asset_params_get_fields";
public final static String ONCOMPLETE_CONSTANTS = "oncomplete";

// public static final Collection<String> LOADING_OPERATIONS = Sets.newHashSet(
// "intcblock", "intc", "intc_0", "intc_1", "intc_2", "intc_3", "bytecblock", "bytec", "bytec_0"
Expand Down Expand Up @@ -128,7 +129,7 @@ public final class TEALKeywords {
.map(f -> new TEALFieldElement(f))
.collect(Collectors.toList());

public static final List<LookupElement> TYPE_ENUM_MAPPING_ELEMENTS = TEALOpCodeFactory.getInstance()
public static final List<LookupElement> TYPEENUM_CONSTANT_ELEMENTS = TEALOpCodeFactory.getInstance()
.getFields(TYPE_ENUM_MAPPING)
.stream()
.map(f -> new TEALFieldElement(f))
Expand Down Expand Up @@ -156,4 +157,12 @@ public final class TEALKeywords {
.map(TEALFieldElement::getLookupElement)
.collect(Collectors.toList());

public static final List<LookupElement> ONCOMPLETE_CONSTANT_ELEMENTS = TEALOpCodeFactory.getInstance()
.getFields(ONCOMPLETE_CONSTANTS)
.stream()
.map(f -> new TEALFieldElement(f))
.map(TEALFieldElement::getLookupElement)
.collect(Collectors.toList());


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2020 BloxBean Project
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.bloxbean.algodea.idea.language.completion.providers;

import com.bloxbean.algodea.idea.language.TEALLanguage;
import com.bloxbean.algodea.idea.language.TEALParserDefinition;
import com.bloxbean.algodea.idea.language.completion.metadata.atoms.TEALKeywords;
import com.bloxbean.algodea.idea.language.psi.TEALTypes;
import com.intellij.codeInsight.completion.CompletionParameters;
import com.intellij.codeInsight.completion.CompletionResultSet;
import com.intellij.patterns.ElementPattern;
import com.intellij.psi.PsiElement;
import com.intellij.util.ProcessingContext;
import org.jetbrains.annotations.NotNull;

import static com.intellij.patterns.PlatformPatterns.psiElement;

public final class NamedIntegerConstantsCompletionProvider extends BaseCompletionProvider {

public static final ElementPattern<PsiElement> PATTERN = psiElement()
.afterLeaf(psiElement(TEALTypes.INT)
.withParent(psiElement(TEALTypes.INT_STATEMENT)))
.withLanguage(TEALLanguage.INSTANCE)
.andNot(psiElement(TEALParserDefinition.LINE_COMMENT))
.andNot(psiElement(TEALParserDefinition.BLOCK_COMMENT));

@Override
protected void addCompletions(@NotNull CompletionParameters parameters,
ProcessingContext context,
@NotNull CompletionResultSet result) {
result.addAllElements(TEALKeywords.ONCOMPLETE_CONSTANT_ELEMENTS);
result.addAllElements(TEALKeywords.TYPEENUM_CONSTANT_ELEMENTS);
result.stopHere();
}
}
54 changes: 46 additions & 8 deletions src/main/resources/opcodes/fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,45 @@
"note": "The new frozen value, 0 or 1. LogicSigVersion >= 2."
}
],
"type_enum_mapping": [
"oncomplete": [
{
"index": 0,
"name": "NoOp",
"type": "NoOp",
"desc": "NoOp"
},
{
"index": 1,
"name": "OptIn",
"type": "OptIn",
"desc": "OptIn"
},
{
"index": 2,
"name": "CloseOut",
"type": "CloseOut",
"desc": "CloseOut"
},
{
"index": 3,
"name": "ClearState",
"type": "ClearState",
"desc": "ClearState"
},
{
"index": 4,
"name": "UpdateApplication",
"type": "UpdateApplication",
"desc": "UpdateApplication"
},
{
"index": 5,
"name": "DeleteApplication",
"type": "DeleteApplication",
"desc": "DeleteApplication"
}
],
"typeenum_constants": [
{
"index": 0,
"name": "unknown",
Expand All @@ -298,37 +336,37 @@
},
{
"index": 1,
"name": "pay",
"name": "Payment",
"type": "pay",
"desc": "Payment"
},
{
"index": 2,
"name": "keyreg",
"name": "KeyRegistration",
"type": "keyreg",
"desc": "KeyRegistration"
},
{
"index": 3,
"name": "acfg",
"name": "AssetConfig",
"type": "acfg",
"desc": "AssetConfig"
},
{
"index": 4,
"name": "axfer",
"name": "AssetTransfer",
"type": "axfer",
"desc": "AssetTransfer"
},
{
"index": 5,
"name": "afrz",
"name": "AssetFreeze",
"type": "afrz",
"desc": "AssetFreeze"
},
{
"index": 6,
"name": "appl",
"name": "ApplicationCall",
"type": "appl",
"desc": "ApplicationCall"
}
Expand Down Expand Up @@ -471,4 +509,4 @@
"note": "Clawback address"
}
]
}
}

0 comments on commit dfa785c

Please sign in to comment.