diff --git a/CHANGELOG.md b/CHANGELOG.md index ba36c32..8997fa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ## [v1.10.0] - Add sync flow for Secrets and IaC +- Fix scan on save for individual files ## [v1.9.4] diff --git a/src/extension.ts b/src/extension.ts index 79d9701..52f1f03 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -31,6 +31,7 @@ import {getAuthState} from './utils/auth/auth_common'; import {sastScan} from './services/scanners/SastScanner'; import {captureException, initSentry} from './sentry'; import {refreshDiagnosticCollectionData} from './services/diagnostics/common'; +import {getVsCodeRootPathPrefix} from './utils/GlobalConfig'; export async function activate(context: vscode.ExtensionContext) { initSentry(); @@ -100,14 +101,11 @@ export async function activate(context: vscode.ExtensionContext) { } const projectPath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath; - if (!projectPath) { - return; - } - // verify that file in the workspace - // user can trigger save of a VS Code settings file - // which we don't want to scan - if (!fileFsPath.startsWith(projectPath)) { + const vsCodeAppRootPrefix = getVsCodeRootPathPrefix(); + console.log('vsCodeAppRootPrefix', vsCodeAppRootPrefix); + if (fileFsPath.startsWith(vsCodeAppRootPrefix)) { + // user can trigger save of a VS Code settings files which we don't want to scan return; } diff --git a/src/utils/GlobalConfig.ts b/src/utils/GlobalConfig.ts new file mode 100644 index 0000000..1c221ee --- /dev/null +++ b/src/utils/GlobalConfig.ts @@ -0,0 +1,23 @@ +import * as os from 'os'; +import * as path from 'path'; + +export const getVsCodeRootPathPrefix = (): string => { + // Get the path to the global VS Code app folder based on OS + // Ref: https://github.com/microsoft/vscode/issues/3884#issue-139391403 + + const homeDir = os.homedir(); + let globalConfigPath: string; + if (process.platform === 'win32') { + // Windows + globalConfigPath = path.join(homeDir, 'AppData', 'Roaming', 'Code'); + } else if (process.platform === 'darwin') { + // macOS + globalConfigPath = path.join(homeDir, 'Library', 'Application Support', 'Code'); + } else { + // Linux + globalConfigPath = path.join(homeDir, '.config', 'Code'); + } + + return globalConfigPath; +}; +