-
Notifications
You must be signed in to change notification settings - Fork 21
[INIT] install VSCode extension #699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
06ff851
f0f38b5
c1368e7
bcbd55d
dc22b4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import ast | ||
import os | ||
import re | ||
import shutil | ||
import subprocess | ||
import sys | ||
from enum import Enum, auto | ||
|
@@ -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 | ||
|
@@ -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})" | ||
|
@@ -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") | ||
if not vscode_path: | ||
return | ||
|
||
error = "" | ||
with progress_bar("Installing Codeflash for VSCode…"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it doesn't the extension is around 250kb There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it takes 2 seconds to initialize the cli and install the extension There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(): | ||
|
There was a problem hiding this comment.
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?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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:
(not sure about macos but it should be in Application Support dir)
then manually add the codeflash identifier to the extensions.json file.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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