Skip to content

Commit 75a2154

Browse files
committed
wip: rust support
1 parent 9b65491 commit 75a2154

File tree

10 files changed

+271
-0
lines changed

10 files changed

+271
-0
lines changed

marker/rs-marker/build.gradle.kts

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
plugins {
2+
kotlin("jvm")
3+
id("maven-publish")
4+
}
5+
6+
val vertxVersion: String by project
7+
val jupiterVersion: String by project
8+
val guavaVersion: String by project
9+
val projectVersion: String by project
10+
val protocolVersion = project.properties["protocolVersion"] as String? ?: projectVersion
11+
12+
group = "plus.sourceplus.interface"
13+
version = project.properties["projectVersion"] as String? ?: projectVersion
14+
15+
intellij {
16+
type.set("IC")
17+
plugins.set(listOf("com.jetbrains.rust:232.20527.212"))
18+
}
19+
20+
val sourcesJar = tasks.register<Jar>("sourcesJar") {
21+
archiveClassifier.set("sources")
22+
from(project.the<SourceSetContainer>()["main"].allSource)
23+
}
24+
25+
configure<PublishingExtension> {
26+
repositories {
27+
maven {
28+
name = "GitHubPackages"
29+
url = uri("https://maven.pkg.github.com/sourceplusplus/interface-jetbrains")
30+
credentials {
31+
username = System.getenv("GH_PUBLISH_USERNAME")?.toString()
32+
password = System.getenv("GH_PUBLISH_TOKEN")?.toString()
33+
}
34+
}
35+
}
36+
37+
publishing {
38+
publications {
39+
create<MavenPublication>("maven") {
40+
groupId = project.group.toString()
41+
artifactId = "jetbrains-marker-rs"
42+
version = project.version.toString()
43+
44+
from(components["kotlin"])
45+
46+
// Ship the sources jar
47+
artifact(sourcesJar)
48+
}
49+
}
50+
}
51+
}
52+
53+
dependencies {
54+
implementation(projectDependency(":core"))
55+
implementation(projectDependency(":marker"))
56+
implementation("plus.sourceplus:protocol:$protocolVersion")
57+
implementation("io.vertx:vertx-core:$vertxVersion")
58+
implementation("io.vertx:vertx-lang-kotlin-coroutines:$vertxVersion") {
59+
exclude(group = "org.jetbrains.kotlinx")
60+
}
61+
62+
compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
63+
compileOnly("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
64+
compileOnly("com.google.guava:guava:$guavaVersion")
65+
compileOnly("org.jetbrains:annotations:24.0.1")
66+
67+
testRuntimeOnly(projectDependency(":marker:ult-marker"))
68+
testImplementation("org.junit.jupiter:junit-jupiter:$jupiterVersion")
69+
}
70+
71+
fun projectDependency(name: String): ProjectDependency {
72+
return if (rootProject.name.contains("jetbrains")) {
73+
DependencyHandlerScope.of(rootProject.dependencies).project(name)
74+
} else {
75+
DependencyHandlerScope.of(rootProject.dependencies).project(":interfaces:jetbrains$name")
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Source++, the continuous feedback platform for developers.
3+
* Copyright (C) 2022-2024 CodeBrig, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package spp.jetbrains.marker.rs
18+
19+
import com.intellij.openapi.project.Project
20+
import org.rust.lang.core.psi.RsFile
21+
import spp.jetbrains.artifact.service.ArtifactModelService
22+
import spp.jetbrains.artifact.service.ArtifactTypeService
23+
import spp.jetbrains.marker.LanguageProvider
24+
import spp.jetbrains.marker.rs.service.RustArtifactModelService
25+
import spp.jetbrains.marker.rs.service.RustArtifactTypeService
26+
import spp.jetbrains.marker.source.SourceFileMarker
27+
28+
/**
29+
* Provides Rust support for the Marker API.
30+
*
31+
* @author [Brandon Fergerson](mailto:bfergerson@apache.org)
32+
*/
33+
class RustLanguageProvider : LanguageProvider {
34+
35+
override fun canSetup() = classExists("org.rust.lang.core.psi.ext.RsElement")
36+
37+
override fun setup(project: Project, setupDetectors: Boolean) {
38+
SourceFileMarker.SUPPORTED_FILE_TYPES.add(RsFile::class.java)
39+
40+
ArtifactModelService.addService(RustArtifactModelService(), "Rust")
41+
ArtifactTypeService.addService(RustArtifactTypeService(), "Rust")
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Source++, the continuous feedback platform for developers.
3+
* Copyright (C) 2022-2024 CodeBrig, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package spp.jetbrains.marker.rs.model
18+
19+
import org.rust.lang.core.psi.RsIfExpr
20+
import spp.jetbrains.artifact.model.ArtifactElement
21+
import spp.jetbrains.artifact.model.IfArtifact
22+
import spp.jetbrains.artifact.service.toArtifact
23+
24+
class RustIfArtifact(override val psiElement: RsIfExpr) : IfArtifact(psiElement) {
25+
26+
override val condition: ArtifactElement?
27+
get() = psiElement.condition.toArtifact()
28+
29+
override val thenBranch: ArtifactElement?
30+
get() = null
31+
32+
override val elseBranch: ArtifactElement?
33+
get() = psiElement.elseBranch?.toArtifact()
34+
35+
override fun clone(): RustIfArtifact {
36+
return RustIfArtifact(psiElement)
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Source++, the continuous feedback platform for developers.
3+
* Copyright (C) 2022-2024 CodeBrig, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package spp.jetbrains.marker.rs.service
18+
19+
import com.intellij.psi.PsiElement
20+
import org.rust.lang.core.psi.RsIfExpr
21+
import spp.jetbrains.artifact.model.ArtifactElement
22+
import spp.jetbrains.artifact.service.define.IArtifactModelService
23+
import spp.jetbrains.marker.rs.model.RustIfArtifact
24+
25+
/**
26+
* Provides language-agnostic artifact model service for Rust.
27+
*
28+
* @author [Brandon Fergerson](mailto:bfergerson@apache.org)
29+
*/
30+
class RustArtifactModelService : IArtifactModelService {
31+
32+
override fun toArtifact(element: PsiElement): ArtifactElement? {
33+
return when (element) {
34+
is RsIfExpr -> RustIfArtifact(element)
35+
else -> null
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Source++, the continuous feedback platform for developers.
3+
* Copyright (C) 2022-2024 CodeBrig, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package spp.jetbrains.marker.rs.service
18+
19+
import com.intellij.psi.PsiComment
20+
import com.intellij.psi.PsiElement
21+
import com.intellij.psi.impl.source.tree.LeafPsiElement
22+
import org.rust.lang.core.psi.RsExpr
23+
import org.rust.lang.core.psi.RsFunction
24+
import spp.jetbrains.artifact.service.define.IArtifactTypeService
25+
import spp.protocol.artifact.ArtifactType
26+
27+
/**
28+
* Used to determine the type of Rust artifacts.
29+
*
30+
* @author [Brandon Fergerson](mailto:bfergerson@apache.org)
31+
*/
32+
class RustArtifactTypeService : IArtifactTypeService {
33+
34+
override fun getAnnotations(element: PsiElement): List<PsiElement> {
35+
return emptyList() //todo: implement
36+
}
37+
38+
override fun getAnnotationOwnerIfAnnotation(element: PsiElement): PsiElement? {
39+
return null //todo: implement
40+
}
41+
42+
override fun getAnnotationOwnerIfAnnotation(element: PsiElement, line: Int): PsiElement? {
43+
return null //todo: implement
44+
}
45+
46+
override fun isComment(element: PsiElement): Boolean {
47+
val comment = element is PsiComment
48+
if (comment) return true
49+
50+
return if (element is LeafPsiElement) {
51+
isComment(element.parent)
52+
} else false
53+
}
54+
55+
override fun getType(element: PsiElement): ArtifactType? {
56+
return when (element) {
57+
is RsFunction -> ArtifactType.FUNCTION
58+
is RsExpr -> ArtifactType.EXPRESSION
59+
60+
else -> null
61+
}
62+
}
63+
64+
override fun isLiteral(element: PsiElement): Boolean {
65+
return super.isLiteral(element) //todo: implement
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spp.jetbrains.marker.rs.RustLanguageProvider

plugin/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ dependencies {
7474
runtimeOnly(projectDependency(":marker:js-marker"))
7575
runtimeOnly(projectDependency(":marker:jvm-marker"))
7676
runtimeOnly(projectDependency(":marker:py-marker"))
77+
runtimeOnly(projectDependency(":marker:rs-marker"))
7778
runtimeOnly(projectDependency(":marker:ult-marker"))
7879
implementation("plus.sourceplus:protocol:$protocolVersion")
7980

plugin/src/main/resources/META-INF/plugin.xml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<depends optional="true" config-file="withKotlin.xml">org.jetbrains.kotlin</depends>
1212
<depends optional="true" config-file="withPython.xml">com.intellij.modules.python</depends>
1313
<depends optional="true" config-file="withJavascript.xml">JavaScript</depends>
14+
<depends optional="true" config-file="withRust.xml">com.jetbrains.rust</depends>
1415
<depends optional="true" config-file="withJavascriptDebugger.xml">JavaScriptDebugger</depends>
1516

1617
<extensions defaultExtensionNs="com.intellij">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<idea-plugin>
2+
<extensions defaultExtensionNs="com.intellij">
3+
</extensions>
4+
</idea-plugin>

settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ include 'marker'
1717
include 'marker:js-marker'
1818
include 'marker:jvm-marker'
1919
include 'marker:py-marker'
20+
include 'marker:rs-marker'
2021
include 'marker:ult-marker'
2122
include 'plugin'

0 commit comments

Comments
 (0)