@microsoft/compose-language-service
Version:
Language service for Docker Compose documents
98 lines • 4.17 kB
JavaScript
;
/*!--------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.DocumentSettingsClientFeature = void 0;
// Largely copied from https://github.com/microsoft/compose-language-service/blob/main/src/test/clientExtension/DocumentSettingsClientFeature.ts
const DocumentSettingsClientCapabilities_1 = require("../common/DocumentSettingsClientCapabilities");
const vscode = __importStar(require("vscode"));
/**
* This class implements functionality to allow the language server to request information about an open document (including tab size and line endings), and also
* notify the language server if those settings change
*/
class DocumentSettingsClientFeature {
client;
disposables = [];
constructor(client) {
this.client = client;
}
clear() {
this.dispose();
}
getState() {
return {
kind: 'static'
};
}
fillClientCapabilities(capabilities) {
const docSettingsClientCapabilities = {
notify: true,
request: true,
};
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
capabilities.experimental = {
...capabilities.experimental,
documentSettings: docSettingsClientCapabilities,
};
}
initialize() {
this.disposables.push(this.client.onRequest(DocumentSettingsClientCapabilities_1.DocumentSettingsRequest.type, (params) => {
const textEditor = vscode.window.visibleTextEditors.find(e => e.document.uri.toString() === params.textDocument.uri);
if (!textEditor) {
return undefined;
}
return {
eol: textEditor.document.eol,
tabSize: Number(textEditor.options.tabSize),
};
}));
this.disposables.push(vscode.window.onDidChangeTextEditorOptions((e) => {
const params = {
textDocument: { uri: e.textEditor.document.uri.toString() },
eol: e.textEditor.document.eol,
tabSize: Number(e.options.tabSize),
};
void this.client.sendNotification(DocumentSettingsClientCapabilities_1.DocumentSettingsNotification.type, params);
}));
}
dispose() {
this.disposables.forEach(d => void d.dispose());
}
}
exports.DocumentSettingsClientFeature = DocumentSettingsClientFeature;
//# sourceMappingURL=DocumentSettingsClientFeature.js.map