Skip to content

Commit e78bb45

Browse files
authored
Merge pull request #87 from lord41ph4/develop
[IDEA] usage of version catalogs, kotlin version update and fix for #86
2 parents 1164ddd + 1da58e6 commit e78bb45

18 files changed

Lines changed: 160 additions & 80 deletions

File tree

.github/workflows/idea-gradle-build-and-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@v4
16-
- name: Set up JDK 17
16+
- name: Set up JDK 21
1717
uses: actions/setup-java@v4
1818
with:
1919
distribution: 'temurin'
20-
java-version: '17'
20+
java-version: '21'
2121
- name: Run tests and build plugin
2222
run: |
2323
cd IDEA

IDEA/build.gradle.kts

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import org.jetbrains.grammarkit.tasks.GenerateLexerTask
22
import org.jetbrains.grammarkit.tasks.GenerateParserTask
33
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
4+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
45
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
56

67
plugins {
7-
id("org.jetbrains.intellij.platform") version "2.0.1"
8-
id("org.jetbrains.kotlin.jvm") version "2.0.20"
9-
id("org.jetbrains.grammarkit") version "2022.3.2.2"
8+
alias(libs.plugins.intellijPlattform)
9+
alias(libs.plugins.kotlin)
10+
alias(libs.plugins.grammarkit)
1011
}
1112

