Skip to content

Commit

Permalink
wip: rust support
Browse files Browse the repository at this point in the history
  • Loading branch information
BFergerson committed Apr 1, 2024
1 parent 9b65491 commit 75a2154
Show file tree
Hide file tree
Showing 10 changed files with 271 additions and 0 deletions.
77 changes: 77 additions & 0 deletions marker/rs-marker/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
plugins {
kotlin("jvm")
id("maven-publish")
}

val vertxVersion: String by project
val jupiterVersion: String by project
val guavaVersion: String by project
val projectVersion: String by project
val protocolVersion = project.properties["protocolVersion"] as String? ?: projectVersion

group = "plus.sourceplus.interface"
version = project.properties["projectVersion"] as String? ?: projectVersion

intellij {
type.set("IC")
plugins.set(listOf("com.jetbrains.rust:232.20527.212"))
}

val sourcesJar = tasks.register<Jar>("sourcesJar") {
archiveClassifier.set("sources")
from(project.the<SourceSetContainer>()["main"].allSource)
}

configure<PublishingExtension> {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/sourceplusplus/interface-jetbrains")
credentials {
username = System.getenv("GH_PUBLISH_USERNAME")?.toString()
password = System.getenv("GH_PUBLISH_TOKEN")?.toString()
}
}
}

publishing {
publications {
create<MavenPublication>("maven") {
groupId = project.group.toString()
artifactId = "jetbrains-marker-rs"
version = project.version.toString()

from(components["kotlin"])

// Ship the sources jar
artifact(sourcesJar)
}
}
}
}

