🎨 Neon bindings working with VS Code extension
This commit is contained in:
parent
25c96ac295
commit
db6ffadd44
18 changed files with 96 additions and 175 deletions
1
core/.gitignore
vendored
1
core/.gitignore
vendored
|
|
@ -1,5 +1,4 @@
|
|||
target
|
||||
index.node
|
||||
**/node_modules
|
||||
**/.DS_Store
|
||||
npm-debug.log*
|
||||
|
|
|
|||
119
core/README.md
119
core/README.md
|
|
@ -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](<https://en.wikipedia.org/wiki/Library_(computing)#Shared_libraries>). 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).
|
||||
|
|
@ -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"
|
||||
},
|
||||
|
|
|
|||
4
extensions/vscode/.gitignore
vendored
4
extensions/vscode/.gitignore
vendored
|
|
@ -7,4 +7,6 @@ src/client
|
|||
.continue
|
||||
|
||||
gui
|
||||
exe
|
||||
exe
|
||||
|
||||
sync.node
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
})();
|
||||
|
|
|
|||
19
extensions/vscode/package-lock.json
generated
19
extensions/vscode/package-lock.json
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
3
gui/package-lock.json
generated
3
gui/package-lock.json
generated
|
|
@ -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",
|
||||
|
|
|
|||
30
core/Cargo.lock → sync/Cargo.lock
generated
30
core/Cargo.lock → sync/Cargo.lock
generated
|
|
@ -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"
|
||||
|
|
@ -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"
|
||||
|
|
@ -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<JsNumber> {
|
||||
Ok(cx.number(2.0 as f64))
|
||||
}
|
||||
|
||||
#[neon::main]
|
||||
fn main(mut cx: ModuleContext) -> NeonResult<()> {
|
||||
cx.export_function("get", get_num_cpus)?;
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue