@microsoft/compose-language-service
Version:
Language service for Docker Compose documents
62 lines • 3.46 kB
JavaScript
;
/*!--------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.MultiCompletionProvider = void 0;
const ActionContext_1 = require("../../utils/ActionContext");
const ProviderBase_1 = require("../ProviderBase");
const BuildCompletionCollection_1 = require("./BuildCompletionCollection");
const PortsCompletionCollection_1 = require("./PortsCompletionCollection");
const RootCompletionCollection_1 = require("./RootCompletionCollection");
const ServiceCompletionCollection_1 = require("./ServiceCompletionCollection");
const VolumesCompletionCollection_1 = require("./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
*/
class MultiCompletionProvider extends ProviderBase_1.ProviderBase {
constructor(basicCompletions, advancedCompletions) {
super();
this.basicCompletions = basicCompletions;
this.advancedCompletions = advancedCompletions;
this.completionCollections = [
RootCompletionCollection_1.RootCompletionCollection,
ServiceCompletionCollection_1.ServiceCompletionCollection,
BuildCompletionCollection_1.BuildCompletionCollection,
VolumesCompletionCollection_1.VolumesCompletionCollection,
PortsCompletionCollection_1.PortsCompletionCollection,
];
}
async on(params, token, workDoneProgress) {
const ctx = (0, ActionContext_1.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 === null || subresults === void 0 ? void 0 : 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;
}
}
exports.MultiCompletionProvider = MultiCompletionProvider;
//# sourceMappingURL=MultiCompletionProvider.js.map