Skip to content

Commit

Permalink
Support workspaceFolder in trusted folders and folder configs
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-nahrgang authored and XYPRO-23\kyle.nahrgang committed Dec 16, 2024
1 parent 1b81854 commit 6d00bd9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 20 additions & 2 deletions src/snyk/common/languageServer/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
};
Expand Down
22 changes: 19 additions & 3 deletions src/test/integration/configuration.test.ts
Original file line number Diff line number Diff line change
@@ -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, '');
Expand Down Expand Up @@ -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}');
});
});

0 comments on commit 6d00bd9

Please sign in to comment.