Code coverage report for lib/services/cssNavigation.js

# all files / lib/services/ cssNavigation.js

50% Statements 51/102
55.74% Branches 34/61
47.06% Functions 8/17
51% Lines 51/100

    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
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    1761×
    1×
    1×
    1×

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

    1×

    1×

    1×
    39×
    39×
    39×
    39×
    1×

    38×
    38×
    38×
    38×
    1116×
    1060×
    72×

    72×

    56×

    4×

    1044×

    38×

    1×

    1×

    1×

    1×

    1×
    1×
    76×

    1×
    76×
    5×

    71×
    35×
    4×
    2×

    69×
    69×

    29×

    40×

     (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", "vscode-languageserver-types", "../parser/cssSymbolScope", "../services/languageFacts", "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 vscode_languageserver_types_1 = require("vscode-languageserver-types");
        var cssSymbolScope_1 = require("../parser/cssSymbolScope");
        var languageFacts_1 = require("../services/languageFacts");
        var nls = require("vscode-nls");
        var localize = nls.loadMessageBundle();
        var CSSNavigation = (function () {
            function CSSNavigation() {
            }
            CSSNavigation.prototype.findDefinition = function (document, position, stylesheet) {
                var symbols = new cssSymbolScope_1.Symbols(stylesheet);
                var offset = document.offsetAt(position);
                var node = nodes.getNodeAtOffset(stylesheet, offset);
                if (!node) {
                    //workaround for https://github.com/Microsoft/vscode-languageserver-node/issues/45
                    return {
                        uri: document.uri,
                        range: vscode_languageserver_types_1.Range.create(position, position)
                    };
                }
                var symbol = symbols.findSymbolFromNode(node);
                if (!symbol) {
                    //workaround for https://github.com/Microsoft/vscode-languageserver-node/issues/45
                    return {
                        uri: document.uri,
                        range: vscode_languageserver_types_1.Range.create(position, position)
                    };
                }
                return {
                    uri: document.uri,
                    range: getRange(symbol.node, document)
                };
            };
            CSSNavigation.prototype.findReferences = function (document, position, stylesheet) {
                var highlights = this.findDocumentHighlights(document, position, stylesheet);
                return highlights.map(function (h) {
                    return {
                        uri: document.uri,
                        range: h.range
                    };
                });
            };
            CSSNavigation.prototype.findDocumentHighlights = function (document, position, stylesheet) {
                var result = [];
                var offset = document.offsetAt(position);
                var node = nodes.getNodeAtOffset(stylesheet, offset);
                if (!node || node.type === nodes.NodeType.Stylesheet || node.type === nodes.NodeType.Declarations) {
                    return result;
                }
                var symbols = new cssSymbolScope_1.Symbols(stylesheet);
                var symbol = symbols.findSymbolFromNode(node);
                var name = node.getText();
                stylesheet.accept(function (candidate) {
                    if (symbol) {
                        if (symbols.matchesSymbol(candidate, symbol)) {
                            result.push({
                                kind: getHighlightKind(candidate),
                                range: getRange(candidate, document)
                            });
                            return false;
                        }
                    }
                    else if (node.type === candidate.type && node.length === candidate.length && name === candidate.getText()) {
                        // Same node type and data
                        result.push({
                            kind: getHighlightKind(candidate),
                            range: getRange(candidate, document)
                        });
                    }
                    return true;
                });
                return result;
            };
            CSSNavigation.prototype.findDocumentSymbols = function (document, stylesheet) {
                var result = [];
                stylesheet.accept(function (node) {
                    var entry = {
                        name: null,
                        kind: vscode_languageserver_types_1.SymbolKind.Class,
                        location: null
                    };
                    var locationNode = node;
                    if (node instanceof nodes.Selector) {
                        entry.name = node.getText();
                        locationNode = node.findParent(nodes.NodeType.Ruleset);
                    }
                    else if (node instanceof nodes.VariableDeclaration) {
                        entry.name = node.getName();
                        entry.kind = vscode_languageserver_types_1.SymbolKind.Variable;
                    }
                    else if (node instanceof nodes.MixinDeclaration) {
                        entry.name = node.getName();
                        entry.kind = vscode_languageserver_types_1.SymbolKind.Method;
                    }
                    else if (node instanceof nodes.FunctionDeclaration) {
                        entry.name = node.getName();
                        entry.kind = vscode_languageserver_types_1.SymbolKind.Function;
                    }
                    else if (node instanceof nodes.Keyframe) {
                        entry.name = localize('literal.keyframes', "@keyframes {0}", node.getName());
                    }
                    else if (node instanceof nodes.FontFace) {
                        entry.name = localize('literal.fontface', "@font-face");
                    }
                    if (entry.name) {
                        entry.location = vscode_languageserver_types_1.Location.create(document.uri, getRange(locationNode, document));
                        result.push(entry);
                    }
                    return true;
                });
                return result;
            };
            CSSNavigation.prototype.findColorSymbols = function (document, stylesheet) {
                var result = [];
                stylesheet.accept(function (node) {
                    if (languageFacts_1.isColorValue(node)) {
                        result.push(getRange(node, document));
                    }
                    return true;
                });
                return result;
            };
            CSSNavigation.prototype.doRename = function (document, position, newName, stylesheet) {
                var highlights = this.findDocumentHighlights(document, position, stylesheet);
                var edits = highlights.map(function (h) { return vscode_languageserver_types_1.TextEdit.replace(h.range, newName); });
                return {
                    changes: (_a = {}, _a[document.uri] = edits, _a)
                };
                var _a;
            };
            return CSSNavigation;
        }());
        exports.CSSNavigation = CSSNavigation;
        function getRange(node, document) {
            return vscode_languageserver_types_1.Range.create(document.positionAt(node.offset), document.positionAt(node.end));
        }
        function getHighlightKind(node) {
            if (node.type === nodes.NodeType.Selector) {
                return vscode_languageserver_types_1.DocumentHighlightKind.Write;
            }
            if (node instanceof nodes.Identifier) {
                if (node.parent && node.parent instanceof nodes.Property) {
                    if (node.isCustomProperty) {
                        return vscode_languageserver_types_1.DocumentHighlightKind.Write;
                    }
                }
            }
            Eif (node.parent) {
                switch (node.parent.type) {
                    case nodes.NodeType.FunctionDeclaration:
                    case nodes.NodeType.MixinDeclaration:
                    case nodes.NodeType.Keyframe:
                    case nodes.NodeType.VariableDeclaration:
                    case nodes.NodeType.FunctionParameter:
                        return vscode_languageserver_types_1.DocumentHighlightKind.Write;
                }
            }
            return vscode_languageserver_types_1.DocumentHighlightKind.Read;
        }
    });
    //# sourceMappingURL=cssNavigation.js.map