From db6ffadd445b994117be48987ec8f8b78ce5fa54 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Fri, 5 Jan 2024 20:36:35 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Neon=20bindings=20working=20with?= =?UTF-8?q?=20VS=20Code=20extension?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/.gitignore | 1 - core/README.md | 119 ------------------- core/package.json | 9 +- extensions/vscode/.gitignore | 4 +- extensions/vscode/esbuild.js | 52 +++++--- extensions/vscode/package-lock.json | 19 ++- extensions/vscode/package.json | 8 +- extensions/vscode/src/activation/activate.ts | 3 + extensions/vscode/yarn.lock | 5 + gui/package-lock.json | 3 - {core => sync}/Cargo.lock | 30 ++--- {core => sync}/Cargo.toml | 4 +- {core => sync}/src/README.md | 0 {core => sync}/src/gitignore.rs | 0 {core => sync}/src/lib.rs | 14 ++- {core => sync}/src/sync/merkle.rs | 0 {core => sync}/src/sync/mod.rs | 0 {core => sync}/src/utils/mod.rs | 0 18 files changed, 96 insertions(+), 175 deletions(-) delete mode 100644 core/README.md rename {core => sync}/Cargo.lock (99%) rename {core => sync}/Cargo.toml (91%) rename {core => sync}/src/README.md (100%) rename {core => sync}/src/gitignore.rs (100%) rename {core => sync}/src/lib.rs (79%) rename {core => sync}/src/sync/merkle.rs (100%) rename {core => sync}/src/sync/mod.rs (100%) rename {core => sync}/src/utils/mod.rs (100%) diff --git a/core/.gitignore b/core/.gitignore index 6ca71fb5f..6d41026be 100644 --- a/core/.gitignore +++ b/core/.gitignore @@ -1,5 +1,4 @@ target -index.node **/node_modules **/.DS_Store npm-debug.log* diff --git a/core/README.md b/core/README.md deleted file mode 100644 index 6f2cf2a36..000000000 --- a/core/README.md +++ /dev/null @@ -1,119 +0,0 @@ -# Continue Core - -This project was bootstrapped by [create-neon](https://www.npmjs.com/package/create-neon). - -## Installing core - -Installing core requires a [supported version of Node and Rust](https://github.com/neon-bindings/neon#platform-support). - -You can install the project with npm. In the project directory, run: - -```sh -$ npm install -``` - -This fully installs the project, including installing any dependencies and running the build. - -## Building core - -If you have already installed the project and only want to run the build, run: - -```sh -$ npm run build -``` - -This command uses the [cargo-cp-artifact](https://github.com/neon-bindings/cargo-cp-artifact) utility to run the Rust build and copy the built library into `./index.node`. - -## Exploring core - -After building core, you can explore its exports at the Node REPL: - -```sh -$ npm install -$ node -> require('.').hello() -"hello node" -``` - -## Available Scripts - -In the project directory, you can run: - -### `npm install` - -Installs the project, including running `npm run build`. - -### `npm build` - -Builds the Node addon (`index.node`) from source. - -Additional [`cargo build`](https://doc.rust-lang.org/cargo/commands/cargo-build.html) arguments may be passed to `npm build` and `npm build-*` commands. For example, to enable a [cargo feature](https://doc.rust-lang.org/cargo/reference/features.html): - -``` -npm run build -- --feature=beetle -``` - -#### `npm build-debug` - -Alias for `npm build`. - -#### `npm build-release` - -Same as [`npm build`](#npm-build) but, builds the module with the [`release`](https://doc.rust-lang.org/cargo/reference/profiles.html#release) profile. Release builds will compile slower, but run faster. - -### `npm test` - -Runs the unit tests by calling `cargo test`. You can learn more about [adding tests to your Rust code](https://doc.rust-lang.org/book/ch11-01-writing-tests.html) from the [Rust book](https://doc.rust-lang.org/book/). - -## Project Layout - -The directory structure of this project is: - -``` -core/ -├── Cargo.toml -├── README.md -├── index.node -├── package.json -├── src/ -| └── lib.rs -└── target/ -``` - -### Cargo.toml - -The Cargo [manifest file](https://doc.rust-lang.org/cargo/reference/manifest.html), which informs the `cargo` command. - -### README.md - -This file. - -### index.node - -The Node addon—i.e., a binary Node module—generated by building the project. This is the main module for this package, as dictated by the `"main"` key in `package.json`. - -Under the hood, a [Node addon](https://nodejs.org/api/addons.html) is a [dynamically-linked shared object](). The `"build"` script produces this file by copying it from within the `target/` directory, which is where the Rust build produces the shared object. - -### package.json - -The npm [manifest file](https://docs.npmjs.com/cli/v7/configuring-npm/package-json), which informs the `npm` command. - -### src/ - -The directory tree containing the Rust source code for the project. - -### src/lib.rs - -The Rust library's main module. - -### target/ - -Binary artifacts generated by the Rust build. - -## Learn More - -To learn more about Neon, see the [Neon documentation](https://neon-bindings.com). - -To learn more about Rust, see the [Rust documentation](https://www.rust-lang.org). - -To learn more about Node, see the [Node documentation](https://nodejs.org). diff --git a/core/package.json b/core/package.json index 80a841580..05f3b403a 100644 --- a/core/package.json +++ b/core/package.json @@ -2,14 +2,8 @@ "name": "core", "version": "1.0.0", "description": "The Continue Core contains functionality that can be shared across web, VS Code, or Node.js server. It is written in TypeScript and contains much of the functionality that was previously inside of the legacy Continue Python Server.", - "main": "index.node", "scripts": { - "test": "jest ./test/diff.test.ts", - "build": "cargo-cp-artifact -nc index.node -- cargo build --message-format=json-render-diagnostics", - "build-debug": "npm run build --", - "build-release": "npm run build -- --release", - "install": "npm run build-release", - "test:rust": "cargo test" + "test": "jest ./test/diff.test.ts" }, "author": "Nate Sesti and Ty Dunn", "license": "Apache-2.0", @@ -18,7 +12,6 @@ "@types/jest": "^29.5.11", "@types/mustache": "^4.2.5", "@types/uuid": "^9.0.7", - "cargo-cp-artifact": "^0.1", "jest": "^29.7.0", "ts-jest": "^29.1.1" }, diff --git a/extensions/vscode/.gitignore b/extensions/vscode/.gitignore index 45d3b3d67..7078ee554 100644 --- a/extensions/vscode/.gitignore +++ b/extensions/vscode/.gitignore @@ -7,4 +7,6 @@ src/client .continue gui -exe \ No newline at end of file +exe + +sync.node \ No newline at end of file diff --git a/extensions/vscode/esbuild.js b/extensions/vscode/esbuild.js index ce9ec7137..9b72d31b5 100644 --- a/extensions/vscode/esbuild.js +++ b/extensions/vscode/esbuild.js @@ -1,6 +1,7 @@ const esbuild = require("esbuild"); const ncp = require("ncp").ncp; const fs = require("fs"); +const { exec } = require("child_process"); (async () => { // Bundles the extension into one file @@ -8,7 +9,7 @@ const fs = require("fs"); entryPoints: ["src/extension.ts"], bundle: true, outfile: "out/extension.js", - external: ["vscode", "esbuild"], + external: ["vscode", "esbuild", "../sync.node"], format: "cjs", platform: "node", sourcemap: true, @@ -18,23 +19,42 @@ const fs = require("fs"); }, }); - // Return instead of copying if on ARM Mac - // This is an env var created in the GH Action - if (process.env.target === "darwin-arm64") { - return; - } - - fs.mkdirSync("out/node_modules", { recursive: true }); - - ncp.ncp("node_modules/esbuild", "out/node_modules/esbuild", function (err) { - if (err) { - return console.error(err); + exec("npm run build-release:rust", (error, stdout, stderr) => { + if (error) { + console.log("Error building sync.node"); + console.log("stdout: ", stdout); + console.log("stderr: ", stderr); + throw error; } - }); - ncp.ncp("node_modules/@esbuild", "out/node_modules/@esbuild", function (err) { - if (err) { - return console.error(err); + ncp.ncp("sync.node", "out/sync.node", (err) => { + if (err) { + return console.error(err); + } + }); + + // Return instead of copying if on ARM Mac + // This is an env var created in the GH Action + if (process.env.target === "darwin-arm64") { + return; } + + fs.mkdirSync("out/node_modules", { recursive: true }); + + ncp.ncp("node_modules/esbuild", "out/node_modules/esbuild", function (err) { + if (err) { + return console.error(err); + } + }); + + ncp.ncp( + "node_modules/@esbuild", + "out/node_modules/@esbuild", + function (err) { + if (err) { + return console.error(err); + } + } + ); }); })(); diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 7681a3230..4d418a74b 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -56,6 +56,7 @@ "@typescript-eslint/parser": "^5.45.0", "@vscode/test-electron": "^2.2.0", "@vscode/vsce": "^2.22.0", + "cargo-cp-artifact": "^0.1", "esbuild": "^0.17.19", "eslint": "^8.28.0", "glob": "^8.0.3", @@ -74,7 +75,6 @@ }, "../../core": { "version": "1.0.0", - "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { "@xenova/transformers": "^2.13.4", @@ -91,7 +91,6 @@ "@types/jest": "^29.5.11", "@types/mustache": "^4.2.5", "@types/uuid": "^9.0.7", - "cargo-cp-artifact": "^0.1", "jest": "^29.7.0", "ts-jest": "^29.1.1" } @@ -3697,6 +3696,15 @@ } ] }, + "node_modules/cargo-cp-artifact": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/cargo-cp-artifact/-/cargo-cp-artifact-0.1.8.tgz", + "integrity": "sha512-3j4DaoTrsCD1MRkTF2Soacii0Nx7UHCce0EwUf4fHnggwiE4fbmF2AbnfzayR36DF8KGadfh7M/Yfy625kgPlA==", + "dev": true, + "bin": { + "cargo-cp-artifact": "bin/cargo-cp-artifact.js" + } + }, "node_modules/caseless": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", @@ -14592,6 +14600,12 @@ "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001570.tgz", "integrity": "sha512-+3e0ASu4sw1SWaoCtvPeyXp+5PsjigkSt8OXZbF9StH5pQWbxEjLAZE3n8Aup5udop1uRiKA7a4utUk/uoSpUw==" }, + "cargo-cp-artifact": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/cargo-cp-artifact/-/cargo-cp-artifact-0.1.8.tgz", + "integrity": "sha512-3j4DaoTrsCD1MRkTF2Soacii0Nx7UHCce0EwUf4fHnggwiE4fbmF2AbnfzayR36DF8KGadfh7M/Yfy625kgPlA==", + "dev": true + }, "caseless": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", @@ -14984,7 +14998,6 @@ "@types/mustache": "^4.2.5", "@types/uuid": "^9.0.7", "@xenova/transformers": "^2.13.4", - "cargo-cp-artifact": "^0.1", "dotenv": "^16.3.1", "fastest-levenshtein": "^1.0.16", "handlebars": "^4.7.8", diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 5905354e5..8ff2a5938 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -356,7 +356,10 @@ "test": "npm run build-test && node ./out/test-runner/runTestOnVSCodeHost.js", "prepackage": "node scripts/prepackage.js", "package": "node scripts/package.js", - "package:pre-release": "node scripts/package.js --pre-release" + "package:pre-release": "node scripts/package.js --pre-release", + "build:rust": "cargo-cp-artifact -ac sync sync.node -- cargo build --manifest-path ../../sync/Cargo.toml --message-format=json-render-diagnostics", + "build-debug:rust": "npm run build:rust --", + "build-release:rust": "npm run build:rust -- --release" }, "devDependencies": { "@nestjs/common": "^8.4.7", @@ -382,7 +385,8 @@ "ovsx": "^0.8.3", "typescript": "^5.3.3", "vite": "^4.3.9", - "vsce": "^2.15.0" + "vsce": "^2.15.0", + "cargo-cp-artifact": "^0.1" }, "dependencies": { "@electron/rebuild": "^3.2.10", diff --git a/extensions/vscode/src/activation/activate.ts b/extensions/vscode/src/activation/activate.ts index 778ac4a90..210781a39 100644 --- a/extensions/vscode/src/activation/activate.ts +++ b/extensions/vscode/src/activation/activate.ts @@ -10,6 +10,7 @@ import { registerAllCodeLensProviders } from "../lang-server/codeLens"; import { getExtensionUri } from "../util/vscode"; import { setupInlineTips } from "./inlineTips"; import { startProxy } from "./proxy"; +const cpuCount = require("../sync.node"); export let extensionContext: vscode.ExtensionContext | undefined = undefined; export let ideProtocolClient: IdeProtocolClient; @@ -99,6 +100,8 @@ function showRefactorMigrationMessage() { } export async function activateExtension(context: vscode.ExtensionContext) { + console.log("owijfio: ", cpuCount.get()); + // Add necessary files getTsConfigPath(); diff --git a/extensions/vscode/yarn.lock b/extensions/vscode/yarn.lock index 4252ba601..7b50d6319 100644 --- a/extensions/vscode/yarn.lock +++ b/extensions/vscode/yarn.lock @@ -1809,6 +1809,11 @@ caniuse-lite@^1.0.30001565: resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001570.tgz" integrity sha512-+3e0ASu4sw1SWaoCtvPeyXp+5PsjigkSt8OXZbF9StH5pQWbxEjLAZE3n8Aup5udop1uRiKA7a4utUk/uoSpUw== +cargo-cp-artifact@^0.1: + version "0.1.8" + resolved "https://registry.npmjs.org/cargo-cp-artifact/-/cargo-cp-artifact-0.1.8.tgz" + integrity sha512-3j4DaoTrsCD1MRkTF2Soacii0Nx7UHCce0EwUf4fHnggwiE4fbmF2AbnfzayR36DF8KGadfh7M/Yfy625kgPlA== + caseless@~0.12.0: version "0.12.0" resolved "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz" diff --git a/gui/package-lock.json b/gui/package-lock.json index ce84baba3..7af299b9f 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -64,7 +64,6 @@ }, "../core": { "version": "1.0.0", - "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { "@xenova/transformers": "^2.13.4", @@ -81,7 +80,6 @@ "@types/jest": "^29.5.11", "@types/mustache": "^4.2.5", "@types/uuid": "^9.0.7", - "cargo-cp-artifact": "^0.1", "jest": "^29.7.0", "ts-jest": "^29.1.1" } @@ -7484,7 +7482,6 @@ "@types/mustache": "^4.2.5", "@types/uuid": "^9.0.7", "@xenova/transformers": "^2.13.4", - "cargo-cp-artifact": "^0.1", "dotenv": "^16.3.1", "fastest-levenshtein": "^1.0.16", "handlebars": "^4.7.8", diff --git a/core/Cargo.lock b/sync/Cargo.lock similarity index 99% rename from core/Cargo.lock rename to sync/Cargo.lock index 17ff2915a..f2a18a5c8 100644 --- a/core/Cargo.lock +++ b/sync/Cargo.lock @@ -97,21 +97,6 @@ dependencies = [ "windows-targets 0.48.5", ] -[[package]] -name = "core" -version = "0.1.0" -dependencies = [ - "hex-literal", - "homedir", - "ignore", - "neon", - "pyo3", - "serde", - "serde_json", - "sha1", - "tempfile", -] - [[package]] name = "core-foundation-sys" version = "0.8.6" @@ -804,6 +789,21 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "sync" +version = "0.1.0" +dependencies = [ + "hex-literal", + "homedir", + "ignore", + "neon", + "pyo3", + "serde", + "serde_json", + "sha1", + "tempfile", +] + [[package]] name = "target-lexicon" version = "0.12.12" diff --git a/core/Cargo.toml b/sync/Cargo.toml similarity index 91% rename from core/Cargo.toml rename to sync/Cargo.toml index 042904a8a..a50cc1f44 100644 --- a/core/Cargo.toml +++ b/sync/Cargo.toml @@ -1,7 +1,7 @@ [package] -name = "core" +name = "sync" version = "0.1.0" -description = "Continue Core" +description = "Continue Codebase Syncing" authors = ["Nate Sesti and Ty Dunn"] license = "Apache-2.0" edition = "2018" diff --git a/core/src/README.md b/sync/src/README.md similarity index 100% rename from core/src/README.md rename to sync/src/README.md diff --git a/core/src/gitignore.rs b/sync/src/gitignore.rs similarity index 100% rename from core/src/gitignore.rs rename to sync/src/gitignore.rs diff --git a/core/src/lib.rs b/sync/src/lib.rs similarity index 79% rename from core/src/lib.rs rename to sync/src/lib.rs index 6efbdedc2..ee784f5e1 100644 --- a/core/src/lib.rs +++ b/sync/src/lib.rs @@ -28,8 +28,12 @@ use neon::prelude::*; // Ok(js_array) // } -// #[neon::main] -// fn main(mut cx: ModuleContext) -> NeonResult<()> { -// cx.export_function("get", get_num_cpus)?; -// Ok(()) -// } +fn get_num_cpus(mut cx: FunctionContext) -> JsResult { + Ok(cx.number(2.0 as f64)) +} + +#[neon::main] +fn main(mut cx: ModuleContext) -> NeonResult<()> { + cx.export_function("get", get_num_cpus)?; + Ok(()) +} diff --git a/core/src/sync/merkle.rs b/sync/src/sync/merkle.rs similarity index 100% rename from core/src/sync/merkle.rs rename to sync/src/sync/merkle.rs diff --git a/core/src/sync/mod.rs b/sync/src/sync/mod.rs similarity index 100% rename from core/src/sync/mod.rs rename to sync/src/sync/mod.rs diff --git a/core/src/utils/mod.rs b/sync/src/utils/mod.rs similarity index 100% rename from core/src/utils/mod.rs rename to sync/src/utils/mod.rs