1213
repositories {
@@ -18,7 +19,7 @@ repositories {
1819

1920
// Java target version
2021
java {
21-
sourceCompatibility = JavaVersion.VERSION_17
22+
sourceCompatibility = JavaVersion.VERSION_21
2223
}
2324

2425
sourceSets {
@@ -29,33 +30,36 @@ sourceSets {
2930

3031
kotlin {
3132
java {
32-
sourceCompatibility = JavaVersion.VERSION_17
33-
targetCompatibility = JavaVersion.VERSION_17
33+
compilerOptions {
34+
jvmTarget = JvmTarget.JVM_21
35+
freeCompilerArgs = listOf("-Xjvm-default=all")
36+
}
37+
sourceCompatibility = JavaVersion.VERSION_21
38+
targetCompatibility = JavaVersion.VERSION_21
3439
}
3540
}
3641

3742
dependencies {
3843
intellijPlatform {
39-
intellijIdeaCommunity("2024.2.1")
44+
intellijIdeaCommunity("2025.1.1")
4045

4146
bundledPlugins(listOf("com.intellij.java"))
42-
instrumentationTools()
4347

4448
testFramework(TestFrameworkType.Platform)
4549
}
4650

4751
// From Kotlin documentation
48-
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.8.22")
52+
implementation(libs.kotlin.stdlib)
4953
// just in case, version number specified in buildscript is used by default
50-
implementation("org.jetbrains.kotlin:kotlin-reflect:1.8.22")
54+
implementation(libs.kotlin.reflect)
5155

5256
// IntelliJ test framework needs junit 4.
53-
testImplementation("junit:junit:4.13")
54-
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.7.0")
57+
testImplementation(libs.junit4)
58+
testRuntimeOnly(libs.junit.vintage.engine)
5559

5660
// Use junit 5.
57-
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
58-
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0")
61+
testImplementation(libs.junit.jupiter.api)
62+
testRuntimeOnly(libs.junit.jupiter.engine)
5963
}
6064

6165
// Configure Gradle IntelliJ Plugin
@@ -74,39 +78,30 @@ intellijPlatform {
7478
}
7579

7680
project(":") {
77-
val generateLexer = task<GenerateLexerTask>("generateMyLexer") {
78-
sourceFile.set(file("src/main/grammar/KerboScript.flex"))
79-
targetOutputDir.set(file("src/gen/ksp/kos/ideaplugin/parser"))
80-
// targetClass.set("KerboScriptLexer")
81-
purgeOldFiles.set(true)
82-
}
83-
84-
val generateParser = task<GenerateParserTask>("generateMyParser") {
81+
val generateLexer =
82+
tasks.register<GenerateLexerTask>("generateMyLexer", fun GenerateLexerTask.() {
83+
sourceFile.set(file("src/main/grammar/KerboScript.flex"))
84+
targetOutputDir.set(file("src/gen/ksp/kos/ideaplugin/parser"))
85+
purgeOldFiles.set(true)
86+
})
87+
88+
val generateParser = tasks.register<GenerateParserTask>("generateMyParser", fun GenerateParserTask.() {
8589
sourceFile.set(file("src/main/grammar/KerboScript.bnf"))
8690
targetRootOutputDir.set(file("src/gen"))
8791
pathToParser.set("/ksp/kos/ideaplugin/parser/KerboScriptParser.java")
8892
pathToPsiRoot.set("/ksp/kos/ideaplugin/psi")
8993
purgeOldFiles.set(true)
90-
}
94+
})
9195

9296
tasks {
9397
withType<KotlinCompile> {
9498
dependsOn(generateLexer, generateParser)
9599
}
96100

97-
// Set the compatibility versions to 17
101+
// Set the compatibility versions to 21
98102
withType<JavaCompile> {
99-
sourceCompatibility = "17"
100-
targetCompatibility = "17"
101-
}
102-
103-
listOf("compileKotlin", "compileTestKotlin").forEach {
104-
getByName<KotlinCompile>(it) {
105-
kotlinOptions {
106-
jvmTarget = "17"
107-
freeCompilerArgs = listOf("-Xjvm-default=all")
108-
}
109-
}
103+
sourceCompatibility = "21"
104+
targetCompatibility = "21"
110105
}
111106

112107
publishPlugin {

IDEA/gradle/libs.versions.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[versions]
2+
intellij = "2.5.0"
3+
kotlin = "2.1.20"
4+
kotlin-std-lib = "1.8.22"
5+
grammarkit = "2022.3.2.2"
6+
junit4 = "4.13.1"
7+
junit5 = "5.7.0"
8+
9+
[libraries]
10+
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
11+
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
12+
13+
junit4 = { module = "junit:junit", version.ref = "junit4" }
14+
junit-vintage-engine = { module = "org.junit.vintage:junit-vintage-engine", version.ref = "junit5" }
15+
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit5"}
16+
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit5"}
17+
18+
[plugins]
19+
intellijPlattform = { id = "org.jetbrains.intellij.platform", version.ref = "intellij" }
20+
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
21+
grammarkit = { id = "org.jetbrains.grammarkit", version.ref = "grammarkit" }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

IDEA/src/main/grammar/KerboScript.bnf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
tokenTypeClass="ksp.kos.ideaplugin.psi.KerboScriptTokenType"
2626

2727
extends(".*_stmt|directive|instruction_block")=instruction
28-
extends("lazyglobal_directive")=directive
28+
extends("lazyglobal_directive|clobberbuiltins_directive")=directive
2929
extends("function_trailer|array_trailer")=suffixterm_trailer
3030
extends("[a-z]*_expr|factor|suffix|suffixterm|atom|.*number")=expr
3131

@@ -109,13 +109,14 @@
109109
ALL = 'regexp:(?i)all'
110110
IDENTIFIER = 'regexp:[a-zA-Z_][a-zA-Z0-9_]*'
111111
FILEIDENT = 'regexp:[a-zA-Z_][a-zA-Z0-9_]*(\.[a-zA-Z0-9_][a-zA-Z0-9_]*)*'
112-
INTEGER = 'regexp:[0-9]+'
113-
DOUBLE = 'regexp:[0-9]*\.[0-9]+'
112+
INTEGER = 'regexp:[0-9][0-9_]*'
113+
DOUBLE = 'regexp:([0-9]+(_[0-9]*)*)?\.[0-9]+(_[0-9]*)*'
114114
STRING = 'regexp:@?"(""|[^"])*"'
115115
EOI = '.'
116116
//Compiler Directives
117117
ATSIGN = '@'
118118
LAZYGLOBAL = 'regexp:(?i)lazyglobal'
119+
CLOBBERBUILTINS = 'regexp:(?i)clobberbuiltins'
119120
//Special
120121
//EOF = '$'
121122
//[Skip]
@@ -127,7 +128,7 @@
127128

128129
// Rules
129130
// ===================================================
130-
Start ::= (instruction)*
131+
Start ::= (directive|instruction)*
131132
instruction_block ::= CURLYOPEN instruction* CURLYCLOSE
132133
instruction ::= !(CURLYCLOSE | <<eof>>) instruction_inner {
133134
pin = 1
@@ -174,7 +175,6 @@ private instruction_inner ::= empty_stmt |
174175
unset_stmt |
175176
instruction_block |
176177
identifier_led_stmt | // any statement that starts with an identifier.
177-
directive // allow directives anywhere for now, let the compiler decide if it's in the wrong place, not the parser.
178178

179179
// ------------ directives --------------------
180180
lazyglobal_directive ::= LAZYGLOBAL onoff_trailer EOI

IDEA/src/main/grammar/KerboScript.flex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ ARRAYINDEX = #
9898
ALL = all
9999
IDENTIFIER = [a-zA-Z_][a-zA-Z0-9_]*
100100
FILEIDENT = [a-zA-Z_][a-zA-Z0-9_]*(\.[a-zA-Z0-9_][a-zA-Z0-9_]*)*
101-
INTEGER = [0-9]+
102-
DOUBLE = [0-9]*\.[0-9]+
101+
INTEGER = [0-9][0-9_]*
102+
DOUBLE = ([0-9]+(_[0-9]*)*)?\.[0-9]+(_[0-9]*)*
103103
STRING = @?\"(\"\"|[^\"])*\"
104104
EOI = \.
105105
//Compiler Directives

IDEA/src/main/java/ksp/kos/ideaplugin/Magic.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ object Magic {
5858
KerboScriptTypes.UNSET,
5959
KerboScriptTypes.CHOOSE,
6060
KerboScriptTypes.ATSIGN,
61-
KerboScriptTypes.LAZYGLOBAL
61+
KerboScriptTypes.LAZYGLOBAL,
62+
KerboScriptTypes.CLOBBERBUILTINS
6263
)
6364
}

IDEA/src/main/java/ksp/kos/ideaplugin/actions/differentiate/DiffContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public DiffContext(FileContext origFile, FileDuality diffFile, FileContextResolv
3535
registerFile(origFile.getName());
3636
}
3737

38-
public static List<ReferenceResolver<LocalContext>> createDiffResolvers(FileContextResolver fileResolver) {
39-
List<ReferenceResolver<LocalContext>> resolvers = FileContext.createResolvers(fileResolver);
38+
public static List<ReferenceResolver> createDiffResolvers(FileContextResolver fileResolver) {
39+
List<ReferenceResolver> resolvers = FileContext.createResolvers(fileResolver);
4040
resolvers.add((context, reference, createAllowed) -> {
4141
if (createAllowed && reference.getName().endsWith("_")) {
4242
String name1 = reference.getName();

IDEA/src/main/java/ksp/kos/ideaplugin/completion/KerboScriptKeywordProvider.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.intellij.codeInsight.completion.CompletionResultSet
66
import com.intellij.codeInsight.lookup.LookupElementBuilder
77
import com.intellij.util.ProcessingContext
88
import ksp.kos.ideaplugin.Magic
9+
import java.util.Locale
910

1011
class KerboScriptKeywordProvider : CompletionProvider<CompletionParameters>() {
1112
override fun addCompletions(completionParameters: CompletionParameters, context: ProcessingContext, resultSet: CompletionResultSet) {
@@ -15,8 +16,8 @@ class KerboScriptKeywordProvider : CompletionProvider<CompletionParameters>() {
1516
// when you type in lowercase, the completion shows uppercase (which can be somewhat unreadable when
1617
// you're not used to it).
1718
listOf(
18-
LookupElementBuilder.create(it.toString().toUpperCase()),
19-
LookupElementBuilder.create(it.toString().toLowerCase())
19+
LookupElementBuilder.create(it.toString().uppercase(Locale.getDefault())),
20+
LookupElementBuilder.create(it.toString().lowercase(Locale.getDefault()))
2021
)
2122
})
2223
}

IDEA/src/main/java/ksp/kos/ideaplugin/dataflow/ContextBuilder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ public void visit(ExpressionVisitor visitor) {
3131
}
3232

3333
public String getText() {
34-
String text = "";
34+
StringBuilder text = new StringBuilder();
3535
for (Flow<?> flow : getList()) {
36-
if (!text.isEmpty()) text += "\n";
37-
text += flow.getText();
36+
if (!text.isEmpty()) {
37+
text.append("\n");
38+
}
39+
text.append(flow.getText());
3840
}
39-
return text;
41+
return text.toString();
4042
}
4143

4244
public void differentiate(LocalContext context, ContextBuilder contextBuilder) {

0 commit comments

Comments
 (0)