Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support workspaceFolder in trusted folders and folder configs #565

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}');
});
});