All files / utilities config-scope.ts

100% Statements 15/15
100% Branches 10/10
100% Functions 5/5
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66          73x 73x 73x                               6x                 14x               73x 3x   1x   1x   1x                 73x 3x   1x   1x   1x    
/**
 * List of configuration targets supported by Mentor. The values correspond to
 * the VS Code ConfigurationTarget enum (https://code.visualstudio.com/api/references/vscode-api#ConfigurationTarget).
 * But we define our own enum here to avoid a dependency on the 'vscode' module for webviews and LSP processes.
 */
export enum ConfigurationScope {
	User = 1,
	Workspace = 2
}
 
/**
 * String form of a {@link ConfigurationScope}, used as a serializable
 * discriminator in webview messages, settings-panel state and section
 * descriptors.
 */
export type ScopeKey = 'user' | 'workspace';
 
/**
 * Converts a {@link ConfigurationScope} into its serializable {@link ScopeKey}.
 * @param scope A configuration scope value.
 * @returns The corresponding scope key.
 */
export function scopeToKey(scope: ConfigurationScope): ScopeKey {
	return scope === ConfigurationScope.User ? 'user' : 'workspace';
}
 
/**
 * Converts a serializable {@link ScopeKey} back into its {@link ConfigurationScope}.
 * @param key A scope key.
 * @returns The corresponding configuration scope.
 */
export function keyToScope(key: ScopeKey): ConfigurationScope {
	return key === 'user' ? ConfigurationScope.User : ConfigurationScope.Workspace;
}
 
/**
 * Get a label for a configuration scope.
 * @param scope A configuration scope value.
 * @returns A string label for the configuration scope.
 */
export const getConfigurationScopeLabel = (scope: ConfigurationScope) => {
	switch (scope) {
		case ConfigurationScope.User:
			return 'User';
		case ConfigurationScope.Workspace:
			return 'Workspace';
		default:
			return 'Unknown';
	}
};
 
/**
 * Get a description for a configuration scope.
 * @param scope A configuration scope value.
 * @returns A string description of the configuration scope.
 */
export const getConfigurationScopeDescription = (scope: ConfigurationScope) => {
	switch (scope) {
		case ConfigurationScope.User:
			return 'The settings will be available in all Visual Studio Code sessions on your local machine.';
		case ConfigurationScope.Workspace:
			return 'The settings are stored in the .vscode folder. All connection parameters except secrets can be shared with version control.';
		default:
			return '';
	}
}