'use strict' ; import * as path from 'path' ; import * as vscode from 'vscode' ; import { localize } from './utilities' ; export function activate ( context ) { context . subscriptions . push ( vscode . debug . registerDebugConfigurationProvider ( 'lrdb' , new LRDBConfigurationProvider ( ) ) ) ; } export function deactivate ( ) { } class LRDBConfigurationProvider implements vscode . DebugConfigurationProvider { /**
     * Returns an initial debug configuration based on contextual information, e.g. package.json or folder.
     */ provideDebugConfigurations ( folder ) { return [ createLaunchConfigFromContext ( folder , false ) ] ; } /**
     * Try to add all missing attributes to the debug configuration being launched.
     */ resolveDebugConfiguration ( folder , config ) { if ( ! config . type && ! config . request && ! config . name ) { config = createLaunchConfigFromContext ( folder , true ) ; if ( ! config . program ) { const message = 'Cannot find a program to debug' ; return vscode . window . showInformationMessage ( message ) . then ( ( ) => { return undefined ; } ) ; } } if ( ! config . cwd ) { if ( folder ) { config . cwd = folder . uri . fsPath ; } else if ( config . program ) { config . cwd = path . dirname ( config . program ) ; } } return config ; } } function createLaunchConfigFromContext ( folder , resolve ) { const config = { type : 'lrdb' , request : 'launch' , name : localize ( 'lrdb.launch.config.name' , 'Launch Lua program' ) , } ; let program ; const editor = vscode . window . activeTextEditor ; if ( editor ) { const languageId = editor . document . languageId ; if ( languageId === 'lua' ) { const wf = vscode . workspace . getWorkspaceFolder ( editor . document . uri ) ; if ( wf === folder ) { program = vscode . workspace . asRelativePath ( editor . document . uri ) ; if ( ! path . isAbsolute ( program ) ) { program = '${workspaceFolder}/' + program ; } } } } if ( ! resolve && ! program ) { program = '${file}' ; } if ( program ) { config [ 'program' ] = program ; } return config ; }