All files / languages/turtle/providers turtle-code-formatting-provider.ts

100% Statements 6/6
100% Branches 2/2
100% Functions 1/1
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31          13x             8x   8x 8x               8x         8x    
import * as vscode from 'vscode';
import { TurtleFormatter } from '@faubulous/mentor-rdf-serializers';
import { getConfig } from '@src/utilities/vscode/config';
 
export class TurtleCodeFormattingProvider implements vscode.DocumentFormattingEditProvider {
    private _formatter = new TurtleFormatter();
 
    provideDocumentFormattingEdits(
        document: vscode.TextDocument,
        options: vscode.FormattingOptions,
        token: vscode.CancellationToken
    ): vscode.TextEdit[] {
        const config = getConfig('formatting.turtle');
 
        const text = document.getText();
        const result = this._formatter.formatFromText(text, {
            indent: options.insertSpaces ? ' '.repeat(options.tabSize) : '\t',
            prettyPrint: true,
            maxLineWidth: config.get('maxLineWidth', 120),
            spaceBeforePunctuation: config.get('spaceBeforePunctuation', true),
            blankLinesBetweenSubjects: config.get('blankLinesBetweenSubjects', true),
        });
 
        const fullRange = new vscode.Range(
            document.positionAt(0),
            document.positionAt(text.length)
        );
 
        return [vscode.TextEdit.replace(fullRange, result.output)];
    }
}