Merge branch 'main' into nate/polish-client

This commit is contained in:
Nate 2025-02-07 20:42:41 -08:00
commit 71dce41de6
15 changed files with 69 additions and 64 deletions

View file

@ -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:

View file

@ -90,7 +90,12 @@ const getClipboardSnippets = async (
const getDiffSnippets = async (
ide: IDE,
): Promise<AutocompleteDiffSnippet[]> => {
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 {

View file

@ -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<string, string> = {
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(

View file

@ -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];

View file

@ -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<string> {
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);
}

View file

@ -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

View file

@ -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)
}
}

View file

@ -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

View file

@ -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(

View file

@ -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

View file

@ -213,7 +213,7 @@
{
"command": "continue.toggleFullScreen",
"category": "Continue",
"title": "Toggle Full Screen",
"title": "Open in new window",
"icon": "$(link-external)",
"group": "Continue"
},

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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)) {