| 30 | * npm script, or the npm scripts section. |
| 31 | */ |
| 32 | export class NpmScriptLenProvider implements CodeLensProvider, IDisposable { |
| 33 | private lensLocation = getFreshLensLocation(); |
| 34 | private changeEmitter = new EventEmitter<void>(); |
| 35 | private subscriptions: IDisposable[] = []; |
| 36 | |
| 37 | /** |
| 38 | * @inheritdoc |
| 39 | */ |
| 40 | public onDidChangeCodeLenses = this.changeEmitter.event; |
| 41 | |
| 42 | constructor() { |
| 43 | this.subscriptions.push( |
| 44 | workspace.onDidChangeConfiguration(evt => { |
| 45 | if (evt.affectsConfiguration(Configuration.NpmScriptLens)) { |
| 46 | this.lensLocation = getFreshLensLocation(); |
| 47 | this.changeEmitter.fire(); |
| 48 | } |
| 49 | }), |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @inheritdoc |
| 55 | */ |
| 56 | public provideCodeLenses(document: TextDocument): ProviderResult<CodeLens[]> { |
| 57 | if (this.lensLocation === 'never') { |
| 58 | return []; |
| 59 | } |
| 60 | |
| 61 | const tokens = this.tokenizeScripts(document); |
| 62 | if (!tokens) { |
| 63 | return []; |
| 64 | } |
| 65 | |
| 66 | const title = localize('codelens.debug', '{0} Debug', '$(debug-start)'); |
| 67 | const cwd = path.dirname(document.uri.fsPath); |
| 68 | if (this.lensLocation === 'top') { |
| 69 | return [ |
| 70 | new CodeLens( |
| 71 | new Range(tokens.scriptStart, tokens.scriptStart), |
| 72 | asCommand({ |
| 73 | title, |
| 74 | command: Commands.DebugNpmScript, |
| 75 | arguments: [cwd], |
| 76 | }), |
| 77 | ), |
| 78 | ]; |
| 79 | } |
| 80 | |
| 81 | if (this.lensLocation === 'all') { |
| 82 | const workspaceFolder = workspace.getWorkspaceFolder(document.uri); |
| 83 | return tokens.scripts.map( |
| 84 | ({ name, position }) => |
| 85 | new CodeLens( |
| 86 | new Range(position, position), |
| 87 | asCommand({ |
| 88 | title, |
| 89 | command: Commands.CreateDebuggerTerminal, |
nothing calls this directly
no test coverage detected