'use strict' ; import { CompletionItemProvider , CompletionItem , TextDocument , Position , CancellationToken , CompletionContext } from 'vscode' ; import { UnknownFileInfo } from 'pddl-workspace' ; import { ProblemInfo } from 'pddl-workspace' ; import { DomainInfo } from 'pddl-workspace' ; import { CodePddlWorkspace } from '../workspace/CodePddlWorkspace' ; import { DomainCompletionItemProvider } from './DomainCompletionItemProvider' ; import { ProblemCompletionItemProvider } from './ProblemCompletionItemProvider' ; import { UnknownPddlCompletionItemProvider } from './UnknownPddlCompletionItemProvider' ; export class PddlCompletionItemProvider implements CompletionItemProvider { private domainProvider : DomainCompletionItemProvider | undefined ; private problemProvider : ProblemCompletionItemProvider | undefined ; private unknownProvider : UnknownPddlCompletionItemProvider | undefined ; constructor ( private codePddlWorkspace ) { } async provideCompletionItems ( document , position , token , context ) { if ( token . isCancellationRequested ) { return undefined ; } const fileInfo = await this . codePddlWorkspace ?. upsertAndParseFile ( document ) ; if ( fileInfo instanceof DomainInfo ) { return await this . getOrCreateDomainCompletionItemProvider ( ) . provide ( document , fileInfo as DomainInfo , position , context ) ; } else if ( fileInfo instanceof ProblemInfo ) { return await this . getOrCreateProblemCompletionItemProvider ( ) . provide ( document , fileInfo as ProblemInfo , position , context ) ; } else if ( fileInfo instanceof UnknownFileInfo || fileInfo === null ) { return await this . getOrCreateUnknownFileItemProvider ( ) . provide ( document , position , context ) ; } return [ ] ; } private getOrCreateDomainCompletionItemProvider ( ) { return this . domainProvider ?? ( this . domainProvider = new DomainCompletionItemProvider ( ) ) ; } private getOrCreateProblemCompletionItemProvider ( ) { return this . problemProvider ?? ( this . problemProvider = new ProblemCompletionItemProvider ( ) ) ; } private getOrCreateUnknownFileItemProvider ( ) { return this . unknownProvider ?? ( this . unknownProvider = new UnknownPddlCompletionItemProvider ( ) ) ; } }