'use strict' ; import { CompletionItem , CompletionItemKind , MarkdownString , SnippetString } from 'vscode' ; import { DomainInfo , TypeObjectMap } from 'pddl-workspace' ; import { Variable } from 'pddl-workspace' ; export abstract class Delegate { createOperator ( label , detail , documentation , snippet ? ) { return this . createCompletionItem ( label , detail , documentation , CompletionItemKind . Operator , snippet ) ; } createParameterized ( label , detail , documentation , snippet ? ) { return this . createCompletionItem ( label , detail , documentation , CompletionItemKind . TypeParameter , snippet ) ; } createCompletionItem ( label , detail , documentation , kind , snippet ? ) { const item = new CompletionItem ( label , kind ) ; item . detail = detail ; item . documentation = documentation ; if ( snippet ) { item . insertText = snippet ; } return item ; } static toNamesCsv ( variables ) { return variables . map ( var1 => var1 . name ) . join ( ',' ) ; } static toTypeLessNamesCsv ( variables ) { return variables . map ( var1 => var1 . declaredNameWithoutTypes ) . join ( ',' ) ; } getObjects ( allTypeObjects , types ) { return types . map ( typeName => allTypeObjects . getTypeCaseInsensitive ( typeName ) ) . filter ( typeObjects => ! ! typeObjects ) . map ( typeObjects => typeObjects ! . getObjects ( ) ) . reduce ( ( x , y ) => x . concat ( y ) , [ ] ) ; } getTypesInvolved ( variables , domainFile ) { const typesDirectlyInvolved = variables . map ( p => p . parameters ) . reduce ( ( x , y ) => x . concat ( y ) , [ ] ) . map ( p => p . type ) . filter ( ( v , i , a ) => a . indexOf ( v ) === i ) ; const typesInheriting = typesDirectlyInvolved . map ( type1 => domainFile . getTypesInheritingFrom ( type1 ) ) . reduce ( ( x , y ) => x . concat ( y ) , [ ] ) ; return typesInheriting . concat ( typesDirectlyInvolved ) ; } getSymmetricPredicates ( domainFile ) { return domainFile . getPredicates ( ) . filter ( this . isSymmetric ) ; } getSymmetricFunctions ( domainFile ) { return domainFile . getFunctions ( ) . filter ( this . isSymmetric ) ; } isSymmetric ( variable ) { return variable . parameters . length === 2 && variable . parameters [ 0 ] . type === variable . parameters [ 1 ] . type ; } }