UNPKG

@microsoft/compose-language-service

Version:
61 lines 3.11 kB
/*!-------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See LICENSE in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { getCurrentContext } from '../../utils/ActionContext'; import { ProviderBase } from '../ProviderBase'; import { BuildCompletionCollection } from './BuildCompletionCollection'; import { PortsCompletionCollection } from './PortsCompletionCollection'; import { RootCompletionCollection } from './RootCompletionCollection'; import { ServiceCompletionCollection } from './ServiceCompletionCollection'; import { VolumesCompletionCollection } from './VolumesCompletionCollection'; /** * Completions are one of the more involved features so we will split up the code, with this multi-provider calling each of them * Most will no-op but the results will all be aggregated upon return * Importantly, if any fail, we will throw an error--all other results will be ignored */ export class MultiCompletionProvider extends ProviderBase { basicCompletions; advancedCompletions; completionCollections; constructor(basicCompletions, advancedCompletions) { super(); this.basicCompletions = basicCompletions; this.advancedCompletions = advancedCompletions; this.completionCollections = [ RootCompletionCollection, ServiceCompletionCollection, BuildCompletionCollection, VolumesCompletionCollection, PortsCompletionCollection, ]; } async on(params, token, workDoneProgress) { const ctx = getCurrentContext(); const extendedParams = { ...params, positionInfo: await params.document.getPositionInfo(params), basicCompletions: this.basicCompletions, advancedCompletions: this.advancedCompletions, }; const results = []; const respondingCollections = []; for (const collection of this.completionCollections) { // Within each loop we'll check for cancellation if (token.isCancellationRequested) { return undefined; } const subresults = collection.getActiveCompletionItems(extendedParams); if (subresults?.length) { respondingCollections.push(collection.name); results.push(...subresults); } // The set of collections that answer will be attached as a property ctx.telemetry.properties.respondingCollections = respondingCollections.sort().join(','); } // It should be noted, many of the completions include tabs `\t` which aren't allowed in YAML, however, // VSCode automatically translates these into the configured tab size in spaces. It does the same for line endings. return results.length > 0 ? results : undefined; } } //# sourceMappingURL=MultiCompletionProvider.js.map