UNPKG

alm

Version:

The best IDE for TypeScript

54 lines (53 loc) 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * This is the main backend for the tsFlow feature */ /** Imports */ var utils = require("../../../../common/utils"); /** We just use the *active* project if any */ var activeProject = require("../activeProject"); var getProject = activeProject.GetProject.getCurrentIfAny; function getFlowRoots(query) { var project = activeProject.GetProject.getCurrentIfAny(); var languageService = project.languageService; var filePath = query.filePath; var sourceFile = project.getSourceFile(query.filePath); var flowPoints = []; var declarations = sourceFile.getNamedDeclarations(); for (var index in declarations) { for (var _i = 0, _a = declarations[index]; _i < _a.length; _i++) { var declaration = _a[_i]; var flowPoint = { filePath: filePath, from: project.languageServiceHost.getLineAndCharacterOfPosition(filePath, declaration.getStart()), to: project.languageServiceHost.getLineAndCharacterOfPosition(filePath, declaration.getStart()), displayName: getDeclarationName(declaration) }; // TODO: filter based on kind // getNodeKind(declaration) flowPoints.push(flowPoint); } } return utils.resolve({ flowPoints: flowPoints }); } exports.getFlowRoots = getFlowRoots; /** * Utility functions */ var getNodeKind = ts.getNodeKind; function getTextOfIdentifierOrLiteral(node) { if (node.kind === ts.SyntaxKind.Identifier || node.kind === ts.SyntaxKind.StringLiteral || node.kind === ts.SyntaxKind.NumericLiteral) { return node.text; } return undefined; } function getDeclarationName(declaration) { var result = ts.getNameOfDeclaration(declaration); if (result === undefined) { return ''; } return result.getText(); }