-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow intellij project to work with different biome configs (#53)
* allow intellij project to work with different biome configs * add comment * add information about automatic mode in readme
- Loading branch information
Showing
9 changed files
with
162 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 2 additions & 22 deletions
24
src/main/kotlin/com/github/biomejs/intellijbiome/actions/BiomeCheckOnSaveAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,21 @@ | ||
package com.github.biomejs.intellijbiome.actions | ||
|
||
import com.github.biomejs.intellijbiome.Feature | ||
import com.github.biomejs.intellijbiome.settings.BiomeSettings | ||
import com.intellij.ide.actionsOnSave.impl.ActionsOnSaveFileDocumentManagerListener | ||
import com.intellij.openapi.editor.Document | ||
import com.intellij.openapi.project.Project | ||
import java.util.* | ||
|
||
|
||
class BiomeCheckOnSaveAction() : | ||
ActionsOnSaveFileDocumentManagerListener.ActionOnSave() { | ||
private var features: EnumSet<Feature> = EnumSet.noneOf(Feature::class.java) | ||
override fun isEnabledForProject(project: Project): Boolean { | ||
val settings = BiomeSettings.getInstance(project) | ||
|
||
setFeatures(settings) | ||
|
||
return settings.formatOnSave || settings.applySafeFixesOnSave || settings.applyUnsafeFixesOnSave | ||
} | ||
|
||
override fun processDocuments(project: Project, documents: Array<Document>) { | ||
BiomeCheckRunner().run(project, features, documents) | ||
} | ||
|
||
private fun setFeatures(settings: BiomeSettings) { | ||
features = EnumSet.noneOf(Feature::class.java) | ||
|
||
if (settings.formatOnSave) { | ||
features.add(Feature.Format) | ||
} | ||
|
||
if (settings.applySafeFixesOnSave) { | ||
features.add(Feature.SafeFixes) | ||
} | ||
|
||
if (settings.applyUnsafeFixesOnSave) { | ||
features.add(Feature.UnsafeFixes) | ||
} | ||
val settings = BiomeSettings.getInstance(project) | ||
BiomeCheckRunner().run(project, settings.getEnabledFeatures(), documents) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/kotlin/com/github/biomejs/intellijbiome/listeners/BiomeEditorPanelListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.github.biomejs.intellijbiome.listeners | ||
|
||
import com.github.biomejs.intellijbiome.BiomePackage | ||
import com.github.biomejs.intellijbiome.services.BiomeServerService | ||
import com.github.biomejs.intellijbiome.settings.BiomeSettings | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.fileEditor.FileEditorManagerEvent | ||
import com.intellij.openapi.fileEditor.FileEditorManagerListener | ||
import com.intellij.openapi.project.Project | ||
|
||
// This implements a listener for file editor manager events. | ||
// It listens for file selection changes in IDE and restarts LSP server if selected file in editor should be checked with different Biome config. | ||
class BiomeEditorPanelListener(private val project: Project) : FileEditorManagerListener { | ||
|
||
private var currentConfigPath: String? = null | ||
|
||
// on selection change, check if the new file should not use different biome config. | ||
// if so, restart biome server to use the new config. | ||
override fun selectionChanged(fileEditorManagerEvent: FileEditorManagerEvent) { | ||
val settings = BiomeSettings.getInstance(project) | ||
val isEnabled = settings.isEnabled() | ||
if (fileEditorManagerEvent.newFile != null) { | ||
val newConfigPath = BiomePackage(project).configPath(fileEditorManagerEvent.newFile!!) | ||
val biomeServerService = project.service<BiomeServerService>() | ||
// stop biome LSP server if selected file does not have biome config. | ||
if (newConfigPath == null) { | ||
currentConfigPath = null | ||
biomeServerService.stopBiomeServer() | ||
return | ||
} | ||
if (isEnabled && currentConfigPath != newConfigPath) { | ||
currentConfigPath = newConfigPath | ||
biomeServerService.restartBiomeServer() | ||
} | ||
} | ||
} | ||
|
||
fun getCurrentConfigPath(): String? { | ||
return currentConfigPath | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/github/biomejs/intellijbiome/services/BiomeServerService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters