How to use yaml-language-server - 10 common examples

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 / yamlLanguageServiceWrapper.ts View on Github external
constructor(completionContributions: JSONWorkerContribution[]) {
        this.jsonSchemaService = new JSONSchemaService(null, {
            resolveRelativePath: (relativePath: string, resource: string) => {
                return path.resolve(resource, relativePath);
            }
        }, null);


        this.yamlValidation = new YAMLValidation(this.jsonSchemaService);
        this.yamlValidation.configure({ validate: true });
        this.yamlDocumentSymbols = new YAMLDocumentSymbols();
        this.yamlCompletion = new YAMLCompletion(this.jsonSchemaService, completionContributions);
        // enables auto completion suggestions for tags like !include ()
        // commeted because they end up at the top of the list which does not look nice :-)
        // this.yamlCompletion.configure(null, this.getValidYamlTags()); 
        this.yamlHover = new YAMLHover(this.jsonSchemaService);
        this.yamlFormatter = new YAMLFormatter();
    }
github keesschollaart81 / vscode-home-assistant / src / server / yamlLanguageServiceWrapper.ts View on Github external
constructor(completionContributions: JSONWorkerContribution[]) {
        this.jsonSchemaService = new JSONSchemaService(null, {
            resolveRelativePath: (relativePath: string, resource: string) => {
                return path.resolve(resource, relativePath);
            }
        }, null);


        this.yamlValidation = new YAMLValidation(this.jsonSchemaService);
        this.yamlValidation.configure({ validate: true });
        this.yamlDocumentSymbols = new YAMLDocumentSymbols();
        this.yamlCompletion = new YAMLCompletion(this.jsonSchemaService, completionContributions);
        // enables auto completion suggestions for tags like !include ()
        // commeted because they end up at the top of the list which does not look nice :-)
        // this.yamlCompletion.configure(null, this.getValidYamlTags()); 
        this.yamlHover = new YAMLHover(this.jsonSchemaService);
        this.yamlFormatter = new YAMLFormatter();
    }
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 / server / yamlLanguageServiceWrapper.ts View on Github external
constructor(completionContributions: JSONWorkerContribution[]) {
        this.jsonSchemaService = new JSONSchemaService(null, {
            resolveRelativePath: (relativePath: string, resource: string) => {
                return path.resolve(resource, relativePath);
            }
        }, null);


        this.yamlValidation = new YAMLValidation(this.jsonSchemaService);
        this.yamlValidation.configure({ validate: true });
        this.yamlDocumentSymbols = new YAMLDocumentSymbols();
        this.yamlCompletion = new YAMLCompletion(this.jsonSchemaService, completionContributions);
        // enables auto completion suggestions for tags like !include ()
        // commeted because they end up at the top of the list which does not look nice :-)
        // this.yamlCompletion.configure(null, this.getValidYamlTags()); 
        this.yamlHover = new YAMLHover(this.jsonSchemaService);
        this.yamlFormatter = new YAMLFormatter();
    }
github keesschollaart81 / vscode-home-assistant / src / server / yamlLanguageServiceWrapper.ts View on Github external
constructor(completionContributions: JSONWorkerContribution[]) {
        this.jsonSchemaService = new JSONSchemaService(null, {
            resolveRelativePath: (relativePath: string, resource: string) => {
                return path.resolve(resource, relativePath);
            }
        }, null);


        this.yamlValidation = new YAMLValidation(this.jsonSchemaService);
        this.yamlValidation.configure({ validate: true });
        this.yamlDocumentSymbols = new YAMLDocumentSymbols();
        this.yamlCompletion = new YAMLCompletion(this.jsonSchemaService, completionContributions);
        // enables auto completion suggestions for tags like !include ()
        // commeted because they end up at the top of the list which does not look nice :-)
        // this.yamlCompletion.configure(null, this.getValidYamlTags()); 
        this.yamlHover = new YAMLHover(this.jsonSchemaService);
        this.yamlFormatter = new YAMLFormatter();
    }
