diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index bd5f4b7ac..945f8d84b 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -4,6 +4,13 @@ on: release: types: [prereleased] + workflow_dispatch: + inputs: + publish_build: + description: "Whether or not to publish the built extension to the VS Code marketplace" + required: true + default: false + jobs: check_release_name: runs-on: ubuntu-latest @@ -21,7 +28,7 @@ jobs: build: needs: check_release_name - if: needs.check_release_name.outputs.should_run == 'true' + if: needs.check_release_name.outputs.should_run == 'true' || github.event_name == 'workflow_dispatch' strategy: matrix: include: @@ -197,6 +204,7 @@ jobs: runs-on: ubuntu-latest needs: - build + if: github.event.inputs.publish_build == 'true' permissions: contents: write steps: diff --git a/core/autocomplete/snippets/getAllSnippets.ts b/core/autocomplete/snippets/getAllSnippets.ts index 198bf16c6..fc6538b41 100644 --- a/core/autocomplete/snippets/getAllSnippets.ts +++ b/core/autocomplete/snippets/getAllSnippets.ts @@ -90,7 +90,12 @@ const getClipboardSnippets = async ( const getDiffSnippets = async ( ide: IDE, ): Promise => { - const diff = await ide.getDiff(true); + let diff: string[] = []; + try { + diff = await ide.getDiff(true); + } catch (e) { + console.error("Error getting diff for autocomplete", e); + } return diff.map((item) => { return { diff --git a/core/promptFiles/v1/slashCommandFromPromptFile.ts b/core/promptFiles/v1/slashCommandFromPromptFile.ts index d89ee1082..b0dc0f881 100644 --- a/core/promptFiles/v1/slashCommandFromPromptFile.ts +++ b/core/promptFiles/v1/slashCommandFromPromptFile.ts @@ -25,15 +25,20 @@ async function renderPromptV1( ) { const helpers = getContextProviderHelpers(context); - // A few context providers that don't need to be in config.json to work in .prompt files - const diff = await context.ide.getDiff(true); - const currentFile = await context.ide.getCurrentFile(); const inputData: Record = { - diff: diff.join("\n"), input: userInput, }; - if (currentFile) { - inputData.currentFile = currentFile.path; + + // A few context providers that don't need to be in config.json to work in .prompt files + if (helpers?.find((helper) => helper[0] === "diff")) { + const diff = await context.ide.getDiff(true); + inputData.diff = diff.join("\n"); + } + if (helpers?.find((helper) => helper[0] === "currentFile")) { + const currentFile = await context.ide.getCurrentFile(); + if (currentFile) { + inputData.currentFile = currentFile.path; + } } return renderTemplatedString( diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index 9cc19504d..3598e06ea 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -79,10 +79,6 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & { navigateTo: [{ path: string; toggle?: boolean }, void]; addModel: [undefined, void]; - /** - * @deprecated Use navigateTo with a path instead. - */ - viewHistory: [undefined, void]; focusContinueSessionId: [{ sessionId: string | undefined }, void]; newSession: [undefined, void]; setTheme: [{ theme: any }, void]; diff --git a/core/util/ideUtils.ts b/core/util/ideUtils.ts index 9ed4a47fc..352aad6ca 100644 --- a/core/util/ideUtils.ts +++ b/core/util/ideUtils.ts @@ -34,10 +34,11 @@ export async function resolveRelativePathInDir( If no meaninful path match just concatenates to first dir's uri */ export async function inferResolvedUriFromRelativePath( - relativePath: string, + _relativePath: string, ide: IDE, dirCandidates?: string[], ): Promise { + const relativePath = _relativePath.trim().replaceAll("\\", "/"); const dirs = dirCandidates ?? (await ide.getWorkspaceDirs()); if (dirs.length === 0) { @@ -51,7 +52,7 @@ export async function inferResolvedUriFromRelativePath( suffixes.push(segments.slice(i).join("/")); } - // For each suffix, try to find a unique matching directory + // For each suffix, try to find a unique matching dir/file for (const suffix of suffixes) { const uris = dirs.map((dir) => ({ dir, @@ -78,6 +79,13 @@ export async function inferResolvedUriFromRelativePath( } } + // Sometimes the model will decide to only output the base name or small number of path parts + // in which case we shouldn't create a new file if it matches the current file + const activeFile = await ide.getCurrentFile(); + if (activeFile && activeFile.path.endsWith(relativePath)) { + return activeFile.path; + } + // If no unique match found, use the first directory return joinPathsToUri(dirs[0], relativePath); } diff --git a/extensions/intellij/gradle.properties b/extensions/intellij/gradle.properties index 7028aa723..870baaad5 100644 --- a/extensions/intellij/gradle.properties +++ b/extensions/intellij/gradle.properties @@ -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=0.0.87 +pluginVersion=0.0.88 # 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 diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/actions/ContinuePluginActions.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/actions/ContinuePluginActions.kt index b93d294e1..8e2d34de4 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/actions/ContinuePluginActions.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/actions/ContinuePluginActions.kt @@ -113,7 +113,8 @@ class NewContinueSessionAction : AnAction() { class ViewHistoryAction : AnAction() { override fun actionPerformed(e: AnActionEvent) { val continuePluginService = getContinuePluginService(e.project) ?: return - continuePluginService.sendToWebview("viewHistory", null) + val params = mapOf("path" to "/history", "toggle" to true) + continuePluginService.sendToWebview("navigateTo", params) } } diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/autocomplete/AutocompleteEditorListener.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/autocomplete/AutocompleteEditorListener.kt index f4ef8128b..19b0dfa3a 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/autocomplete/AutocompleteEditorListener.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/autocomplete/AutocompleteEditorListener.kt @@ -3,6 +3,7 @@ package com.github.continuedev.continueintellijextension.autocomplete import com.intellij.openapi.application.invokeLater import com.intellij.openapi.components.service import com.intellij.openapi.editor.Editor +import com.intellij.openapi.editor.EditorKind import com.intellij.openapi.editor.event.* import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.openapi.fileEditor.FileEditorManagerEvent @@ -11,6 +12,10 @@ import com.intellij.openapi.util.TextRange class AutocompleteCaretListener : CaretListener { override fun caretPositionChanged(event: CaretEvent) { + if(event.editor.editorKind != EditorKind.MAIN_EDITOR) { + return + } + val caret = event.caret ?: return val offset = caret.offset val editor = caret.editor 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 efffc54ee..0e009001a 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 @@ -43,27 +43,12 @@ class IdeProtocolClient( ) } - private fun send(messageType: String, data: Any?, messageId: String? = null) { - val id = messageId ?: uuid() - continuePluginService.sendToWebview(messageType, data, id) - } - fun handleMessage(msg: String, respond: (Any?) -> Unit) { coroutineScope.launch(Dispatchers.IO) { val message = Gson().fromJson(msg, Message::class.java) val messageType = message.messageType val dataElement = message.data - // A couple oddball messages respond directly to GUI, expect a different message format - // e.g. jetbrains/isOSREnabled - fun respondToWebview(content: Any) { - respond(mutableMapOf( - "done" to true, - "status" to "success", - "content" to content - )) - } - try { when (messageType) { "toggleDevTools" -> { @@ -77,12 +62,12 @@ class IdeProtocolClient( "jetbrains/isOSREnabled" -> { val isOSREnabled = ServiceManager.getService(ContinueExtensionSettings::class.java).continueState.enableOSR - respondToWebview(isOSREnabled) + respond(isOSREnabled) } "jetbrains/getColors" -> { val colors = GetTheme().getTheme(); - respondToWebview(colors) + respond(colors) } "jetbrains/onLoad" -> { @@ -92,7 +77,7 @@ class IdeProtocolClient( "vscMachineId" to getMachineUniqueID(), "vscMediaUrl" to "http://continue", ) - respondToWebview(jsonData) + respond(jsonData) } "getIdeSettings" -> { @@ -593,11 +578,11 @@ class IdeProtocolClient( fun sendAcceptRejectDiff(accepted: Boolean, stepIndex: Int) { - send("acceptRejectDiff", AcceptRejectDiff(accepted, stepIndex), uuid()) + continuePluginService.sendToWebview("acceptRejectDiff", AcceptRejectDiff(accepted, stepIndex), uuid()) } fun deleteAtIndex(index: Int) { - send("deleteAtIndex", DeleteAtIndex(index), uuid()) + continuePluginService.sendToWebview("deleteAtIndex", DeleteAtIndex(index), uuid()) } private fun getModelByRole( diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt index 2eb9ae924..4c2ad3b59 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt @@ -53,7 +53,6 @@ class ContinueBrowser(val project: Project, url: String) { ContinuePluginService::class.java ) - val respond = fun(data: Any?) { sendToWebview(messageType, data, messageId ?: uuid()) } @@ -63,8 +62,18 @@ class ContinueBrowser(val project: Project, url: String) { return@addHandler null } + // If not pass through, then put it in the status/content/done format for webview + // Core already sends this format + val respondToWebview = fun(data: Any?) { + sendToWebview(messageType, mapOf( + "status" to "success", + "content" to data, + "done" to true + ), messageId ?: uuid()) + } + if (msg != null) { - continuePluginService.ideProtocolClient?.handleMessage(msg, respond) + continuePluginService.ideProtocolClient?.handleMessage(msg, respondToWebview) } null diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index bb45a07be..f610d5887 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -213,7 +213,7 @@ { "command": "continue.toggleFullScreen", "category": "Continue", - "title": "Toggle Full Screen", + "title": "Open in new window", "icon": "$(link-external)", "group": "Continue" }, diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 76045f196..54e84b083 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -710,7 +710,7 @@ const getCommandsMap: ( sidebar.webviewProtocol?.request("newSession", undefined); }, "continue.viewHistory": () => { - sidebar.webviewProtocol?.request("viewHistory", undefined); + vscode.commands.executeCommand("continue.navigateTo", "/history", true); }, "continue.focusContinueSessionId": async ( sessionId: string | undefined, diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index 801abfd1c..e9c12f993 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -9,6 +9,7 @@ import { focusEdit, setEditStatus } from "../redux/slices/editModeState"; import { addCodeToEdit, newSession, + selectIsInEditMode, setMode, updateApplyState, } from "../redux/slices/sessionSlice"; @@ -115,19 +116,6 @@ const Layout = () => { [navigate], ); - useWebviewListener( - "viewHistory", - async () => { - // Toggle the history page / main page - if (location.pathname === "/history") { - navigate("/"); - } else { - navigate("/history"); - } - }, - [location, navigate], - ); - useWebviewListener( "navigateTo", async (data) => { @@ -226,7 +214,11 @@ const Layout = () => { [], ); + const isInEditMode = useAppSelector(selectIsInEditMode); useWebviewListener("exitEditMode", async () => { + if (!isInEditMode) { + return; + } dispatch( loadLastSession({ saveCurrentSession: false, diff --git a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx index 45faf550a..99e449cc7 100644 --- a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx +++ b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx @@ -99,16 +99,6 @@ export default function StepContainerPreToolbar( ideMessenger.ide, ); - // Sometimes the model will decide to only output the base name - // in which case we shouldn't create a new file if it matches the current file - const exists = await ideMessenger.ide.fileExists(fileUri); - if (!exists) { - const activeFile = await ideMessenger.ide.getCurrentFile(); - if (activeFile && activeFile.path.endsWith(props.relativeFilepath)) { - fileUri = activeFile.path; - } - } - ideMessenger.post("applyToFile", { streamId: streamIdRef.current, filepath: fileUri, diff --git a/gui/src/pages/gui/StreamError.tsx b/gui/src/pages/gui/StreamError.tsx index ca3bc04bc..2a8465c30 100644 --- a/gui/src/pages/gui/StreamError.tsx +++ b/gui/src/pages/gui/StreamError.tsx @@ -51,7 +51,8 @@ const StreamErrorDialog = ({ error }: StreamErrorProps) => { typeof error["message"] === "string" ) { message = error["message"]; - const status = message?.split(" ")[0]; + const parts = message?.split(" ") ?? []; + const status = parts[0] === "HTTP" ? parts[1] : parts[0]; if (status) { const code = Number(status); if (!Number.isNaN(statusCode)) {