How to use the yaml-language-server/out/server/src/languageservice/utils/arrUtils.getLineOffsets function in yaml-language-server

To help you get started, we’ve selected a few yaml-language-server examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github keesschollaart81 / vscode-home-assistant / src / server / completionHelpers / utils.ts View on Github external
export function completionHelper(document: TextDocument, textDocumentPosition: Position): CompletionAdjustment {
    // Get the string we are looking at via a substring
    const lineNumber: number = textDocumentPosition.line;
    const lineOffsets: number[] = getLineOffsets(document.getText());
    const start: number = lineOffsets[lineNumber];  // Start of where the autocompletion is happening
    let end = 0;                                    // End of where the autocompletion is happening

    if (lineOffsets[lineNumber + 1] !== undefined) {
        end = lineOffsets[lineNumber + 1];
    } else {
        end = document.getText().length;
    }

    while (end - 1 >= start && is_EOL(document.getText().charCodeAt(end - 1))) {
        end--;
    }

    const textLine = document.getText().substring(start, end);

    // Check if the string we are looking at is a node
github keesschollaart81 / vscode-home-assistant / src / language-service / src / haLanguageService.ts View on Github external
private findAutoCompletionProperty = (document: TextDocument, textDocumentPosition: Position, properties: { [provider: string]: string[] }): string => {
        let currentLine = textDocumentPosition.line;
        while (currentLine >= 0) {
            const lineOffsets: number[] = getLineOffsets(document.getText());
            const start: number = lineOffsets[currentLine];
            var end = 0;
            if (lineOffsets[currentLine + 1] !== undefined) {
                end = lineOffsets[currentLine + 1];
            } else {
                end = document.getText().length;
            }
            let thisLine = document.getText().substring(start, end);

            let isOtherItemInList = thisLine.match(/-\s*([-\w]+)?(\.)?([-\w]+?)?\s*$/);
            if (isOtherItemInList) {
                currentLine--;
                continue;
            }
            for (var key in properties) {
                if (properties[key].some(propertyName => new RegExp(`(.*)${propertyName}(:)([\s]*)([\w]*)(\s*)`).test(thisLine))) {