Skip to content

Commit 5cfd521

Browse files
authored
feat: consume new login flow (#189)
This should let us avoid stale state caused by the prior implementation, which handled the "finish" step as a notification, rather than as a request.
1 parent fc1633d commit 5cfd521

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/commands.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import type { Environment } from "./env";
44
import { restartLsp } from "./lsp";
55
import {
66
type SearchParams,
7-
login,
87
loginFinish,
8+
loginStart,
99
loginStatus,
1010
logout,
1111
refreshRules,
@@ -61,10 +61,13 @@ export function registerCommands(env: Environment): Disposable[] {
6161
/************/
6262

6363
vscode.commands.registerCommand("semgrep.login", async () => {
64-
const result = await env.client?.sendRequest(login);
64+
const result = await env.client?.sendRequest(loginStart);
6565
if (result) {
6666
vscode.env.openExternal(vscode.Uri.parse(result.url));
67-
env.client?.sendNotification(loginFinish, result);
67+
const status = await env.client?.sendRequest(loginFinish, result);
68+
if (status) {
69+
env.loggedIn = status.loggedIn;
70+
}
6871
}
6972
}),
7073

src/lspExtensions.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ export const scanWorkspace = new lc.NotificationType<ScanWorkspaceParams>(
2020
"semgrep/scanWorkspace",
2121
);
2222

23-
export interface LoginParams {
23+
export interface LoginStartResponse {
2424
url: string;
2525
sessionId: string;
2626
}
2727

28-
export interface LoginStatusParams {
28+
export interface LoginStatusResponse {
2929
loggedIn: boolean;
3030
}
3131

@@ -55,13 +55,15 @@ export interface LspErrorParams {
5555
stack: string;
5656
}
5757

58-
export const login = new lc.RequestType0<LoginParams | null, void>(
59-
"semgrep/login",
58+
export const loginStart = new lc.RequestType0<LoginStartResponse | null, void>(
59+
"semgrep/loginStart",
6060
);
6161

62-
export const loginFinish = new lc.NotificationType<LoginParams>(
63-
"semgrep/loginFinish",
64-
);
62+
export const loginFinish = new lc.RequestType<
63+
LoginStartResponse,
64+
LoginStatusResponse,
65+
void
66+
>("semgrep/loginFinish");
6567

6668
export const logout = new lc.NotificationType("semgrep/logout");
6769

@@ -75,9 +77,10 @@ export const workspaceRules = new lc.RequestType0<any[], void>(
7577
"semgrep/workspaceRules",
7678
);
7779

78-
export const loginStatus = new lc.RequestType0<LoginStatusParams | null, void>(
79-
"semgrep/loginStatus",
80-
);
80+
export const loginStatus = new lc.RequestType0<
81+
LoginStatusResponse | null,
82+
void
83+
>("semgrep/loginStatus");
8184

8285
export const search = new lc.RequestType<LspSearchParams, SearchResults, void>(
8386
"semgrep/search",

0 commit comments

Comments
 (0)