-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPredictiveSaveActionExtension.kt
More file actions
31 lines (26 loc) · 1.04 KB
/
PredictiveSaveActionExtension.kt
File metadata and controls
31 lines (26 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
* Copyright 2023 CodeMaker AI Inc. All rights reserved.
*/
package ai.codemaker.jetbrains.extension
import ai.codemaker.jetbrains.predictor.Predictor
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 PredictiveSaveActionExtension : ActionOnSave() {
override fun isEnabledForProject(project: Project): Boolean {
return project.getService(Predictor::class.java) != null
}
override fun processDocuments(project: Project, documents: Array<Document>) {
try {
val predictor = project.getService(Predictor::class.java)
val documentManager = PsiDocumentManager.getInstance(project)
documents.forEach {
val psiFile = documentManager.getPsiFile(it) ?: return
predictor.refresh(psiFile.virtualFile)
}
} catch (ignore: Exception) {
// ignores
}
}
}