Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions src/main/kotlin/com/dioxuslabs/dioxus/DioxusPluginDisposable.kt

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.dioxuslabs.dioxus.formatting

import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.process.CapturingProcessAdapter
import com.intellij.execution.process.OSProcessHandler
import com.intellij.execution.process.ProcessEvent
import com.intellij.formatting.service.AsyncDocumentFormattingService
import com.intellij.formatting.service.AsyncFormattingRequest
import com.intellij.formatting.service.FormattingService
import com.intellij.openapi.util.NlsSafe
import com.intellij.psi.PsiFile
import org.rust.lang.core.psi.RsFile
import java.util.*

class DioxusDocumentFormattingService : AsyncDocumentFormattingService() {
private val FEATURES: MutableSet<FormattingService.Feature?> = EnumSet.noneOf(FormattingService.Feature::class.java)

override fun canFormat(file: PsiFile): Boolean = file is RsFile

override fun getFeatures(): Set<FormattingService.Feature?> = FEATURES

override fun getNotificationGroupId(): String = "Dioxus Formatting Notification Group"

override fun getName(): @NlsSafe String = "Dioxus Formatter"

override fun createFormattingTask(request: AsyncFormattingRequest): FormattingTask? {
val commandLine = GeneralCommandLine("dx")
.withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE)
commandLine.addParameters(listOf("fmt", "--file", "-"))
commandLine.withInput(request.ioFile)

val handler = OSProcessHandler(commandLine.withCharset(Charsets.UTF_8))

return object : FormattingTask {
override fun run() {
handler.addProcessListener(object : CapturingProcessAdapter() {
override fun processTerminated(event: ProcessEvent) {
if (event.exitCode == 0) {
request.onTextReady(output.stdout)
} else {
request.onError(
"Dioxus Formatter",
"dx fmt returned non-zero exit code: ${event.exitCode}\n${output.stderr}"
)
}
}
})
handler.startNotify()
}

override fun cancel(): Boolean {
handler.destroyProcess()
return true
}

override fun isRunUnderProgress(): Boolean = true
}
}
}
25 changes: 0 additions & 25 deletions src/main/kotlin/com/dioxuslabs/dioxus/native/DioxusIntellij.kt

This file was deleted.

9 changes: 6 additions & 3 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
<!-- Extension points defined by the plugin.
Read more: https://plugins.jetbrains.com/docs/intellij/plugin-extension-points.html -->
<extensions defaultExtensionNs="com.intellij">
<actionOnSave id="DioxusCheckOnSaveAction"
implementation="com.dioxuslabs.dioxus.actions.DioxusCheckOnSaveAction"
order="after FormatOnSaveAction" />
<formattingService implementation="com.dioxuslabs.dioxus.formatting.DioxusDocumentFormattingService"
id="DioxusDocumentFormattingService"
order="first"/>

<notificationGroup id="Dioxus Formatting Notification Group"
displayType="BALLOON"/>
</extensions>
</idea-plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package org.rust.cargo.project.model.impl

import com.intellij.openapi.project.Project

// This is here as workaround for https://youtrack.jetbrains.com/issue/RUST-16312
class TestCargoProjectsServiceImpl(project: Project) : CargoProjectsServiceImpl(project)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.dioxuslabs.dioxus.formatter

import com.intellij.psi.formatter.FormatterTestCase

class DioxusDocumentFormattingServiceTest : FormatterTestCase() {
override fun getTestDataPath(): String = "src/test/testData"

override fun getBasePath(): String = "formatting"

override fun getFileExtension(): String = "rs"

// Tests below this line

// If you want to use bigger files to format use the following
// Files are stored in src/test/testData/formatting
// fun testBigFile() {
// doTest("bigFile.rs", "bigFileAfter.rs")
// }

fun testBasicFormatting() {
// Test basic RSX formatting with spaces
val unformattedCode = """
fn main() {
let app = rsx! {
div {
h1 { "Hello, world!" }
p { "This is a test." }
}
};
}
""".trimIndent()

val expectedFormattedCode = """
fn main() {
let app = rsx! {
div {
h1 { "Hello, world!" }
p { "This is a test." }
}
};
}
""".trimIndent()

doTextTest(unformattedCode, expectedFormattedCode)
}
}
Loading