Skip to content

Commit

Permalink
Use CustomizedDataContext instead of extended DataContext which i…
Browse files Browse the repository at this point in the history
…s now reported as "Unknown data context kind"
  • Loading branch information
timaliberdov committed Aug 7, 2024
1 parent c8b1032 commit 6c1882c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions test/org/jetbrains/plugins/hocon/HoconActionTest.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jetbrains.plugins.hocon

import com.intellij.ide.DataManager
import com.intellij.openapi.actionSystem._
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.fileEditor.{FileEditorManager, OpenFileDescriptor}
Expand Down Expand Up @@ -29,7 +30,7 @@ abstract class HoconActionTest protected(protected val actionId: String, subPath
editor.getCaretModel.moveToOffset(offset)

try {
executeAction(new MockDataContext(psiFile, editor), editor)
executeAction(mockDataContext(psiFile, editor), editor)
extractResult(psiFile, editor)
} finally {
editorManager.closeFile(psiFile.getVirtualFile)
Expand All @@ -53,12 +54,13 @@ abstract class HoconActionTest protected(protected val actionId: String, subPath

object HoconActionTest {

private class MockDataContext(file: PsiFile, editor: Editor) extends DataContext with DataProvider {
def getData(dataId: String): AnyRef = {
private def mockDataContext(file: PsiFile, editor: Editor) = {
val parentContext = DataManager.getInstance().getDataContext(editor.getComponent)
CustomizedDataContext.withProvider(parentContext, (dataId: String) => {
if (CommonDataKeys.PROJECT is dataId) file.getProject
else if (CommonDataKeys.EDITOR is dataId) editor
else null
}
})
}

}

0 comments on commit 6c1882c

Please sign in to comment.