Skip to content

Commit

Permalink
Color settings page fix
Browse files Browse the repository at this point in the history
 - add highlight in color settings page for directive, function and type
  • Loading branch information
devyatkinalexandr authored Nov 30, 2022
1 parent 4726190 commit 7b147fb
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 146 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.wavesplatform.rideplugin.highlighter

import com.intellij.openapi.editor.colors.ColorKey
import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.openapi.fileTypes.SyntaxHighlighter
import com.intellij.openapi.options.colors.AttributesDescriptor
import com.intellij.openapi.options.colors.ColorDescriptor
import com.intellij.openapi.options.colors.ColorSettingsPage
import com.wavesplatform.rideplugin.RideIcons
import com.wavesplatform.rideplugin.loadCodeSampleResource
import javax.swing.Icon


Expand All @@ -19,151 +19,13 @@ class RideColorSettingsPage : ColorSettingsPage {
return RideSyntaxHighlighter()
}

override fun getDemoText(): String {
return """
{-# SCRIPT_TYPE ACCOUNT #-}
{-# CONTENT_TYPE LIBRARY #-}
{-# STDLIB_VERSION 5 #-}
# hm
# another
let a = 42 # Integer variable definition
let b = "Ride the Waves!" # String variable definition
let bool = true # Boolean variable definition
@Callable(i)
func lazyIsGood() = {
let a = base58'AAAAA'
strict balanceBefore = wavesBalance(this).value().regular
strict result = invoke(
dApp2,
"bar",
args,
[AttachedPayment(unit,100000000)]
)
strict balanceAfter = wavesBalance(this).regular
let c = {
strict d = 1
true
}
c
}
func reward() = {
let p = value(i.payments[0])
if p.assetId != lpTokenId {
true
} else {
false
}
if p.assetId > lpTokenId
then throw("Incorrect payment")
else {
let lpQty = assetInfo(lpTokenId).value().quantity
let rewardQty = assetInfo(rewardTokenId).value().quantity
let share = fraction(p.amount,rewardQty,lpQty)
strict result = invoke(this, "burn", [p.amount], [1])
[
ScriptTransfer(i.caller, share, rewardTokenId)
]
}
}
let list = [1, 2, 3]
let a1 = list.size()
let a2 = size(list)
let b1 = getInteger(this, "key")
let b2 = this.getInteger("key")
func say() = {
"Hello world!"
}
func main(amount: Int) = {
if (amount > 0)
then
"Done!"
else
throw("Error!")
}
let someConstant = 42
func doSomething() = {
1 + 1
}
func main(amount: Int, assetId: ByteVector|Unit, names: List[String]) = {
throw("Error")
}
match tx {
case ex: ExchangeTransaction|MassTransferTransaction =>
let pair = AssetPair(assetId, unit)
let rate = extract(getInteger(issuer, "exchangeRate"))
let rateDiff = rate - fraction(100000000, ex.price, ex.amount)
ex.buyOrder.assetPair == pair && rateDiff > -100 && rateDiff < 100
case _ => {true}
}
match tx {
case t: TransferTransaction|ExchangeTransaction|MassTransferTransaction|Order => false # deny any transfer of funds from the account
case _: Transaction => sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) # allow all other known transaction types if the signature is correct
case _ => {false} # deny any other (new, unknown) entity type since they are not supported in the Ride version used
}
func sum(accum: Int, next: Int) = accum
let arr = [1,2,3,4,5]
FOLD<5>(arr, 0, sum) # Result: 15
func mult(accum: Int, next: Int) = { accum }
let arr = [
1,
2,
3,
4,
5
]
FOLD<5>(arr, 1, mult) # Result: 120
func filterEven(accum: List[Int|String], next: Int) = {
if (next % 2 == 0) then accum :+ next else accum
}
let arr = [1,2,3,4,5]
FOLD<5>(arr, [], filterEven) # Result: [2, 4]
func map(accum: List[Int], next: Int) = (next - 1) :: accum
let arr = [1, 2, 3, 4, 5]
FOLD<5>(arr, [], map) # Result: [4, 3, 2, 1, 0]
let keys = ["key1", "key2", "key3"]
let values = ["value1", "value2", "value3"]
func addStringEntry(accum: (List[StringEntry], Int), nextValue: String) =
{ #comment
let (result, j) = accum
(result :+ StringEntry(keys[j], nextValue), j + 1)
}
let r = FOLD<10>(values, ([], 0), addStringEntry)
r._1
wavesBalance(Address(base58'3Mz9N7YPfZPWGd4yYaX6H53Gcgrq6ifYiH7'))
wavesBalance(Alias("merry")) # The result is the same
let addr = Address(base58'3N4iKL6ikwxiL7yNvWQmw7rg3wGna8uL6LU')
getInteger(addr,"integerVal") # Returns 1
getInteger(addr,"noKey") # Returns unit
size(getString("key"))
size(getStringValue("key"))
""".trimIndent()
}
override fun getDemoText(): String = loadCodeSampleResource(this, "sample/highlighter_example.ride")

