UNPKG

@microsoft/compose-language-service

Version:
47 lines 2.89 kB
"use strict"; /*!-------------------------------------------------------------------------------------------- * 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.DiagnosticProvider = void 0; const vscode_languageserver_1 = require("vscode-languageserver"); const ActionContext_1 = require("../utils/ActionContext"); const debounce_1 = require("../utils/debounce"); const yamlRangeToLspRange_1 = require("../utils/yamlRangeToLspRange"); const ProviderBase_1 = require("./ProviderBase"); // The default time between when typing stops and when diagnostics will be sent (milliseconds) const DiagnosticDelay = 1000; class DiagnosticProvider extends ProviderBase_1.ProviderBase { constructor(diagnosticDelay = DiagnosticDelay, syntaxValidation, schemaValidation) { super(); this.diagnosticDelay = diagnosticDelay; this.syntaxValidation = syntaxValidation; this.schemaValidation = schemaValidation; } on(params) { var _a; if (!this.syntaxValidation) { // Do nothing if syntax validation is disabled. At present schema validation is not supported, https://github.com/microsoft/compose-language-service/issues/84 return; } const ctx = (0, ActionContext_1.getCurrentContext)(); ctx.telemetry.suppressAll = true; // Diagnostics is async and telemetry won't really work ctx.telemetry.properties.isActivationEvent = 'true'; // In case we do someday enable it, let's make sure it's treated as an activation event since it is done automatically if (!((_a = ctx.clientCapabilities.textDocument) === null || _a === void 0 ? void 0 : _a.publishDiagnostics)) { return; } (0, debounce_1.debounce)(this.diagnosticDelay, { uri: params.document.textDocument.uri, callId: 'diagnostics' }, () => { const diagnostics = []; for (const error of [...params.document.yamlDocument.value.errors, ...params.document.yamlDocument.value.warnings]) { diagnostics.push(vscode_languageserver_1.Diagnostic.create((0, yamlRangeToLspRange_1.yamlRangeToLspRange)(params.document.textDocument, error.pos), error.message, error.name === 'YAMLWarning' ? vscode_languageserver_1.DiagnosticSeverity.Warning : vscode_languageserver_1.DiagnosticSeverity.Error, error.code)); } void ctx.connection.sendDiagnostics({ uri: params.document.textDocument.uri, diagnostics: diagnostics, }); }, this); } } exports.DiagnosticProvider = DiagnosticProvider; //# sourceMappingURL=DiagnosticProvider.js.map