Skip to content

Commit

Permalink
[ #25 ] Finished.
Browse files Browse the repository at this point in the history
Closes #25.
  • Loading branch information
ice1000 committed Jan 28, 2018
1 parent 326ee66 commit 9578299
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 16 additions & 9 deletions src/org/ice1000/julia/lang/execution/julia-console-filter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package org.ice1000.julia.lang.execution

import com.intellij.execution.filters.*
import com.intellij.openapi.project.Project
import com.intellij.psi.search.GlobalSearchScope
import org.ice1000.julia.lang.JULIA_ERROR_FILE_LOCATION_REGEX
import org.ice1000.julia.lang.JULIA_STACK_FRAME_LOCATION_REGEX
import org.ice1000.julia.lang.module.projectSdk
import java.util.regex.Pattern


/*
Stack trace example:
[1] include_from_node1(::String) at ./loading.jl:576
[1] include_from_node1(::String) at ./loading.jl:576
...
while loading /home/ice1000/git-repos/big-projects/cov/cov-plugin-test/src/a.jl, in expression starting on line 8
while loading /home/ice1000/git-repos/big-projects/cov/cov-plugin-test/src/a.jl, in expression starting on line 8
*/
class JuliaConsoleFilter(private val project: Project) : Filter {
private val sdkHomeCache = project.projectSdk?.homePath
Expand All @@ -21,14 +23,16 @@ class JuliaConsoleFilter(private val project: Project) : Filter {
private val ERROR_FILE_LOCATION = Pattern.compile(JULIA_ERROR_FILE_LOCATION_REGEX)
}

private fun default(startPoint: Int, entireLength: Int) = Filter.Result(startPoint, entireLength, null)
override fun applyFilter(line: String, entireLength: Int): Filter.Result? {
val startPoint = entireLength - line.length
if (line.startsWith('[')) {
if (line.startsWith(" [")) {
val matcher = STACK_FRAME_LOCATION.matcher(line)
if (matcher.find()) {
val (path, lineNumber) = matcher.group().drop(3).split(':') // "at ".length
// val sdkHome = sdkHomeCache ?: return null
val resultFile = project.baseDir.fileSystem.findFileByPath(path) ?: return null
val resultFile = project.baseDir.fileSystem.findFileByPath(path)
?: return default(startPoint, entireLength)
return Filter.Result(
startPoint + matcher.start(),
startPoint + matcher.end(),
Expand All @@ -37,18 +41,21 @@ class JuliaConsoleFilter(private val project: Project) : Filter {
} else {
val matcher = ERROR_FILE_LOCATION.matcher(line)
if (matcher.find()) {
val resultFile = project.baseDir.fileSystem.findFileByPath(matcher.group()) ?: return null
val lineNumber = line.split(' ').lastOrNull()?.toInt() ?: return null
val resultFile = project.baseDir.fileSystem.findFileByPath(matcher.group().dropLast(1))
?: return default(startPoint, entireLength)
val lineNumber = line.split(' ').lastOrNull()?.trim()?.toIntOrNull()
?: return default(startPoint, entireLength)
return Filter.Result(
startPoint + matcher.start(),
startPoint + matcher.end(),
OpenFileHyperlinkInfo(project, resultFile, lineNumber))
OpenFileHyperlinkInfo(project, resultFile, if (lineNumber > 0) lineNumber - 1 else lineNumber))
}
}
return null
return default(startPoint, entireLength)
}
}

class JuliaConsoleFilterProvider : ConsoleFilterProvider {
class JuliaConsoleFilterProvider : ConsoleFilterProviderEx {
override fun getDefaultFilters(project: Project, scope: GlobalSearchScope) = getDefaultFilters(project)
override fun getDefaultFilters(project: Project) = arrayOf(JuliaConsoleFilter(project))
}
2 changes: 1 addition & 1 deletion src/org/ice1000/julia/lang/julia-constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.jetbrains.annotations.NonNls
@NonNls @Language("RegExp") const val JULIA_CHAR_SINGLE_UNICODE_U_REGEX = "\\\\u([A-Fa-f0-9]){4}"
@NonNls @Language("RegExp") const val JULIA_CHAR_TRIPLE_UNICODE_X_REGEX = "(\\\\x([A-Fa-f0-9]){2}){3}"
@NonNls @Language("RegExp") const val JULIA_STACK_FRAME_LOCATION_REGEX = "at ([^:])+:\\d+"
@NonNls @Language("RegExp") const val JULIA_ERROR_FILE_LOCATION_REGEX = "[^ ,]+"
@NonNls @Language("RegExp") const val JULIA_ERROR_FILE_LOCATION_REGEX = "[^ ,]+,"

@NonNls const val JULIA_DEFAULT_MODULE_NAME = "MyBizarreJuliaModule"
@NonNls const val JULIA_WEBSITE = "https://julialang.org/downloads/"
Expand Down

0 comments on commit 9578299

Please sign in to comment.