Skip to content

Commit

Permalink
CM-40894 - Fix scan on save for individual files
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshalX committed Oct 7, 2024
1 parent 5384741 commit 61aef01
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## [v1.10.0]

- Add sync flow for Secrets and IaC
- Fix scan on save for individual files

## [v1.9.4]

Expand Down
12 changes: 5 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down
23 changes: 23 additions & 0 deletions src/utils/GlobalConfig.ts
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit 61aef01

Please sign in to comment.