fix: replaced Path.exists() calls with File.toFile().exists()

This commit is contained in:
FalsePattern 2025-01-12 14:15:20 +01:00
parent adb8797051
commit a3143dbc0c
Signed by: falsepattern
GPG key ID: E930CDEC50C50E23
9 changed files with 19 additions and 21 deletions

View file

@ -17,6 +17,10 @@ Changelog structure reference:
## [Unreleased]
### Fixed
- Zig source file path highlighter made the terminal lag with some files
## [20.1.1]
### Fixed

View file

@ -43,7 +43,6 @@ import java.nio.file.Path
import java.util.stream.Stream
import kotlin.io.path.isExecutable
import kotlin.io.path.isRegularFile
import kotlin.io.path.notExists
class ZigDebugParametersBuild(
driverConfiguration: DebuggerDriverConfiguration,
@ -73,7 +72,7 @@ class ZigDebugParametersBuild(
fail("debug.build.compile.failed.no-workdir")
}
val expectedOutputDir = workingDir.resolve(Path.of("zig-out", "bin"))
if (expectedOutputDir.notExists()) {
if (!expectedOutputDir.toFile().exists()) {
fail("debug.build.compile.failed.autodetect")
}
@ -82,7 +81,7 @@ class ZigDebugParametersBuild(
}
}
if (exe.notExists())
if (!exe.toFile().exists())
fail("debug.build.compile.failed.no-file", exe)
else if (!exe.isExecutable())
fail("debug.build.compile.failed.non-exec-file", exe)

View file

@ -55,7 +55,6 @@ import java.net.URL
import java.nio.file.Path
import java.util.*
import kotlin.io.path.name
import kotlin.io.path.notExists
@Service
class ZigDebuggerToolchainService {
@ -80,7 +79,7 @@ class ZigDebuggerToolchainService {
val lldbPath = lldbPath()
val frameworkFile = lldbPath.resolve(frameworkPath)
val frontendFile = lldbPath.resolve(frontendPath)
if (frameworkFile.notExists() || frontendFile.notExists()) return DebuggerAvailability.NeedToDownload
if (!frameworkFile.toFile().exists() || !frontendFile.toFile().exists()) return DebuggerAvailability.NeedToDownload
val versions = loadDebuggerVersions(DebuggerKind.LLDB)
val (lldbFrameworkUrl, lldbFrontendUrl) = lldbUrls() ?: return DebuggerAvailability.Unavailable
@ -105,7 +104,7 @@ class ZigDebuggerToolchainService {
}
val gdbFile = gdbPath().resolve(gdbBinaryPath)
if (gdbFile.notExists()) return DebuggerAvailability.NeedToDownload
if (!gdbFile.toFile().exists()) return DebuggerAvailability.NeedToDownload
val versions = loadDebuggerVersions(DebuggerKind.GDB)
val gdbUrl = gdbUrl() ?: return DebuggerAvailability.Unavailable
@ -123,7 +122,7 @@ class ZigDebuggerToolchainService {
val msvcBinaryPath = "vsdbg.exe"
val msvcFile = msvcPath().resolve(msvcBinaryPath)
if (msvcFile.notExists()) return DebuggerAvailability.NeedToDownload
if (!msvcFile.toFile().exists()) return DebuggerAvailability.NeedToDownload
val msvcUrl = msvcUrl() ?: return DebuggerAvailability.Binaries(MSVCBinaries(msvcFile))

View file

@ -41,7 +41,7 @@ data class Env(val env: Map<String, String>) {
val paths = path ?: return null
for (dir in paths) {
val path = dir.toNioPathOrNull()?.absolute() ?: continue
if (path.notExists() || !path.isDirectory())
if (!path.toFile().exists() || !path.isDirectory())
continue
val exePath = path.resolve(exeName).absolute()
if (!exePath.isRegularFile() || !exePath.isExecutable())

View file

@ -48,7 +48,6 @@ import org.eclipse.lsp4j.services.LanguageServer
import java.nio.file.Path
import kotlin.io.path.isExecutable
import kotlin.io.path.isRegularFile
import kotlin.io.path.notExists
import kotlin.io.path.pathString
class ZLSStreamConnectionProvider private constructor(private val project: Project, commandLine: GeneralCommandLine?) : OSProcessStreamConnectionProvider(commandLine) {
@ -106,7 +105,7 @@ class ZLSStreamConnectionProvider private constructor(private val project: Proje
}
}
}
if (zlsPath.notExists()) {
if (!zlsPath.toFile().exists()) {
Notification(
"zigbrains-lsp",
ZLSBundle.message("notification.message.zls-exe-not-exists.content", zlsPath),
@ -125,7 +124,7 @@ class ZLSStreamConnectionProvider private constructor(private val project: Proje
val configPath: Path? = state.zlsConfigPath.let { configPath ->
if (configPath.isNotBlank()) {
configPath.toNioPathOrNull()?.let { nioPath ->
if (nioPath.notExists()) {
if (!nioPath.toFile().exists()) {
Notification(
"zigbrains-lsp",
ZLSBundle.message("notification.message.zls-config-not-exists.content", nioPath),

View file

@ -37,7 +37,6 @@ import java.util.concurrent.locks.ReentrantLock
import kotlin.concurrent.withLock
import kotlin.io.path.isExecutable
import kotlin.io.path.isRegularFile
import kotlin.io.path.notExists
@Service(Service.Level.PROJECT)
@State(
@ -108,7 +107,7 @@ private suspend fun doValidate(project: Project, state: ZLSSettings): Boolean {
}
}
}
if (zlsPath.notExists()) {
if (!zlsPath.toFile().exists()) {
return false
}
if (!zlsPath.isRegularFile() || !zlsPath.isExecutable()) {

View file

@ -33,7 +33,6 @@ import com.intellij.openapi.vfs.toNioPathOrNull
import java.nio.file.InvalidPathException
import java.nio.file.Path
import kotlin.io.path.isRegularFile
import kotlin.io.path.notExists
import kotlin.math.max
@ -62,9 +61,11 @@ class ZigSourceFileFilter(private val project: Project): Filter {
try {
val pathStr = line.substring(i, end)
var path: Path = pathStr.toNioPathOrNull() ?: continue
if ((path.notExists() || !path.isRegularFile()) && projectPath != null) {
var file = path.toFile()
if ((!file.exists() || !path.isRegularFile()) && projectPath != null) {
path = projectPath.resolve(pathStr)
if (path.notExists() || !path.isRegularFile())
file = path.toFile()
if (!file.exists() || !path.isRegularFile())
continue
}
longest = path

View file

@ -51,8 +51,6 @@ import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import javax.swing.event.DocumentEvent
import kotlin.io.path.exists
import kotlin.io.path.notExists
import kotlin.io.path.pathString
class ZigProjectSettingsPanel(private val project: Project?) : Disposable {
@ -160,7 +158,7 @@ class ZigProjectSettingsPanel(private val project: Project?) : Disposable {
delay(200)
val toolchain = pathToToolchain?.let { LocalZigToolchain(it) }
val zig = toolchain?.zig
if (zig?.path()?.exists() != true) {
if (zig?.path()?.toFile()?.exists() != true) {
toolchainVersion.text = ""
if (!stdFieldOverride.isSelected) {

View file

@ -30,7 +30,6 @@ import com.intellij.notification.NotificationType
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.UserDataHolderBase
import com.intellij.openapi.util.io.toNioPathOrNull
import kotlin.io.path.notExists
import kotlin.io.path.pathString
class ToolchainZLSConfigProvider: SuspendingZLSConfigProvider {
@ -49,7 +48,7 @@ class ToolchainZLSConfigProvider: SuspendingZLSConfigProvider {
).notify(project)
return previous
}
if (exe.notExists()) {
if (!exe.toFile().exists()) {
Notification(
"zigbrains-lsp",
"Zig executable does not exiust: $exe",