override fun getAdditionalHighlightingTagToDescriptorMap(): Map<String, TextAttributesKey> {
return mapOf(
"Directive" to RideSyntaxHighlighter.DIRECTIVE,
"Function" to RideSyntaxHighlighter.FUNCTION,
"Type" to RideSyntaxHighlighter.TYPE,
"Annotation" to RideSyntaxHighlighter.ANNOTATION
)
}
Expand All @@ -186,9 +48,9 @@ class RideColorSettingsPage : ColorSettingsPage {
AttributesDescriptor("Number", RideSyntaxHighlighter.NUMBER),
AttributesDescriptor("String", RideSyntaxHighlighter.STRING),
AttributesDescriptor("Brackets", RideSyntaxHighlighter.BRACKETS),
AttributesDescriptor("Operator", RideSyntaxHighlighter.OPERATORS),
//AttributesDescriptor("Operator", RideSyntaxHighlighter.OPERATORS),
AttributesDescriptor("Bad value", RideSyntaxHighlighter.BAD_CHARACTER),
AttributesDescriptor("Identifier", RideSyntaxHighlighter.IDENTIFIER),
//AttributesDescriptor("Identifier", RideSyntaxHighlighter.IDENTIFIER),
AttributesDescriptor("Directive", RideSyntaxHighlighter.DIRECTIVE),
AttributesDescriptor("Annotation", RideSyntaxHighlighter.ANNOTATION),
AttributesDescriptor("Function", RideSyntaxHighlighter.FUNCTION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class RideSyntaxHighlighter : SyntaxHighlighterBase() {
fillMap(attributes, RideParserDefinition.KEYWORDS, KEYWORDS)
fillMap(attributes, RideParserDefinition.NUMBERS, NUMBER)
fillMap(attributes, RideParserDefinition.STRINGS, STRING)
fillMap(attributes, RideParserDefinition.OPERATORS, OPERATORS)
fillMap(attributes, RideParserDefinition.IDENTIFIER, IDENTIFIER)
//fillMap(attributes, RideParserDefinition.OPERATORS, OPERATORS)
//fillMap(attributes, RideParserDefinition.IDENTIFIER, IDENTIFIER)
fillMap(attributes, RideParserDefinition.COMMA, COMMA)
fillMap(attributes, RideParserDefinition.PARENTHESES, PARENTHESES)
fillMap(attributes, RideParserDefinition.COLON, COLON)
Expand Down
10 changes: 10 additions & 0 deletions src/main/kotlin/com/wavesplatform/rideplugin/util.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.wavesplatform.rideplugin

import com.intellij.openapi.util.io.StreamUtil
import java.io.BufferedReader
import java.io.InputStreamReader

fun loadCodeSampleResource(ctx: Any, resource: String): String {
val stream = ctx.javaClass.classLoader.getResourceAsStream(resource)!!
return StreamUtil.convertSeparators(StreamUtil.readText(BufferedReader(InputStreamReader(stream))))
}
35 changes: 35 additions & 0 deletions src/main/resources/sample/highlighter_example.ride
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Directive>{-# SCRIPT_TYPE ACCOUNT #-}</Directive>
<Directive>{-# CONTENT_TYPE LIBRARY #-}</Directive>
<Directive>{-# STDLIB_VERSION 5 #-}</Directive>


let int = 42 # Integer variable definition
let string = "Ride the Waves!" # String variable definition
let bool = true # Boolean variable definition

<Annotation>@Callable(i)</Annotation>
func <Function>functionName</Function>() = {
let encodedString = base58'AAAAA'
strict balance = <Function>wavesBalance</Function>(this).<Function>value</Function>().regular
let array = [AttachedPayment(unit,100000000)]
true
}

func <Function>sum</Function>(accum: <Type>Int</Type>, next: <Type>Int</Type>) = accum
let arr = [1,2,3,4,5]
FOLD<5>(arr, 0, sum)

func <Function>getAddressKey</Function>() = {
let addr = <Type>Address</Type>(base58'3N4iKL6ikwxiL7yNvWQmw7rg3wGna8uL6LU')
<Function>getInteger</Function>(addr, "noKey")
}

match tx {
case t: <Type>TransferTransaction|ExchangeTransaction|MassTransferTransaction|Order</Type> => false
case _: <Type>Transaction</Type> => <Function>sigVerify</Function>(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
case _ => {false}
}

func <Function>filterEven</Function>(accum: <Type>List[Int|String]</Type>, next: <Type>Int</Type>) = {
if (next % 2 == 0) then accum :+ next else accum
}

0 comments on commit 7b147fb

Please sign in to comment.