Skip to content

Commit

Permalink
fix: Resolved errors related to incorrect URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
lkk214 committed Dec 26, 2024
1 parent 3df34b7 commit 0a7da20
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -162,7 +162,7 @@ class ContinuePluginStartupActivity : StartupActivity, DumbAware {
override fun after(events: List<VFileEvent>) {
// Collect all relevant URIs for deletions
val deletedURIs = events.filterIsInstance<VFileDeleteEvent>()
.map { event -> event.file.url }
.mapNotNull { event -> event.file.toUriOrNull() }

// Send "files/deleted" message if there are any deletions
if (deletedURIs.isNotEmpty()) {
Expand All @@ -172,7 +172,7 @@ class ContinuePluginStartupActivity : StartupActivity, DumbAware {

// Collect all relevant URIs for content changes
val changedURIs = events.filterIsInstance<VFileContentChangeEvent>()
.map { event -> event.file.url }
.mapNotNull { event -> event.file.toUriOrNull() }

// Send "files/changed" message if there are any content changes
if (changedURIs.isNotEmpty()) {
Expand Down Expand Up @@ -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) } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -307,16 +308,16 @@ class IntelliJIDE(

override suspend fun getOpenFiles(): List<String> {
val fileEditorManager = FileEditorManager.getInstance(project)
return fileEditorManager.openFiles.map { it.url }.toList()
return fileEditorManager.openFiles.mapNotNull { it.toUriOrNull() }.toList()
}

override suspend fun getCurrentFile(): Map<String, Any>? {
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
)
Expand Down Expand Up @@ -382,7 +383,7 @@ class IntelliJIDE(

problems.add(
Problem(
filepath = psiFile.virtualFile?.url ?: "",
filepath = psiFile.virtualFile?.toUriOrNull() ?: "",
range = Range(
start = Position(
line = startLineNumber,
Expand Down Expand Up @@ -561,6 +562,6 @@ class IntelliJIDE(
return dirs
}

return listOfNotNull(project.guessProjectDir()?.url).toTypedArray()
return listOfNotNull(project.guessProjectDir()?.toUriOrNull()).toTypedArray()
}
}
Original file line number Diff line number Diff line change
@@ -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.*
Expand Down Expand Up @@ -77,4 +78,6 @@ fun getMachineUniqueID(): String {

fun uuid(): String {
return UUID.randomUUID().toString()
}
}

fun VirtualFile.toUriOrNull(): String? = fileSystem.getNioPath(this)?.toUri()?.toString()?.removeSuffix("/")

0 comments on commit 0a7da20

Please sign in to comment.