github keesschollaart81 / vscode-home-assistant / src / server / yamlLanguageServiceWrapper.ts View on Github external
this.jsonSchemaService = new JSONSchemaService(null, {
            resolveRelativePath: (relativePath: string, resource: string) => {
                return path.resolve(resource, relativePath);
            }
        }, null);


        this.yamlValidation = new YAMLValidation(this.jsonSchemaService);
        this.yamlValidation.configure({ validate: true });
        this.yamlDocumentSymbols = new YAMLDocumentSymbols();
        this.yamlCompletion = new YAMLCompletion(this.jsonSchemaService, completionContributions);
        // enables auto completion suggestions for tags like !include ()
        // commeted because they end up at the top of the list which does not look nice :-)
        // this.yamlCompletion.configure(null, this.getValidYamlTags()); 
        this.yamlHover = new YAMLHover(this.jsonSchemaService);
        this.yamlFormatter = new YAMLFormatter();
    }
github keesschollaart81 / vscode-home-assistant / src / server / yamlLanguageServiceWrapper.ts View on Github external
constructor(completionContributions: JSONWorkerContribution[]) {
        this.jsonSchemaService = new JSONSchemaService(null, {
            resolveRelativePath: (relativePath: string, resource: string) => {
                return path.resolve(resource, relativePath);
            }
        }, null);


        this.yamlValidation = new YAMLValidation(this.jsonSchemaService);
        this.yamlValidation.configure({ validate: true });
        this.yamlDocumentSymbols = new YAMLDocumentSymbols();
        this.yamlCompletion = new YAMLCompletion(this.jsonSchemaService, completionContributions);
        // enables auto completion suggestions for tags like !include ()
        // commeted because they end up at the top of the list which does not look nice :-)
        // this.yamlCompletion.configure(null, this.getValidYamlTags()); 
        this.yamlHover = new YAMLHover(this.jsonSchemaService);
        this.yamlFormatter = new YAMLFormatter();
    }
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))) {
github keesschollaart81 / vscode-home-assistant / src / server / yamlLanguageService.ts View on Github external
export function getLanguageService(workspaceContext, promiseConstructor?): LanguageService {
    let promise = promiseConstructor || Promise;

    let jsonSchemaService = new JSONSchemaService(null, workspaceContext, null);

    var jsonPath = path.join(__dirname, '..', 'lovelace-schema', 'ui-lovelace.json');
    var sc = fs.readFileSync(jsonPath,"utf-8");
    var schema = JSON.parse(sc);

    jsonSchemaService.setSchemaContributions({
        schemas: {
            "http://schema.ha.com/lovelace": schema
        },
        schemaAssociations:{ 
            "**/ui-lovelace.yaml": ["http://schema.ha.com/lovelace"]
        }
    });
   
    let yamlvalidation = new YAMLValidation(jsonSchemaService, promise);
    yamlvalidation.configure({
github keesschollaart81 / vscode-home-assistant / src / server / yamlLanguageService.ts View on Github external
let jsonSchemaService = new JSONSchemaService(null, workspaceContext, null);

    var jsonPath = path.join(__dirname, '..', 'lovelace-schema', 'ui-lovelace.json');
    var sc = fs.readFileSync(jsonPath,"utf-8");
    var schema = JSON.parse(sc);

    jsonSchemaService.setSchemaContributions({
        schemas: {
            "http://schema.ha.com/lovelace": schema
        },
        schemaAssociations:{ 
            "**/ui-lovelace.yaml": ["http://schema.ha.com/lovelace"]
        }
    });
   
    let yamlvalidation = new YAMLValidation(jsonSchemaService, promise);
    yamlvalidation.configure({ 
        validate: true ,
        customTags: [
            "!include scalar",
            "!include_dir_list scalar"
        ]
    });

    return { 
        doValidation: yamlvalidation.doValidation.bind(yamlvalidation)  
    };
}