diff options
Diffstat (limited to 'extension/src')
| -rw-r--r-- | extension/src/activation/activate.ts | 2 | ||||
| -rw-r--r-- | extension/src/activation/environmentSetup.ts | 8 | ||||
| -rw-r--r-- | extension/src/bridge.ts | 6 | ||||
| -rw-r--r-- | extension/src/commands.ts | 7 | ||||
| -rw-r--r-- | extension/src/diffs.ts | 46 | ||||
| -rw-r--r-- | extension/src/lang-server/codeActions.ts | 55 | ||||
| -rw-r--r-- | extension/src/suggestions.ts | 60 | 
7 files changed, 119 insertions, 65 deletions
| diff --git a/extension/src/activation/activate.ts b/extension/src/activation/activate.ts index cd885b12..5c6ffa02 100644 --- a/extension/src/activation/activate.ts +++ b/extension/src/activation/activate.ts @@ -10,6 +10,7 @@ import {    startContinuePythonServer,  } from "./environmentSetup";  import fetch from "node-fetch"; +import registerQuickFixProvider from "../lang-server/codeActions";  // import { CapturedTerminal } from "../terminal/terminalEmulator";  const PACKAGE_JSON_RAW_GITHUB_URL = @@ -55,6 +56,7 @@ export async function activateExtension(context: vscode.ExtensionContext) {    sendTelemetryEvent(TelemetryEvent.ExtensionActivated);    registerAllCodeLensProviders(context);    registerAllCommands(context); +  registerQuickFixProvider();    // Initialize IDE Protocol Client    const serverUrl = getContinueServerUrl(); diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index df609a34..69a3b75a 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -400,6 +400,14 @@ function serverPath(): string {    return sPath;  } +export function devDataPath(): string { +  const sPath = path.join(getContinueGlobalPath(), "dev_data"); +  if (!fs.existsSync(sPath)) { +    fs.mkdirSync(sPath); +  } +  return sPath; +} +  function serverVersionPath(): string {    return path.join(serverPath(), "server_version.txt");  } diff --git a/extension/src/bridge.ts b/extension/src/bridge.ts index 7e6398be..d614ace4 100644 --- a/extension/src/bridge.ts +++ b/extension/src/bridge.ts @@ -1,11 +1,7 @@  import fetch from "node-fetch";  import * as path from "path";  import * as vscode from "vscode"; -import { -  Configuration, -  DebugApi, -  UnittestApi, -} from "./client"; +import { Configuration, DebugApi, UnittestApi } from "./client";  import { convertSingleToDoubleQuoteJSON } from "./util/util";  import { getExtensionUri } from "./util/vscode";  import { extensionContext } from "./activation/activate"; diff --git a/extension/src/commands.ts b/extension/src/commands.ts index 888f01ed..2b7f4c0c 100644 --- a/extension/src/commands.ts +++ b/extension/src/commands.ts @@ -34,6 +34,13 @@ const commandsMap: { [command: string]: (...args: any) => any } = {    "continue.rejectDiff": rejectDiffCommand,    "continue.acceptAllSuggestions": acceptAllSuggestionsCommand,    "continue.rejectAllSuggestions": rejectAllSuggestionsCommand, +  "continue.quickFix": async (message: string, code: string, edit: boolean) => { +    ideProtocolClient.sendMainUserInput( +      `${ +        edit ? "/edit " : "" +      }${code}\n\nHow do I fix this problem in the above code?: ${message}` +    ); +  },    "continue.focusContinueInput": async () => {      if (focusedOnContinueInput) {        vscode.commands.executeCommand("workbench.action.focusActiveEditorGroup"); diff --git a/extension/src/diffs.ts b/extension/src/diffs.ts index 2860258d..0bab326a 100644 --- a/extension/src/diffs.ts +++ b/extension/src/diffs.ts @@ -4,6 +4,7 @@ import * as fs from "fs";  import * as vscode from "vscode";  import { extensionContext, ideProtocolClient } from "./activation/activate";  import { getMetaKeyLabel } from "./util/util"; +import { devDataPath } from "./activation/environmentSetup";  interface DiffInfo {    originalFilepath: string; @@ -13,7 +14,9 @@ interface DiffInfo {    range: vscode.Range;  } -export const DIFF_DIRECTORY = path.join(os.homedir(), ".continue", "diffs").replace(/^C:/, "c:"); +export const DIFF_DIRECTORY = path +  .join(os.homedir(), ".continue", "diffs") +  .replace(/^C:/, "c:");  class DiffManager {    // Create a temporary file in the global .continue directory which displays the updated version @@ -222,6 +225,8 @@ class DiffManager {          );          this.cleanUpDiff(diffInfo);        }); + +    recordAcceptReject(true, diffInfo);    }    rejectDiff(newFilepath?: string) { @@ -251,11 +256,50 @@ class DiffManager {        .then(() => {          this.cleanUpDiff(diffInfo);        }); + +    recordAcceptReject(false, diffInfo);    }  }  export const diffManager = new DiffManager(); +function recordAcceptReject(accepted: boolean, diffInfo: DiffInfo) { +  const collectOn = vscode.workspace +    .getConfiguration("continue") +    .get<boolean>("dataSwitch"); + +  if (collectOn) { +    const devDataDir = devDataPath(); +    const suggestionsPath = path.join(devDataDir, "suggestions.json"); + +    // Initialize suggestions list +    let suggestions = []; + +    // Check if suggestions.json exists +    if (fs.existsSync(suggestionsPath)) { +      const rawData = fs.readFileSync(suggestionsPath, "utf-8"); +      suggestions = JSON.parse(rawData); +    } + +    // Add the new suggestion to the list +    suggestions.push({ +      accepted, +      timestamp: Date.now(), +      suggestion: diffInfo.originalFilepath, +    }); + +    // Send the suggestion to the server +    ideProtocolClient.sendAcceptRejectSuggestion(accepted); + +    // Write the updated suggestions back to the file +    fs.writeFileSync( +      suggestionsPath, +      JSON.stringify(suggestions, null, 4), +      "utf-8" +    ); +  } +} +  export async function acceptDiffCommand(newFilepath?: string) {    diffManager.acceptDiff(newFilepath);    ideProtocolClient.sendAcceptRejectDiff(true); diff --git a/extension/src/lang-server/codeActions.ts b/extension/src/lang-server/codeActions.ts new file mode 100644 index 00000000..f0d61ace --- /dev/null +++ b/extension/src/lang-server/codeActions.ts @@ -0,0 +1,55 @@ +import * as vscode from "vscode"; + +class ContinueQuickFixProvider implements vscode.CodeActionProvider { +  public static readonly providedCodeActionKinds = [ +    vscode.CodeActionKind.QuickFix, +  ]; + +  provideCodeActions( +    document: vscode.TextDocument, +    range: vscode.Range | vscode.Selection, +    context: vscode.CodeActionContext, +    token: vscode.CancellationToken +  ): vscode.ProviderResult<(vscode.Command | vscode.CodeAction)[]> { +    if (context.diagnostics.length === 0) { +      return []; +    } + +    const createQuickFix = (edit: boolean) => { +      const diagnostic = context.diagnostics[0]; +      const quickFix = new vscode.CodeAction( +        edit ? "Fix with Continue" : "Ask Continue", +        vscode.CodeActionKind.QuickFix +      ); +      quickFix.isPreferred = false; +      const surroundingRange = new vscode.Range( +        Math.max(0, range.start.line - 3), +        0, +        Math.min(document.lineCount, range.end.line + 3), +        0 +      ); +      quickFix.command = { +        command: "continue.quickFix", +        title: "Continue Quick Fix", +        arguments: [ +          diagnostic.message, +          document.getText(surroundingRange), +          edit, +        ], +      }; +      return quickFix; +    }; +    return [createQuickFix(true), createQuickFix(false)]; +  } +} + +export default function registerQuickFixProvider() { +  // In your extension's activate function: +  vscode.languages.registerCodeActionsProvider( +    { language: "*" }, +    new ContinueQuickFixProvider(), +    { +      providedCodeActionKinds: ContinueQuickFixProvider.providedCodeActionKinds, +    } +  ); +} diff --git a/extension/src/suggestions.ts b/extension/src/suggestions.ts index 6e5a444f..c2373223 100644 --- a/extension/src/suggestions.ts +++ b/extension/src/suggestions.ts @@ -1,9 +1,7 @@  import * as vscode from "vscode";  import { sendTelemetryEvent, TelemetryEvent } from "./telemetry";  import { openEditorAndRevealRange } from "./util/vscode"; -import { translate, readFileAtRange } from "./util/vscode"; -import * as fs from "fs"; -import * as path from "path"; +import { translate } from "./util/vscode";  import { registerAllCodeLensProviders } from "./lang-server/codeLens";  import { extensionContext, ideProtocolClient } from "./activation/activate"; @@ -214,62 +212,6 @@ function selectSuggestion(          : suggestion.newRange;    } -  let workspaceDir = vscode.workspace.workspaceFolders -    ? vscode.workspace.workspaceFolders[0]?.uri.fsPath -    : undefined; - -  let collectOn = vscode.workspace -    .getConfiguration("continue") -    .get<boolean>("dataSwitch"); - -  if (workspaceDir && collectOn) { -    let continueDir = path.join(workspaceDir, ".continue"); - -    // Check if .continue directory doesn't exists -    if (!fs.existsSync(continueDir)) { -      fs.mkdirSync(continueDir); -    } - -    let suggestionsPath = path.join(continueDir, "suggestions.json"); - -    // Initialize suggestions list -    let suggestions = []; - -    // Check if suggestions.json exists -    if (fs.existsSync(suggestionsPath)) { -      let rawData = fs.readFileSync(suggestionsPath, "utf-8"); -      suggestions = JSON.parse(rawData); -    } - -    const accepted = -      accept === "new" || (accept === "selected" && suggestion.newSelected); -    suggestions.push({ -      accepted, -      timestamp: Date.now(), -      suggestion: suggestion.newContent, -    }); -    ideProtocolClient.sendAcceptRejectSuggestion(accepted); - -    // Write the updated suggestions back to the file -    fs.writeFileSync( -      suggestionsPath, -      JSON.stringify(suggestions, null, 4), -      "utf-8" -    ); - -    // If it's not already there, add .continue to .gitignore -    const gitignorePath = path.join(workspaceDir, ".gitignore"); -    if (fs.existsSync(gitignorePath)) { -      const gitignoreData = fs.readFileSync(gitignorePath, "utf-8"); -      const gitIgnoreLines = gitignoreData.split("\n"); -      if (!gitIgnoreLines.includes(".continue")) { -        fs.appendFileSync(gitignorePath, "\n.continue\n"); -      } -    } else { -      fs.writeFileSync(gitignorePath, ".continue\n"); -    } -  } -    rangeToDelete = new vscode.Range(      rangeToDelete.start,      new vscode.Position(rangeToDelete.end.line, 0) | 
