@@ -8,6 +8,7 @@ import com.intellij.openapi.editor.event.DocumentEvent
88import com.intellij.openapi.editor.event.EditorFactoryEvent
99import com.intellij.openapi.editor.event.EditorFactoryListener
1010import com.intellij.openapi.editor.impl.EditorImpl
11+ import com.intellij.openapi.vfs.findPsiFile
1112import com.intellij.psi.PsiDocumentManager
1213import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.isCodeWhispererEnabled
1314import software.aws.toolkits.jetbrains.services.codewhisperer.language.programmingLanguage
@@ -17,27 +18,26 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.telemetry.CodeWhis
1718class CodeWhispererEditorListener : EditorFactoryListener {
1819 override fun editorCreated (event : EditorFactoryEvent ) {
1920 val editor = (event.editor as ? EditorImpl ) ? : return
20- editor.project?.let { project ->
21- PsiDocumentManager .getInstance(project).getPsiFile(editor.document)?.programmingLanguage() ?. let { language ->
22- // If language is not supported by CodeWhisperer, no action needed
23- if (! language.isCodeCompletionSupported()) return
24- // If language is supported, install document listener for CodeWhisperer service
25- editor.document.addDocumentListener(
26- object : BulkAwareDocumentListener {
27- // TODO: Track only deletion changes within the current 5-min interval which will give
28- // the most accurate code percentage data.
29- override fun documentChanged (event : DocumentEvent ) {
30- if (! isCodeWhispererEnabled(project)) return
31- CodeWhispererInvocationStatus .getInstance().documentChanged()
32- CodeWhispererCodeCoverageTracker .getInstance(project, language).apply {
33- activateTrackerIfNotActive()
34- documentChanged(event)
35- }
36- }
37- },
38- editor.disposable
39- )
40- }
41- }
21+ val project = editor.project ? : return
22+
23+ val language = editor.virtualFile.programmingLanguage()
24+ // If language is not supported by CodeWhisperer, no action needed
25+ if (! language.isCodeCompletionSupported()) return
26+ // If language is supported, install document listener for CodeWhisperer service
27+ editor.document.addDocumentListener(
28+ object : BulkAwareDocumentListener {
29+ // TODO: Track only deletion changes within the current 5-min interval which will give
30+ // the most accurate code percentage data.
31+ override fun documentChanged (event : DocumentEvent ) {
32+ if (! isCodeWhispererEnabled(project)) return
33+ CodeWhispererInvocationStatus .getInstance().documentChanged()
34+ CodeWhispererCodeCoverageTracker .getInstance(project, language).apply {
35+ activateTrackerIfNotActive()
36+ documentChanged(event)
37+ }
38+ }
39+ },
40+ editor.disposable
41+ )
4242 }
4343}
0 commit comments