Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sestinj committed Jun 12, 2024
2 parents 309e801 + a565519 commit 13bb578
Show file tree
Hide file tree
Showing 70 changed files with 2,590 additions and 21,630 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,7 @@ continue_server.dist
Icon
Icon?

.continue
.continue

# Sandbox env default file
extensions/vscode/manual-testing-sandbox/example.ts
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"${workspaceFolder}/extensions/vscode/manual-testing-sandbox/test.js",
"--extensionDevelopmentPath=${workspaceFolder}/extensions/vscode"
],
"pauseForSourceMap": false,
"outFiles": [
"${workspaceFolder}/extensions/vscode/out/extension.js",
"/Users/natesesti/.continue/config.ts"
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ nvm use
1. The new VS Code window with the extension is referred to as the _Host VS Code_
2. The window you started debugging from is referred to as the _Main VS Code_

4. To package the extension, run `npm package` in the `extensions/vscode` directory. This will generate `extensions/vscode/build/continue-patch.vsix`, which you can install by right-clicking and selecting "Install Extension VSIX".
4. To package the extension, run `npm run package` in the `extensions/vscode` directory. This will generate `extensions/vscode/build/continue-{VERSION}.vsix`, which you can install by right-clicking and selecting "Install Extension VSIX".

##### Debugging

Expand Down
23 changes: 19 additions & 4 deletions binary/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ const fs = require("fs");
const path = require("path");
const ncp = require("ncp").ncp;
const { rimrafSync } = require("rimraf");
const { validateFilesPresent, execCmdSync } = require("../scripts/util");
const {
validateFilesPresent,
execCmdSync,
autodetectPlatformAndArch,
} = require("../scripts/util");

// Clean slate
const bin = path.join(__dirname, "bin");
Expand All @@ -23,6 +27,8 @@ let targets = [
"win32-x64",
];

const [currentPlatform, currentArch] = autodetectPlatformAndArch();

const assetBackups = [
"node_modules/win-ca/lib/crypt32-ia32.node.bak",
"node_modules/win-ca/lib/crypt32-x64.node.bak",
Expand Down Expand Up @@ -51,7 +57,7 @@ async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) {
console.log(`Copying ${packageName} to ${toCopy}`);
// This is a way to install only one package without npm trying to install all the dependencies
// Create a temporary directory for installing the package
const adjustedName = toCopy.replace(/^@/, "").replace("/", "-");
const adjustedName = packageName.replace(/@/g, "").replace("/", "-");
const tempDir = path.join(
__dirname,
"tmp",
Expand All @@ -78,7 +84,6 @@ async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) {
);

// Without this it seems the file isn't completely written to disk
// Ideally we validate file integrity in the validation at the end
await new Promise((resolve) => setTimeout(resolve, 2000));

// Copy the installed package back to the current directory
Expand Down Expand Up @@ -169,7 +174,7 @@ async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) {
entryPoints: ["src/index.ts"],
bundle: true,
outfile: esbuildOutputFile,
external: ["esbuild", "./xhr-sync-worker.js", "vscode"],
external: ["esbuild", "./xhr-sync-worker.js", "vscode", "./index.node"],
format: "cjs",
platform: "node",
sourcemap: true,
Expand Down Expand Up @@ -214,6 +219,16 @@ async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) {
`${targetDir}/build/Release/node_sqlite3.node`,
`${targetDir}/node_sqlite3.node`,
);

// Copy to build directory for testing
const [platform, arch] = target.split("-");
if (platform === currentPlatform && arch === currentArch) {
fs.copyFileSync(
`${targetDir}/node_sqlite3.node`,
`build/node_sqlite3.node`,
);
}

fs.unlinkSync(`${targetDir}/build.tar.gz`);
fs.rmSync(`${targetDir}/build`, {
recursive: true,
Expand Down
1 change: 1 addition & 0 deletions binary/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 29 additions & 26 deletions core/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"extends": ["plugin:require-extensions/recommended"],
"plugins": ["@typescript-eslint", "import", "require-extensions"],
"rules": {
"quotes": ["warn", "double", {}],
"import/extensions": ["error", "always", {
"js": "never",
"jsx": "never",
"ts": "never",
"tsx": "never"
}],
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
},
"ignorePatterns": ["out", "dist", "**/*.d.ts"]
}

"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"extends": ["plugin:require-extensions/recommended"],
"plugins": ["@typescript-eslint", "import", "require-extensions"],
"rules": {
"quotes": ["warn", "double", {}],
"import/extensions": [
"error",
"always",
{
"js": "never",
"jsx": "never",
"ts": "never",
"tsx": "never"
}
],
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
},
"ignorePatterns": ["out", "dist", "**/*.d.ts"]
}
31 changes: 19 additions & 12 deletions core/autocomplete/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,43 @@ export class AutocompleteLruCache {
return new AutocompleteLruCache(db);
}

async get(key: string): Promise<string | undefined> {
async get(prefix: string): Promise<string | undefined> {
// NOTE: Right now prompts with different suffixes will be considered the same

// If the query is "co" and we have "c" -> "ontinue" in the cache,
// we should return "ntinue" as the completion.
// Have to make sure we take the key with shortest length
const result = await this.db.get(
"SELECT value FROM cache WHERE key = ?",
key,
"SELECT key, value FROM cache WHERE ? LIKE key || '%' ORDER BY LENGTH(key) DESC LIMIT 1",
prefix,
);

if (result) {
// Validate that the cached compeltion is a valid completion for the prefix
if (result && result.value.startsWith(prefix.slice(result.key.length))) {
await this.db.run(
"UPDATE cache SET timestamp = ? WHERE key = ?",
Date.now(),
key,
prefix,
);
return result.value;
// And then truncate so we aren't writing something that's already there
return result.value.slice(prefix.length - result.key.length);
}

return undefined;
}

async put(key: string, value: string) {
async put(prefix: string, completion: string) {
const result = await this.db.get(
"SELECT key FROM cache WHERE key = ?",
key,
prefix,
);

if (result) {
await this.db.run(
"UPDATE cache SET value = ?, timestamp = ? WHERE key = ?",
value,
completion,
Date.now(),
key,
prefix,
);
} else {
const count = await this.db.get("SELECT COUNT(*) as count FROM cache");
Expand All @@ -71,8 +78,8 @@ export class AutocompleteLruCache {

await this.db.run(
"INSERT INTO cache (key, value, timestamp) VALUES (?, ?, ?)",
key,
value,
prefix,
completion,
Date.now(),
);
}
Expand Down
4 changes: 3 additions & 1 deletion core/autocomplete/charStream.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export async function* onlyWhitespaceAfterEndOfLine(
stream: AsyncGenerator<string>,
endOfLine: string[],
fullStop: () => void,
): AsyncGenerator<string> {
let pending = "";
for await (let chunk of stream) {
Expand All @@ -12,6 +13,7 @@ export async function* onlyWhitespaceAfterEndOfLine(
chunk[i + 1].trim() === chunk[i + 1]
) {
yield chunk.slice(0, i + 1);
fullStop();
return;
}
}
Expand All @@ -30,7 +32,7 @@ export async function* noFirstCharNewline(stream: AsyncGenerator<string>) {
for await (const char of stream) {
if (first) {
first = false;
if (char === "\n") {
if (char.startsWith("\n") || char.startsWith("\r")) {
return;
}
}
Expand Down
Loading

0 comments on commit 13bb578

Please sign in to comment.