Comparing version 0.3.1 to 0.3.2
@@ -44,2 +44,3 @@ "use strict"; | ||
[/\b(private|public|protected|abstract|namespace|declare|@)\b/, 'magenta'], | ||
[/\b(keyof|readonly)\b/, 'green'], | ||
]; | ||
@@ -122,3 +123,3 @@ while (line !== '') { | ||
function printHelp() { | ||
console.log("\ntsun repl commands\n:type symbol print the type of an identifier\n:clear clear all the code\n:print print code input so far\n:help print this manual\n:paste enter paste mode".blue); | ||
console.log("\ntsun repl commands\n:type symbol print the type of an identifier\n:doc symbol print the documentation for an identifier\n:clear clear all the code\n:print print code input so far\n:help print this manual\n:paste enter paste mode".blue); | ||
if (argv.dere) { | ||
@@ -238,3 +239,3 @@ console.log(':baka Who would like some pervert like you, baka~'.blue); | ||
rl.question(prompt, function (code) { | ||
if (/^:(type)/.test(code)) { | ||
if (/^:(type|doc)/.test(code)) { | ||
var identifier = code.split(' ')[1]; | ||
@@ -245,3 +246,9 @@ if (!identifier) { | ||
} | ||
service_1.getType(identifier, code.indexOf('detail') === 1); | ||
var ret = service_1.getType(identifier, code.indexOf('doc') === 1); | ||
if (ret) { | ||
console.log(colorize(ret)); | ||
} | ||
else { | ||
console.log(("no info for \"" + identifier + "\" is found").yellow); | ||
} | ||
return repl(prompt); | ||
@@ -248,0 +255,0 @@ } |
@@ -133,46 +133,2 @@ "use strict"; | ||
} | ||
function getMemberInfo(member, file, parentDeclaration) { | ||
// member info is stored as the first | ||
var pos = member.getStart(); | ||
var quickInfo = service.getQuickInfoAtPosition(file, pos); | ||
if (quickInfo) | ||
return ts.displayPartsToString(quickInfo.displayParts); | ||
// DeclarationName includes Identifier which does not have name and will not go here | ||
var name = member.name && member.name.getText(); | ||
if (!name) | ||
return member.getText(); | ||
var declarations = exports.getDeclarations(true)[file][name]; | ||
for (var _i = 0, declarations_1 = declarations; _i < declarations_1.length; _i++) { | ||
var decl = declarations_1[_i]; | ||
var d = decl; | ||
if (parentDeclaration.parent.name.getText() == d.parent.parent.name.getText()) { | ||
var quickInfo_1 = service.getQuickInfoAtPosition(file, d.getEnd()); | ||
return ts.displayPartsToString(quickInfo_1.displayParts); | ||
} | ||
} | ||
return member.getText(); | ||
} | ||
function getTypeInfo(decl, file, detailed) { | ||
// getStart will count comment | ||
var pos = decl.getEnd(); | ||
var ret = [("declaration in: " + file)]; | ||
var quickInfo = service.getQuickInfoAtPosition(file, pos); | ||
ret.push(ts.displayPartsToString(quickInfo.displayParts)); | ||
if (!detailed) | ||
return ret; | ||
var parentName = ret[1].split(' ')[1]; | ||
var symbolType = quickInfo.displayParts[0].text; | ||
if (symbolType === 'interface' || symbolType === 'class') { | ||
var classLikeDeclaration = decl.parent; | ||
for (var _i = 0, _a = classLikeDeclaration.members; _i < _a.length; _i++) { | ||
var member = _a[_i]; | ||
var memberInfo = getMemberInfo(member, file, decl).split('\n').map(function (mInfo) { | ||
mInfo = mInfo.replace(new RegExp(parentName + '\\.', 'g'), ''); | ||
return ' ' + mInfo; | ||
}); | ||
ret.push(memberInfo.join('\n')); | ||
} | ||
} | ||
return ret; | ||
} | ||
function completer(line) { | ||
@@ -210,13 +166,14 @@ // append new line to get completions, then revert new line | ||
function getType(name, detailed) { | ||
var declarations = exports.getDeclarations(); | ||
for (var file in declarations) { | ||
var names = declarations[file]; | ||
if (names[name]) { | ||
var decl = names[name][0]; | ||
var infoString = getTypeInfo(decl, file, detailed); | ||
console.log(infoString.join('\n').cyan); | ||
return; | ||
} | ||
versionCounter++; | ||
var originalCodes = exports.acceptedCodes; | ||
exports.acceptedCodes += '\n;' + name; | ||
var typeInfo = service.getQuickInfoAtPosition(DUMMY_FILE, exports.acceptedCodes.length - 1); | ||
var ret = ''; | ||
if (typeInfo) { | ||
ret = detailed | ||
? ts.displayPartsToString(typeInfo.documentation) | ||
: ts.displayPartsToString(typeInfo.displayParts); | ||
} | ||
console.log(("identifier " + name + " not found").yellow); | ||
exports.acceptedCodes = originalCodes; | ||
return ret; | ||
} | ||
@@ -223,0 +180,0 @@ exports.getType = getType; |
{ | ||
"name": "tsun", | ||
"preferGlobal": true, | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "TSUN: a repl for TypeScript Upgraded Node", | ||
@@ -6,0 +6,0 @@ "bin": "./bin/tsun", |
26147
615