UNPKG

@microsoft/compose-language-service

Version:
60 lines (59 loc) 3.4 kB
/*!-------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See LICENSE in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { Position, TextDocumentIdentifier, TextDocumentsConfiguration } from 'vscode-languageserver'; import { DocumentUri, TextDocument } from 'vscode-languageserver-textdocument'; import { Document as YamlDocument, Node as YamlNode } from 'yaml'; import { DocumentSettings } from '../client/DocumentSettings'; import { ExtendedPositionParams, PositionInfo } from './ExtendedParams'; import { Lazy } from './utils/Lazy'; export declare class ComposeDocument { #private; readonly yamlDocument: Lazy<YamlDocument<YamlNode>>; private documentSettings; get textDocument(): TextDocument; get id(): TextDocumentIdentifier; get uri(): DocumentUri; private constructor(); private update; /** * Gets the text of a line at a given line number or position, including the line break (`\n` or `\r\n`) at the end if present * @param line The line number or `Position` * @returns The line text */ lineAt(line: Position | number): string; /** * Gets settings from the document. If already populated, that will be returned. If supported, the info will be requested from the client. * Otherwise, the settings will be heuristically guessed based on document contents. * Note: The client is also directed to notify the server if the settings change, via the `DocumentSettingsNotification` notification. * @returns The document settings (tab size, line endings, etc.) */ getSettings(): Promise<DocumentSettings>; /** * Updates the settings (tab size, line endings, etc.) for the document. This is meant to be called by the server upon receiving a `DocumentSettingsNotification`. * @param params The new settings for the document */ updateSettings(params: DocumentSettings): void; /** * Gets information about the position, including the tab depth and a logical path describing where in the YAML tree the position is * @param params The `ExtendedPositionParams` for the position being queried * @returns A `PositionInfo` object with tab depth and logical path * @example If the position is in a service foo's `image` key, the logical path would be `/services/foo/image`. */ getPositionInfo(params: ExtendedPositionParams): Promise<PositionInfo>; static DocumentManagerConfig: TextDocumentsConfiguration<ComposeDocument>; private buildYamlDocument; private guessDocumentSettings; /** * This method is responsible for determining the part of the logical path for the line where the cursor is, given the * cursor's position. * This is similar to the body of `getPositionInfo` but differs in a key way--the position is on this line, so the * character position can fundamentally affect what the logical path is * @param params Parameters including position * @param tabSize The tab size (needed to determine indent depth) * @returns The part(s) of the logical path at the current line */ private getFirstLinePositionInfo; } export declare const KeyValueRegex: RegExp;