backport: 23.1.2
This commit is contained in:
parent
6da7815895
commit
de68e65d7a
4 changed files with 68 additions and 11 deletions
|
@ -17,6 +17,13 @@ Changelog structure reference:
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [23.1.2]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- LSP
|
||||||
|
- IDE warning when renaming symbols
|
||||||
|
|
||||||
## [23.1.1]
|
## [23.1.1]
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
pluginName=ZigBrains
|
pluginName=ZigBrains
|
||||||
pluginRepositoryUrl=https://github.com/FalsePattern/ZigBrains
|
pluginRepositoryUrl=https://github.com/FalsePattern/ZigBrains
|
||||||
|
|
||||||
pluginVersion=23.1.1
|
pluginVersion=23.1.2
|
||||||
|
|
||||||
pluginSinceBuild=242
|
pluginSinceBuild=242
|
||||||
pluginUntilBuild=242.*
|
pluginUntilBuild=242.*
|
||||||
|
|
|
@ -24,7 +24,8 @@ package com.falsepattern.zigbrains.lsp.notification
|
||||||
|
|
||||||
import com.falsepattern.zigbrains.lsp.ZLSBundle
|
import com.falsepattern.zigbrains.lsp.ZLSBundle
|
||||||
import com.falsepattern.zigbrains.lsp.settings.zlsSettings
|
import com.falsepattern.zigbrains.lsp.settings.zlsSettings
|
||||||
import com.falsepattern.zigbrains.lsp.zlsRunningSync
|
import com.falsepattern.zigbrains.lsp.zlsRunningAsync
|
||||||
|
import com.falsepattern.zigbrains.shared.zigCoroutineScope
|
||||||
import com.falsepattern.zigbrains.zig.ZigFileType
|
import com.falsepattern.zigbrains.zig.ZigFileType
|
||||||
import com.falsepattern.zigbrains.zon.ZonFileType
|
import com.falsepattern.zigbrains.zon.ZonFileType
|
||||||
import com.intellij.openapi.fileEditor.FileEditor
|
import com.intellij.openapi.fileEditor.FileEditor
|
||||||
|
@ -33,6 +34,8 @@ import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import com.intellij.ui.EditorNotificationPanel
|
import com.intellij.ui.EditorNotificationPanel
|
||||||
import com.intellij.ui.EditorNotificationProvider
|
import com.intellij.ui.EditorNotificationProvider
|
||||||
|
import kotlinx.coroutines.async
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import java.util.function.Function
|
import java.util.function.Function
|
||||||
import javax.swing.JComponent
|
import javax.swing.JComponent
|
||||||
|
|
||||||
|
@ -45,13 +48,21 @@ class ZigEditorNotificationProvider: EditorNotificationProvider, DumbAware {
|
||||||
ZigFileType, ZonFileType -> {}
|
ZigFileType, ZonFileType -> {}
|
||||||
else -> return null
|
else -> return null
|
||||||
}
|
}
|
||||||
if (project.zlsRunningSync()) {
|
val task = project.zigCoroutineScope.async {
|
||||||
return null
|
if (project.zlsRunningAsync()) {
|
||||||
|
return@async null
|
||||||
|
} else {
|
||||||
|
return@async project.zlsSettings.validateAsync()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Function { editor ->
|
return Function { editor ->
|
||||||
val status: EditorNotificationPanel.Status
|
val status: EditorNotificationPanel.Status
|
||||||
val message: String
|
val message: String
|
||||||
if (!project.zlsSettings.validateSync()) {
|
val result = runBlocking { task.await() }
|
||||||
|
if (result == null)
|
||||||
|
return@Function null
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
status = EditorNotificationPanel.Status.Error
|
status = EditorNotificationPanel.Status.Error
|
||||||
message = ZLSBundle.message("notification.banner.zls-bad-config")
|
message = ZLSBundle.message("notification.banner.zls-bad-config")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -27,6 +27,7 @@ import com.falsepattern.zigbrains.direnv.getDirenv
|
||||||
import com.falsepattern.zigbrains.lsp.ZLSBundle
|
import com.falsepattern.zigbrains.lsp.ZLSBundle
|
||||||
import com.falsepattern.zigbrains.lsp.startLSP
|
import com.falsepattern.zigbrains.lsp.startLSP
|
||||||
import com.falsepattern.zigbrains.project.settings.zigProjectSettings
|
import com.falsepattern.zigbrains.project.settings.zigProjectSettings
|
||||||
|
import com.intellij.ide.IdeEventQueue
|
||||||
import com.intellij.openapi.components.*
|
import com.intellij.openapi.components.*
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.util.io.toNioPathOrNull
|
import com.intellij.openapi.util.io.toNioPathOrNull
|
||||||
|
@ -83,17 +84,55 @@ class ZLSProjectSettingsService(val project: Project): PersistentStateComponent<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun validateSync() = if (application.isDispatchThread && !application.isWriteAccessAllowed) {
|
fun validateSync(): Boolean {
|
||||||
runWithModalProgressBlocking(ModalTaskOwner.project(project), ZLSBundle.message("progress.title.validate")) {
|
val isValid: Boolean? = runBlocking {
|
||||||
validateAsync()
|
mutex.withLock {
|
||||||
|
if (dirty)
|
||||||
|
null
|
||||||
|
else
|
||||||
|
valid
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
if (isValid != null) {
|
||||||
runBlocking {
|
return isValid
|
||||||
validateAsync()
|
}
|
||||||
|
return if (useModalProgress()) {
|
||||||
|
runWithModalProgressBlocking(ModalTaskOwner.project(project), ZLSBundle.message("progress.title.validate")) {
|
||||||
|
validateAsync()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
runBlocking {
|
||||||
|
validateAsync()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val prohibitClass: Class<*>? = runCatching {
|
||||||
|
Class.forName("com_intellij_ide_ProhibitAWTEvents".replace('_', '.'))
|
||||||
|
}.getOrNull()
|
||||||
|
|
||||||
|
private val postProcessors: List<*>? = runCatching {
|
||||||
|
if (prohibitClass == null)
|
||||||
|
return@runCatching null
|
||||||
|
val postProcessorsField = IdeEventQueue::class.java.getDeclaredField("postProcessors")
|
||||||
|
postProcessorsField.isAccessible = true
|
||||||
|
postProcessorsField.get(IdeEventQueue.getInstance()) as? List<*>
|
||||||
|
}.getOrNull()
|
||||||
|
|
||||||
|
private fun useModalProgress(): Boolean {
|
||||||
|
if (!application.isDispatchThread)
|
||||||
|
return false
|
||||||
|
|
||||||
|
if (application.isWriteAccessAllowed)
|
||||||
|
return false
|
||||||
|
|
||||||
|
if (postProcessors == null)
|
||||||
|
return true
|
||||||
|
|
||||||
|
return postProcessors.none { prohibitClass!!.isInstance(it) }
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun doValidate(project: Project, state: ZLSSettings): Boolean {
|
private suspend fun doValidate(project: Project, state: ZLSSettings): Boolean {
|
||||||
val zlsPath: Path = state.zlsPath.let { zlsPath ->
|
val zlsPath: Path = state.zlsPath.let { zlsPath ->
|
||||||
if (zlsPath.isEmpty()) {
|
if (zlsPath.isEmpty()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue