From 178e180e9c68ec7e89554c0b99a93dbb111c42b0 Mon Sep 17 00:00:00 2001 From: Kirill Dubovitskiy Date: Sat, 5 Aug 2023 01:28:20 -0700 Subject: Minor refactoring to fix up typing --- extension/src/activation/environmentSetup.ts | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index 1ca32841..7c18913a 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -1,7 +1,7 @@ import { getExtensionUri } from "../util/vscode"; -const util = require("util"); -const exec = util.promisify(require("child_process").exec); -const { spawn } = require("child_process"); +import { promisify } from "util"; +import { exec as execCb } from "child_process"; +import { spawn } from "child_process"; import * as path from "path"; import * as fs from "fs"; import { getContinueServerUrl } from "../bridge"; @@ -10,11 +10,13 @@ import * as vscode from "vscode"; import * as os from "os"; import fkill from "fkill"; import { finished } from "stream/promises"; -const request = require("request"); +import * as request from "request"; + +const exec = promisify(execCb); async function runCommand(cmd: string): Promise<[string, string | undefined]> { - var stdout: any = ""; - var stderr: any = ""; + var stdout = ""; + var stderr = ""; try { var { stdout, stderr } = await exec(cmd, { shell: process.platform === "win32" ? "powershell.exe" : undefined, @@ -23,14 +25,9 @@ async function runCommand(cmd: string): Promise<[string, string | undefined]> { stderr = e.stderr; stdout = e.stdout; } - if (stderr === "") { - stderr = undefined; - } - if (typeof stdout === "undefined") { - stdout = ""; - } - return [stdout, stderr]; + const stderrOrUndefined = stderr === "" ? undefined : stderr; + return [stdout, stderrOrUndefined]; } async function checkServerRunning(serverUrl: string): Promise { -- cgit v1.2.3-70-g09d2 From 57139952995014ec154e5190a932c32f180aa5dc Mon Sep 17 00:00:00 2001 From: Kirill Dubovitskiy Date: Sat, 5 Aug 2023 02:15:20 -0700 Subject: Initial stab at adding more launch configurations --- .vscode/launch.json | 31 ++++++++++++++++++++++++++----- .vscode/tasks.json | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ extension/src/bridge.ts | 11 ++++------- 3 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json index cc7b1ce4..f6a37bed 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,13 +5,34 @@ "version": "0.2.0", "configurations": [ { - "name": "Python: Module", + "name": "Server", "type": "python", "request": "launch", "module": "continuedev.src.continuedev.server.main", - "args": ["--port", "8001"], + "args": [ + "--port", + "8001" + ], "justMyCode": false, - "subProcess": false - } + "subProcess": false, + // Does it need a build task? + // What about a watch task? - type errors? + }, + { + "name": "VSCode Extension", + "type": "extensionHost", + "request": "launch", + "cwd": "${workspaceFolder}/extension", + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}/extension", + ], + "outFiles": [ + "${workspaceFolder}/extension/out/**/*.js" + ], + "preLaunchTask": "vscode-extension:build-watch", + "env": { + "CONTINUE_SERVER_URL": "http://localhost:8001" + } + }, ] -} +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..aad0d2e4 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,49 @@ +// See https://go.microsoft.com/fwlink/?LinkId=733558 +// for the documentation about the tasks.json format +{ + "version": "2.0.0", + "tasks": [ + { + "label": "vscode-extension:build-watch", + "type": "npm", + "script": "esbuild-watch", + "path": "extension", + "isBackground": true, + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [ + // We rely on tsc to emit type errors in a separate task + ], + // Depends on prevents the task from running until the other task has completed, not want we want + // does not start the extension + // "dependsOn": [ + // // esbuild does not emit type errors so we need a separate task for that + // // https://esbuild.github.io/content-types/#typescript + // "vscode-extension:tsc-watch" + // ] + }, + { + "label": "vscode-extension:tsc-watch", + "type": "npm", + "script": "watch", + "path": "extension", + "isBackground": true, + "problemMatcher": [ + "$tsc-watch" + ], + // Problems are currently broken due to path resolution not being relative to the workspace root + // The way cursorless does it it by having top level package.json which is not ideal. + // Multi root workspaces would help here + "presentation": { + "revealProblems": "onProblem", + "clear": true + }, + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} \ No newline at end of file diff --git a/extension/src/bridge.ts b/extension/src/bridge.ts index 0d665826..e4c74771 100644 --- a/extension/src/bridge.ts +++ b/extension/src/bridge.ts @@ -1,14 +1,11 @@ import * as vscode from "vscode"; -import { extensionContext } from "./activation/activate"; export function getContinueServerUrl() { - // If in debug mode, always use 8001 - if ( - extensionContext && - extensionContext.extensionMode === vscode.ExtensionMode.Development - ) { - return "http://localhost:8001"; + // Passed in from launch.json + if (process.env.CONTINUE_SERVER_URL) { + return process.env.CONTINUE_SERVER_URL; } + return ( vscode.workspace.getConfiguration("continue").get("serverUrl") || "http://localhost:65432" -- cgit v1.2.3-70-g09d2 From 1598a614b248085d16006b79cd55f6fbce4d6bf5 Mon Sep 17 00:00:00 2001 From: Kirill Dubovitskiy Date: Sun, 6 Aug 2023 18:31:52 -0700 Subject: Fixed up broken script for installing extension built locally - we can probably just kill this code --- extension/scripts/install_from_source.py | 35 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/extension/scripts/install_from_source.py b/extension/scripts/install_from_source.py index 5e16bf21..cd8f5cde 100644 --- a/extension/scripts/install_from_source.py +++ b/extension/scripts/install_from_source.py @@ -1,3 +1,5 @@ +# Run from extension/scripts directory + import os import subprocess @@ -5,23 +7,22 @@ import subprocess def run(cmd: str): return subprocess.run(cmd, shell=True, capture_output=False) - def get_latest_version() -> str: - latest = None - latest_major = 0 - latest_minor = 0 - latest_patch = 0 - for file in os.listdir("../build"): - if file.endswith(".vsix"): - version = file.split("-")[1].split(".vsix")[0] - major, minor, patch = list( - map(lambda x: int(x), version.split("."))) - if latest is None or (major >= latest_major and minor >= latest_minor and patch > latest_patch): - latest = file - latest_major = major - latest_minor = minor - latest_patch = patch - + # Ensure build directory exists + if not os.path.exists("../build"): + os.mkdir("../build") + + def version_tuple(filename): + version = filename.split("-")[1].split(".vsix")[0] + return tuple(map(int, version.split("."))) + + versions = [file for file in os.listdir("../build") if file.endswith(".vsix")] + + # Ensure we have at least one version + if len(versions) == 0: + return None + + return max(versions, key=version_tuple) def main(): # Clear out old stuff @@ -62,7 +63,7 @@ def main(): latest = get_latest_version() resp = run(f"cd ..; code --install-extension ./build/{latest}") - + print("Continue VS Code extension installed successfully. Please restart VS Code to use it.") -- cgit v1.2.3-70-g09d2 From 400d1da490dab08a9b2ef2c88ab842ae5bc75620 Mon Sep 17 00:00:00 2001 From: Kirill Dubovitskiy Date: Sun, 6 Aug 2023 18:48:30 -0700 Subject: Added a launch configuration to start debugging both server + extension --- .gitignore | 1 - .vscode/launch.json | 14 ++++++- .vscode/settings.json | 3 ++ .vscode/tasks.json | 61 ++++++++++++++++------------ extension/package.json | 12 +++--- extension/src/activation/environmentSetup.ts | 2 +- 6 files changed, 57 insertions(+), 36 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 8f403dfe..ad37b017 100644 --- a/.gitignore +++ b/.gitignore @@ -131,7 +131,6 @@ dmypy.json **/node_modules **/out -**/.vscode/settings.json notes.txt cached_embeddings.pkl .ruff_cache diff --git a/.vscode/launch.json b/.vscode/launch.json index f6a37bed..2c7d1a27 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -3,6 +3,16 @@ // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", + "compounds": [ + { + "name": "Server + Extension (VSCode)", + "stopAll": true, + "configurations": [ + "Server", + "Extension (VSCode)" + ] + } + ], "configurations": [ { "name": "Server", @@ -19,7 +29,7 @@ // What about a watch task? - type errors? }, { - "name": "VSCode Extension", + "name": "Extension (VSCode)", "type": "extensionHost", "request": "launch", "cwd": "${workspaceFolder}/extension", @@ -29,7 +39,7 @@ "outFiles": [ "${workspaceFolder}/extension/out/**/*.js" ], - "preLaunchTask": "vscode-extension:build-watch", + "preLaunchTask": "vscode-extension:build", "env": { "CONTINUE_SERVER_URL": "http://localhost:8001" } diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..2195200a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.defaultInterpreterPath": "${workspaceFolder}/continuedev/.venv/bin/python", +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index aad0d2e4..3b6b62e8 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,44 +1,53 @@ -// See https://go.microsoft.com/fwlink/?LinkId=733558 -// for the documentation about the tasks.json format { "version": "2.0.0", "tasks": [ { - "label": "vscode-extension:build-watch", - "type": "npm", - "script": "esbuild-watch", - "path": "extension", - "isBackground": true, + "label": "vscode-extension:build", + "dependsOn": [ + // To detect compile errors + "vscode-extension:tsc", + // To bundle the code the same way we do for publishing + "vscode-extension:esbuild" + ], "group": { "kind": "build", "isDefault": true - }, - "problemMatcher": [ - // We rely on tsc to emit type errors in a separate task - ], - // Depends on prevents the task from running until the other task has completed, not want we want - // does not start the extension - // "dependsOn": [ - // // esbuild does not emit type errors so we need a separate task for that - // // https://esbuild.github.io/content-types/#typescript - // "vscode-extension:tsc-watch" - // ] + } }, { - "label": "vscode-extension:tsc-watch", + "label": "vscode-extension:esbuild", "type": "npm", - "script": "watch", + "script": "esbuild", "path": "extension", - "isBackground": true, "problemMatcher": [ - "$tsc-watch" + { + "pattern": [ + { + "regexp": "> (.*?):([0-9]+):([0-9]+): (warning|error): (.+)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + ], + } + ], + }, + // Tsc currently errors out due to testing setup issues, will be resolved in a different PR + // This will be useful for preventing debugging if there are compile errors + { + "label": "vscode-extension:tsc", + "type": "shell", + "command": "echo lol", + // "script": "tsc", + // "path": "extension", + "problemMatcher": [ + "$tsc" ], - // Problems are currently broken due to path resolution not being relative to the workspace root - // The way cursorless does it it by having top level package.json which is not ideal. - // Multi root workspaces would help here "presentation": { "revealProblems": "onProblem", - "clear": true + "clear": true, }, "group": { "kind": "build", diff --git a/extension/package.json b/extension/package.json index 26998ec9..59a8d9df 100644 --- a/extension/package.json +++ b/extension/package.json @@ -185,17 +185,17 @@ "scripts": { "vscode:prepublish": "npm run esbuild-base -- --minify", "esbuild-base": "rm -rf ./out && esbuild ./src/extension.ts --bundle --outfile=out/extension.js --external:vscode --format=cjs --platform=node", - "esbuild": "rm -rf ./out && node esbuild.mjs", + "esbuild": "npm run esbuild-base -- --sourcemap", "esbuild-watch": "npm run esbuild-base -- --sourcemap --watch", - "test-compile": "tsc -p ./", + "tsc": "tsc -p ./", + "tsc-watch": "tsc -watch -p ./", + "typegen": "node scripts/typegen.js", "clientgen": "rm -rf src/client/ && npx @openapitools/openapi-generator-cli generate -i ../schema/openapi.json -g typescript-fetch -o src/client/ --additional-properties=supportsES6=true,npmVersion=8.19.2,typescriptThreePlus=true", "rebuild": "electron-rebuild -v 19.1.8 node-pty", - "watch": "tsc -watch -p ./", - "pretest": "npm run compile && npm run lint", + "pretest": "npm run build && npm run lint", "lint": "eslint src --ext ts", "test": "node ./out/test/runTest.js", "jest": "jest --config ./jest.config.js", - "typegen": "node scripts/typegen.js", "package": "npm install && npm run typegen && npm run clientgen && cd react-app && npm install && npm run build && cd .. && mkdir -p ./build && vsce package --out ./build" }, "devDependencies": { @@ -244,4 +244,4 @@ "optionalDependencies": { "@esbuild/android-arm": "^0.18.17" } -} +} \ No newline at end of file diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index 7c18913a..c8e8b85f 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -10,7 +10,7 @@ import * as vscode from "vscode"; import * as os from "os"; import fkill from "fkill"; import { finished } from "stream/promises"; -import * as request from "request"; +import request = require("request"); const exec = promisify(execCb); -- cgit v1.2.3-70-g09d2 From c3723a132f5c45adb765301b7854ca6b4b6ce82c Mon Sep 17 00:00:00 2001 From: Kirill Dubovitskiy Date: Sun, 6 Aug 2023 18:49:50 -0700 Subject: Added a task to install all dependencies from top level without having to figure out commands in multiple sub projects. Developers should run this before the first debugging session and anytime they pull --- .vscode/tasks.json | 12 +++++++----- continuedev/install-dependencies.sh | 16 ++++++++++++++++ install-dependencies.sh | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100755 continuedev/install-dependencies.sh create mode 100755 install-dependencies.sh diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 3b6b62e8..808b6d1f 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -49,10 +49,12 @@ "revealProblems": "onProblem", "clear": true, }, - "group": { - "kind": "build", - "isDefault": true - } - } + }, + // Install or update all dependencies for all projects in the monrepo + { + "label": "install-all-dependencies", + "type": "shell", + "command": "./install-dependencies.sh", + }, ] } \ No newline at end of file diff --git a/continuedev/install-dependencies.sh b/continuedev/install-dependencies.sh new file mode 100755 index 00000000..8f1b5d27 --- /dev/null +++ b/continuedev/install-dependencies.sh @@ -0,0 +1,16 @@ + +#!/bin/bash + +# Check if Poetry is installed +if ! command -v poetry &> /dev/null +then + echo "Poetry not found, installing..." + curl -sSL https://install.python-poetry.org | python3 - +fi + +# Install or update dependencies & create .venv if it doesn't exist +echo "Installing dependencies..." +poetry install + +echo "Running type generation..." +poetry run typegen diff --git a/install-dependencies.sh b/install-dependencies.sh new file mode 100755 index 00000000..a913f971 --- /dev/null +++ b/install-dependencies.sh @@ -0,0 +1,18 @@ + +#!/bin/bash +# This is used in a task in .vscode/tasks.json +# Start developing with: +# - Run Task -> Install Dependencies +# - Debug -> Server + Extension + +# Server +echo "Installing server dependencies..." +pushd continuedev || exit +./install-dependencies.sh +popd || exit + +# VSCode Extension (will also package GUI) +echo "Installing VSCode extension dependencies..." +pushd extension || exit +# This does way too many things inline but is the common denominator between many of the scripts +npm run package \ No newline at end of file -- cgit v1.2.3-70-g09d2 From a387ba0d3b4987c5f6603744515004e8c9a6e87b Mon Sep 17 00:00:00 2001 From: Kirill Dubovitskiy Date: Sun, 6 Aug 2023 21:24:48 -0700 Subject: Forgot to update build script name --- extension/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/package.json b/extension/package.json index 59a8d9df..5bae8f05 100644 --- a/extension/package.json +++ b/extension/package.json @@ -192,7 +192,7 @@ "typegen": "node scripts/typegen.js", "clientgen": "rm -rf src/client/ && npx @openapitools/openapi-generator-cli generate -i ../schema/openapi.json -g typescript-fetch -o src/client/ --additional-properties=supportsES6=true,npmVersion=8.19.2,typescriptThreePlus=true", "rebuild": "electron-rebuild -v 19.1.8 node-pty", - "pretest": "npm run build && npm run lint", + "pretest": "npm run tsc && npm run lint", "lint": "eslint src --ext ts", "test": "node ./out/test/runTest.js", "jest": "jest --config ./jest.config.js", -- cgit v1.2.3-70-g09d2 From 915199ac6aa5fa0fa2ccb1f9239c2ca1f84e03be Mon Sep 17 00:00:00 2001 From: Kirill Dubovitskiy Date: Mon, 7 Aug 2023 00:07:30 -0700 Subject: Touchup on esbuild configuration + installing depdencies --- .vscode/tasks.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 808b6d1f..64e18f28 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -55,6 +55,7 @@ "label": "install-all-dependencies", "type": "shell", "command": "./install-dependencies.sh", + "problemMatcher": [], // Empty so users are not promted to select progress reporting }, ] } \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 0d1963628c7a5f998aeaf1cf63d8abab2e8923ea Mon Sep 17 00:00:00 2001 From: Kirill Dubovitskiy Date: Mon, 7 Aug 2023 00:22:58 -0700 Subject: Using esbuild.mjs for configuration Added example directory with a typescript program and open it by default in the extension host - its nice to have an isolated environment where the extension can be played with. You can always open an actual project folder if you want to --- .vscode/launch.json | 1 + extension/manual-testing-sandbox/example.ts | 3 +++ extension/manual-testing-sandbox/readme.md | 3 +++ extension/package.json | 2 +- 4 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 extension/manual-testing-sandbox/example.ts create mode 100644 extension/manual-testing-sandbox/readme.md diff --git a/.vscode/launch.json b/.vscode/launch.json index 2c7d1a27..c598750f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -34,6 +34,7 @@ "request": "launch", "cwd": "${workspaceFolder}/extension", "args": [ + "${workspaceFolder}/extension/manual-testing-sandbox", "--extensionDevelopmentPath=${workspaceFolder}/extension", ], "outFiles": [ diff --git a/extension/manual-testing-sandbox/example.ts b/extension/manual-testing-sandbox/example.ts new file mode 100644 index 00000000..0633beaf --- /dev/null +++ b/extension/manual-testing-sandbox/example.ts @@ -0,0 +1,3 @@ +function mergeSortAlgorithm() { + // TODO: implement +} \ No newline at end of file diff --git a/extension/manual-testing-sandbox/readme.md b/extension/manual-testing-sandbox/readme.md new file mode 100644 index 00000000..5b25d31e --- /dev/null +++ b/extension/manual-testing-sandbox/readme.md @@ -0,0 +1,3 @@ +The sole purpose of this folder is to open it when debugging the extension. +It is not used by the extension itself. +You can add more files that can be useful when manually testing the extension. \ No newline at end of file diff --git a/extension/package.json b/extension/package.json index 5bae8f05..c30b3aa9 100644 --- a/extension/package.json +++ b/extension/package.json @@ -183,8 +183,8 @@ ] }, "scripts": { + "esbuild-base": "rm -rf ./out && node esbuild.mjs", "vscode:prepublish": "npm run esbuild-base -- --minify", - "esbuild-base": "rm -rf ./out && esbuild ./src/extension.ts --bundle --outfile=out/extension.js --external:vscode --format=cjs --platform=node", "esbuild": "npm run esbuild-base -- --sourcemap", "esbuild-watch": "npm run esbuild-base -- --sourcemap --watch", "tsc": "tsc -p ./", -- cgit v1.2.3-70-g09d2