Skip to content

Commit 8044acb

Browse files
author
XYPRO-23\kyle.nahrgang
committed
Support workspaceFolder in trusted folders and folder configs
1 parent 1b81854 commit 8044acb

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Change default CLI download path to be in extension directory.
1010
- Delete sentry reporting.
1111
- send analytics event "plugin installed" the first time the extension is started
12+
- Allow `${workspaceFolder}` in `trustedFolders` and `folderConfigs`
1213

1314
## [2.19.2]
1415
- Update download endpoint to downloads.snyk.io.

src/snyk/common/languageServer/settings.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { CLI_INTEGRATION_NAME } from '../../cli/contants/integration';
33
import { Configuration, FolderConfig, IConfiguration, SeverityFilter } from '../configuration/configuration';
44
import { User } from '../user';
55
import { PROTOCOL_VERSION } from '../constants/languageServer';
6+
import { vsCodeWorkspace } from '../vscode/workspace';
67

78
export type ServerSettings = {
89
// Feature toggles
@@ -80,12 +81,29 @@ export class LanguageServerSettings {
8081
scanningMode: configuration.scanningMode,
8182
insecure: `${configuration.getInsecure()}`,
8283
enableTrustedFoldersFeature: 'true',
83-
trustedFolders: configuration.getTrustedFolders(),
84+
trustedFolders: configuration.getTrustedFolders().map((value, _index, _array) => {
85+
const wf = vsCodeWorkspace.getWorkspaceFolders()?.[0];
86+
if (wf) {
87+
return value.replace('${workspaceFolder}', wf);
88+
} else {
89+
return value;
90+
}
91+
}),
8492
integrationName: CLI_INTEGRATION_NAME,
8593
integrationVersion: await Configuration.getVersion(),
8694
deviceId: user.anonymousId,
8795
requiredProtocolVersion: `${PROTOCOL_VERSION}`,
88-
folderConfigs: configuration.getFolderConfigs(),
96+
folderConfigs: configuration.getFolderConfigs().map((value, _index, _array) => {
97+
const wf = vsCodeWorkspace.getWorkspaceFolders()?.[0];
98+
if (wf) {
99+
return {
100+
folderPath: value.folderPath.replace('${workspaceFolder}', wf),
101+
baseBranch: value.baseBranch,
102+
localBranches: value.localBranches,
103+
};
104+
}
105+
return value;
106+
}),
89107
enableSnykOSSQuickFixCodeActions: `${configuration.getPreviewFeatures().ossQuickfixes}`,
90108
hoverVerbosity: 1,
91109
};

src/test/integration/configuration.test.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { deepStrictEqual, strictEqual } from 'assert';
1+
import { deepStrictEqual, strictEqual, notStrictEqual } from 'assert';
22
import { FeaturesConfiguration } from '../../snyk/common/configuration/configuration';
33
import { configuration } from '../../snyk/common/configuration/instance';
44
import vscode from 'vscode';
5-
import { ADVANCED_CUSTOM_ENDPOINT } from '../../snyk/common/constants/settings';
6-
5+
import { ADVANCED_CUSTOM_ENDPOINT, FOLDER_CONFIGS, TRUSTED_FOLDERS } from '../../snyk/common/constants/settings';
6+
import { LanguageServerSettings } from '../../snyk/common/languageServer/settings';
7+
import { User } from '../../snyk/common/user';
78
suite('Configuration', () => {
89
test('settings change is reflected', async () => {
910
await vscode.workspace.getConfiguration().update(ADVANCED_CUSTOM_ENDPOINT, '');
@@ -32,4 +33,19 @@ suite('Configuration', () => {
3233
deepStrictEqual(configuration.getFeaturesConfiguration(), featuresConfig);
3334
await configuration.setToken('');
3435
});
36+
37+
test('workspaceFolder is transformed', async () => {
38+
await vscode.workspace.getConfiguration().update(TRUSTED_FOLDERS, ['${workspaceFolder}']);
39+
await vscode.workspace.getConfiguration().update(FOLDER_CONFIGS, [
40+
{
41+
folderPath: '${workspaceFolder}',
42+
baseBranch: 'baseBranch',
43+
localBranches: [],
44+
},
45+
]);
46+
47+
const serverSettings = await LanguageServerSettings.fromConfiguration(configuration, new User());
48+
notStrictEqual(serverSettings.trustedFolders?.at(0), '${workspaceFolder}');
49+
notStrictEqual(serverSettings.folderConfigs?.at(0)?.folderPath, '${workspaceFolder}');
50+
});
3551
});

0 commit comments

Comments
 (0)