dependencies {
implementation(projectDependency(":core"))
implementation(projectDependency(":marker"))
implementation("plus.sourceplus:protocol:$protocolVersion")
implementation("io.vertx:vertx-core:$vertxVersion")
implementation("io.vertx:vertx-lang-kotlin-coroutines:$vertxVersion") {
exclude(group = "org.jetbrains.kotlinx")
}

compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
compileOnly("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
compileOnly("com.google.guava:guava:$guavaVersion")
compileOnly("org.jetbrains:annotations:24.0.1")

testRuntimeOnly(projectDependency(":marker:ult-marker"))
testImplementation("org.junit.jupiter:junit-jupiter:$jupiterVersion")
}

fun projectDependency(name: String): ProjectDependency {
return if (rootProject.name.contains("jetbrains")) {
DependencyHandlerScope.of(rootProject.dependencies).project(name)
} else {
DependencyHandlerScope.of(rootProject.dependencies).project(":interfaces:jetbrains$name")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Source++, the continuous feedback platform for developers.
* Copyright (C) 2022-2024 CodeBrig, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package spp.jetbrains.marker.rs

import com.intellij.openapi.project.Project
import org.rust.lang.core.psi.RsFile
import spp.jetbrains.artifact.service.ArtifactModelService
import spp.jetbrains.artifact.service.ArtifactTypeService
import spp.jetbrains.marker.LanguageProvider
import spp.jetbrains.marker.rs.service.RustArtifactModelService
import spp.jetbrains.marker.rs.service.RustArtifactTypeService
import spp.jetbrains.marker.source.SourceFileMarker

/**
* Provides Rust support for the Marker API.
*
* @author [Brandon Fergerson](mailto:[email protected])
*/
class RustLanguageProvider : LanguageProvider {

override fun canSetup() = classExists("org.rust.lang.core.psi.ext.RsElement")

override fun setup(project: Project, setupDetectors: Boolean) {
SourceFileMarker.SUPPORTED_FILE_TYPES.add(RsFile::class.java)

ArtifactModelService.addService(RustArtifactModelService(), "Rust")
ArtifactTypeService.addService(RustArtifactTypeService(), "Rust")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Source++, the continuous feedback platform for developers.
* Copyright (C) 2022-2024 CodeBrig, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package spp.jetbrains.marker.rs.model

import org.rust.lang.core.psi.RsIfExpr
import spp.jetbrains.artifact.model.ArtifactElement
import spp.jetbrains.artifact.model.IfArtifact
import spp.jetbrains.artifact.service.toArtifact

class RustIfArtifact(override val psiElement: RsIfExpr) : IfArtifact(psiElement) {

override val condition: ArtifactElement?
get() = psiElement.condition.toArtifact()

override val thenBranch: ArtifactElement?
get() = null

override val elseBranch: ArtifactElement?
get() = psiElement.elseBranch?.toArtifact()

override fun clone(): RustIfArtifact {
return RustIfArtifact(psiElement)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Source++, the continuous feedback platform for developers.
* Copyright (C) 2022-2024 CodeBrig, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package spp.jetbrains.marker.rs.service

import com.intellij.psi.PsiElement
import org.rust.lang.core.psi.RsIfExpr
import spp.jetbrains.artifact.model.ArtifactElement
import spp.jetbrains.artifact.service.define.IArtifactModelService
import spp.jetbrains.marker.rs.model.RustIfArtifact

/**
* Provides language-agnostic artifact model service for Rust.
*
* @author [Brandon Fergerson](mailto:[email protected])
*/
class RustArtifactModelService : IArtifactModelService {

override fun toArtifact(element: PsiElement): ArtifactElement? {
return when (element) {
is RsIfExpr -> RustIfArtifact(element)
else -> null
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Source++, the continuous feedback platform for developers.
* Copyright (C) 2022-2024 CodeBrig, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package spp.jetbrains.marker.rs.service

import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import com.intellij.psi.impl.source.tree.LeafPsiElement
import org.rust.lang.core.psi.RsExpr
import org.rust.lang.core.psi.RsFunction
import spp.jetbrains.artifact.service.define.IArtifactTypeService
import spp.protocol.artifact.ArtifactType

/**
* Used to determine the type of Rust artifacts.
*
* @author [Brandon Fergerson](mailto:[email protected])
*/
class RustArtifactTypeService : IArtifactTypeService {

override fun getAnnotations(element: PsiElement): List<PsiElement> {
return emptyList() //todo: implement
}

override fun getAnnotationOwnerIfAnnotation(element: PsiElement): PsiElement? {
return null //todo: implement
}

override fun getAnnotationOwnerIfAnnotation(element: PsiElement, line: Int): PsiElement? {
return null //todo: implement
}

override fun isComment(element: PsiElement): Boolean {
val comment = element is PsiComment
if (comment) return true

return if (element is LeafPsiElement) {
isComment(element.parent)
} else false
}

override fun getType(element: PsiElement): ArtifactType? {
return when (element) {
is RsFunction -> ArtifactType.FUNCTION
is RsExpr -> ArtifactType.EXPRESSION

else -> null
}
}

override fun isLiteral(element: PsiElement): Boolean {
return super.isLiteral(element) //todo: implement
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spp.jetbrains.marker.rs.RustLanguageProvider
1 change: 1 addition & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ dependencies {
runtimeOnly(projectDependency(":marker:js-marker"))
runtimeOnly(projectDependency(":marker:jvm-marker"))
runtimeOnly(projectDependency(":marker:py-marker"))
runtimeOnly(projectDependency(":marker:rs-marker"))
runtimeOnly(projectDependency(":marker:ult-marker"))
implementation("plus.sourceplus:protocol:$protocolVersion")

Expand Down
1 change: 1 addition & 0 deletions plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<depends optional="true" config-file="withKotlin.xml">org.jetbrains.kotlin</depends>
<depends optional="true" config-file="withPython.xml">com.intellij.modules.python</depends>
<depends optional="true" config-file="withJavascript.xml">JavaScript</depends>
<depends optional="true" config-file="withRust.xml">com.jetbrains.rust</depends>
<depends optional="true" config-file="withJavascriptDebugger.xml">JavaScriptDebugger</depends>

<extensions defaultExtensionNs="com.intellij">
Expand Down
4 changes: 4 additions & 0 deletions plugin/src/main/resources/META-INF/withRust.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
</extensions>
</idea-plugin>
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ include 'marker'
include 'marker:js-marker'
include 'marker:jvm-marker'
include 'marker:py-marker'
include 'marker:rs-marker'
include 'marker:ult-marker'
include 'plugin'

0 comments on commit 75a2154

Please sign in to comment.