Skip to content

Commit

Permalink
fix(context): fix null pointer exception in MethodContext and JSWrite…
Browse files Browse the repository at this point in the history
…TestService

- 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.
  • Loading branch information
phodal committed Jan 16, 2024
1 parent ad06431 commit e476620
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Expand Up @@ -39,7 +39,7 @@ class JSWriteTestService : WriteTestService() {
val language = sourceFile.language
val testFilePath = Util.getTestFilePath(element)?.toString() ?: return null

val elementToTest = Util.getElementToTest(element) ?: return null
val elementToTest = runReadAction { Util.getElementToTest(element) } ?: return null
val elementName = JSPsiUtil.elementName(elementToTest) ?: return null

var testFile = LocalFileSystem.getInstance().findFileByPath(testFilePath)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/cc/unitmesh/devti/context/MethodContext.kt
Expand Up @@ -22,7 +22,6 @@ class MethodContext(
private val classContext: ClassContext?
private val project: Project = root.project


init {
classContext = if (includeClassContext && enclosingClass != null) {
ClassContextProvider(false).from(enclosingClass)
Expand All @@ -39,6 +38,7 @@ class MethodContext(
}

var query = """
path: ${root.containingFile?.virtualFile?.path ?: "_"}
language: ${language ?: "_"}
fun name: ${name ?: "_"}
fun signature: ${signature ?: "_"}
Expand Down

0 comments on commit e476620

Please sign in to comment.