-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] Run linting in the background.
Add GitlabLintNotificationProvider for manually showing error notification.
- Loading branch information
Showing
9 changed files
with
118 additions
and
54 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
31 changes: 0 additions & 31 deletions
31
src/main/kotlin/com/github/blarc/gitlab/template/lint/plugin/GitlabLintInspector.kt
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
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
34 changes: 34 additions & 0 deletions
34
...in/kotlin/com/github/blarc/gitlab/template/lint/plugin/inspections/GitlabLintInspector.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,34 @@ | ||
package com.github.blarc.gitlab.template.lint.plugin.inspections | ||
|
||
import com.github.blarc.gitlab.template.lint.plugin.GitlabLintRunner | ||
import com.github.blarc.gitlab.template.lint.plugin.GitlabLintUtils.Companion.matchesGitlabLintRegex | ||
import com.github.blarc.gitlab.template.lint.plugin.settings.AppSettingsState | ||
import com.intellij.codeInspection.LocalInspectionTool | ||
import com.intellij.codeInspection.ProblemsHolder | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.progress.runBackgroundableTask | ||
import com.intellij.psi.PsiElementVisitor | ||
import com.intellij.psi.PsiFile | ||
import com.intellij.ui.EditorNotifications | ||
|
||
class GitlabLintInspector : LocalInspectionTool() { | ||
|
||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor { | ||
return object : PsiElementVisitor() { | ||
override fun visitFile(file: PsiFile) { | ||
runBackgroundableTask("Gitlab Lint", file.project) { | ||
it.isIndeterminate = true | ||
val project = file.project | ||
if (matchesGitlabLintRegex(file.name)) { | ||
val gitlabToken = AppSettingsState.instance?.gitlabToken | ||
if (gitlabToken != null && gitlabToken.isNotEmpty()) { | ||
val linter = project.service<GitlabLintRunner>() | ||
linter.run(file.text, file.virtualFile.path) | ||
} | ||
} | ||
EditorNotifications.getInstance(project).updateAllNotifications() | ||
} | ||
} | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...om/github/blarc/gitlab/template/lint/plugin/inspections/GitlabLintNotificationProvider.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,43 @@ | ||
package com.github.blarc.gitlab.template.lint.plugin.inspections | ||
|
||
import com.github.blarc.gitlab.template.lint.plugin.GitlabLintRunner | ||
import com.github.blarc.gitlab.template.lint.plugin.GitlabLintUtils.Companion.matchesGitlabLintRegex | ||
import com.github.blarc.gitlab.template.lint.plugin.widgets.LintStatusEnum | ||
import com.intellij.codeInsight.hint.HintUtil | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.fileEditor.FileEditor | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.util.Key | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.ui.EditorNotificationPanel | ||
import com.intellij.ui.EditorNotifications | ||
|
||
class GitlabLintNotificationProvider : EditorNotifications.Provider<EditorNotificationPanel>() { | ||
|
||
companion object { | ||
private val KEY = Key.create<EditorNotificationPanel>("GitlabLintNotificationProvider") | ||
} | ||
|
||
override fun getKey(): Key<EditorNotificationPanel> = KEY | ||
|
||
override fun createNotificationPanel( | ||
file: VirtualFile, | ||
fileEditor: FileEditor, | ||
project: Project | ||
): EditorNotificationPanel? { | ||
|
||
val gitlabRunner = project.service<GitlabLintRunner>() | ||
|
||
if (gitlabRunner.status == LintStatusEnum.INVALID && matchesGitlabLintRegex(file.name)) { | ||
val panel = EditorNotificationPanel(HintUtil.ERROR_COLOR_KEY) | ||
panel.text = gitlabRunner.gitlabLintResponse?.errors.toString() | ||
// TODO @Blarc: Implement error ignoring. | ||
// panel.createActionLabel("Ignore this error.") { | ||
// EditorNotifications.getInstance(project).updateAllNotifications() | ||
// } | ||
|
||
return panel | ||
} | ||
return null | ||
} | ||
} |
23 changes: 12 additions & 11 deletions
23
...github/blarc/gitlab/template/lint/plugin/listeners/GitlabLintFileEditorManagerListener.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