Skip to content

Commit

Permalink
✨ Disable Pester CodeLens Adapter Prompt (#75)
Browse files Browse the repository at this point in the history
Adds a prompt to disable the Pester Codelens adapter when the Pester extension is in use.
  • Loading branch information
JustinGrote authored Oct 16, 2021
1 parent f2b977e commit dee5619
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"type": "boolean",
"default": true,
"markdownDescription": "Automatically runs Pester test files upon changes being detected on save. Uncheck this box to disable this behavior."
},
"pester.suppressCodeLensNotice": {
"type": "boolean",
"markdownDescription": "It is recommended to disable the PowerShell Pester CodeLens when using this extension. Check this box to suppress this dialog. Choosing 'No' in the dialog box will also enable this at a user level"
}
}
}
Expand Down
52 changes: 49 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,63 @@
import { ExtensionContext } from 'vscode'
import { ExtensionContext, window, workspace } from 'vscode'
import { PesterTestController } from './pesterTestController'
import { getPowerShellExtension } from './powershellExtensionClient'
import {
getPowerShellExtension,
PowerShellExtensionClient
} from './powershellExtensionClient'
export async function activate(context: ExtensionContext) {
// PowerShell extension is a prerequisite, but we allow either preview or normal, which is why we do this instead of
// leverage package.json dependencies
const powershellExtension = getPowerShellExtension(context)

// Short circuit this activate call if we didn't find a PowerShell Extension. Another activate will be triggered once
// the powershell extension is available

if (!powershellExtension) {
return
}

// Disable PowerShell codelens setting if present
const psExtensionCodeLensSetting =
PowerShellExtensionClient.GetPesterSettings().codeLens
const suppressCodeLensNotice = workspace
.getConfiguration('pester')
.get<boolean>('suppressCodeLensNotice')

if (psExtensionCodeLensSetting && !suppressCodeLensNotice) {
window
.showInformationMessage(
'The Pester Tests extension recommends disabling the built-in PowerShell extension CodeLens. Would you like to do this?',
'Yes',
'Workspace Only',
'No',
'Dont Ask Again'
)
.then(response => {
switch (response) {
case 'No': {
return
}
case 'Yes': {
workspace
.getConfiguration('powershell.pester')
.update('codeLens', false, true)
break
}
case 'This Workspace Only': {
workspace
.getConfiguration('powershell.pester')
.update('codeLens', false, false)
break
}
case 'Dont Ask Again': {
workspace
.getConfiguration('pester')
.update('suppressCodeLensNotice', true, true)
break
}
}
})
}

context.subscriptions.push(
new PesterTestController(powershellExtension, context)
)
Expand Down

0 comments on commit dee5619

Please sign in to comment.