-
Notifications
You must be signed in to change notification settings - Fork 763
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extension/src/goTest: disable when exp-vscode-go is installed
Adds 'experimental features' to preview versions. The first experimental feature: when exp-vscode-go is installed, disable goTest (the test explorer implementation). Adds a setting to disable this behavior Notifies the user the first time goTest is disabled for this reason. Modifies goTest to support being unloaded or reloaded based on configuration changes. Change-Id: I7a4b2188b5038f9f6b5841ed47a5b27307e24ef1 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/613695 Reviewed-by: Hyang-Ah Hana Kim <[email protected]> kokoro-CI: kokoro <[email protected]> Commit-Queue: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Hongxiang Jiang <[email protected]> Auto-Submit: Hyang-Ah Hana Kim <[email protected]>
- Loading branch information
1 parent
866878e
commit 33b0b78
Showing
9 changed files
with
249 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Experiments | ||
|
||
Pre-release versions of [vscode-go][vscode-go] include experimental features. | ||
These features may be individually enabled or disabled via the setting | ||
`go.experiments`. | ||
|
||
[vscode-go]: https://github.com/golang/vscode-go/blob/master/README.md#pre-release-versions | ||
|
||
## Test explorer | ||
|
||
[Go Companion][exp-vscode-go] includes an experimental test explorer | ||
implementation based on `gopls`'s test discovery. This requires gopls v0.17.0 or | ||
newer. If Go Companion is present and vscode-go is a pre-release version, | ||
vscode-go will prefer Go Companion's test explorer, disabling its own, unless | ||
the experiment is set to `off`. The experimental test explorer provides more | ||
robust test discovery by using gopls, including static discovery of _some_ | ||
subtests. It also implements: | ||
|
||
- Ignore tests within files excluded by `files.exclude` or | ||
`goExp.testExplorer.exclude`. | ||
- Disable automatic discovery of tests by setting `goExp.testExplorer.discovery` | ||
to "off". | ||
- Control how tests are displayed with `goExp.testExplorer.showFiles`, | ||
`goExp.testExplorer.nestPackages`, and `goExp.testExplorer.nestSubtests`. | ||
- Debugging a test updates its status in the test explorer. | ||
- Support for continuous runs. | ||
- Support for code coverage. | ||
- Code lenses (hidden by default) that are integrated with the test explorer. | ||
- Integrated viewer for pprof profiles. | ||
|
||
[exp-vscode-go]: https://marketplace.visualstudio.com/items?itemName=ethan-reesor.exp-vscode-go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright 2024 The Go Authors. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for license information. | ||
*--------------------------------------------------------*/ | ||
|
||
import { EventEmitter, ExtensionContext, ExtensionMode, extensions, workspace } from 'vscode'; | ||
import { extensionInfo } from './config'; | ||
|
||
type Settings = { | ||
testExplorer: boolean; | ||
}; | ||
|
||
class Experiments { | ||
#didChange = new EventEmitter<Experiments>(); | ||
|
||
// Default to disabled | ||
#testExplorer = false; | ||
|
||
activate(ctx: ExtensionContext) { | ||
// Cleanup the event emitter when the extension is unloaded | ||
ctx.subscriptions.push(this.#didChange); | ||
|
||
// Don't enable any experiments in a production release | ||
if (ctx.extensionMode === ExtensionMode.Production && !extensionInfo.isPreview) { | ||
return; | ||
} | ||
|
||
// Check on boot | ||
this.#maybeEnableExperiments(); | ||
|
||
// Check when an extension is installed or uninstalled | ||
ctx.subscriptions.push(extensions.onDidChange(() => this.#maybeEnableExperiments())); | ||
|
||
// Check when the configuration changes | ||
ctx.subscriptions.push( | ||
workspace.onDidChangeConfiguration((e) => { | ||
if (e.affectsConfiguration('go.experiments')) { | ||
this.#maybeEnableExperiments(); | ||
} | ||
}) | ||
); | ||
} | ||
|
||
/** | ||
* Checks whether experiments should be enabled or disabled. If the | ||
* enable/disable state of an experiment changes, an {@link onDidChange} | ||
* event is issued. | ||
*/ | ||
#maybeEnableExperiments() { | ||
const settings = workspace.getConfiguration('go').get<Settings>('experiments'); | ||
|
||
// Check if the test explorer experiment should be activated | ||
const goExp = extensions.getExtension('ethan-reesor.exp-vscode-go'); | ||
const testExplorer = settings?.testExplorer !== false && !!goExp; | ||
if (testExplorer !== this.#testExplorer) { | ||
this.#testExplorer = testExplorer; | ||
this.#didChange.fire(this); | ||
} | ||
} | ||
|
||
/** | ||
* onDidChange issues an event whenever the enable/disable status of an | ||
* experiment changes. This can happen due to configuration changes or | ||
* companion extensions being loaded or unloaded. | ||
*/ | ||
readonly onDidChange = this.#didChange.event; | ||
|
||
/** | ||
* If true, this extension's test explorer is disabled in favor of Go | ||
* Companion's test explorer. | ||
*/ | ||
get testExplorer() { | ||
return this.#testExplorer; | ||
} | ||
} | ||
|
||
export const experiments = new Experiments(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.