Skip to content

Commit

Permalink
Document settings in situ
Browse files Browse the repository at this point in the history
  • Loading branch information
firelizzard18 committed Nov 13, 2024
1 parent ed0f8e5 commit 5533a5e
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 123 deletions.
75 changes: 0 additions & 75 deletions docs/settings.md

This file was deleted.

66 changes: 39 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,72 +55,84 @@
"configuration": {
"title": "Go Companion",
"properties": {
"goExp.testExplorer.enable": {
"exp-vscode-go.testExplorer.enable": {
"order": 0,
"type": "boolean",
"default": true,
"scope": "window",
"description": "Enable the Go test explorer"
"markdownDescription": "Enable the Go test explorer"
},
"goExp.testExplorer.exclude": {
"type": "object",
"default": {},
"description": "Exclude directories and/or files from the test explorer. The value of `go.testExplorer.exclude` is merged with `files.exclude`. `go.testExplorer.exclude` takes precedence if an entry appears in both. If `files.exclude` contains `\"examples\": true` and `go.testExplorer.exclude` contains `\"examples\": false`, the latter will take precedence - matching entries will be excluded from the file explorer but included in the test explorer. Otherwise if either `go.testExplorer.exclude` or `files.exclude` contains an entry with a value of `true`, tests and/or packages matching that entry will be excluded from the test explorer.",
"scope": "resource",
"additionalProperties": {
"type": "boolean"
}
},
"goExp.testExplorer.discovery": {
"exp-vscode-go.testExplorer.discovery": {
"order": 1,
"type": "string",
"scope": "resource",
"markdownDescription": "Enable automatic discovery of tests.",
"default": "on",
"enum": [
"on",
"off"
],
"markdownEnumDescriptions": [
"Enable automatic discovery of tests in open workspaces",
"Disable automatic discovery. No tests are shown until a file is open, and only tests within the same package will be shown. Tests within that package will continue to be shown (even if all files are closed) until the editor/extension is restarted."
]
},
"exp-vscode-go.testExplorer.exclude": {
"type": "object",
"default": {},
"markdownDescription": "Exclude directories and/or files from the test explorer. This is merged with `#files.exclude#`. This setting takes precedence if an entry appears in both. If `#files.exclude#` contains `\"examples\": true` and this setting contains `\"examples\": false`, the latter will take precedence - matching entries will be excluded from the file explorer but included in the test explorer. Otherwise if either this setting or `#files.exclude#` contains an entry with a value of `true`, tests and/or packages matching that entry will be excluded from the test explorer.",
"scope": "resource",
"description": "Control automatic discovery of tests"
"additionalProperties": {
"type": "boolean"
}
},
"goExp.testExplorer.showFiles": {
"exp-vscode-go.testExplorer.showFiles": {
"type": "boolean",
"default": false,
"scope": "resource",
"description": "Show files"
"markdownDescription": "Show files\n - `false` - tests are nested within packages:\n - foo (package)\n - TestFoo\n - `true` - test are nested within files:\n - foo (package)\n - test_foo.go\n - TestFoo"
},
"goExp.testExplorer.nestPackages": {
"exp-vscode-go.testExplorer.nestPackages": {
"type": "boolean",
"default": false,
"scope": "resource",
"description": "Nest packages"
"markdownDescription": "Nest packages\n - `false` - packages are siblings:\n - example.com (module)\n - foo (package)\n - foo/bar (package)\n - `true` - packages are nested:\n - example.com (module)\n - foo (package)\n - bar (package)\n - Directories that are not packages are ignored regardless of this setting. If\n `foo` is not a package, foo/bar will not be nested:\n - example.com (module)\n - foo/bar (package)"
},
"goExp.testExplorer.nestSubtests": {
"exp-vscode-go.testExplorer.nestSubtests": {
"type": "boolean",
"default": true,
"scope": "resource",
"description": "Nest subtests"
"markdownDescription": "Nest subtests\n - `true` - subtests are nested:\n - TestFoo\n - Bar\n - Baz\n - `false` - all tests are siblings\n - TestFoo\n - TestFoo/Bar\n - TestFoo/Bar/Baz"
},
"goExp.testExplorer.codeLens": {
"exp-vscode-go.testExplorer.codeLens": {
"type": "string",
"default": "off",
"scope": "resource",
"markdownDescription": "Show code lenses for running and debugging tests",
"enum": [
"on",
"off",
"debug",
"run"
],
"default": "off",
"scope": "resource",
"description": "Show code lenses for running and debugging tests"
"markdownEnumDescriptions": [
"Enable code lenses for tests",
"Disable code lenses for tests",
"Enable only \"run test\" code lenses",
"Enable only \"debug test\" code lenses"
]
},
"goExp.testExplorer.dynamicSubtestLimit": {
"exp-vscode-go.testExplorer.dynamicSubtestLimit": {
"type": "integer",
"default": 50,
"scope": "resource",
"description": "Limits the number of subtests that are included in the test explorer. Set to 0 to include all subtests."
"markdownDescription": "Limits the number of (dynamic) subtests that are included. If the number of subtests of a test reaches this limit, additional subtests will be ignored. Set this to 0 to disable the limit, though this may cause the test explorer to perform badly."
},
"goExp.testExplorer.runPackageBenchmarks": {
"exp-vscode-go.testExplorer.runPackageBenchmarks": {
"type": "boolean",
"default": false,
"scope": "resource",
"description": "When the test explorer is used to run all tests within a package, include benchmarks"
"markdownDescription": "Always run benchmarks. By default (with this set to `false`), benchmarks are excluded from test runs unless benchmarks are explicitly selected or the run contains nothing but benchmarks."
}
}
},
Expand Down
7 changes: 4 additions & 3 deletions src/test/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class TestConfig {
* Get a configuration value.
*/
get<T>(name: string) {
return this.#workspace.getConfiguration('goExp', this.#scope).get<T>(`testExplorer.${name}`);
return this.#workspace.getConfiguration('exp-vscode-go', this.#scope).get<T>(`testExplorer.${name}`);
}

readonly enable = () => this.get<boolean>('enable');
Expand All @@ -61,10 +61,11 @@ export class TestConfig {
};

/**
* @returns An array of compiled minimatch patterns from `goExp.testExplorer.exclude` and `files.exclude`.
* @returns An array of compiled minimatch patterns from
* `exp-vscode-go.testExplorer.exclude` and `files.exclude`.
*/
readonly exclude = () => {
// Merge files.exclude and goExp.testExplorer.exclude
// Merge files.exclude and exp-vscode-go.testExplorer.exclude
const a = this.get<Record<string, boolean>>('exclude') || {};
const b = this.#workspace.getConfiguration('files', this.#scope).get<Record<string, boolean>>('exclude') || {};
const v = Object.assign({}, b, a);
Expand Down
16 changes: 8 additions & 8 deletions src/test/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ async function registerTestController(ctx: ExtensionContext, testCtx: Context) {

// [Event] Configuration change
event(workspace.onDidChangeConfiguration, 'changed configuration', async (e) => {
if (e.affectsConfiguration('goExp.testExplorer.enable')) {
const enabled = workspace.getConfiguration('goExp').get<boolean>('testExplorer.enable');
if (e.affectsConfiguration('exp-vscode-go.testExplorer.enable')) {
const enabled = workspace.getConfiguration('exp-vscode-go').get<boolean>('testExplorer.enable');
if (enabled === manager.enabled) {
return;
}
Expand All @@ -81,11 +81,11 @@ async function registerTestController(ctx: ExtensionContext, testCtx: Context) {
}
if (
e.affectsConfiguration('files.exclude') ||
e.affectsConfiguration('goExp.testExplorer.exclude') ||
e.affectsConfiguration('goExp.testExplorer.discovery') ||
e.affectsConfiguration('goExp.testExplorer.showFiles') ||
e.affectsConfiguration('goExp.testExplorer.nestPackages') ||
e.affectsConfiguration('goExp.testExplorer.nestSubtests')
e.affectsConfiguration('exp-vscode-go.testExplorer.exclude') ||
e.affectsConfiguration('exp-vscode-go.testExplorer.discovery') ||
e.affectsConfiguration('exp-vscode-go.testExplorer.showFiles') ||
e.affectsConfiguration('exp-vscode-go.testExplorer.nestPackages') ||
e.affectsConfiguration('exp-vscode-go.testExplorer.nestSubtests')
) {
await manager.reloadView();
}
Expand Down Expand Up @@ -130,7 +130,7 @@ async function registerTestController(ctx: ExtensionContext, testCtx: Context) {
event(watcher.onDidDelete, 'deleted file', async (e) => manager.enabled && manager.reloadUri(e));

// Setup the controller (if enabled)
if (workspace.getConfiguration('goExp').get<boolean>('testExplorer.enable')) {
if (workspace.getConfiguration('exp-vscode-go').get<boolean>('testExplorer.enable')) {
await setup();
}
}
2 changes: 1 addition & 1 deletion src/test/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export function shouldRunBenchmarks(workspace: Workspace, pkg: Package) {
// `testExplorer.runPackageBenchmarks`. However, if the user clicks the run
// button on a file or package that contains benchmarks and nothing else,
// they likely expect those benchmarks to run.
if (workspace.getConfiguration('goExp', pkg.uri).get<boolean>('testExplorer.runPackageBenchmarks')) {
if (workspace.getConfiguration('exp-vscode-go', pkg.uri).get<boolean>('testExplorer.runPackageBenchmarks')) {
return true;
}
for (const test of pkg.getTests()) {
Expand Down
1 change: 0 additions & 1 deletion src/test/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export type FileSystem = Pick<vscode.FileSystem, 'delete' | 'createDirectory' |

// The subset of vscode.workspace that is used by the test explorer.
export type Workspace = Pick<typeof vscode.workspace, 'workspaceFolders' | 'getWorkspaceFolder' | 'saveAll'> & {
// Only allow reading the goExp config
getConfiguration(section: string, scope?: vscode.ConfigurationScope | null): ConfigValue;

readonly fs: FileSystem;
Expand Down
16 changes: 8 additions & 8 deletions test/component/test/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ class TestCommands implements Commands {
class TestWorkspace implements Workspace {
readonly workspaceFolders: WorkspaceFolder[] = [];
readonly config: Configuration = {
enable: config['goExp.testExplorer.enable'].default,
exclude: config['goExp.testExplorer.exclude'].default,
discovery: config['goExp.testExplorer.discovery'].default as any,
showFiles: config['goExp.testExplorer.showFiles'].default,
nestPackages: config['goExp.testExplorer.nestPackages'].default,
nestSubtests: config['goExp.testExplorer.nestSubtests'].default,
runPackageBenchmarks: config['goExp.testExplorer.runPackageBenchmarks'].default,
enable: config['exp-vscode-go.testExplorer.enable'].default,
exclude: config['exp-vscode-go.testExplorer.exclude'].default,
discovery: config['exp-vscode-go.testExplorer.discovery'].default as any,
showFiles: config['exp-vscode-go.testExplorer.showFiles'].default,
nestPackages: config['exp-vscode-go.testExplorer.nestPackages'].default,
nestSubtests: config['exp-vscode-go.testExplorer.nestSubtests'].default,
runPackageBenchmarks: config['exp-vscode-go.testExplorer.runPackageBenchmarks'].default,
};

readonly fs = new MockFileSystem();
Expand All @@ -150,7 +150,7 @@ class TestWorkspace implements Workspace {
}

getConfiguration(section: string): ConfigValue {
if (section !== 'goExp') {
if (section !== 'exp-vscode-go') {
return { get: () => undefined };
}
return {
Expand Down

0 comments on commit 5533a5e

Please sign in to comment.