diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt index facc894245..72819421ac 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/activities/ContinuePluginStartupActivity.kt @@ -10,7 +10,7 @@ import com.github.continuedev.continueintellijextension.listeners.ContinuePlugin import com.github.continuedev.continueintellijextension.services.ContinueExtensionSettings import com.github.continuedev.continueintellijextension.services.ContinuePluginService import com.github.continuedev.continueintellijextension.services.SettingsListener -import com.intellij.openapi.Disposable +import com.github.continuedev.continueintellijextension.utils.toUriOrNull import com.intellij.openapi.actionSystem.KeyboardShortcut import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ApplicationNamesInfo @@ -162,7 +162,7 @@ class ContinuePluginStartupActivity : StartupActivity, DumbAware { override fun after(events: List) { // Collect all relevant URIs for deletions val deletedURIs = events.filterIsInstance() - .map { event -> event.file.url } + .mapNotNull { event -> event.file.toUriOrNull() } // Send "files/deleted" message if there are any deletions if (deletedURIs.isNotEmpty()) { @@ -172,7 +172,7 @@ class ContinuePluginStartupActivity : StartupActivity, DumbAware { // Collect all relevant URIs for content changes val changedURIs = events.filterIsInstance() - .map { event -> event.file.url } + .mapNotNull { event -> event.file.toUriOrNull() } // Send "files/changed" message if there are any content changes if (changedURIs.isNotEmpty()) { @@ -220,7 +220,7 @@ class ContinuePluginStartupActivity : StartupActivity, DumbAware { // Reload the WebView continuePluginService?.let { pluginService -> val allModulePaths = ModuleManager.getInstance(project).modules - .flatMap { module -> ModuleRootManager.getInstance(module).contentRoots.map { it.url } } + .flatMap { module -> ModuleRootManager.getInstance(module).contentRoots.mapNotNull { it.toUriOrNull() } } val topLevelModulePaths = allModulePaths .filter { modulePath -> allModulePaths.none { it != modulePath && modulePath.startsWith(it) } } diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/autocomplete/AutocompleteService.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/autocomplete/AutocompleteService.kt index e7a1fb8305..2941aae8ef 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/autocomplete/AutocompleteService.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/autocomplete/AutocompleteService.kt @@ -2,6 +2,7 @@ package com.github.continuedev.continueintellijextension.autocomplete import com.github.continuedev.continueintellijextension.services.ContinueExtensionSettings import com.github.continuedev.continueintellijextension.services.ContinuePluginService +import com.github.continuedev.continueintellijextension.utils.toUriOrNull import com.github.continuedev.continueintellijextension.utils.uuid import com.intellij.injected.editor.VirtualFileWindow import com.intellij.openapi.application.* @@ -83,11 +84,14 @@ class AutocompleteService(private val project: Project) { // Request a completion from the core val virtualFile = FileDocumentManager.getInstance().getFile(editor.document) + + val uri = virtualFile?.toUriOrNull() ?: return + val line = editor.caretModel.primaryCaret.logicalPosition.line val column = editor.caretModel.primaryCaret.logicalPosition.column val input = mapOf( "completionId" to completionId, - "filepath" to virtualFile?.url, + "filepath" to uri, "pos" to mapOf( "line" to line, "character" to column diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt index 69e06e89e6..43ee85e290 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt @@ -546,12 +546,14 @@ class IdeProtocolClient( val startChar = startOffset - document.getLineStartOffset(startLine) val endChar = endOffset - document.getLineStartOffset(endLine) - return@runReadAction RangeInFileWithContents( - virtualFile.url, Range( - Position(startLine, startChar), - Position(endLine, endChar) - ), selectedText - ) + return@runReadAction virtualFile.toUriOrNull()?.let { + RangeInFileWithContents( + it, Range( + Position(startLine, startChar), + Position(endLine, endChar) + ), selectedText + ) + } } return result diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt index 154476f5e0..39d7b36812 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt @@ -5,6 +5,7 @@ import com.github.continuedev.continueintellijextension.services.ContinuePluginS import com.github.continuedev.continueintellijextension.utils.OS import com.github.continuedev.continueintellijextension.utils.getMachineUniqueID import com.github.continuedev.continueintellijextension.utils.getOS +import com.github.continuedev.continueintellijextension.utils.toUriOrNull import com.intellij.codeInsight.daemon.impl.HighlightInfo import com.intellij.execution.configurations.GeneralCommandLine import com.intellij.execution.util.ExecUtil @@ -180,7 +181,7 @@ class IntelliJIDE( for (workspaceDir in workspaceDirs) { val dir = VirtualFileManager.getInstance().findFileByUrl(workspaceDir) if (dir != null) { - val contents = dir.children.map { it.url } + val contents = dir.children.mapNotNull { it.toUriOrNull() } // Find any .continuerc.json files for (file in contents) { @@ -307,16 +308,16 @@ class IntelliJIDE( override suspend fun getOpenFiles(): List { val fileEditorManager = FileEditorManager.getInstance(project) - return fileEditorManager.openFiles.map { it.url }.toList() + return fileEditorManager.openFiles.mapNotNull { it.toUriOrNull() }.toList() } override suspend fun getCurrentFile(): Map? { val fileEditorManager = FileEditorManager.getInstance(project) val editor = fileEditorManager.selectedTextEditor val virtualFile = editor?.document?.let { FileDocumentManager.getInstance().getFile(it) } - return virtualFile?.let { + return virtualFile?.toUriOrNull()?.let { mapOf( - "path" to it.url, + "path" to it, "contents" to editor.document.text, "isUntitled" to false ) @@ -382,7 +383,7 @@ class IntelliJIDE( problems.add( Problem( - filepath = psiFile.virtualFile?.url ?: "", + filepath = psiFile.virtualFile?.toUriOrNull() ?: "", range = Range( start = Position( line = startLineNumber, @@ -561,6 +562,6 @@ class IntelliJIDE( return dirs } - return listOfNotNull(project.guessProjectDir()?.url).toTypedArray() + return listOfNotNull(project.guessProjectDir()?.toUriOrNull()).toTypedArray() } } \ No newline at end of file diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/utils/Utils.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/utils/Utils.kt index fe29b6235e..7e90ba99e9 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/utils/Utils.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/utils/Utils.kt @@ -1,5 +1,6 @@ package com.github.continuedev.continueintellijextension.utils +import com.intellij.openapi.vfs.VirtualFile import java.net.NetworkInterface import java.util.* import java.awt.event.KeyEvent.* @@ -77,4 +78,6 @@ fun getMachineUniqueID(): String { fun uuid(): String { return UUID.randomUUID().toString() -} \ No newline at end of file +} + +fun VirtualFile.toUriOrNull(): String? = fileSystem.getNioPath(this)?.toUri()?.toString()?.removeSuffix("/") \ No newline at end of file