backport: 20.2.0

This commit is contained in:
FalsePattern 2025-01-21 14:02:29 +01:00
parent 5c10704f43
commit 2e0870c883
Signed by: falsepattern
GPG key ID: E930CDEC50C50E23
30 changed files with 116 additions and 69 deletions

View file

@ -17,6 +17,13 @@ Changelog structure reference:
## [Unreleased]
## [20.2.0]
### Added
- Zig
- Live template support
## [20.1.3]
### Added

View file

@ -8,7 +8,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
plugins {
kotlin("jvm") version "1.9.24" apply false
kotlin("plugin.serialization") version "1.9.24" apply false
id("org.jetbrains.intellij.platform") version "2.1.0"
id("org.jetbrains.intellij.platform") version "2.2.1"
id("org.jetbrains.changelog") version "2.2.1"
id("org.jetbrains.grammarkit") version "2022.3.2.2" apply false
idea
@ -93,11 +93,6 @@ allprojects {
defaultRepositories()
}
}
dependencies {
intellijPlatform {
instrumentationTools()
}
}
}
dependencies {

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.messages.Message
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest
import java.io.InputStream
import java.lang.RuntimeException
import java.security.MessageDigest
import java.util.Base64
@ -73,7 +74,7 @@ class WinDAPDriver(handler: Handler) : DAPDriver<IDebugProtocolServer, WinDAPDri
handshakeFinished.acquire()
}
inner class WinDAPDebuggerClient: DAPDriver<IDebugProtocolServer, WinDAPDriver.WinDAPDebuggerClient>.DAPDebuggerClient() {
inner class WinDAPDebuggerClient: DAPDriver<IDebugProtocolServer, WinDAPDebuggerClient>.DAPDebuggerClient() {
override fun output(args: OutputEventArguments) {
if ("telemetry" == args.category)
return
@ -92,7 +93,7 @@ class WinDAPDriver(handler: Handler) : DAPDriver<IDebugProtocolServer, WinDAPDri
val hasher = MessageDigest.getInstance("SHA-256")
hasher.update(handshake.value.encodeToByteArray())
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.finished()
val b = ByteArray(1)

View file

@ -65,10 +65,10 @@ object DirenvCmd {
return emptyEnv
}
}
if (runOutput.output.isBlank()) {
return emptyEnv
return if (runOutput.output.isBlank()) {
emptyEnv
} 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 {
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) {

View file

@ -224,7 +224,7 @@ class FilePathConfigurable(
}
}
class CheckboxConfigurable(
open class CheckboxConfigurable(
@Transient private val serializedName: String,
@Transient @Nls private val label: String,
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) =
CheckboxConfigurable(serializedName, ZigBrainsBundle.message("exec.option.label.direnv"), project.zigProjectSettings.state.direnv)
class DirenvConfigurable(serializedName: String, project: Project): CheckboxConfigurable(serializedName, ZigBrainsBundle.message("exec.option.label.direnv"), project.zigProjectSettings.state.direnv) {
override fun clone(): DirenvConfigurable {
return super.clone() as DirenvConfigurable
}
}
class OptimizationConfigurable(
@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.direnv.DirenvCmd
import com.falsepattern.zigbrains.project.toolchain.AbstractZigToolchain
import com.intellij.execution.ExecutionException
import com.intellij.execution.Executor
import com.intellij.execution.configurations.ConfigurationFactory

View file

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

View file

@ -82,10 +82,10 @@ class ZigExecConfigBuild(project: Project, factory: ConfigurationFactory): ZigEx
override fun getConfigurables(): List<ZigConfigurable<*>> {
val baseCfg = super.getConfigurables() + listOf(buildSteps, extraArgs, colored)
if (ZBFeatures.debug()) {
return baseCfg + listOf(exePath, exeArgs)
return if (ZBFeatures.debug()) {
baseCfg + listOf(exePath, exeArgs)
} 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.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.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.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.template.ZigInitTemplate
import com.falsepattern.zigbrains.project.template.ZigProjectTemplate
import com.falsepattern.zigbrains.shared.coroutine.withEDTContext
import com.falsepattern.zigbrains.shared.zigCoroutineScope
import com.intellij.notification.Notification
import com.intellij.notification.NotificationType
import com.intellij.openapi.GitRepositoryInitializer
import com.intellij.openapi.application.writeAction
import com.intellij.openapi.progress.coroutineToIndicator
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VfsUtil
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.util.ResourceUtil
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.withContext
@JvmRecord
data class ZigProjectConfigurationData(
@ -141,7 +135,7 @@ private suspend fun createGitIgnoreFile(project: Project, projectDir: VirtualFil
writeAction {
ZigProjectConfigurationData::class.java.getResourceAsStream("/fileTemplates/internal/gitignore")?.use {
val file = projectDir.createChildData(requestor, ".gitignore")
file.setCharset(Charsets.UTF_8)
file.charset = Charsets.UTF_8
file.setBinaryContent(it.readAllBytes())
}
}

View file

@ -48,17 +48,17 @@ class ZigProcessHandler : KillableColoredProcessHandler, ColoredTextAcceptor {
private val VT100_CHARS = CharArray(256).apply {
this.fill(' ')
this[0x6A] = '┘';
this[0x6B] = '┐';
this[0x6C] = '┌';
this[0x6D] = '└';
this[0x6E] = '┼';
this[0x71] = '─';
this[0x74] = '├';
this[0x75] = '┤';
this[0x76] = '┴';
this[0x77] = '┬';
this[0x78] = '│';
this[0x6A] = '┘'
this[0x6B] = '┐'
this[0x6C] = '┌'
this[0x6D] = '└'
this[0x6E] = '┼'
this[0x71] = '─'
this[0x74] = '├'
this[0x75] = '┤'
this[0x76] = '┴'
this[0x77] = '┬'
this[0x78] = '│'
}
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.settings.zigProjectSettings
import com.falsepattern.zigbrains.project.toolchain.AbstractZigToolchain
import com.falsepattern.zigbrains.shared.coroutine.withEDTContext
import com.falsepattern.zigbrains.shared.zigCoroutineScope
import com.intellij.execution.ExecutionException
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.ZigToolchainProvider
import com.falsepattern.zigbrains.shared.coroutine.launchWithEDT
import com.falsepattern.zigbrains.shared.coroutine.withEDTContext
import com.falsepattern.zigbrains.shared.zigCoroutineScope
import com.intellij.openapi.Disposable
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory

View file

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

View file

@ -44,7 +44,7 @@ class ZigStepDiscoveryService(private val project: Project) {
private val reloading = AtomicBoolean(false)
private val reloadScheduled = AtomicBoolean(false)
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 listenerMutex = Mutex()
@ -83,10 +83,10 @@ class ZigStepDiscoveryService(private val project: Project) {
val result = zig.callWithArgs(
project.guessProjectDir()?.toNioPathOrNull(),
"build", "-l",
timeoutMillis = CURRENT_TIMEOUT_SEC * 1000L
timeoutMillis = currentTimeoutSec * 1000L
)
if (result.checkSuccess(LOG)) {
CURRENT_TIMEOUT_SEC = DEFAULT_TIMEOUT_SEC
currentTimeoutSec = DEFAULT_TIMEOUT_SEC
val lines = result.stdoutLines
val steps = ArrayList<Pair<String, String?>>()
for (line in lines) {
@ -99,8 +99,8 @@ class ZigStepDiscoveryService(private val project: Project) {
}
postReload(steps)
} else if (result.isTimeout) {
timeoutReload(CURRENT_TIMEOUT_SEC)
CURRENT_TIMEOUT_SEC *= 2
timeoutReload(currentTimeoutSec)
currentTimeoutSec *= 2
} 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)
} else {

View file

@ -0,0 +1,48 @@
/*
* This file is part of ZigBrains.
*
* Copyright (C) 2023-2024 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* ZigBrains is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* ZigBrains is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZigBrains. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.zigbrains.zig.codeInsight
import com.falsepattern.zigbrains.ZigBrainsBundle
import com.falsepattern.zigbrains.zig.psi.ZigFile
import com.falsepattern.zigbrains.zig.psi.ZigTypes
import com.intellij.codeInsight.template.TemplateActionContext
import com.intellij.codeInsight.template.TemplateContextType
import com.intellij.psi.util.elementType
class ZigContext: TemplateContextType(ZigBrainsBundle.message("zig")) {
override fun isInContext(templateActionContext: TemplateActionContext): Boolean {
val file = templateActionContext.file
val offset = templateActionContext.startOffset
if (file !is ZigFile)
return false
val element = file.findElementAt(offset) ?: return true
return when (element.elementType) {
ZigTypes.LINE_COMMENT, ZigTypes.CONTAINER_DOC_COMMENT, ZigTypes.DOC_COMMENT -> false
ZigTypes.STRING_LITERAL_SINGLE, ZigTypes.STRING_LITERAL_MULTI -> false
else -> true
}
}
}

View file

@ -41,7 +41,7 @@ class ZigStringElementManipulator: AbstractElementManipulator<ZigStringLiteral>(
val originalContext = element.text!!
val isMultiline = element.isMultiline
@NonNls
val prefix = "const x = \n";
val prefix = "const x = \n"
val suffix = "\n;"
val sbFactory: (Int) -> StringBuilder = {
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 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) {
editor ?: return

View file

@ -41,7 +41,7 @@ class MakeStringQuoted: PsiElementBaseIntentionAction() {
override fun getFamilyName() = ZigBrainsBundle.message("intention.family.name.make-string-quoted")
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) {
editor ?: return

View file

@ -24,5 +24,4 @@ package com.falsepattern.zigbrains.zig.lexerstring
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 isMultiline = myHost.isMultiline
val contentRanges = myHost.contentRanges.also { _contentRanges = it }
var decoded = false;
var decoded = false
for (range in contentRanges) {
val intersection = range.intersection(rangeInsideHost) ?: continue
decoded = true

View file

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

View file

@ -170,6 +170,11 @@
icon="/icons/zig_build_tool.svg"
id="zigbrains.build"
/>
<liveTemplateContext
contextId="ZIG"
implementation="com.falsepattern.zigbrains.zig.codeInsight.ZigContext"
/>
</extensions>
<extensions defaultExtensionNs="com.falsepattern.zigbrains">

View file

@ -115,3 +115,4 @@ build.tool.window.status.error.missing-build-zig=No build.zig file found
build.tool.window.status.error.missing-toolchain=No zig toolchain configured
build.tool.window.status.error.general=Error while running zig build -l
build.tool.window.status.timeout=zig build -l timed out after {0} seconds.
zig=Zig

View file

@ -1,7 +1,7 @@
pluginName=ZigBrains
pluginRepositoryUrl=https://github.com/FalsePattern/ZigBrains
pluginVersion=20.1.3
pluginVersion=20.2.0
pluginSinceBuild=242
pluginUntilBuild=242.*
@ -14,7 +14,7 @@ javaVersion=21
runIdeTarget=clion
lsp4jVersion=0.21.1
lsp4ijVersion=0.7.0
lsp4ijVersion=0.9.0
lsp4ijNightly=false
kotlin.stdlib.default.dependency=false

View file

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME

3
gradlew vendored
View file

@ -86,8 +86,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum