Skip to content

Commit

Permalink
Remove line separator detection logic (#7251)
Browse files Browse the repository at this point in the history
This is now full handled by the IntelliJ components in the embeddable
compiler.
  • Loading branch information
3flex committed May 6, 2024
1 parent 60b2413 commit 0951519
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 34 deletions.
Expand Up @@ -27,21 +27,8 @@ open class KtCompiler(
}
}

fun createKtFile(@Language("kotlin") content: String, path: Path): KtFile {
val psiFile = psiFileFactory.createPhysicalFile(path.name, StringUtilRt.convertLineSeparators(content))

return psiFile.apply {
val normalizedAbsolutePath = path.absolute().normalize()
this.absolutePath = normalizedAbsolutePath
virtualFile.detectedLineSeparator = content.determineLineSeparator()
fun createKtFile(@Language("kotlin") content: String, path: Path): KtFile =
psiFileFactory.createPhysicalFile(path.name, StringUtilRt.convertLineSeparators(content)).apply {
absolutePath = path.absolute().normalize()
}
}
}

internal fun String.determineLineSeparator(): String {
val i = this.lastIndexOf('\n')
if (i == -1) {
return if (this.lastIndexOf('\r') == -1) System.lineSeparator() else "\r"
}
return if (i != 0 && this[i - 1] == '\r') "\r\n" else "\n"
}
Expand Up @@ -58,22 +58,4 @@ class KtCompilerSpec {
.withMessage("$cssPath is not a Kotlin file")
}
}

@Nested
inner class `line ending detection` {
@Test
fun `detects CRLF line endings`() {
assertThat("1\r\n2".determineLineSeparator()).isEqualTo("\r\n")
}

@Test
fun `detects LF line endings`() {
assertThat("1\n2".determineLineSeparator()).isEqualTo("\n")
}

@Test
fun `detects CR line endings`() {
assertThat("1\r2".determineLineSeparator()).isEqualTo("\r")
}
}
}

0 comments on commit 0951519

Please sign in to comment.