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] ## [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] ## [20.1.1]
### Fixed ### Fixed

View file

@ -43,7 +43,6 @@ import java.nio.file.Path
import java.util.stream.Stream import java.util.stream.Stream
import kotlin.io.path.isExecutable import kotlin.io.path.isExecutable
import kotlin.io.path.isRegularFile import kotlin.io.path.isRegularFile
import kotlin.io.path.notExists
class ZigDebugParametersBuild( class ZigDebugParametersBuild(
driverConfiguration: DebuggerDriverConfiguration, driverConfiguration: DebuggerDriverConfiguration,
@ -73,7 +72,7 @@ class ZigDebugParametersBuild(
fail("debug.build.compile.failed.no-workdir") fail("debug.build.compile.failed.no-workdir")
} }
val expectedOutputDir = workingDir.resolve(Path.of("zig-out", "bin")) val expectedOutputDir = workingDir.resolve(Path.of("zig-out", "bin"))
if (expectedOutputDir.notExists()) { if (!expectedOutputDir.toFile().exists()) {
fail("debug.build.compile.failed.autodetect") 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) fail("debug.build.compile.failed.no-file", exe)
else if (!exe.isExecutable()) else if (!exe.isExecutable())
fail("debug.build.compile.failed.non-exec-file", exe) 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.nio.file.Path
import java.util.* import java.util.*
import kotlin.io.path.name import kotlin.io.path.name
import kotlin.io.path.notExists
@Service @Service
class ZigDebuggerToolchainService { class ZigDebuggerToolchainService {
@ -80,7 +79,7 @@ class ZigDebuggerToolchainService {
val lldbPath = lldbPath() val lldbPath = lldbPath()
val frameworkFile = lldbPath.resolve(frameworkPath) val frameworkFile = lldbPath.resolve(frameworkPath)
val frontendFile = lldbPath.resolve(frontendPath) 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 versions = loadDebuggerVersions(DebuggerKind.LLDB)
val (lldbFrameworkUrl, lldbFrontendUrl) = lldbUrls() ?: return DebuggerAvailability.Unavailable val (lldbFrameworkUrl, lldbFrontendUrl) = lldbUrls() ?: return DebuggerAvailability.Unavailable
@ -105,7 +104,7 @@ class ZigDebuggerToolchainService {
} }
val gdbFile = gdbPath().resolve(gdbBinaryPath) val gdbFile = gdbPath().resolve(gdbBinaryPath)
if (gdbFile.notExists()) return DebuggerAvailability.NeedToDownload if (!gdbFile.toFile().exists()) return DebuggerAvailability.NeedToDownload
val versions = loadDebuggerVersions(DebuggerKind.GDB) val versions = loadDebuggerVersions(DebuggerKind.GDB)
val gdbUrl = gdbUrl() ?: return DebuggerAvailability.Unavailable val gdbUrl = gdbUrl() ?: return DebuggerAvailability.Unavailable
@ -123,7 +122,7 @@ class ZigDebuggerToolchainService {
val msvcBinaryPath = "vsdbg.exe" val msvcBinaryPath = "vsdbg.exe"
val msvcFile = msvcPath().resolve(msvcBinaryPath) 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)) 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> <<EOF>> { yybegin(YYINITIAL); return BAD_SQUOT; }
<UNT_SQUOT> {CRLF} { 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> <<EOF>> { yybegin(YYINITIAL); return BAD_DQUOT; }
<UNT_DQUOT> {CRLF} { 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; } <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 val paths = path ?: return null
for (dir in paths) { for (dir in paths) {
val path = dir.toNioPathOrNull()?.absolute() ?: continue val path = dir.toNioPathOrNull()?.absolute() ?: continue
if (path.notExists() || !path.isDirectory()) if (!path.toFile().exists() || !path.isDirectory())
continue continue
val exePath = path.resolve(exeName).absolute() val exePath = path.resolve(exeName).absolute()
if (!exePath.isRegularFile() || !exePath.isExecutable()) if (!exePath.isRegularFile() || !exePath.isExecutable())

View file

@ -48,7 +48,6 @@ import org.eclipse.lsp4j.services.LanguageServer
import java.nio.file.Path import java.nio.file.Path
import kotlin.io.path.isExecutable import kotlin.io.path.isExecutable
import kotlin.io.path.isRegularFile import kotlin.io.path.isRegularFile
import kotlin.io.path.notExists
import kotlin.io.path.pathString import kotlin.io.path.pathString
class ZLSStreamConnectionProvider private constructor(private val project: Project, commandLine: GeneralCommandLine?) : OSProcessStreamConnectionProvider(commandLine) { 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( Notification(
"zigbrains-lsp", "zigbrains-lsp",
ZLSBundle.message("notification.message.zls-exe-not-exists.content", zlsPath), 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 -> val configPath: Path? = state.zlsConfigPath.let { configPath ->
if (configPath.isNotBlank()) { if (configPath.isNotBlank()) {
configPath.toNioPathOrNull()?.let { nioPath -> configPath.toNioPathOrNull()?.let { nioPath ->
if (nioPath.notExists()) { if (!nioPath.toFile().exists()) {
Notification( Notification(
"zigbrains-lsp", "zigbrains-lsp",
ZLSBundle.message("notification.message.zls-config-not-exists.content", nioPath), 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.concurrent.withLock
import kotlin.io.path.isExecutable import kotlin.io.path.isExecutable
import kotlin.io.path.isRegularFile import kotlin.io.path.isRegularFile
import kotlin.io.path.notExists
@Service(Service.Level.PROJECT) @Service(Service.Level.PROJECT)
@State( @State(
@ -108,7 +107,7 @@ private suspend fun doValidate(project: Project, state: ZLSSettings): Boolean {
} }
} }
} }
if (zlsPath.notExists()) { if (!zlsPath.toFile().exists()) {
return false return false
} }
if (!zlsPath.isRegularFile() || !zlsPath.isExecutable()) { 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.execution.filters.OpenFileHyperlinkInfo
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.util.io.toNioPathOrNull
import com.intellij.openapi.vfs.refreshAndFindVirtualFile import com.intellij.openapi.vfs.refreshAndFindVirtualFile
import com.intellij.openapi.vfs.toNioPathOrNull import com.intellij.openapi.vfs.toNioPathOrNull
import java.io.File
import java.nio.file.InvalidPathException import java.nio.file.InvalidPathException
import java.nio.file.Path import java.nio.file.Path
import kotlin.io.path.isRegularFile
import kotlin.io.path.notExists
import kotlin.math.max import kotlin.math.max
class ZigSourceFileFilter(private val project: Project): Filter { 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? { override fun applyFilter(line: String, entireLength: Int): Filter.Result? {
val lineStart = entireLength - line.length val lineStart = entireLength - line.length
val projectPath = project.guessProjectDir()?.toNioPathOrNull()
val results = ArrayList<ResultItem>() val results = ArrayList<ResultItem>()
val matcher = LEN_REGEX.findAll(line) val matcher = LEN_REGEX.findAll(line)
for (match in matcher) { for (match in matcher) {
val start = match.range.first val start = match.range.first
val pair = findLongestParsablePathFromOffset(line, start, projectPath) val pair = findLongestParsablePathFromOffset(line, start)
val path = pair?.first ?: return null val path = pair?.first ?: return null
val file = path.refreshAndFindVirtualFile() ?: return null val file = path.refreshAndFindVirtualFile() ?: return null
val lineNumber = max(match.groups[1]!!.value.toInt() - 1, 0) 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) 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 longestStart = -1
var longest: Path? = null var longest: File? = null
for (i in end - 1 downTo 0) { for (i in end - 1 downTo 0) {
try { try {
val pathStr = line.substring(i, end) val pathStr = line.substring(i, end)
var path: Path = pathStr.toNioPathOrNull() ?: continue var file = File(pathStr)
if ((path.notExists() || !path.isRegularFile()) && projectPath != null) { if (!file.isFile) {
path = projectPath.resolve(pathStr) if (projectPath == null) {
if (path.notExists() || !path.isRegularFile())
continue continue
}
file = projectPath.resolve(pathStr)
if (!file.isFile) {
continue
}
} }
longest = path longest = file
longestStart = i longestStart = i
} catch (ignored: InvalidPathException) { } catch (ignored: InvalidPathException) {
} }
} }
longest ?: return null 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.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import javax.swing.event.DocumentEvent import javax.swing.event.DocumentEvent
import kotlin.io.path.exists
import kotlin.io.path.notExists
import kotlin.io.path.pathString import kotlin.io.path.pathString
class ZigProjectSettingsPanel(private val project: Project?) : Disposable { class ZigProjectSettingsPanel(private val project: Project?) : Disposable {
@ -162,7 +160,7 @@ class ZigProjectSettingsPanel(private val project: Project?) : Disposable {
delay(200) delay(200)
val toolchain = pathToToolchain?.let { LocalZigToolchain(it) } val toolchain = pathToToolchain?.let { LocalZigToolchain(it) }
val zig = toolchain?.zig val zig = toolchain?.zig
if (zig?.path()?.exists() != true) { if (zig?.path()?.toFile()?.exists() != true) {
toolchainVersion.text = "" toolchainVersion.text = ""
if (!stdFieldOverride.isSelected) { if (!stdFieldOverride.isSelected) {

View file

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

View file

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