Code coverage report for lib/services/cssCodeActions.js

# all files / lib/services/ cssCodeActions.js

92.98% Statements 53/57
64% Branches 16/25
100% Functions 8/8
94.64% Lines 53/56

    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
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    831×
    1×
    1×
    1×

    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×

    1×
    2×
    2×
    2×
    2×
    2×

    2×

    1×
    2×
    2×
    2×
    1132×
    1132×
    16×

    2×
    38×

    2×
    2×
    5×
    5×
    5×
    5×
    5×
    5×
    1×

    1×
    2×

    2×
    2×
    2×
    2×
    6×
    6×
    2×
    2×
    2×
    2×

    1×

    1×

     (function (factory) {
        Eif (typeof module === "object" && typeof module.exports === "object") {
            var v = factory(require, exports);
            Iif (v !== undefined) module.exports = v;
        }
        else if (typeof define === "function" && define.amd) {
            define(["require", "exports", "../parser/cssNodes", "./languageFacts", "../utils/strings", "../services/lintRules", "vscode-languageserver-types", "vscode-nls"], factory);
        }
    })(function (require, exports) {
        /*---------------------------------------------------------------------------------------------
         *  Copyright (c) Microsoft Corporation. All rights reserved.
         *  Licensed under the MIT License. See License.txt in the project root for license information.
         *--------------------------------------------------------------------------------------------*/
        'use strict';
        Object.defineProperty(exports, "__esModule", { value: true });
        var nodes = require("../parser/cssNodes");
        var languageFacts = require("./languageFacts");
        var strings_1 = require("../utils/strings");
        var lintRules_1 = require("../services/lintRules");
        var vscode_languageserver_types_1 = require("vscode-languageserver-types");
        var nls = require("vscode-nls");
        var localize = nls.loadMessageBundle();
        var CSSCodeActions = (function () {
            function CSSCodeActions() {
            }
            CSSCodeActions.prototype.doCodeActions = function (document, range, context, stylesheet) {
                var result = [];
                Eif (context.diagnostics) {
                    for (var _i = 0, _a = context.diagnostics; _i < _a.length; _i++) {
                        var diagnostic = _a[_i];
                        this.appendFixesForMarker(document, stylesheet, diagnostic, result);
                    }
                }
                return result;
            };
            CSSCodeActions.prototype.getFixesForUnknownProperty = function (document, property, marker, result) {
                var propertyName = property.getName();
                var candidates = [];
                for (var p in languageFacts.getProperties()) {
                    var score = strings_1.difference(propertyName, p);
                    if (score >= propertyName.length / 2 /*score_lim*/) {
                        candidates.push({ property: p, score: score });
                    }
                }
                // Sort in descending order.
                candidates.sort(function (a, b) {
                    return b.score - a.score;
                });
                var maxActions = 3;
                for (var _i = 0, candidates_1 = candidates; _i < candidates_1.length; _i++) {
                    var candidate = candidates_1[_i];
                    var propertyName_1 = candidate.property;
                    var title = localize('css.codeaction.rename', "Rename to '{0}'", propertyName_1);
                    var edit = vscode_languageserver_types_1.TextEdit.replace(marker.range, propertyName_1);
                    result.push(vscode_languageserver_types_1.Command.create(title, '_css.applyCodeAction', document.uri, document.version, [edit]));
                    if (--maxActions <= 0) {
                        return;
                    }
                }
            };
            CSSCodeActions.prototype.appendFixesForMarker = function (document, stylesheet, marker, result) {
                Iif (marker.code !== lintRules_1.Rules.UnknownProperty.id) {
                    return;
                }
                var offset = document.offsetAt(marker.range.start);
                var end = document.offsetAt(marker.range.end);
                var nodepath = nodes.getNodePath(stylesheet, offset);
                for (var i = nodepath.length - 1; i >= 0; i--) {
                    var node = nodepath[i];
                    if (node instanceof nodes.Declaration) {
                        var property = node.getProperty();
                        Eif (property && property.offset === offset && property.end === end) {
                            this.getFixesForUnknownProperty(document, property, marker, result);
                            return;
                        }
                    }
                }
            };
            return CSSCodeActions;
        }());
        exports.CSSCodeActions = CSSCodeActions;
    });
    //# sourceMappingURL=cssCodeActions.js.map