diff --git a/CHANGELOG.md b/CHANGELOG.md index ed10373..b14102c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +## Removed + +- Removed the "Show AST" and "Show named AST" commands from right-click + ## 1.14.0 - 2025-08-22 ## Fixed diff --git a/package.json b/package.json index 47835a8..58d4899 100644 --- a/package.json +++ b/package.json @@ -59,15 +59,6 @@ "command": "semgrep.refreshRules", "title": "Semgrep: Update rules" }, - { - "command": "semgrep.showAst", - "title": "Semgrep: Show AST" - }, - { - "command": "semgrep.showAstNamed", - "title": "Semgrep: Show named AST", - "when": "semgrep.cli.minor >= 36 || config.semgrep.ignoreCliVersion" - }, { "command": "semgrep.search", "title": "Semgrep: Search by pattern", @@ -236,18 +227,6 @@ ] }, "menus": { - "editor/context": [ - { - "command": "semgrep.showAst", - "when": "editorTextFocus", - "group": "navigation" - }, - { - "command": "semgrep.showAstNamed", - "when": "editorTextFocus", - "group": "navigation" - } - ], "commandPalette": [ { "command": "semgrep.login", diff --git a/src/commands.ts b/src/commands.ts index 1cbb9e6..0bce208 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -10,10 +10,8 @@ import { logout, refreshRules, scanWorkspace, - showAst, } from "./lspExtensions"; import { handleSearch } from "./search"; -import { encodeUri } from "./showAstDocument"; import { applyFixAndSave, isRealFileEditor, replaceAll } from "./utils"; import type { ViewResults } from "./webviews/types/results"; import { setupMcp } from "./mcp"; @@ -33,26 +31,6 @@ import path from "node:path"; See `package.json` which also defines where some of these commands are used. */ -/*****************************************************************************/ -/* Helpers */ -/*****************************************************************************/ - -// We need to do this, or openTextDocument will open the same text document, if previously -// opened. This means that running showAst twice will always show the same thing. -async function replaceAndOpenUriContent( - uri: vscode.Uri, - content: string, - active_editor: vscode.TextEditor, -): Promise { - const doc = await vscode.workspace.openTextDocument(uri); - const edit = new vscode.WorkspaceEdit(); - edit.replace(uri, new vscode.Range(0, 0, doc.lineCount, 0), content); - vscode.workspace.applyEdit(edit); - if (active_editor.viewColumn) { - vscode.window.showTextDocument(doc, active_editor.viewColumn + 1 || 0); - } -} - /*****************************************************************************/ /* Commands */ /*****************************************************************************/ @@ -178,44 +156,6 @@ export function registerCommands(env: Environment): Disposable[] { return "Refreshed rules"; }), - /************/ - /* SHOW AST */ - /************/ - - vscode.commands.registerCommand("semgrep.showAstNamed", async () => { - if ( - !isRealFileEditor(vscode.window.activeTextEditor) || - !vscode.window.activeTextEditor - ) { - return; - } - if (env.client) { - const ast_text = await env.client.sendRequest(showAst, { - named: true, - uri: vscode.window.activeTextEditor?.document.uri.fsPath, - }); - const uri = encodeUri(vscode.window.activeTextEditor.document.uri); - - replaceAndOpenUriContent(uri, ast_text, vscode.window.activeTextEditor); - } - }), - vscode.commands.registerCommand("semgrep.showAst", async () => { - if ( - !isRealFileEditor(vscode.window.activeTextEditor) || - !vscode.window.activeTextEditor - ) { - return; - } - if (env.client) { - const ast_text = await env.client.sendRequest(showAst, { - named: false, - uri: vscode.window.activeTextEditor?.document.uri.fsPath, - }); - const uri = encodeUri(vscode.window.activeTextEditor.document.uri); - replaceAndOpenUriContent(uri, ast_text, vscode.window.activeTextEditor); - } - }), - /**********/ /* SEARCH */ /**********/ diff --git a/src/env.ts b/src/env.ts index e6f2170..5e7af13 100644 --- a/src/env.ts +++ b/src/env.ts @@ -11,7 +11,6 @@ import { } from "vscode"; import type { LanguageClient } from "vscode-languageclient/node"; import { VSCODE_CONFIG_KEY, VSCODE_EXT_NAME } from "./constants"; -import { SemgrepDocumentProvider } from "./showAstDocument"; import { Logger } from "./utils"; import type { SemgrepSearchWebviewProvider } from "./views/webview"; import { NodeSDK } from "@opentelemetry/sdk-node"; @@ -107,7 +106,6 @@ export class Environment { private _provider: SemgrepSearchWebviewProvider | null = null; private constructor( readonly context: ExtensionContext, - readonly documentView: SemgrepDocumentProvider, readonly channel: OutputChannel, readonly logger: Logger, public config: Config, @@ -211,8 +209,7 @@ export class Environment { const config = await Environment.loadConfig(context); const channel = window.createOutputChannel(VSCODE_EXT_NAME); const logger = new Logger(config.trace, channel); - const documentView = new SemgrepDocumentProvider(); - return new Environment(context, documentView, channel, logger, config); + return new Environment(context, channel, logger, config); } static async loadConfig(context: ExtensionContext): Promise { diff --git a/src/extension.ts b/src/extension.ts index 69c62bb..3aac63b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -5,7 +5,6 @@ import { registerCommands } from "./commands"; import { VSCODE_CONFIG_KEY } from "./constants"; import { DeploymentInfo, Environment } from "./env"; import { activateLsp, deactivateLsp, restartLsp } from "./lsp"; -import { SemgrepDocumentProvider } from "./showAstDocument"; import { createStatusBar } from "./statusBar"; import { initTelemetry, stopTelemetry } from "./telemetry/telemetry"; import { deregisterExistingOtel, withSpan } from "./utilities/tracing"; @@ -69,13 +68,6 @@ async function afterClientStart(context: ExtensionContext, env: Environment) { ), ); - // register content provider for the AST showing document - context.subscriptions.push( - vscode.workspace.registerTextDocumentContentProvider( - SemgrepDocumentProvider.scheme, - env.documentView, - ), - ); // Handle configuration changes context.subscriptions.push( vscode.workspace.onDidChangeConfiguration( diff --git a/src/lspExtensions.ts b/src/lspExtensions.ts index 0e09e7f..0730f6b 100644 --- a/src/lspExtensions.ts +++ b/src/lspExtensions.ts @@ -12,11 +12,6 @@ export interface ScanWorkspaceParams { full?: boolean; } -export type ShowAstParams = { - named: boolean; - uri: string; -}; - export const scanWorkspace = new lc.NotificationType( "semgrep/scanWorkspace", ); @@ -85,7 +80,3 @@ export const search = new lc.RequestType( export const searchOngoing = new lc.RequestType0( "semgrep/searchOngoing", ); - -export const showAst = new lc.RequestType( - "semgrep/showAst", -); diff --git a/src/showAstDocument.ts b/src/showAstDocument.ts deleted file mode 100644 index 7b55709..0000000 --- a/src/showAstDocument.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type * as vscode from "vscode"; - -export class SemgrepDocumentProvider - implements vscode.TextDocumentContentProvider -{ - static scheme = "showAst"; - - private text = ""; - - // Apparently, you can have this function have no arguments, and it's fine, - // even though it's specifically supposed to take in two arguments. - // I have no idea why this should work. - provideTextDocumentContent(): string { - return this.text; - } -} - -export function encodeUri(uri: vscode.Uri): vscode.Uri { - // Needs to be a .ml here, regrettably, or you won't get OCaml syntax - // highlighting for the tree. - return uri.with({ - path: uri.path + ".semgrep_ast.ml", - scheme: SemgrepDocumentProvider.scheme, - }); -}