diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e1100a3c..4eefcc0bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Change default CLI download path to be in extension directory. - Delete sentry reporting. - send analytics event "plugin installed" the first time the extension is started +- Allow `${workspaceFolder}` in `trustedFolders` and `folderConfigs` ## [2.19.2] - Update download endpoint to downloads.snyk.io. diff --git a/src/snyk/common/languageServer/settings.ts b/src/snyk/common/languageServer/settings.ts index e1351d348..c3dcf450b 100644 --- a/src/snyk/common/languageServer/settings.ts +++ b/src/snyk/common/languageServer/settings.ts @@ -3,6 +3,7 @@ import { CLI_INTEGRATION_NAME } from '../../cli/contants/integration'; import { Configuration, FolderConfig, IConfiguration, SeverityFilter } from '../configuration/configuration'; import { User } from '../user'; import { PROTOCOL_VERSION } from '../constants/languageServer'; +import { vsCodeWorkspace } from '../vscode/workspace'; export type ServerSettings = { // Feature toggles @@ -80,12 +81,29 @@ export class LanguageServerSettings { scanningMode: configuration.scanningMode, insecure: `${configuration.getInsecure()}`, enableTrustedFoldersFeature: 'true', - trustedFolders: configuration.getTrustedFolders(), + trustedFolders: configuration.getTrustedFolders().map((value, _index, _array) => { + const wf = vsCodeWorkspace.getWorkspaceFolders()?.[0]; + if (wf) { + return value.replace('${workspaceFolder}', wf); + } else { + return value; + } + }), integrationName: CLI_INTEGRATION_NAME, integrationVersion: await Configuration.getVersion(), deviceId: user.anonymousId, requiredProtocolVersion: `${PROTOCOL_VERSION}`, - folderConfigs: configuration.getFolderConfigs(), + folderConfigs: configuration.getFolderConfigs().map((value, _index, _array) => { + const wf = vsCodeWorkspace.getWorkspaceFolders()?.[0]; + if (wf) { + return { + folderPath: value.folderPath.replace('${workspaceFolder}', wf), + baseBranch: value.baseBranch, + localBranches: value.localBranches, + }; + } + return value; + }), enableSnykOSSQuickFixCodeActions: `${configuration.getPreviewFeatures().ossQuickfixes}`, hoverVerbosity: 1, }; diff --git a/src/test/integration/configuration.test.ts b/src/test/integration/configuration.test.ts index 5c3e5d43a..29edd4ff4 100644 --- a/src/test/integration/configuration.test.ts +++ b/src/test/integration/configuration.test.ts @@ -1,9 +1,10 @@ -import { deepStrictEqual, strictEqual } from 'assert'; +import { deepStrictEqual, strictEqual, notStrictEqual } from 'assert'; import { FeaturesConfiguration } from '../../snyk/common/configuration/configuration'; import { configuration } from '../../snyk/common/configuration/instance'; import vscode from 'vscode'; -import { ADVANCED_CUSTOM_ENDPOINT } from '../../snyk/common/constants/settings'; - +import { ADVANCED_CUSTOM_ENDPOINT, FOLDER_CONFIGS, TRUSTED_FOLDERS } from '../../snyk/common/constants/settings'; +import { LanguageServerSettings } from '../../snyk/common/languageServer/settings'; +import { User } from '../../snyk/common/user'; suite('Configuration', () => { test('settings change is reflected', async () => { await vscode.workspace.getConfiguration().update(ADVANCED_CUSTOM_ENDPOINT, ''); @@ -32,4 +33,19 @@ suite('Configuration', () => { deepStrictEqual(configuration.getFeaturesConfiguration(), featuresConfig); await configuration.setToken(''); }); + + test('workspaceFolder is transformed', async () => { + await vscode.workspace.getConfiguration().update(TRUSTED_FOLDERS, ['${workspaceFolder}']); + await vscode.workspace.getConfiguration().update(FOLDER_CONFIGS, [ + { + folderPath: '${workspaceFolder}', + baseBranch: 'baseBranch', + localBranches: [], + }, + ]); + + const serverSettings = await LanguageServerSettings.fromConfiguration(configuration, new User()); + notStrictEqual(serverSettings.trustedFolders?.at(0), '${workspaceFolder}'); + notStrictEqual(serverSettings.folderConfigs?.at(0)?.folderPath, '${workspaceFolder}'); + }); });