Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.oxc.project.oxcintellijplugin.listeners

import com.github.oxc.project.oxcintellijplugin.services.OxcServerService
import com.github.oxc.project.oxcintellijplugin.settings.OxcSettings
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.FileEditorManagerListener
import com.intellij.openapi.vfs.VirtualFile

class EditorWatcher : FileEditorManagerListener {

override fun fileClosed(source: FileEditorManager, file: VirtualFile) {
val project = source.project
if (source.allEditors.isEmpty()) {
OxcServerService.getInstance(project).stopServer()
return
}

val stillHasSupportedFileOpen = source.allEditors.any {
OxcSettings.getInstance(project).fileSupported(it.file)
}
if (!stillHasSupportedFileOpen) {
OxcServerService.getInstance(project).stopServer()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.oxc.project.oxcintellijplugin.lsp
import com.github.oxc.project.oxcintellijplugin.OxcIcons
import com.github.oxc.project.oxcintellijplugin.OxcPackage
import com.github.oxc.project.oxcintellijplugin.settings.OxcConfigurable
import com.github.oxc.project.oxcintellijplugin.settings.OxcSettings
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
Expand All @@ -19,6 +20,10 @@ class OxcLspServerSupportProvider : LspServerSupportProvider {
serverStarter: LspServerSupportProvider.LspServerStarter) {
thisLogger().debug("Handling fileOpened for ${file.path}")

if (!OxcSettings.getInstance(project).fileSupported(file)) {
return
}

val oxc = OxcPackage(project)
if (!oxc.isEnabled()) {
return
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@
topic="com.intellij.openapi.vfs.newvfs.BulkFileListener"
/>
</applicationListeners>

<projectListeners>
<listener class="com.github.oxc.project.oxcintellijplugin.listeners.EditorWatcher"
topic="com.intellij.openapi.fileEditor.FileEditorManagerListener"/>
</projectListeners>
</idea-plugin>