33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6+ import * as nls from 'vs/nls' ;
67import * as Types from 'vs/base/common/types' ;
78import { IJSONSchemaMap } from 'vs/base/common/jsonSchema' ;
89import * as Objects from 'vs/base/common/objects' ;
@@ -12,6 +13,7 @@ import { ProblemMatcher } from 'vs/workbench/contrib/tasks/common/problemMatcher
1213import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace' ;
1314import { RawContextKey } from 'vs/platform/contextkey/common/contextkey' ;
1415import { IExtensionDescription } from 'vs/platform/extensions/common/extensions' ;
16+ import { TaskDefinitionRegistry } from 'vs/workbench/contrib/tasks/common/taskDefinitionRegistry' ;
1517
1618export const TASK_RUNNING_STATE = new RawContextKey < boolean > ( 'taskRunning' , false ) ;
1719
@@ -921,4 +923,76 @@ export namespace TaskEvent {
921923 return Object . freeze ( { kind : TaskEventKind . Changed } ) ;
922924 }
923925 }
924- }
926+ }
927+
928+ export namespace KeyedTaskIdentifier {
929+ function sortedStringify ( literal : any ) : string {
930+ const keys = Object . keys ( literal ) . sort ( ) ;
931+ let result : string = '' ;
932+ for ( let position in keys ) {
933+ let stringified = literal [ keys [ position ] ] ;
934+ if ( stringified instanceof Object ) {
935+ stringified = sortedStringify ( test ) ;
936+ } else if ( typeof stringified === 'string' ) {
937+ stringified = stringified . replace ( / , / g, ',,' ) ;
938+ }
939+ result += keys [ position ] + ',' + stringified + ',' ;
940+ }
941+ return result ;
942+ }
943+ export function create ( value : TaskIdentifier ) : KeyedTaskIdentifier {
944+ const resultKey = sortedStringify ( value ) ;
945+ console . log ( resultKey ) ;
946+ return { _key : resultKey , type : value . taskType } ;
947+ }
948+ }
949+
950+ export namespace TaskDefinition {
951+ export function createTaskIdentifier ( external : TaskIdentifier , reporter : { error ( message : string ) : void ; } ) : KeyedTaskIdentifier | undefined {
952+ let definition = TaskDefinitionRegistry . get ( external . type ) ;
953+ if ( definition === undefined ) {
954+ // We have no task definition so we can't sanitize the literal. Take it as is
955+ let copy = Objects . deepClone ( external ) ;
956+ delete copy . _key ;
957+ return KeyedTaskIdentifier . create ( copy ) ;
958+ }
959+
960+ let literal : { type : string ; [ name : string ] : any } = Object . create ( null ) ;
961+ literal . type = definition . taskType ;
962+ let required : Set < string > = new Set ( ) ;
963+ definition . required . forEach ( element => required . add ( element ) ) ;
964+
965+ let properties = definition . properties ;
966+ for ( let property of Object . keys ( properties ) ) {
967+ let value = external [ property ] ;
968+ if ( value !== undefined && value !== null ) {
969+ literal [ property ] = value ;
970+ } else if ( required . has ( property ) ) {
971+ let schema = properties [ property ] ;
972+ if ( schema . default !== undefined ) {
973+ literal [ property ] = Objects . deepClone ( schema . default ) ;
974+ } else {
975+ switch ( schema . type ) {
976+ case 'boolean' :
977+ literal [ property ] = false ;
978+ break ;
979+ case 'number' :
980+ case 'integer' :
981+ literal [ property ] = 0 ;
982+ break ;
983+ case 'string' :
984+ literal [ property ] = '' ;
985+ break ;
986+ default :
987+ reporter . error ( nls . localize (
988+ 'TaskDefinition.missingRequiredProperty' ,
989+ 'Error: the task identifier \'{0}\' is missing the required property \'{1}\'. The task identifier will be ignored.' , JSON . stringify ( external , undefined , 0 ) , property
990+ ) ) ;
991+ return undefined ;
992+ }
993+ }
994+ }
995+ }
996+ return KeyedTaskIdentifier . create ( literal ) ;
997+ }
998+ }
0 commit comments