Skip to content
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

refactor(agent&vscode): connect vscode extension to agent via lsp. #2247

Merged
merged 4 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 20 additions & 27 deletions clients/tabby-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,23 @@
"node": ">=18"
},
"files": [
"./dist/cli.js",
"./dist/index.js",
"./dist/index.mjs",
"./dist/index.d.ts",
"./dist/wasm/**",
"./dist/win-ca/**"
"./dist/**"
],
"bin": {
"tabby-agent": "./dist/cli.js"
"tabby-agent": "./dist/node/index.js"
},
"main": "./dist/index.js",
"browser": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"main": "./dist/protocol.js",
"types": "./dist/protocol.d.ts",
"scripts": {
"build": "tsc --noEmit && tsup --minify --treeshake smallest",
"watch": "tsc-watch --noEmit --onSuccess \"tsup\"",
"openapi-codegen": "openapi-typescript ./openapi/tabby.json -o ./src/types/tabbyApi.d.ts",
"dev": "tsup --watch --no-minify --no-treeshake",
"build": "tsc --noEmit && tsup",
"test": "mocha",
"lint": "eslint --ext .ts ./src && prettier --check .",
"lint:fix": "eslint --fix --ext .ts ./src && prettier --write ."
},
"devDependencies": {
"@orama/orama": "^2.0.18",
"@types/chai": "^4.3.5",
"@types/dedent": "^0.7.2",
"@types/deep-equal": "^1.0.4",
Expand All @@ -54,41 +49,39 @@
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"chai": "^4.3.7",
"chokidar": "^3.5.3",
"dedent": "^0.7.0",
"deep-equal": "^2.2.1",
"deepmerge-ts": "^5.1.0",
"dot-prop": "^8.0.2",
"esbuild-plugin-copy": "^2.1.1",
"esbuild-plugin-polyfill-node": "^0.3.0",
"eslint": "^8.55.0",
"eslint-config-prettier": "^9.0.0",
"glob": "^7.2.0",
"mocha": "^10.2.0",
"openapi-typescript": "^6.6.1",
"prettier": "^3.0.0",
"ts-node": "^10.9.1",
"tsup": "^7.1.0",
"typescript": "^5.3.2"
},
"dependencies": {
"axios": "^1.7.2",
"chokidar": "^3.5.3",
"deep-equal": "^2.2.1",
"deepmerge-ts": "^5.1.0",
"dot-prop": "^8.0.2",
"eventsource-parser": "^1.1.2",
"fast-levenshtein": "^3.0.0",
"file-stream-rotator": "^1.0.0",
"form-data": "^4.0.0",
"fs-extra": "^11.1.1",
"glob": "^7.2.0",
"jwt-decode": "^3.1.2",
"lru-cache": "^9.1.1",
"mac-ca": "^2.0.3",
"mocha": "^10.2.0",
"object-hash": "^3.0.0",
"openapi-fetch": "^0.7.6",
"openapi-typescript": "^6.6.1",
"pino": "^8.14.1",
"prettier": "^3.0.0",
"semver": "^7.6.0",
"stats-logscale": "^1.0.9",
"toml": "^3.0.0",
"ts-node": "^10.9.1",
"tsc-watch": "^6.2.0",
"tsup": "^8.0.2",
"typescript": "^5.3.2",
"uuid": "^9.0.0",
"vscode-languageserver": "^9.0.1",
"vscode-languageserver-protocol": "^3.17.5",
"vscode-languageserver-textdocument": "^1.0.11",
"web-tree-sitter": "^0.20.8",
"win-ca": "^3.5.1"
Expand Down
4 changes: 2 additions & 2 deletions clients/tabby-agent/src/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class Auth extends EventEmitter {
clearInterval(timer);
resolve(true);
} catch (error) {
if (error! instanceof HttpError && [400, 401, 403, 405].includes(error.status)) {
if (!(error instanceof HttpError && [400, 401, 403, 405].includes(error.status))) {
// unknown error but still keep polling
this.logger.error("Failed due to unknown error when polling auth token", error);
}
Expand Down Expand Up @@ -211,7 +211,7 @@ export class Auth extends EventEmitter {
payload: decodeJwt(refreshedJwt.data.jwt),
};
} catch (error) {
if (error! instanceof HttpError && [400, 401, 403, 405].includes(error.status)) {
if (!(error instanceof HttpError && [400, 401, 403, 405].includes(error.status))) {
// unknown error, retry a few times
this.logger.error("Failed due to unknown error when refreshing auth token.", error);
if (retry < options.maxTry) {
Expand Down
3 changes: 2 additions & 1 deletion clients/tabby-agent/src/CompletionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export type CompletionRequest = {

export type Declaration = {
filepath: string;
offset: number;
text: string;
offset?: number;
};

export type CodeSnippet = {
Expand Down Expand Up @@ -183,6 +183,7 @@ export class CompletionContext {
!this.declarations?.find((declaration) => {
return (
declaration.filepath === snippet.filepath &&
declaration.offset &&
// Is range overlapping
Math.max(declaration.offset, snippet.offset) <=
Math.min(declaration.offset + declaration.text.length, snippet.offset + snippet.text.length)
Expand Down
219 changes: 0 additions & 219 deletions clients/tabby-agent/src/LspServer.ts

This file was deleted.

2 changes: 1 addition & 1 deletion clients/tabby-agent/src/TabbyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export class TabbyAgent extends EventEmitter implements Agent {
} catch (error) {
if (isUnauthorizedError(error)) {
this.logger.debug(`Fetch server provided config request failed due to unauthorized. [${requestId}]`);
} else if (error! instanceof HttpError) {
} else if (!(error instanceof HttpError)) {
this.logger.error(`Fetch server provided config request failed. [${requestId}]`, error);
}
}
Expand Down
8 changes: 4 additions & 4 deletions clients/tabby-agent/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import { TabbyAgent } from "./TabbyAgent";
import { JsonLineServer } from "./JsonLineServer";
import { LspServer } from "./LspServer";
import { Server as LspServer } from "./lsp/Server";

const args = process.argv.slice(2);

const agent = new TabbyAgent();
let server;
if (args.indexOf("--lsp") >= 0) {
server = new LspServer();
server = new LspServer(agent);
} else {
server = new JsonLineServer();
server.bind(agent);
}
const agent = new TabbyAgent();
server.bind(agent);
server.listen();
Loading