Skip to content

Commit 883295d

Browse files
MarshalXelsapet
andauthored
CM-40894 - Fix scan on save for individual files (#103)
Co-authored-by: elsapet <[email protected]>
1 parent 5384741 commit 883295d

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
## [v1.10.0]
66

77
- Add sync flow for Secrets and IaC
8+
- Fix scan on save for individual files
89

910
## [v1.9.4]
1011

src/extension.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {getAuthState} from './utils/auth/auth_common';
3131
import {sastScan} from './services/scanners/SastScanner';
3232
import {captureException, initSentry} from './sentry';
3333
import {refreshDiagnosticCollectionData} from './services/diagnostics/common';
34+
import {getVsCodeRootPathPrefix} from './utils/GlobalConfig';
3435

3536
export async function activate(context: vscode.ExtensionContext) {
3637
initSentry();
@@ -100,14 +101,10 @@ export async function activate(context: vscode.ExtensionContext) {
100101
}
101102

102103
const projectPath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
103-
if (!projectPath) {
104-
return;
105-
}
106104

107-
// verify that file in the workspace
108-
// user can trigger save of a VS Code settings file
109-
// which we don't want to scan
110-
if (!fileFsPath.startsWith(projectPath)) {
105+
const vsCodeAppRootPrefix = getVsCodeRootPathPrefix();
106+
if (fileFsPath.startsWith(vsCodeAppRootPrefix)) {
107+
// user can trigger save of a VS Code settings files which we don't want to scan
111108
return;
112109
}
113110

src/utils/GlobalConfig.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as os from 'os';
2+
import * as path from 'path';
3+
4+
export const getVsCodeRootPathPrefix = (): string => {
5+
// Get the path to the global VS Code app folder based on OS
6+
// Ref: https://github.com/microsoft/vscode/issues/3884#issue-139391403
7+
8+
const homeDir = os.homedir();
9+
let globalConfigPath: string;
10+
if (process.platform === 'win32') {
11+
// Windows
12+
globalConfigPath = path.join(homeDir, 'AppData', 'Roaming', 'Code');
13+
} else if (process.platform === 'darwin') {
14+
// macOS
15+
globalConfigPath = path.join(homeDir, 'Library', 'Application Support', 'Code');
16+
} else {
17+
// Linux
18+
globalConfigPath = path.join(homeDir, '.config', 'Code');
19+
}
20+
21+
return globalConfigPath;
22+
};
23+

0 commit comments

Comments
 (0)