Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion codeflash/cli_cmds/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from codeflash.cli_cmds import logging_config
from codeflash.cli_cmds.cli_common import apologize_and_exit
from codeflash.cli_cmds.cmd_init import init_codeflash, install_github_actions
from codeflash.cli_cmds.cmd_init import init_codeflash, install_github_actions, install_vscode_extension
from codeflash.cli_cmds.console import logger
from codeflash.code_utils import env_utils
from codeflash.code_utils.code_utils import exit_with_message
Expand All @@ -21,6 +21,9 @@ def parse_args() -> Namespace:
init_parser = subparsers.add_parser("init", help="Initialize Codeflash for a Python project.")
init_parser.set_defaults(func=init_codeflash)

install_vscode_parser = subparsers.add_parser("vscode-install", help="Install the Codeflash VSCode extension")
install_vscode_parser.set_defaults(func=install_vscode_extension)

init_actions_parser = subparsers.add_parser("init-actions", help="Initialize GitHub Actions workflow")
init_actions_parser.set_defaults(func=install_github_actions)

Expand Down
40 changes: 39 additions & 1 deletion codeflash/cli_cmds/cmd_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ast
import os
import re
import shutil
import subprocess
import sys
from enum import Enum, auto
Expand All @@ -23,7 +24,7 @@

from codeflash.api.cfapi import is_github_app_installed_on_repo
from codeflash.cli_cmds.cli_common import apologize_and_exit
from codeflash.cli_cmds.console import console, logger
from codeflash.cli_cmds.console import console, logger, progress_bar
from codeflash.code_utils.compat import LF
from codeflash.code_utils.config_parser import parse_config_file
from codeflash.code_utils.env_utils import check_formatter_installed, get_codeflash_api_key
Expand Down Expand Up @@ -98,6 +99,8 @@ def init_codeflash() -> None:

install_github_actions(override_formatter_check=True)

install_vscode_extension()

module_string = ""
if "setup_info" in locals():
module_string = f" you selected ({setup_info.module_root})"
Expand Down Expand Up @@ -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

if not vscode_path:
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)

try:
result = subprocess.run(
[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)

capture_output=True,
)
except subprocess.TimeoutExpired:
error = "Installation timed out."
except subprocess.CalledProcessError as e:
error = e.stderr or "Unknown error."

if error:
ph("vscode-extension-install-failed", {"error": error.strip()})
click.echo(
"Failed to install Codeflash for VSCode. Please try installing it manually from the Marketplace: https://marketplace.visualstudio.com/items?itemName=codeflash.codeflash"
)
click.echo(error.strip())
else:
output = (result.stdout or "").lower()
if "already installed" in output:
click.echo("✅ Codeflash for VSCode is already installed.")
return
ph("vscode-extension-installed")
click.echo("✅ Installed the latest version of Codeflash for VSCode.")


def determine_dependency_manager(pyproject_data: dict[str, Any]) -> DependencyManager: # noqa: PLR0911
"""Determine which dependency manager is being used based on pyproject.toml contents."""
if (Path.cwd() / "poetry.lock").exists():
Expand Down
Loading