@microsoft/compose-language-service
Version:
Language service for Docker Compose documents
61 lines • 2.55 kB
JavaScript
/*!--------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// Largely copied from https://github.com/microsoft/compose-language-service/blob/main/src/test/clientExtension/DocumentSettingsClientFeature.ts
import { DocumentSettingsNotification, DocumentSettingsRequest } from '../common/DocumentSettingsClientCapabilities';
import * as vscode from '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
*/
export 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(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(DocumentSettingsNotification.type, params);
}));
}
dispose() {
this.disposables.forEach(d => void d.dispose());
}
}
//# sourceMappingURL=DocumentSettingsClientFeature.js.map