{"size": 4038, "ext": "js", "max_stars_repo_path": "out/features/referencesCodeLensProvider.js", "max_stars_repo_name": "program-in-chinese/vsc_cts", "max_stars_repo_stars_event_min_datetime": "2018-02-03T02:23:52.000Z", "max_stars_repo_stars_event_max_datetime": "2018-02-03T02:23:52.000Z", "max_issues_repo_path": "out/features/referencesCodeLensProvider.js", "max_issues_repo_name": "program-in-chinese/vsc_cts", "max_issues_repo_issues_event_min_datetime": "2018-02-02T06:16:10.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-02T06:16:10.000Z", "max_forks_repo_path": "out/features/referencesCodeLensProvider.js", "max_forks_repo_name": "program-in-chinese/vsc_cts", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 44.8666666667, "max_line_length": 133, "alphanum_fraction": 0.573551263}
"use strict";
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
const vscode_1 = require("vscode");
const PConst = require("../protocol.const");
const baseCodeLensProvider_1 = require("./baseCodeLensProvider");
const convert_1 = require("../utils/convert");
const nls = require("vscode-nls");
const localize = nls.loadMessageBundle();
class TypeScriptReferencesCodeLensProvider extends baseCodeLensProvider_1.TypeScriptBaseCodeLensProvider {
    constructor(client, language) {
        super(client);
        this.language = language;
    }
    updateConfiguration() {
        const config = vscode_1.workspace.getConfiguration(this.language);
        this.setEnabled(config.get('referencesCodeLens.enabled', false));
    }
    provideCodeLenses(document, token) {
        if (!this.client.apiVersion.has206Features()) {
            return [];
        }
        return super.provideCodeLenses(document, token);
    }
    resolveCodeLens(inputCodeLens, token) {
        const codeLens = inputCodeLens;
        const args = convert_1.vsPositionToTsFileLocation(codeLens.file, codeLens.range.start);
        return this.client.execute('references', args, token).then(response => {
            if (!response || !response.body) {
                throw codeLens;
            }
            const locations = response.body.refs
                .map(reference => new vscode_1.Location(this.client.asUrl(reference.file), convert_1.tsTextSpanToVsRange(reference)))
                .filter(location => 
            // Exclude original definition from references
            !(location.uri.toString() === codeLens.document.toString() &&
                location.range.start.isEqual(codeLens.range.start)));
            codeLens.command = {
                title: locations.length === 1
                    ? localize('oneReferenceLabel', '1 reference')
                    : localize('manyReferenceLabel', '{0} references', locations.length),
                command: locations.length ? 'editor.action.showReferences' : '',
                arguments: [codeLens.document, codeLens.range.start, locations]
            };
            return codeLens;
        }).catch(() => {
            codeLens.command = {
                title: localize('referenceErrorLabel', 'Could not determine references'),
                command: ''
            };
            return codeLens;
        });
    }
    extractSymbol(document, item, parent) {
        if (parent && parent.kind === PConst.Kind.enum) {
            return super.getSymbolRange(document, item);
        }
        switch (item.kind) {
            case PConst.Kind.const:
            case PConst.Kind.let:
            case PConst.Kind.variable:
            case PConst.Kind.function:
                // Only show references for exported variables
                if (!item.kindModifiers.match(/\bexport\b/) && !item.kindModifiers.match(/\b导出\b/)) {
                    break;
                }
            // fallthrough
            case PConst.Kind.class:
                if (item.text === '<class>') {
                    break;
                }
            // fallthrough
            case PConst.Kind.memberFunction:
            case PConst.Kind.memberVariable:
            case PConst.Kind.memberGetAccessor:
            case PConst.Kind.memberSetAccessor:
            case PConst.Kind.constructorImplementation:
            case PConst.Kind.interface:
            case PConst.Kind.type:
            case PConst.Kind.enum:
                return super.getSymbolRange(document, item);
        }
        return null;
    }
}
exports.default = TypeScriptReferencesCodeLensProvider;
//# sourceMappingURL=referencesCodeLensProvider.js.map