Skip to content

Conversation

mohammedahmed18
Copy link
Contributor

@mohammedahmed18 mohammedahmed18 commented Aug 30, 2025

PR Type

Enhancement


Description

  • Introduce vscode-install CLI subcommand

  • Implement VSCode extension installer with progress bar

  • Invoke extension install in init command flow


Diagram Walkthrough

flowchart LR
  Parser["ArgParser"]
  InitCmd["init command"]
  VSCodeCmd["vscode-install command"]
  Parser -- "init" --> InitCmd
  Parser -- "vscode-install" --> VSCodeCmd
  InitCmd -- "run install_vscode_extension" --> VSCodeCmd
Loading

File Walkthrough

Relevant files
Enhancement
cli.py
Add VSCode install subcommand                                                       

codeflash/cli_cmds/cli.py

  • Imported install_vscode_extension in CLI
  • Added vscode-install subparser and handler
+4/-1     
cmd_init.py
Implement VSCode extension installation                                   

codeflash/cli_cmds/cmd_init.py

  • Imported shutil and progress_bar
  • Added install_vscode_extension function
  • Called installer in init_codeflash flow
+35/-1   

Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Missing Import

The install_vscode_extension function invokes click.echo but click is not imported, which will cause a NameError at runtime.

def install_vscode_extension() -> None:
    vscode_path = shutil.which("code")
    if not vscode_path:
        return

    error = ""
    with progress_bar("Installing Codeflash for VSCode…"):
        try:
            result = subprocess.run(
                [vscode_path, "--install-extension", "codeflash.codeflash", "--force"],
                check=True,
                text=True,
                timeout=60,
                capture_output=True,
            )
        except subprocess.TimeoutExpired:
            error = "Installation timed out."
        except subprocess.CalledProcessError as e:
            error = e.stderr or "Unknown error."

    if error:
        click.echo("❌ Failed to install Codeflash for VSCode.")
        click.echo(error.strip())
    else:
        output = (result.stdout or "").lower()
        if "already installed" in output:
            click.echo("✅ Codeflash for VSCode is already installed.")
            return
        click.echo("✅ Installed the latest version of Codeflash for VSCode.")
Silent Skip

If the VSCode CLI (code) is not found (vscode_path is None), the function returns silently without informing the user. Consider logging or echoing a warning so users know why the extension wasn't installed.

vscode_path = shutil.which("code")
if not vscode_path:
    return

error = ""

Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Use console for output

Replace raw click.echo calls with the existing console to ensure consistent output
handling and avoid undefined references. Use styled output for clarity.

codeflash/cli_cmds/cmd_init.py [829-830]

-click.echo("❌ Failed to install Codeflash for VSCode.")
-click.echo(error.strip())
+console.print("[red]❌ Failed to install Codeflash for VSCode.[/]")
+console.print(f"[red]{error.strip()}[/]")
Suggestion importance[1-10]: 6

__

Why: The raw click.echo calls skip styled output and diverge from existing console usage; replacing them with console.print ensures consistency and improves UX.

Low
Notify missing VSCode CLI

Notify the user when the VSCode CLI isn't found before returning, to avoid silent
failures. Use console.print for consistency.

codeflash/cli_cmds/cmd_init.py [809-811]

 vscode_path = shutil.which("code")
 if not vscode_path:
+    console.print("[yellow]⚠️ VSCode CLI not found; skipping extension installation.[/]")
     return
Suggestion importance[1-10]: 6

__

Why: Silently returning when the VSCode CLI is missing can confuse users; adding a console.print warning enhances feedback and aligns with existing logging.

Low

error = e.stderr or "Unknown error."

if error:
click.echo("❌ Failed to install Codeflash for VSCode.")
Copy link
Contributor

@Saga4 Saga4 Aug 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than failed msg, we can suggest user to install VSC extension and error msg can go to our telemetry for our own logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 👍

@mohammedahmed18 mohammedahmed18 requested a review from Saga4 August 30, 2025 21:17
@@ -802,6 +805,41 @@ def install_github_actions(override_formatter_check: bool = False) -> None: # n
apologize_and_exit()


def install_vscode_extension() -> None:
vscode_path = shutil.which("code")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does vscode automatically install the "code" cli or does the user have to install it manually by following this step?
my question is that is it justified to always assume that code exists? If not , is there a more robust way to discover the installation?

Copy link
Contributor Author

@mohammedahmed18 mohammedahmed18 Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on linux systems, if you use your package manager like apt or pacman ...
you will get the cli in your path without doing extra step.

for macos users they need to add it to their path manually after the installation
https://code.visualstudio.com/docs/setup/mac#_configure-the-path-with-vs-code

another workaround, without using the cli is to manually download the vsix file, unzip it, place it in the vscode installation path, in linux it would be:

  • ~/.vscode/extensions (official vscode)
  • ~/.vscode-oss/extensions (codium)
  • ~/.windsurf/extensions
  • ~/.cursor/extensions
    (not sure about macos but it should be in Application Support dir)

then manually add the codeflash identifier to the extensions.json file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I guess we would need this workaround eventually specially for cursor: https://forum.cursor.com/t/command-line-list-extensions/103565/13

so I'll add this manual installation as a fallback

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but we still need to download the vsix file from somewhere, and it's a bit tricky to do that from the official marketplace, that's why we need to push this to the open vsx registery @Saga4 as they have an api for that

[vscode_path, "--install-extension", "codeflash.codeflash", "--force"],
check=True,
text=True,
timeout=60,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it really takes that much time, i am also thinking that we can run it in parallel with the other init steps and only print that successfully installed the vs code extension.
I am concerned about the blocking experience here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't the extension is around 250kb

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it takes 2 seconds to initialize the cli and install the extension

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but yeah let's run it in parallel, if we are going to manually download and and install the extension #699 (comment)

return

error = ""
with progress_bar("Installing Codeflash for VSCode…"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more thing - what if they have cursor installed? we should also support installing codeflash there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I think for cursor we would need to manually add it because the cli is not working for many people (including me) #699 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants