-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #503 from koxudaxi/fix-multi-project-formatting-is…
…olation Fix: Isolate Ruff formatting to the active project
- Loading branch information
Showing
8 changed files
with
40 additions
and
35 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
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 was deleted.
Oops, something went wrong.
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,26 @@ | ||
package com.koxudaxi.ruff | ||
|
||
import com.intellij.ide.actionsOnSave.impl.ActionsOnSaveFileDocumentManagerListener.ActionOnSave | ||
import com.intellij.openapi.editor.Document | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiDocumentManager | ||
|
||
class RuffActionOnSave : ActionOnSave() { | ||
override fun isEnabledForProject(project: Project): Boolean { | ||
val ruffConfigService = RuffConfigService.getInstance(project) | ||
return ruffConfigService.runRuffOnSave | ||
} | ||
override fun processDocuments(project: Project, documents: Array<Document>) { | ||
val ruffApplyService = RuffApplyService.getInstance(project) | ||
val ruffConfigService = RuffConfigService.getInstance(project) | ||
val ruffCacheService = RuffCacheService.getInstance(project) | ||
val psiDocumentManager = PsiDocumentManager.getInstance(project) | ||
val withFormat = ruffConfigService.useRuffFormat && ruffCacheService.hasFormatter() | ||
for (document in documents) { | ||
val psiFile = psiDocumentManager.getPsiFile(document) ?: continue | ||
if (!psiFile.isApplicableTo) continue | ||
if (ruffConfigService.disableOnSaveOutsideOfProject && !psiFile.virtualFile.isInProjectDir(project)) return | ||
ruffApplyService.apply(document, psiFile.sourceFile, withFormat) | ||
} | ||
} | ||
} |
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