import { ConfigurationTarget , Uri , workspace , WorkspaceConfiguration , WorkspaceFolder } from "vscode" ; import { IActionContext } from "vscode-azureextensionui" ; import { ProjectLanguage } from '../constants' ; import { ext } from "../extensionVariables" ; import { dotnetUtils } from "../utils/dotnetUtils" ; /**
 * Uses ext.prefix 'azureFunctions' unless otherwise specified
 */ export async function updateGlobalSetting < T = string > ( section , value , prefix = ext . prefix ) { const projectConfiguration = workspace . getConfiguration ( prefix ) ; await projectConfiguration . update ( section , value , ConfigurationTarget . Global ) ; } /**
 * Uses ext.prefix 'azureFunctions' unless otherwise specified
 */ export async function updateWorkspaceSetting < T = string > ( section , value , fsPath , prefix = ext . prefix ) { const projectConfiguration = workspace . getConfiguration ( prefix , getScope ( fsPath ) ) ; await projectConfiguration . update ( section , value ) ; } /**
 * Uses ext.prefix 'azureFunctions' unless otherwise specified
 */ export function getGlobalSetting < T > ( key , prefix = ext . prefix ) { const projectConfiguration = workspace . getConfiguration ( prefix ) ; const result = projectConfiguration . inspect < T > ( key ) ; return result && result . globalValue ; } /**
 * Uses ext.prefix 'azureFunctions' unless otherwise specified
 */ export function getWorkspaceSetting < T > ( key , fsPath ? , prefix = ext . prefix ) { const projectConfiguration = workspace . getConfiguration ( prefix , getScope ( fsPath ) ) ; return projectConfiguration . get < T > ( key ) ; } function getScope ( fsPath ) { return typeof fsPath === 'string' ? Uri . file ( fsPath ) : fsPath ; } /**
 * Searches through all open folders and gets the current workspace setting (as long as there are no conflicts)
 * Uses ext.prefix 'azureFunctions' unless otherwise specified
 */ export function getWorkspaceSettingFromAnyFolder ( key , prefix = ext . prefix ) { if ( workspace . workspaceFolders && workspace . workspaceFolders . length > 0 ) { let result ; for ( const folder of workspace . workspaceFolders ) { const projectConfiguration = workspace . getConfiguration ( prefix , folder . uri ) ; const folderResult = projectConfiguration . get < string > ( key ) ; if ( ! result ) { result = folderResult ; } else if ( folderResult && result !== folderResult ) { return undefined ; } } return result ; } else { return getGlobalSetting ( key , prefix ) ; } } /**
 * Gets the "root" worker runtime, aka not the project-specific worker runtime
 * For example, this will return 'dotnet', never 'dotnet-isolated'
 */ export function getRootFunctionsWorkerRuntime ( language ) { switch ( language ) { case ProjectLanguage . JavaScript : case ProjectLanguage . TypeScript : return 'node' ; case ProjectLanguage . CSharp : case ProjectLanguage . FSharp : return 'dotnet' ; case ProjectLanguage . Java : return 'java' ; case ProjectLanguage . Python : return 'python' ; case ProjectLanguage . PowerShell : return 'powershell' ; case ProjectLanguage . Custom : return 'custom' ; default : return undefined ; } } export async function tryGetFunctionsWorkerRuntimeForProject ( context , language , projectPath ) { let runtime = getRootFunctionsWorkerRuntime ( language ) ; if ( language === ProjectLanguage . CSharp || language === ProjectLanguage . FSharp ) { if ( projectPath ) { const projFiles = await dotnetUtils . getProjFiles ( context , language , projectPath ) ; if ( projFiles . length === 1 ) { if ( await dotnetUtils . getIsIsolated ( projFiles [ 0 ] ) ) { runtime += '-isolated' ; } return runtime ; } } return undefined ; } return runtime ; } export function isKnownWorkerRuntime ( runtime ) { return ! ! runtime && [ 'node' , 'dotnet' , 'dotnet-isolated' , 'java' , 'python' , 'powershell' , 'custom' ] . includes ( runtime . toLowerCase ( ) ) ; } export function getFuncWatchProblemMatcher ( language ) { const runtime = getRootFunctionsWorkerRuntime ( language ) ; return runtime && runtime !== 'custom' ? `$func-${ runtime }-watch` : '$func-watch' ; }