@@ -8,7 +8,6 @@ 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.psi.PsiDocumentManager
1211import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.isCodeWhispererEnabled
1312import software.aws.toolkits.jetbrains.services.codewhisperer.language.programmingLanguage
1413import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererInvocationStatus
@@ -17,27 +16,26 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.telemetry.CodeWhis
1716class CodeWhispererEditorListener : EditorFactoryListener {
1817 override fun editorCreated (event : EditorFactoryEvent ) {
1918 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- }
19+ val project = editor.project ? : return
20+
21+ val language = editor.virtualFile.programmingLanguage()
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+ )
4240 }
4341}
0 commit comments