backport: 20.1.2

This commit is contained in:
FalsePattern 2025-01-12 14:15:20 +01:00
parent d3755fbc70
commit 655f05c3b8
Signed by: falsepattern
GPG key ID: E930CDEC50C50E23
11 changed files with 37 additions and 34 deletions

View file

@ -17,6 +17,14 @@ Changelog structure reference:
## [Unreleased]
## [20.1.2]
### Fixed
- Zig
- Source file path highlighter made the terminal lag with some files
- Non-terminating rule in lexer could make the editor hang
## [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

@ -246,10 +246,10 @@ BUILTINIDENTIFIER="@"[A-Za-z_][A-Za-z0-9_]*
<UNT_SQUOT> <<EOF>> { yybegin(YYINITIAL); return BAD_SQUOT; }
<UNT_SQUOT> {CRLF} { yybegin(YYINITIAL); return BAD_SQUOT; }
<UNT_SQUOT> [^\n]* { }
<UNT_SQUOT> [^\n]+ { }
<UNT_DQUOT> <<EOF>> { yybegin(YYINITIAL); return BAD_DQUOT; }
<UNT_DQUOT> {CRLF} { yybegin(YYINITIAL); return BAD_DQUOT; }
<UNT_DQUOT> [^\n]* { }
<UNT_DQUOT> [^\n]+ { }
<YYINITIAL> {WHITE_SPACE} { return WHITE_SPACE; }

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

@ -27,25 +27,23 @@ import com.intellij.execution.filters.Filter.ResultItem
import com.intellij.execution.filters.OpenFileHyperlinkInfo
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.util.io.toNioPathOrNull
import com.intellij.openapi.vfs.refreshAndFindVirtualFile
import com.intellij.openapi.vfs.toNioPathOrNull
import java.io.File
import java.nio.file.InvalidPathException
import java.nio.file.Path
import kotlin.io.path.isRegularFile
import kotlin.io.path.notExists
import kotlin.math.max
class ZigSourceFileFilter(private val project: Project): Filter {
private val projectPath = runCatching { project.guessProjectDir()?.toNioPathOrNull()?.toFile() }.getOrNull()
override fun applyFilter(line: String, entireLength: Int): Filter.Result? {
val lineStart = entireLength - line.length
val projectPath = project.guessProjectDir()?.toNioPathOrNull()
val results = ArrayList<ResultItem>()
val matcher = LEN_REGEX.findAll(line)
for (match in matcher) {
val start = match.range.first
val pair = findLongestParsablePathFromOffset(line, start, projectPath)
val pair = findLongestParsablePathFromOffset(line, start)
val path = pair?.first ?: return null
val file = path.refreshAndFindVirtualFile() ?: return null
val lineNumber = max(match.groups[1]!!.value.toInt() - 1, 0)
@ -55,25 +53,29 @@ class ZigSourceFileFilter(private val project: Project): Filter {
return Filter.Result(results)
}
private fun findLongestParsablePathFromOffset(line: String, end: Int, projectPath: Path?): Pair<Path, Int>? {
private fun findLongestParsablePathFromOffset(line: String, end: Int): Pair<Path, Int>? {
var longestStart = -1
var longest: Path? = null
var longest: File? = null
for (i in end - 1 downTo 0) {
try {
val pathStr = line.substring(i, end)
var path: Path = pathStr.toNioPathOrNull() ?: continue
if ((path.notExists() || !path.isRegularFile()) && projectPath != null) {
path = projectPath.resolve(pathStr)
if (path.notExists() || !path.isRegularFile())
var file = File(pathStr)
if (!file.isFile) {
if (projectPath == null) {
continue
}
file = projectPath.resolve(pathStr)
if (!file.isFile) {
continue
}
}
longest = path
longest = file
longestStart = i
} catch (ignored: InvalidPathException) {
}
}
longest ?: return null
return Pair(longest, longestStart)
return Pair(longest.toPath(), longestStart)
}
}

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 {
@ -162,7 +160,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",

View file

@ -1,7 +1,7 @@
pluginName=ZigBrains
pluginRepositoryUrl=https://github.com/FalsePattern/ZigBrains
pluginVersion=20.1.1
pluginVersion=20.1.2
pluginSinceBuild=241
pluginUntilBuild=241.*