Best JavaScript code snippet using root
debugConfigurationService.ts
Source:debugConfigurationService.ts
1// Copyright (c) Microsoft Corporation. All rights reserved.2// Licensed under the MIT License.3'use strict';4import { inject, injectable, named } from 'inversify';5import { cloneDeep } from 'lodash';6import { CancellationToken, DebugConfiguration, QuickPickItem, WorkspaceFolder } from 'vscode';7import { DebugConfigStrings } from '../../../common/utils/localize';8import {9 IMultiStepInput,10 IMultiStepInputFactory,11 InputStep,12 IQuickPickParameters,13} from '../../../common/utils/multiStepInput';14import { AttachRequestArguments, DebugConfigurationArguments, LaunchRequestArguments } from '../../types';15import { DebugConfigurationState, DebugConfigurationType, IDebugConfigurationService } from '../types';16import { IDebugConfigurationProviderFactory, IDebugConfigurationResolver } from './types';17@injectable()18export class PythonDebugConfigurationService implements IDebugConfigurationService {19 private cacheDebugConfig: DebugConfiguration | undefined = undefined;20 constructor(21 @inject(IDebugConfigurationResolver)22 @named('attach')23 private readonly attachResolver: IDebugConfigurationResolver<AttachRequestArguments>,24 @inject(IDebugConfigurationResolver)25 @named('launch')26 private readonly launchResolver: IDebugConfigurationResolver<LaunchRequestArguments>,27 @inject(IDebugConfigurationProviderFactory)28 private readonly providerFactory: IDebugConfigurationProviderFactory,29 @inject(IMultiStepInputFactory) private readonly multiStepFactory: IMultiStepInputFactory,30 ) {}31 public async provideDebugConfigurations(32 folder: WorkspaceFolder | undefined,33 token?: CancellationToken,34 ): Promise<DebugConfiguration[] | undefined> {35 const config: Partial<DebugConfigurationArguments> = {};36 const state = { config, folder, token };37 // Disabled until configuration issues are addressed by VS Code. See #400738 const multiStep = this.multiStepFactory.create<DebugConfigurationState>();39 await multiStep.run((input, s) => this.pickDebugConfiguration(input, s), state);40 if (Object.keys(state.config).length === 0) {41 return;42 } else {43 return [state.config as DebugConfiguration];44 }45 }46 public async resolveDebugConfiguration(47 folder: WorkspaceFolder | undefined,48 debugConfiguration: DebugConfiguration,49 token?: CancellationToken,50 ): Promise<DebugConfiguration | undefined> {51 if (debugConfiguration.request === 'attach') {52 return this.attachResolver.resolveDebugConfiguration(53 folder,54 debugConfiguration as AttachRequestArguments,55 token,56 );57 } else if (debugConfiguration.request === 'test') {58 // `"request": "test"` is now deprecated. But some users might have it in their59 // launch config. We get here if they triggered it using F5 or start with debugger.60 throw Error(61 'This configuration can only be used by the test debugging commands. `"request": "test"` is deprecated use "purpose" instead.',62 );63 } else {64 if (Object.keys(debugConfiguration).length === 0) {65 if (this.cacheDebugConfig) {66 debugConfiguration = cloneDeep(this.cacheDebugConfig);67 } else {68 const configs = await this.provideDebugConfigurations(folder, token);69 if (configs === undefined) {70 return;71 }72 if (Array.isArray(configs) && configs.length === 1) {73 debugConfiguration = configs[0];74 }75 this.cacheDebugConfig = cloneDeep(debugConfiguration);76 }77 }78 return this.launchResolver.resolveDebugConfiguration(79 folder,80 debugConfiguration as LaunchRequestArguments,81 token,82 );83 }84 }85 public async resolveDebugConfigurationWithSubstitutedVariables(86 folder: WorkspaceFolder | undefined,87 debugConfiguration: DebugConfiguration,88 token?: CancellationToken,89 ): Promise<DebugConfiguration | undefined> {90 function resolve<T extends DebugConfiguration>(resolver: IDebugConfigurationResolver<T>) {91 return resolver.resolveDebugConfigurationWithSubstitutedVariables(folder, debugConfiguration as T, token);92 }93 return debugConfiguration.request === 'attach' ? resolve(this.attachResolver) : resolve(this.launchResolver);94 }95 protected async pickDebugConfiguration(96 input: IMultiStepInput<DebugConfigurationState>,97 state: DebugConfigurationState,98 ): Promise<InputStep<DebugConfigurationState> | void> {99 type DebugConfigurationQuickPickItem = QuickPickItem & { type: DebugConfigurationType };100 const items: DebugConfigurationQuickPickItem[] = [101 {102 label: DebugConfigStrings.file.selectConfiguration.label(),103 type: DebugConfigurationType.launchFile,104 description: DebugConfigStrings.file.selectConfiguration.description(),105 },106 {107 label: DebugConfigStrings.module.selectConfiguration.label(),108 type: DebugConfigurationType.launchModule,109 description: DebugConfigStrings.module.selectConfiguration.description(),110 },111 {112 label: DebugConfigStrings.attach.selectConfiguration.label(),113 type: DebugConfigurationType.remoteAttach,114 description: DebugConfigStrings.attach.selectConfiguration.description(),115 },116 {117 label: DebugConfigStrings.attachPid.selectConfiguration.label(),118 type: DebugConfigurationType.pidAttach,119 description: DebugConfigStrings.attachPid.selectConfiguration.description(),120 },121 {122 label: DebugConfigStrings.django.selectConfiguration.label(),123 type: DebugConfigurationType.launchDjango,124 description: DebugConfigStrings.django.selectConfiguration.description(),125 },126 {127 label: DebugConfigStrings.fastapi.selectConfiguration.label(),128 type: DebugConfigurationType.launchFastAPI,129 description: DebugConfigStrings.fastapi.selectConfiguration.description(),130 },131 {132 label: DebugConfigStrings.flask.selectConfiguration.label(),133 type: DebugConfigurationType.launchFlask,134 description: DebugConfigStrings.flask.selectConfiguration.description(),135 },136 {137 label: DebugConfigStrings.pyramid.selectConfiguration.label(),138 type: DebugConfigurationType.launchPyramid,139 description: DebugConfigStrings.pyramid.selectConfiguration.description(),140 },141 ];142 state.config = {};143 const pick = await input.showQuickPick<144 DebugConfigurationQuickPickItem,145 IQuickPickParameters<DebugConfigurationQuickPickItem>146 >({147 title: DebugConfigStrings.selectConfiguration.title(),148 placeholder: DebugConfigStrings.selectConfiguration.placeholder(),149 activeItem: items[0],150 items: items,151 });152 if (pick) {153 const provider = this.providerFactory.create(pick.type);154 return provider.buildConfiguration.bind(provider);155 }156 }...
configuration.state.ts
Source:configuration.state.ts
1import {createSelector} from '@ngrx/store';2import {selectConfiguration} from '../app.state';3export interface ConfigurationState {4 useCelsius: boolean;5 darkMode: boolean;6 homePageLocationKey: string;7 isSaveLastLocationKey: boolean;8 savedLocationKey: string;9}10export const temperatureUnitSelector = createSelector(11 selectConfiguration,12 (state: ConfigurationState) => state.useCelsius13);14export const darkModeSelector = createSelector(15 selectConfiguration,16 (state: ConfigurationState) => state.darkMode17);18export const getSavedLocationKeySelector = createSelector(19 selectConfiguration,20 (state: ConfigurationState) => state.savedLocationKey21);22export const getIsSaveLocationKeySelector = createSelector(23 selectConfiguration,24 (state: ConfigurationState) => state.isSaveLastLocationKey25);26export const getHomePageSelector = createSelector(27 selectConfiguration,28 (state: ConfigurationState) => state.homePageLocationKey...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!