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

feat: new policy view with login CTA #186

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,19 @@
}
]
},
"viewsWelcome": [
{
"view": "semgrep.view.policy",
"contents": "[Sign in](command:semgrep.login)",
"when": "!semgrep.loggedIn"
}
],
"views": {
"semgrep-sidebar": [
{
"id": "semgrep.view.policy",
"name": "Policy Configuration"
},
{
"type": "webview",
"id": "semgrep.searchView",
Expand Down
6 changes: 6 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
),
),
);
context.subscriptions.push(
vscode.window.registerTreeDataProvider(
SemgrepPolicyViewProvider.viewType,

Check failure on line 66 in src/extension.ts

View workflow job for this annotation

GitHub Actions / vsce-test (macos-latest)

Cannot find name 'SemgrepPolicyViewProvider'.
new SemgrepPolicyViewProvider(context.extensionUri),

Check failure on line 67 in src/extension.ts

View workflow job for this annotation

GitHub Actions / vsce-test (macos-latest)

Cannot find name 'SemgrepPolicyViewProvider'.
),
);

// register content provider for the AST showing document
context.subscriptions.push(
Expand Down
16 changes: 16 additions & 0 deletions src/lsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,24 @@
env.emitRulesRefreshedEvent();
};

// TODO: This is an ugly hack to allow for easily updating the login status.
// It is rather fragile and we should instead do this by cleaning up the LSP
// extensions we use for login. However, this lets us ensure we have
// reasonably up-to-date UI state until then.
const updateLoginStatus: NotificationHandler<ShowMessageParams> = (

Check failure on line 256 in src/lsp.ts

View workflow job for this annotation

GitHub Actions / vsce-test (macos-latest)

Cannot find name 'NotificationHandler'. Did you mean 'NotificationHandler0'?

Check failure on line 256 in src/lsp.ts

View workflow job for this annotation

GitHub Actions / vsce-test (macos-latest)

Cannot find name 'ShowMessageParams'.
s: ShowMessageParams,

Check failure on line 257 in src/lsp.ts

View workflow job for this annotation

GitHub Actions / vsce-test (macos-latest)

Cannot find name 'ShowMessageParams'.
) => {
if (
s.type === MessageType.Info &&

Check failure on line 260 in src/lsp.ts

View workflow job for this annotation

GitHub Actions / vsce-test (macos-latest)

Cannot find name 'MessageType'.
s.message === "Successfully logged into Semgrep Code"
) {
env.loggedIn = true;
}
};

// Register handlers here
c.onNotification(rulesRefreshed, notificationHandler);
c.onNotification(ShowMessageNotification.type, updateLoginStatus);

Check failure on line 269 in src/lsp.ts

View workflow job for this annotation

GitHub Actions / vsce-test (macos-latest)

Cannot find name 'ShowMessageNotification'.
c.onTelemetry((e) => {
// We only send errors, so we can safely cast this
// See RPC_server.ml for the definition of LspErrorParams
Expand Down
21 changes: 21 additions & 0 deletions src/views/policy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as vscode from "vscode";

export class SemgrepPolicyViewProvider
implements vscode.TreeDataProvider<PolicyItem>
{
public static readonly viewType = "semgrep.view.policy";

constructor(private readonly extensionUri: vscode.Uri) {}

getTreeItem(element: PolicyItem): PolicyItem {
return element;
}

getChildren(
element?: PolicyItem | undefined,
): vscode.ProviderResult<PolicyItem[]> {
return [];
}
}

class PolicyItem extends vscode.TreeItem {}
Loading