Skip to content

Commit

Permalink
feat: loggedIn context key
Browse files Browse the repository at this point in the history
This creates a context key, which we can consume in a variety of places
to determine if we should enable some feature (See
https://code.visualstudio.com/api/references/when-clause-contexts).

For instance, an updated walkthrough could make use of this, and we can
use it to choose what views to show at the vscode level too.
  • Loading branch information
kopecs authored Nov 20, 2024
2 parents 444d4ff + d9fed6d commit 6625ea9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
"markdown": "walkthrough/2-sign-in.md"
},
"completionEvents": [
"onCommand:semgrep.login"
"onContext:semgrep.loggedIn"
]
},
{
Expand Down
15 changes: 9 additions & 6 deletions src/env.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import * as fs from "fs";
import * as vscode from "vscode";
import {
ExtensionContext,
OutputChannel,
window,
workspace,
WorkspaceConfiguration,
} from "vscode";
import { window, workspace } from "vscode";
import * as fs from "fs";

import { EventEmitter } from "stream";
import { LanguageClient } from "vscode-languageclient/node";
import { VSCODE_CONFIG_KEY, VSCODE_EXT_NAME } from "./constants";
import { Logger } from "./utils";
import { SemgrepDocumentProvider } from "./showAstDocument";
import { LanguageClient } from "vscode-languageclient/node";
import { EventEmitter } from "stream";
import { SemgrepSearchWebviewProvider } from "./views/webview";
import { setSentryContext } from "./telemetry/sentry";
import { Logger } from "./utils";
import { SemgrepSearchWebviewProvider } from "./views/webview";

export class Config {
get cfg(): WorkspaceConfiguration {
Expand Down Expand Up @@ -73,6 +75,7 @@ export class Environment {
}

set loggedIn(val: boolean) {
vscode.commands.executeCommand("setContext", "semgrep.loggedIn", val);
this.context.globalState.update("loggedIn", val);
}

Expand Down

0 comments on commit 6625ea9

Please sign in to comment.