test: ✅ add a test for URIs with authority components
This commit is contained in:
parent
ca87669416
commit
fbf9b16a2e
3 changed files with 38 additions and 21 deletions
|
|
@ -3,7 +3,7 @@ pluginGroup=com.github.continuedev.continueintellijextension
|
|||
pluginName=continue-intellij-extension
|
||||
pluginRepositoryUrl=https://github.com/continuedev/continue
|
||||
# SemVer format -> https://semver.org
|
||||
pluginVersion=1.0.16
|
||||
pluginVersion=1.0.17
|
||||
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
|
||||
pluginSinceBuild=223
|
||||
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
|
||||
|
|
|
|||
|
|
@ -110,21 +110,31 @@ class IntelliJIDE(
|
|||
}
|
||||
|
||||
companion object {
|
||||
fun uriToFile(uri: String): File {
|
||||
// This should probably just be "parseUri". Change that, update all the usages, then distribute and try it on the windows machine
|
||||
// But honestly just push it to the store to test
|
||||
fun parseUri(uri: String): URI {
|
||||
try {
|
||||
// Remove query parameters if present
|
||||
val uriWithoutQuery = if (uri.contains("?")) {
|
||||
URI(uri.substringBefore("?"))
|
||||
} else {
|
||||
URI(uri)
|
||||
val uriStr = uri.substringBefore("?")
|
||||
|
||||
// Handle Windows file paths with authority component
|
||||
if (uriStr.startsWith("file://") && !uriStr.startsWith("file:///")) {
|
||||
val path = uriStr.substringAfter("file://")
|
||||
return URI("file:///$path")
|
||||
}
|
||||
|
||||
val file = File(uriWithoutQuery)
|
||||
return file
|
||||
// Standard URI handling for other cases
|
||||
val uriWithoutQuery = URI(uriStr)
|
||||
return uriWithoutQuery
|
||||
} catch (e: Exception) {
|
||||
println("Error parsing URI: $uri ${e.message}")
|
||||
throw Exception("Invalid URI: $uri ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
fun uriToFile(uri: String): File {
|
||||
return File(parseUri(uri))
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getIdeSettings(): IdeSettings {
|
||||
|
|
@ -194,7 +204,7 @@ class IntelliJIDE(
|
|||
// Find any .continuerc.json files
|
||||
for (file in contents) {
|
||||
if (file.endsWith(".continuerc.json")) {
|
||||
val fileContent = File(URI(file)).readText()
|
||||
val fileContent = uriToFile(file).readText()
|
||||
configs.add(fileContent)
|
||||
}
|
||||
}
|
||||
|
|
@ -205,12 +215,12 @@ class IntelliJIDE(
|
|||
}
|
||||
|
||||
override suspend fun fileExists(filepath: String): Boolean {
|
||||
val file = File(URI(filepath))
|
||||
val file = uriToFile(filepath)
|
||||
return file.exists()
|
||||
}
|
||||
|
||||
override suspend fun writeFile(path: String, contents: String) {
|
||||
val file = File(URI(path))
|
||||
val file = uriToFile(path)
|
||||
file.parentFile?.mkdirs()
|
||||
file.writeText(contents)
|
||||
}
|
||||
|
|
@ -228,7 +238,7 @@ class IntelliJIDE(
|
|||
|
||||
override suspend fun openFile(path: String) {
|
||||
// Convert URI path to absolute file path
|
||||
val filePath = File(URI(path)).absolutePath
|
||||
val filePath = uriToFile(path).absolutePath
|
||||
// Find the file using the absolute path
|
||||
val file = withContext(Dispatchers.IO) {
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByPath(filePath)
|
||||
|
|
@ -253,7 +263,7 @@ class IntelliJIDE(
|
|||
|
||||
override suspend fun saveFile(filepath: String) {
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
val file = LocalFileSystem.getInstance().findFileByPath(URI(filepath).path) ?: return@invokeLater
|
||||
val file = LocalFileSystem.getInstance().findFileByPath(parseUri(filepath).path) ?: return@invokeLater
|
||||
val fileDocumentManager = FileDocumentManager.getInstance()
|
||||
val document = fileDocumentManager.getDocument(file)
|
||||
|
||||
|
|
@ -266,7 +276,7 @@ class IntelliJIDE(
|
|||
override suspend fun readFile(filepath: String): String {
|
||||
return try {
|
||||
val content = ApplicationManager.getApplication().runReadAction<String?> {
|
||||
val virtualFile = LocalFileSystem.getInstance().findFileByPath(URI(filepath).path)
|
||||
val virtualFile = LocalFileSystem.getInstance().findFileByPath(parseUri(filepath).path)
|
||||
if (virtualFile != null && FileDocumentManager.getInstance().isFileModified(virtualFile)) {
|
||||
return@runReadAction FileDocumentManager.getInstance().getDocument(virtualFile)?.text
|
||||
}
|
||||
|
|
@ -276,7 +286,7 @@ class IntelliJIDE(
|
|||
if (content != null) {
|
||||
content
|
||||
} else {
|
||||
val file = File(URI(filepath))
|
||||
val file = uriToFile(filepath)
|
||||
if (!file.exists() || file.isDirectory) return ""
|
||||
withContext(Dispatchers.IO) {
|
||||
FileInputStream(file).use { fis ->
|
||||
|
|
@ -529,7 +539,7 @@ class IntelliJIDE(
|
|||
return withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val builder = ProcessBuilder("git", "rev-parse", "--abbrev-ref", "HEAD")
|
||||
builder.directory(File(URI(dir)))
|
||||
builder.directory(uriToFile(dir))
|
||||
val process = builder.start()
|
||||
val reader = BufferedReader(InputStreamReader(process.inputStream))
|
||||
val output = reader.readLine()
|
||||
|
|
@ -559,7 +569,7 @@ class IntelliJIDE(
|
|||
|
||||
override suspend fun getRepoName(dir: String): String? {
|
||||
return withContext(Dispatchers.IO) {
|
||||
val directory = File(URI(dir))
|
||||
val directory = uriToFile(dir)
|
||||
val targetDir = if (directory.isFile) directory.parentFile else directory
|
||||
val builder = ProcessBuilder("git", "config", "--get", "remote.origin.url")
|
||||
builder.directory(targetDir)
|
||||
|
|
@ -623,7 +633,7 @@ class IntelliJIDE(
|
|||
override suspend fun getGitRootPath(dir: String): String? {
|
||||
return withContext(Dispatchers.IO) {
|
||||
val builder = ProcessBuilder("git", "rev-parse", "--show-toplevel")
|
||||
builder.directory(File(URI(dir)))
|
||||
builder.directory(uriToFile(dir))
|
||||
val process = builder.start()
|
||||
|
||||
val reader = BufferedReader(InputStreamReader(process.inputStream))
|
||||
|
|
@ -634,7 +644,7 @@ class IntelliJIDE(
|
|||
}
|
||||
|
||||
override suspend fun listDir(dir: String): List<List<Any>> {
|
||||
val files = File(URI(dir)).listFiles()?.map {
|
||||
val files = uriToFile(dir).listFiles()?.map {
|
||||
listOf(it.name, if (it.isDirectory) FileType.DIRECTORY.value else FileType.FILE.value)
|
||||
} ?: emptyList()
|
||||
|
||||
|
|
@ -643,7 +653,7 @@ class IntelliJIDE(
|
|||
|
||||
override suspend fun getFileStats(files: List<String>): Map<String, FileStats> {
|
||||
return files.associateWith { file ->
|
||||
FileStats(File(URI(file)).lastModified(), File(URI(file)).length())
|
||||
FileStats(uriToFile(file).lastModified(), uriToFile(file).length())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -661,7 +671,7 @@ class IntelliJIDE(
|
|||
}
|
||||
|
||||
private fun setFileOpen(filepath: String, open: Boolean = true) {
|
||||
val file = LocalFileSystem.getInstance().findFileByPath(URI(filepath).path)
|
||||
val file = LocalFileSystem.getInstance().findFileByPath(uriToFile(filepath).path)
|
||||
|
||||
file?.let {
|
||||
if (open) {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,13 @@ class IntelliJIDETest {
|
|||
assertEquals(File("C:/path/to/file"), file)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldHandleAuthorityComponent() {
|
||||
val uri = "file://C:/path/to/file"
|
||||
val file = IntelliJIDE.uriToFile(uri)
|
||||
assertEquals(File("/C:/path/to/file"), file)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUriToFileWithSpaces() {
|
||||
val uri = "file:///path/to/file%20with%20spaces"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue