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

VSCode: Schema tag switching #632

Merged
merged 10 commits into from
Oct 19, 2018
55 changes: 55 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"prettier": "1.14.2",
"ts-jest": "^23.1.4",
"ts-node": "^7.0.1",
"tsc-watch": "^1.0.30",
"tslib": "^1.9.3",
"typescript": "^3.0.3",
"vsce": "^1.46.0"
Expand Down
6 changes: 3 additions & 3 deletions packages/apollo-language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"installServer": "installServerIntoExtension ../apollo-vscode ./package.json ./tsconfig.json && ./copy-apollo-libs.sh",
"clean": "rm -rf ../apollo-vscode/server",
"prebuild": "npm run clean",
"build": "npm run installServer && tsc -p .",
"watch": "npm run installServer && tsc -w -p .",
"watchOnly": "tsc -w -p .",
"build": "npm run installServer && tsc",
"watch": "npm run installServer && tsc-watch --onSuccess \"./copy-apollo-libs.sh\"",
"watchOnly": "tsc -w",
"prepare": "npm run build"
},
"engines": {
Expand Down
55 changes: 55 additions & 0 deletions packages/apollo-language-server/src/loadingHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { IConnection, NotificationType } from "vscode-languageserver";

export class LoadingHandler {
constructor(private connection: IConnection) {}
private latestLoadingToken = 0;
async handle<T>(message: string, value: Promise<T>): Promise<T> {
const token = this.latestLoadingToken;
this.latestLoadingToken += 1;
this.connection.sendNotification(
new NotificationType<any, void>("apollographql/loading"),
{ message, token }
);
try {
const ret = await value;
this.connection.sendNotification(
new NotificationType<any, void>("apollographql/loadingComplete"),
token
);
return ret;
} catch (e) {
this.connection.sendNotification(
new NotificationType<any, void>("apollographql/loadingComplete"),
token
);
this.showError(`Error in "${message}": ${e}`);
throw e;
}
}
handleSync<T>(message: string, value: () => T): T {
const token = this.latestLoadingToken;
this.latestLoadingToken += 1;
this.connection.sendNotification(
new NotificationType<any, void>("apollographql/loading"),
{ message, token }
);
try {
const ret = value();
this.connection.sendNotification(
new NotificationType<any, void>("apollographql/loadingComplete"),
token
);
return ret;
} catch (e) {
this.connection.sendNotification(
new NotificationType<any, void>("apollographql/loadingComplete"),
token
);
this.showError(`Error in "${message}": ${e}`);
throw e;
}
}
showError(message: string) {
this.connection.window.showErrorMessage(message);
}
}
Loading