Skip to content

Commit e476620

Browse files
committed
fix(context): fix null pointer exception in MethodContext and JSWriteTestService
- MethodContext.kt: Fixed a null pointer exception that occurred when accessing the virtual file path, language, name, and signature. - JSWriteTestService.kt: Fixed a null pointer exception that occurred when accessing the element to test and the test file path.
1 parent ad06431 commit e476620

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

javascript/src/main/kotlin/cc/unitmesh/ide/javascript/provider/testing/JSWriteTestService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class JSWriteTestService : WriteTestService() {
3939
val language = sourceFile.language
4040
val testFilePath = Util.getTestFilePath(element)?.toString() ?: return null
4141

42-
val elementToTest = Util.getElementToTest(element) ?: return null
42+
val elementToTest = runReadAction { Util.getElementToTest(element) } ?: return null
4343
val elementName = JSPsiUtil.elementName(elementToTest) ?: return null
4444

4545
var testFile = LocalFileSystem.getInstance().findFileByPath(testFilePath)

src/main/kotlin/cc/unitmesh/devti/context/MethodContext.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class MethodContext(
2222
private val classContext: ClassContext?
2323
private val project: Project = root.project
2424

25-
2625
init {
2726
classContext = if (includeClassContext && enclosingClass != null) {
2827
ClassContextProvider(false).from(enclosingClass)
@@ -39,6 +38,7 @@ class MethodContext(
3938
}
4039

4140
var query = """
41+
path: ${root.containingFile?.virtualFile?.path ?: "_"}
4242
language: ${language ?: "_"}
4343
fun name: ${name ?: "_"}
4444
fun signature: ${signature ?: "_"}

0 commit comments

Comments
 (0)