backport: 22.0.1
This commit is contained in:
parent
0162e53b01
commit
eeef01498c
8 changed files with 83 additions and 45 deletions
11
CHANGELOG.md
11
CHANGELOG.md
|
@ -17,6 +17,17 @@ Changelog structure reference:
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [22.0.1]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- LSP
|
||||||
|
- Changing ZLS configs would not restart ZLS
|
||||||
|
|
||||||
|
- Project
|
||||||
|
- Occasional "AWT events are not allowed inside write action" error coming from LSP
|
||||||
|
- IllegalStateException coming from the standard library handler
|
||||||
|
|
||||||
## [22.0.0]
|
## [22.0.0]
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -79,31 +79,23 @@ class ZigSyntheticLibrary(val project: Project) : SyntheticLibrary(), ItemPresen
|
||||||
suspend fun reload(project: Project, state: ZigProjectSettings) {
|
suspend fun reload(project: Project, state: ZigProjectSettings) {
|
||||||
val moduleId = ModuleId(ZIG_MODULE_ID)
|
val moduleId = ModuleId(ZIG_MODULE_ID)
|
||||||
val workspaceModel = WorkspaceModel.getInstance(project)
|
val workspaceModel = WorkspaceModel.getInstance(project)
|
||||||
if (moduleId !in workspaceModel.currentSnapshot) {
|
|
||||||
val baseModuleDir = project.guessProjectDir()?.toVirtualFileUrl(workspaceModel.getVirtualFileUrlManager()) ?: return
|
|
||||||
|
|
||||||
val moduleEntitySource = LegacyBridgeJpsEntitySourceFactory
|
|
||||||
.createEntitySourceForModule(project, baseModuleDir, null)
|
|
||||||
|
|
||||||
val moduleEntity = ModuleEntity(ZIG_MODULE_ID, emptyList(), moduleEntitySource)
|
|
||||||
workspaceModel.update("Add new module") {builder ->
|
|
||||||
builder.addEntity(moduleEntity)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val moduleEntity = workspaceModel.currentSnapshot.resolve(moduleId) ?: return
|
|
||||||
val root = getRoot(state, project) ?: return
|
val root = getRoot(state, project) ?: return
|
||||||
val libRoot = LibraryRoot(root.toVirtualFileUrl(workspaceModel.getVirtualFileUrlManager()), LibraryRootTypeId.SOURCES)
|
val libRoot = LibraryRoot(root.toVirtualFileUrl(workspaceModel.getVirtualFileUrlManager()), LibraryRootTypeId.SOURCES)
|
||||||
val libraryTableId = LibraryTableId.ProjectLibraryTableId
|
val libraryTableId = LibraryTableId.ProjectLibraryTableId
|
||||||
val libraryId = LibraryId(ZIG_LIBRARY_ID, libraryTableId)
|
val libraryId = LibraryId(ZIG_LIBRARY_ID, libraryTableId)
|
||||||
if (libraryId in workspaceModel.currentSnapshot) {
|
val baseModuleDir = project.guessProjectDir()?.toVirtualFileUrl(workspaceModel.getVirtualFileUrlManager()) ?: return
|
||||||
val library = workspaceModel.currentSnapshot.resolve(libraryId) ?: return
|
workspaceModel.update("Update Zig std") { builder ->
|
||||||
workspaceModel.update("Update library") { builder ->
|
builder.resolve(moduleId)?.let { moduleEntity ->
|
||||||
builder.modifyLibraryEntity(library) {
|
builder.removeEntity(moduleEntity)
|
||||||
roots.clear()
|
}
|
||||||
roots.add(libRoot)
|
val moduleEntitySource = LegacyBridgeJpsEntitySourceFactory
|
||||||
}
|
.createEntitySourceForModule(project, baseModuleDir, null)
|
||||||
|
|
||||||
|
val moduleEntity = builder.addEntity(ModuleEntity(ZIG_MODULE_ID, emptyList(), moduleEntitySource))
|
||||||
|
|
||||||
|
builder.resolve(libraryId)?.let { libraryEntity ->
|
||||||
|
builder.removeEntity(libraryEntity)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
val libraryEntitySource = LegacyBridgeJpsEntitySourceFactory
|
val libraryEntitySource = LegacyBridgeJpsEntitySourceFactory
|
||||||
.createEntitySourceForProjectLibrary(project, null)
|
.createEntitySourceForProjectLibrary(project, null)
|
||||||
val libraryEntity = LibraryEntity(
|
val libraryEntity = LibraryEntity(
|
||||||
|
@ -113,13 +105,11 @@ class ZigSyntheticLibrary(val project: Project) : SyntheticLibrary(), ItemPresen
|
||||||
) {
|
) {
|
||||||
roots.add(libRoot)
|
roots.add(libRoot)
|
||||||
}
|
}
|
||||||
workspaceModel.update("Add new library") { builder ->
|
builder.addEntity(libraryEntity)
|
||||||
builder.addEntity(libraryEntity)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
workspaceModel.update("Link dep") { builder ->
|
|
||||||
builder.modifyModuleEntity(moduleEntity) {
|
builder.modifyModuleEntity(moduleEntity) {
|
||||||
dependencies.add(LibraryDependency(libraryId, false, DependencyScope.COMPILE))
|
val dep = LibraryDependency(libraryId, false, DependencyScope.COMPILE)
|
||||||
|
dependencies.clear()
|
||||||
|
dependencies.add(dep)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
pluginName=ZigBrains
|
pluginName=ZigBrains
|
||||||
pluginRepositoryUrl=https://github.com/FalsePattern/ZigBrains
|
pluginRepositoryUrl=https://github.com/FalsePattern/ZigBrains
|
||||||
|
|
||||||
pluginVersion=22.0.0
|
pluginVersion=22.0.1
|
||||||
|
|
||||||
pluginSinceBuild=242
|
pluginSinceBuild=242
|
||||||
pluginUntilBuild=242.*
|
pluginUntilBuild=242.*
|
||||||
|
|
|
@ -55,6 +55,9 @@ class ZLSStartup: ProjectActivity {
|
||||||
EditorNotifications.getInstance(project).updateAllNotifications()
|
EditorNotifications.getInstance(project).updateAllNotifications()
|
||||||
}
|
}
|
||||||
currentState = running
|
currentState = running
|
||||||
|
if (handleStartLSP(project)) {
|
||||||
|
EditorNotifications.getInstance(project).updateAllNotifications()
|
||||||
|
}
|
||||||
delay(1000)
|
delay(1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,11 @@ import com.redhat.devtools.lsp4ij.client.features.LSPClientFeatures
|
||||||
import com.redhat.devtools.lsp4ij.client.features.LSPFormattingFeature
|
import com.redhat.devtools.lsp4ij.client.features.LSPFormattingFeature
|
||||||
import com.redhat.devtools.lsp4ij.client.features.LSPInlayHintFeature
|
import com.redhat.devtools.lsp4ij.client.features.LSPInlayHintFeature
|
||||||
import com.redhat.devtools.lsp4ij.server.StreamConnectionProvider
|
import com.redhat.devtools.lsp4ij.server.StreamConnectionProvider
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
|
||||||
class ZigLanguageServerFactory: LanguageServerFactory, LanguageServerEnablementSupport {
|
class ZigLanguageServerFactory: LanguageServerFactory, LanguageServerEnablementSupport {
|
||||||
override fun createConnectionProvider(project: Project): StreamConnectionProvider {
|
override fun createConnectionProvider(project: Project): StreamConnectionProvider {
|
||||||
|
@ -93,35 +96,67 @@ fun Project.zlsEnabled(value: Boolean) {
|
||||||
suspend fun Project.zlsRunningAsync(): Boolean {
|
suspend fun Project.zlsRunningAsync(): Boolean {
|
||||||
if (!zlsEnabledAsync())
|
if (!zlsEnabledAsync())
|
||||||
return false
|
return false
|
||||||
return zlsRunningLsp4ij()
|
return lsm.isRunning
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Project.zlsRunningSync(): Boolean {
|
fun Project.zlsRunningSync(): Boolean {
|
||||||
if (!zlsEnabledSync())
|
if (!zlsEnabledSync())
|
||||||
return false
|
return false
|
||||||
return zlsRunningLsp4ij()
|
return lsm.isRunning
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Project.zlsRunningLsp4ij(): Boolean {
|
private val Project.lsm get() = service<LanguageServerManager>()
|
||||||
val manager = service<LanguageServerManager>()
|
|
||||||
val status = manager.getServerStatus("ZigBrains")
|
private val LanguageServerManager.isRunning get(): Boolean {
|
||||||
|
val status = getServerStatus("ZigBrains")
|
||||||
return status == ServerStatus.started || status == ServerStatus.starting
|
return status == ServerStatus.started || status == ServerStatus.starting
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val START_MUTEX = Mutex()
|
||||||
|
|
||||||
class ZLSStarter: LanguageServerStarter {
|
class ZLSStarter: LanguageServerStarter {
|
||||||
override fun startLSP(project: Project, restart: Boolean) {
|
override fun startLSP(project: Project, restart: Boolean) {
|
||||||
project.zigCoroutineScope.launch {
|
project.zigCoroutineScope.launch {
|
||||||
val manager = project.service<LanguageServerManager>()
|
START_MUTEX.withLock {
|
||||||
val status = manager.getServerStatus("ZigBrains")
|
if (restart) {
|
||||||
if ((status == ServerStatus.started || status == ServerStatus.starting) && !restart)
|
project.putUserData(RESTART_KEY, Unit)
|
||||||
return@launch
|
} else {
|
||||||
manager.stop("ZigBrains")
|
project.putUserData(START_KEY, Unit)
|
||||||
if (project.zlsSettings.validateAsync()) {
|
}
|
||||||
manager.start("ZigBrains")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val ENABLED_KEY = Key.create<Boolean>("ZLS_ENABLED")
|
private suspend fun doStart(project: Project, restart: Boolean) {
|
||||||
|
if (!restart && project.lsm.isRunning)
|
||||||
|
return
|
||||||
|
while (!project.isDisposed && project.lsm.isRunning) {
|
||||||
|
project.lsm.stop("ZigBrains")
|
||||||
|
delay(250)
|
||||||
|
}
|
||||||
|
if (project.zlsSettings.validateAsync()) {
|
||||||
|
delay(250)
|
||||||
|
project.lsm.start("ZigBrains")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun handleStartLSP(project: Project) = START_MUTEX.withLock {
|
||||||
|
if (project.getUserData(RESTART_KEY) != null) {
|
||||||
|
project.putUserData(RESTART_KEY, null)
|
||||||
|
project.putUserData(START_KEY, null)
|
||||||
|
doStart(project, true)
|
||||||
|
true
|
||||||
|
} else if (project.getUserData(START_KEY) != null) {
|
||||||
|
project.putUserData(START_KEY, null)
|
||||||
|
doStart(project, false)
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val ENABLED_KEY = Key.create<Boolean>("ZLS_ENABLED")
|
||||||
|
|
||||||
|
private val RESTART_KEY = Key.create<Unit>("ZLS_RESTART_REQUEST")
|
||||||
|
private val START_KEY = Key.create<Unit>("ZLS_START_REQUEST")
|
||||||
|
|
|
@ -82,7 +82,7 @@ class ZLSProjectSettingsService(val project: Project): PersistentStateComponent<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun validateSync() = if (application.isDispatchThread) {
|
fun validateSync() = if (application.isDispatchThread && !application.isWriteAccessAllowed) {
|
||||||
runWithModalProgressBlocking(ModalTaskOwner.project(project), ZLSBundle.message("progress.title.validate")) {
|
runWithModalProgressBlocking(ModalTaskOwner.project(project), ZLSBundle.message("progress.title.validate")) {
|
||||||
validateAsync()
|
validateAsync()
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
|
|
||||||
package com.falsepattern.zigbrains.lsp.settings
|
package com.falsepattern.zigbrains.lsp.settings
|
||||||
|
|
||||||
import com.falsepattern.zigbrains.lsp.startLSP
|
|
||||||
import com.falsepattern.zigbrains.shared.SubConfigurable
|
import com.falsepattern.zigbrains.shared.SubConfigurable
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.util.Disposer
|
import com.intellij.openapi.util.Disposer
|
||||||
|
|
|
@ -88,10 +88,10 @@
|
||||||
/>
|
/>
|
||||||
</extensions>
|
</extensions>
|
||||||
|
|
||||||
<applicationListeners>
|
<projectListeners>
|
||||||
<listener
|
<listener
|
||||||
class="com.falsepattern.zigbrains.lsp.ZLSStarter"
|
class="com.falsepattern.zigbrains.lsp.ZLSStarter"
|
||||||
topic="com.falsepattern.zigbrains.lsp.LanguageServerStarter"
|
topic="com.falsepattern.zigbrains.lsp.LanguageServerStarter"
|
||||||
/>
|
/>
|
||||||
</applicationListeners>
|
</projectListeners>
|
||||||
</idea-plugin>
|
</idea-plugin>
|
Loading…
Add table
Reference in a new issue