chore: Fix kotlin style issues

This commit is contained in:
FalsePattern 2025-01-21 14:36:03 +01:00
parent 87d30dfaa2
commit ecf01829cf
Signed by: falsepattern
GPG key ID: E930CDEC50C50E23
22 changed files with 49 additions and 57 deletions

View file

@ -38,6 +38,7 @@ import org.eclipse.lsp4j.jsonrpc.MessageConsumer
import org.eclipse.lsp4j.jsonrpc.debug.messages.DebugResponseMessage import org.eclipse.lsp4j.jsonrpc.debug.messages.DebugResponseMessage
import org.eclipse.lsp4j.jsonrpc.messages.Message import org.eclipse.lsp4j.jsonrpc.messages.Message
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest import org.eclipse.lsp4j.jsonrpc.services.JsonRequest
import java.io.InputStream
import java.lang.RuntimeException import java.lang.RuntimeException
import java.security.MessageDigest import java.security.MessageDigest
import java.util.Base64 import java.util.Base64
@ -73,7 +74,7 @@ class WinDAPDriver(handler: Handler) : DAPDriver<IDebugProtocolServer, WinDAPDri
handshakeFinished.acquire() handshakeFinished.acquire()
} }
inner class WinDAPDebuggerClient: DAPDriver<IDebugProtocolServer, WinDAPDriver.WinDAPDebuggerClient>.DAPDebuggerClient() { inner class WinDAPDebuggerClient: DAPDriver<IDebugProtocolServer, WinDAPDebuggerClient>.DAPDebuggerClient() {
override fun output(args: OutputEventArguments) { override fun output(args: OutputEventArguments) {
if ("telemetry" == args.category) if ("telemetry" == args.category)
return return
@ -92,7 +93,7 @@ class WinDAPDriver(handler: Handler) : DAPDriver<IDebugProtocolServer, WinDAPDri
val hasher = MessageDigest.getInstance("SHA-256") val hasher = MessageDigest.getInstance("SHA-256")
hasher.update(handshake.value.encodeToByteArray()) hasher.update(handshake.value.encodeToByteArray())
val inflater = Inflater(true) val inflater = Inflater(true)
val coconut = DAPDebuggerClient::class.java.getResourceAsStream("/coconut.jpg").use { it.readAllBytes() } ?: throw RuntimeException("No coconut") val coconut = DAPDebuggerClient::class.java.getResourceAsStream("/coconut.jpg")?.use(InputStream::readAllBytes) ?: throw RuntimeException("No coconut")
inflater.setInput(coconut, coconut.size - 80, 77) inflater.setInput(coconut, coconut.size - 80, 77)
inflater.finished() inflater.finished()
val b = ByteArray(1) val b = ByteArray(1)

View file

@ -65,10 +65,10 @@ object DirenvCmd {
return emptyEnv return emptyEnv
} }
} }
if (runOutput.output.isBlank()) { return if (runOutput.output.isBlank()) {
return emptyEnv emptyEnv
} else { } else {
return Env(Json.decodeFromString<Map<String, String>>(runOutput.output)) Env(Json.decodeFromString<Map<String, String>>(runOutput.output))
} }
} }

View file

@ -72,7 +72,7 @@ class ZigLanguageServerFactory: LanguageServerFactory, LanguageServerEnablementS
} }
override fun isEnabled(project: Project): Boolean { override fun isEnabled(project: Project): Boolean {
return (project.getUserData(ENABLED_KEY) ?: true) && project.zlsSettings.validate() return (project.getUserData(ENABLED_KEY) != false) && project.zlsSettings.validate()
} }
override fun setEnabled(enabled: Boolean, project: Project) { override fun setEnabled(enabled: Boolean, project: Project) {

View file

@ -224,7 +224,7 @@ class FilePathConfigurable(
} }
} }
class CheckboxConfigurable( open class CheckboxConfigurable(
@Transient private val serializedName: String, @Transient private val serializedName: String,
@Transient @Nls private val label: String, @Transient @Nls private val label: String,
var value: Boolean var value: Boolean
@ -274,10 +274,17 @@ class CheckboxConfigurable(
} }
} }
fun ColoredConfigurable(serializedName: String) = CheckboxConfigurable(serializedName, ZigBrainsBundle.message("exec.option.label.colored-terminal"), true) class ColoredConfigurable(serializedName: String): CheckboxConfigurable(serializedName, ZigBrainsBundle.message("exec.option.label.colored-terminal"), true) {
override fun clone(): ColoredConfigurable {
return super.clone() as ColoredConfigurable
}
}
fun DirenvConfigurable(serializedName: String, project: Project) = class DirenvConfigurable(serializedName: String, project: Project): CheckboxConfigurable(serializedName, ZigBrainsBundle.message("exec.option.label.direnv"), project.zigProjectSettings.state.direnv) {
CheckboxConfigurable(serializedName, ZigBrainsBundle.message("exec.option.label.direnv"), project.zigProjectSettings.state.direnv) override fun clone(): DirenvConfigurable {
return super.clone() as DirenvConfigurable
}
}
class OptimizationConfigurable( class OptimizationConfigurable(
@Transient private val serializedName: String, @Transient private val serializedName: String,

View file

@ -24,7 +24,6 @@ package com.falsepattern.zigbrains.project.execution.base
import com.falsepattern.zigbrains.ZigBrainsBundle import com.falsepattern.zigbrains.ZigBrainsBundle
import com.falsepattern.zigbrains.direnv.DirenvCmd import com.falsepattern.zigbrains.direnv.DirenvCmd
import com.falsepattern.zigbrains.project.toolchain.AbstractZigToolchain
import com.intellij.execution.ExecutionException import com.intellij.execution.ExecutionException
import com.intellij.execution.Executor import com.intellij.execution.Executor
import com.intellij.execution.configurations.ConfigurationFactory import com.intellij.execution.configurations.ConfigurationFactory

View file

@ -34,7 +34,7 @@ abstract class ZigTopLevelLineMarker: RunLineMarkerContributor() {
private fun getParentIfTopLevel(element: PsiElement): PsiElement? { private fun getParentIfTopLevel(element: PsiElement): PsiElement? {
var parent = getDeclaration(element) var parent = getDeclaration(element)
var nestingLevel = 0; var nestingLevel = 0
while (parent != null && parent !is PsiFile) { while (parent != null && parent !is PsiFile) {
if (parent.elementType == ZigTypes.CONTAINER_DECLARATION) { if (parent.elementType == ZigTypes.CONTAINER_DECLARATION) {
if (nestingLevel != 0) if (nestingLevel != 0)
@ -54,7 +54,7 @@ abstract class ZigTopLevelLineMarker: RunLineMarkerContributor() {
override fun getInfo(element: PsiElement): Info? { override fun getInfo(element: PsiElement): Info? {
if (!elementMatches(element)) if (!elementMatches(element))
return null; return null
val actions = ExecutorAction.getActions(0) val actions = ExecutorAction.getActions(0)
return Info(getIcon(element), actions, null) return Info(getIcon(element), actions, null)
} }

View file

@ -82,10 +82,10 @@ class ZigExecConfigBuild(project: Project, factory: ConfigurationFactory): ZigEx
override fun getConfigurables(): List<ZigConfigurable<*>> { override fun getConfigurables(): List<ZigConfigurable<*>> {
val baseCfg = super.getConfigurables() + listOf(buildSteps, extraArgs, colored) val baseCfg = super.getConfigurables() + listOf(buildSteps, extraArgs, colored)
if (ZBFeatures.debug()) { return if (ZBFeatures.debug()) {
return baseCfg + listOf(exePath, exeArgs) baseCfg + listOf(exePath, exeArgs)
} else { } else {
return baseCfg baseCfg
} }
} }

View file

@ -25,5 +25,4 @@ package com.falsepattern.zigbrains.project.execution.build
import com.falsepattern.zigbrains.project.execution.base.ZigProfileState import com.falsepattern.zigbrains.project.execution.base.ZigProfileState
import com.intellij.execution.runners.ExecutionEnvironment import com.intellij.execution.runners.ExecutionEnvironment
class ZigProfileStateBuild(environment: ExecutionEnvironment, configuration: ZigExecConfigBuild) : ZigProfileState<ZigExecConfigBuild>(environment, configuration) { class ZigProfileStateBuild(environment: ExecutionEnvironment, configuration: ZigExecConfigBuild) : ZigProfileState<ZigExecConfigBuild>(environment, configuration)
}

View file

@ -25,5 +25,4 @@ package com.falsepattern.zigbrains.project.execution.run
import com.falsepattern.zigbrains.project.execution.base.ZigProfileState import com.falsepattern.zigbrains.project.execution.base.ZigProfileState
import com.intellij.execution.runners.ExecutionEnvironment import com.intellij.execution.runners.ExecutionEnvironment
class ZigProfileStateRun(environment: ExecutionEnvironment, configuration: ZigExecConfigRun) : ZigProfileState<ZigExecConfigRun>(environment, configuration) { class ZigProfileStateRun(environment: ExecutionEnvironment, configuration: ZigExecConfigRun) : ZigProfileState<ZigExecConfigRun>(environment, configuration)
}

View file

@ -25,5 +25,4 @@ package com.falsepattern.zigbrains.project.execution.test
import com.falsepattern.zigbrains.project.execution.base.ZigProfileState import com.falsepattern.zigbrains.project.execution.base.ZigProfileState
import com.intellij.execution.runners.ExecutionEnvironment import com.intellij.execution.runners.ExecutionEnvironment
class ZigProfileStateTest(environment: ExecutionEnvironment, configuration: ZigExecConfigTest) : ZigProfileState<ZigExecConfigTest>(environment, configuration) { class ZigProfileStateTest(environment: ExecutionEnvironment, configuration: ZigExecConfigTest) : ZigProfileState<ZigExecConfigTest>(environment, configuration)
}

View file

@ -28,13 +28,11 @@ import com.falsepattern.zigbrains.project.settings.ZigProjectSettings
import com.falsepattern.zigbrains.project.settings.zigProjectSettings import com.falsepattern.zigbrains.project.settings.zigProjectSettings
import com.falsepattern.zigbrains.project.template.ZigInitTemplate import com.falsepattern.zigbrains.project.template.ZigInitTemplate
import com.falsepattern.zigbrains.project.template.ZigProjectTemplate import com.falsepattern.zigbrains.project.template.ZigProjectTemplate
import com.falsepattern.zigbrains.shared.coroutine.withEDTContext
import com.falsepattern.zigbrains.shared.zigCoroutineScope import com.falsepattern.zigbrains.shared.zigCoroutineScope
import com.intellij.notification.Notification import com.intellij.notification.Notification
import com.intellij.notification.NotificationType import com.intellij.notification.NotificationType
import com.intellij.openapi.GitRepositoryInitializer import com.intellij.openapi.GitRepositoryInitializer
import com.intellij.openapi.application.writeAction import com.intellij.openapi.application.writeAction
import com.intellij.openapi.progress.coroutineToIndicator
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VfsUtil import com.intellij.openapi.vfs.VfsUtil
import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFile
@ -42,11 +40,7 @@ import com.intellij.openapi.vfs.toNioPathOrNull
import com.intellij.platform.util.progress.reportProgress import com.intellij.platform.util.progress.reportProgress
import com.intellij.util.ResourceUtil import com.intellij.util.ResourceUtil
import com.intellij.util.concurrency.annotations.RequiresBackgroundThread import com.intellij.util.concurrency.annotations.RequiresBackgroundThread
import com.intellij.util.concurrency.annotations.RequiresEdt
import com.intellij.util.concurrency.annotations.RequiresWriteLock
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@JvmRecord @JvmRecord
data class ZigProjectConfigurationData( data class ZigProjectConfigurationData(
@ -141,7 +135,7 @@ private suspend fun createGitIgnoreFile(project: Project, projectDir: VirtualFil
writeAction { writeAction {
ZigProjectConfigurationData::class.java.getResourceAsStream("/fileTemplates/internal/gitignore")?.use { ZigProjectConfigurationData::class.java.getResourceAsStream("/fileTemplates/internal/gitignore")?.use {
val file = projectDir.createChildData(requestor, ".gitignore") val file = projectDir.createChildData(requestor, ".gitignore")
file.setCharset(Charsets.UTF_8) file.charset = Charsets.UTF_8
file.setBinaryContent(it.readAllBytes()) file.setBinaryContent(it.readAllBytes())
} }
} }

View file

@ -48,17 +48,17 @@ class ZigProcessHandler : KillableColoredProcessHandler, ColoredTextAcceptor {
private val VT100_CHARS = CharArray(256).apply { private val VT100_CHARS = CharArray(256).apply {
this.fill(' ') this.fill(' ')
this[0x6A] = '┘'; this[0x6A] = '┘'
this[0x6B] = '┐'; this[0x6B] = '┐'
this[0x6C] = '┌'; this[0x6C] = '┌'
this[0x6D] = '└'; this[0x6D] = '└'
this[0x6E] = '┼'; this[0x6E] = '┼'
this[0x71] = '─'; this[0x71] = '─'
this[0x74] = '├'; this[0x74] = '├'
this[0x75] = '┤'; this[0x75] = '┤'
this[0x76] = '┴'; this[0x76] = '┴'
this[0x77] = '┬'; this[0x77] = '┬'
this[0x78] = '│'; this[0x78] = '│'
} }
private const val VT100_BEGIN_SEQ = "\u001B(0" private const val VT100_BEGIN_SEQ = "\u001B(0"

View file

@ -25,7 +25,6 @@ package com.falsepattern.zigbrains.project.run
import com.falsepattern.zigbrains.project.execution.base.ZigProfileState import com.falsepattern.zigbrains.project.execution.base.ZigProfileState
import com.falsepattern.zigbrains.project.settings.zigProjectSettings import com.falsepattern.zigbrains.project.settings.zigProjectSettings
import com.falsepattern.zigbrains.project.toolchain.AbstractZigToolchain import com.falsepattern.zigbrains.project.toolchain.AbstractZigToolchain
import com.falsepattern.zigbrains.shared.coroutine.withEDTContext
import com.falsepattern.zigbrains.shared.zigCoroutineScope import com.falsepattern.zigbrains.shared.zigCoroutineScope
import com.intellij.execution.ExecutionException import com.intellij.execution.ExecutionException
import com.intellij.execution.configurations.RunProfileState import com.intellij.execution.configurations.RunProfileState

View file

@ -27,7 +27,6 @@ import com.falsepattern.zigbrains.direnv.DirenvCmd
import com.falsepattern.zigbrains.project.toolchain.LocalZigToolchain import com.falsepattern.zigbrains.project.toolchain.LocalZigToolchain
import com.falsepattern.zigbrains.project.toolchain.ZigToolchainProvider import com.falsepattern.zigbrains.project.toolchain.ZigToolchainProvider
import com.falsepattern.zigbrains.shared.coroutine.launchWithEDT import com.falsepattern.zigbrains.shared.coroutine.launchWithEDT
import com.falsepattern.zigbrains.shared.coroutine.withEDTContext
import com.falsepattern.zigbrains.shared.zigCoroutineScope import com.falsepattern.zigbrains.shared.zigCoroutineScope
import com.intellij.openapi.Disposable import com.intellij.openapi.Disposable
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory

View file

@ -28,9 +28,6 @@ interface ZigStepDiscoveryListener {
suspend fun errorReload(type: ErrorType, details: String?) {} suspend fun errorReload(type: ErrorType, details: String?) {}
suspend fun timeoutReload(seconds: Int) {} suspend fun timeoutReload(seconds: Int) {}
companion object {
}
enum class ErrorType { enum class ErrorType {
MissingToolchain, MissingToolchain,
MissingBuildZig, MissingBuildZig,

View file

@ -44,7 +44,7 @@ class ZigStepDiscoveryService(private val project: Project) {
private val reloading = AtomicBoolean(false) private val reloading = AtomicBoolean(false)
private val reloadScheduled = AtomicBoolean(false) private val reloadScheduled = AtomicBoolean(false)
private val reloadMutex = Mutex() private val reloadMutex = Mutex()
private var CURRENT_TIMEOUT_SEC = DEFAULT_TIMEOUT_SEC private var currentTimeoutSec = DEFAULT_TIMEOUT_SEC
private val listeners = ArrayList<ZigStepDiscoveryListener>() private val listeners = ArrayList<ZigStepDiscoveryListener>()
private val listenerMutex = Mutex() private val listenerMutex = Mutex()
@ -83,10 +83,10 @@ class ZigStepDiscoveryService(private val project: Project) {
val result = zig.callWithArgs( val result = zig.callWithArgs(
project.guessProjectDir()?.toNioPathOrNull(), project.guessProjectDir()?.toNioPathOrNull(),
"build", "-l", "build", "-l",
timeoutMillis = CURRENT_TIMEOUT_SEC * 1000L timeoutMillis = currentTimeoutSec * 1000L
) )
if (result.checkSuccess(LOG)) { if (result.checkSuccess(LOG)) {
CURRENT_TIMEOUT_SEC = DEFAULT_TIMEOUT_SEC currentTimeoutSec = DEFAULT_TIMEOUT_SEC
val lines = result.stdoutLines val lines = result.stdoutLines
val steps = ArrayList<Pair<String, String?>>() val steps = ArrayList<Pair<String, String?>>()
for (line in lines) { for (line in lines) {
@ -99,8 +99,8 @@ class ZigStepDiscoveryService(private val project: Project) {
} }
postReload(steps) postReload(steps)
} else if (result.isTimeout) { } else if (result.isTimeout) {
timeoutReload(CURRENT_TIMEOUT_SEC) timeoutReload(currentTimeoutSec)
CURRENT_TIMEOUT_SEC *= 2 currentTimeoutSec *= 2
} else if (result.stderrLines.any { it.contains("error: no build.zig file found, in the current directory or any parent directories") }) { } else if (result.stderrLines.any { it.contains("error: no build.zig file found, in the current directory or any parent directories") }) {
errorReload(ErrorType.MissingBuildZig, result.stderr) errorReload(ErrorType.MissingBuildZig, result.stderr)
} else { } else {

View file

@ -41,7 +41,7 @@ class ZigStringElementManipulator: AbstractElementManipulator<ZigStringLiteral>(
val originalContext = element.text!! val originalContext = element.text!!
val isMultiline = element.isMultiline val isMultiline = element.isMultiline
@NonNls @NonNls
val prefix = "const x = \n"; val prefix = "const x = \n"
val suffix = "\n;" val suffix = "\n;"
val sbFactory: (Int) -> StringBuilder = { val sbFactory: (Int) -> StringBuilder = {
val sb = StringBuilder(prefix.length + suffix.length + it) val sb = StringBuilder(prefix.length + suffix.length + it)

View file

@ -38,7 +38,7 @@ class MakeStringMultiline: PsiElementBaseIntentionAction() {
override fun getFamilyName() = ZigBrainsBundle.message("intention.family.name.make-string-multiline") override fun getFamilyName() = ZigBrainsBundle.message("intention.family.name.make-string-multiline")
override fun isAvailable(project: Project, editor: Editor?, element: PsiElement) = override fun isAvailable(project: Project, editor: Editor?, element: PsiElement) =
editor != null && element.parentOfType<ZigStringLiteral>()?.isMultiline?.not() ?: false editor != null && element.parentOfType<ZigStringLiteral>()?.isMultiline?.not() == true
override fun invoke(project: Project, editor: Editor?, element: PsiElement) { override fun invoke(project: Project, editor: Editor?, element: PsiElement) {
editor ?: return editor ?: return

View file

@ -41,7 +41,7 @@ class MakeStringQuoted: PsiElementBaseIntentionAction() {
override fun getFamilyName() = ZigBrainsBundle.message("intention.family.name.make-string-quoted") override fun getFamilyName() = ZigBrainsBundle.message("intention.family.name.make-string-quoted")
override fun isAvailable(project: Project, editor: Editor?, element: PsiElement) = override fun isAvailable(project: Project, editor: Editor?, element: PsiElement) =
editor != null && element.parentOfType<ZigStringLiteral>()?.isMultiline ?: false editor != null && element.parentOfType<ZigStringLiteral>()?.isMultiline == true
override fun invoke(project: Project, editor: Editor?, element: PsiElement) { override fun invoke(project: Project, editor: Editor?, element: PsiElement) {
editor ?: return editor ?: return

View file

@ -24,5 +24,4 @@ package com.falsepattern.zigbrains.zig.lexerstring
import com.intellij.lexer.FlexAdapter import com.intellij.lexer.FlexAdapter
class ZigLexerStringAdapter: FlexAdapter(ZigLexerString(null)) { class ZigLexerStringAdapter: FlexAdapter(ZigLexerString(null))
}

View file

@ -67,7 +67,7 @@ abstract class ZigStringLiteralMixinImpl(node: ASTNode): ASTWrapperPsiElement(no
val text = myHost.text.also { _text = it } val text = myHost.text.also { _text = it }
val isMultiline = myHost.isMultiline val isMultiline = myHost.isMultiline
val contentRanges = myHost.contentRanges.also { _contentRanges = it } val contentRanges = myHost.contentRanges.also { _contentRanges = it }
var decoded = false; var decoded = false
for (range in contentRanges) { for (range in contentRanges) {
val intersection = range.intersection(rangeInsideHost) ?: continue val intersection = range.intersection(rangeInsideHost) ?: continue
decoded = true decoded = true

View file

@ -133,7 +133,7 @@ private fun doAddCompletions(
private val ZonProperty.isDependency: Boolean private val ZonProperty.isDependency: Boolean
get() { get() {
return parentOfType<ZonEntry>()?.isDependency ?: false return parentOfType<ZonEntry>()?.isDependency == true
} }
private val ZonEntry.isDependency: Boolean private val ZonEntry.isDependency: Boolean