Use SymbolDisplayParts api

This commit is contained in:
Sheetal Nandi
2014-09-30 17:08:52 -07:00
parent d1a09da676
commit 743046bf45
10 changed files with 625 additions and 933 deletions
+15 -7
View File
@@ -45,6 +45,14 @@ module ts {
string(): string;
}
// TODO this should go back in services
export function getSymbolDisplayPart(text: string, kind: SymbolDisplayPartKind, symbol?: Symbol): SymbolDisplayPart {
return <SymbolDisplayPart> {
text: text,
kind: kind
};
}
/// fullTypeCheck denotes if this instance of the typechecker will be used to get semantic diagnostics.
/// If fullTypeCheck === true, then the typechecker should do every possible check to produce all errors
/// If fullTypeCheck === false, the typechecker can take shortcuts and skip checks that only produce errors.
@@ -931,7 +939,7 @@ module ts {
var displayParts: SymbolDisplayPart[] = [];
return {
displayParts: () => displayParts,
writeKind: (text, kind) => displayParts.push(new SymbolDisplayPart(text, kind, undefined)),
writeKind: (text, kind) => displayParts.push(getSymbolDisplayPart(text, kind)),
writeSymbol: (text, symbol) => displayParts.push(symbolPart(text, symbol)),
// Completely ignore indentation for display part writers. And map newlines to
@@ -7699,27 +7707,27 @@ module ts {
}
export function spacePart() {
return new SymbolDisplayPart(" ", SymbolDisplayPartKind.space, undefined);
return getSymbolDisplayPart(" ", SymbolDisplayPartKind.space, undefined);
}
export function keywordPart(kind: SyntaxKind) {
return new SymbolDisplayPart(tokenToString(kind), SymbolDisplayPartKind.keyword, undefined);
return getSymbolDisplayPart(tokenToString(kind), SymbolDisplayPartKind.keyword, undefined);
}
export function punctuationPart(kind: SyntaxKind) {
return new SymbolDisplayPart(tokenToString(kind), SymbolDisplayPartKind.punctuation, undefined);
return getSymbolDisplayPart(tokenToString(kind), SymbolDisplayPartKind.punctuation, undefined);
}
export function operatorPart(kind: SyntaxKind) {
return new SymbolDisplayPart(tokenToString(kind), SymbolDisplayPartKind.operator, undefined);
return getSymbolDisplayPart(tokenToString(kind), SymbolDisplayPartKind.operator, undefined);
}
export function textPart(text: string) {
return new SymbolDisplayPart(text, SymbolDisplayPartKind.text, undefined);
return getSymbolDisplayPart(text, SymbolDisplayPartKind.text, undefined);
}
export function symbolPart(text: string, symbol: Symbol) {
return new SymbolDisplayPart(text, displayPartKind(symbol), symbol)
return getSymbolDisplayPart(text, displayPartKind(symbol), symbol)
}
function displayPartKind(symbol: Symbol): SymbolDisplayPartKind {
+3 -19
View File
@@ -1190,22 +1190,9 @@ module ts {
verticalTab = 0x0B, // \v
}
export class SymbolDisplayPart {
constructor(public text: string,
public kind: SymbolDisplayPartKind,
public symbol: Symbol) {
}
public toJSON() {
return {
text: this.text,
kind: SymbolDisplayPartKind[this.kind]
};
}
public static toString(parts: SymbolDisplayPart[]) {
return parts.map(p => p.text).join("");
}
export interface SymbolDisplayPart {
text: string;
kind: SymbolDisplayPartKind;
}
export enum SymbolDisplayPartKind {
@@ -1215,20 +1202,17 @@ module ts {
fieldName,
interfaceName,
keyword,
labelName,
lineBreak,
numericLiteral,
stringLiteral,
localName,
methodName,
moduleName,
namespaceName,
operator,
parameterName,
propertyName,
punctuation,
space,
anonymousTypeIndicator,
text,
typeParameterName,
enumMemberName,
+39 -60
View File
@@ -523,17 +523,17 @@ module FourSlash {
}
}
public verifyMemberListContains(symbol: string, type?: string, docComment?: string, fullSymbolName?: string, kind?: string) {
public verifyMemberListContains(symbol: string, text?: string, documentation?: string, kind?: string) {
this.scenarioActions.push('<ShowCompletionList />');
this.scenarioActions.push('<VerifyCompletionContainsItem ItemName="' + symbol + '"/>');
if (type || docComment || fullSymbolName || kind) {
if (text || documentation || kind) {
this.taoInvalidReason = 'verifyMemberListContains only supports the "symbol" parameter';
}
var members = this.getMemberListAtCaret();
if (members) {
this.assertItemInCompletionList(members.entries, symbol, type, docComment, fullSymbolName, kind);
this.assertItemInCompletionList(members.entries, symbol, text, documentation, kind);
}
else {
this.raiseError("Expected a member list, but none was provided");
@@ -632,9 +632,9 @@ module FourSlash {
}
}
public verifyCompletionListContains(symbol: string, type?: string, docComment?: string, fullSymbolName?: string, kind?: string) {
public verifyCompletionListContains(symbol: string, text?: string, documentation?: string, kind?: string) {
var completions = this.getCompletionListAtCaret();
this.assertItemInCompletionList(completions.entries, symbol, type, docComment, fullSymbolName, kind);
this.assertItemInCompletionList(completions.entries, symbol, text, documentation, kind);
}
public verifyCompletionListDoesNotContain(symbol: string) {
@@ -647,19 +647,15 @@ module FourSlash {
}
}
public verifyCompletionEntryDetails(entryName: string, type: string, docComment?: string, fullSymbolName?: string, kind?: string) {
public verifyCompletionEntryDetails(entryName: string, expectedText: string, expectedDocumentation?: string, kind?: string) {
this.taoInvalidReason = 'verifyCompletionEntryDetails NYI';
var details = this.getCompletionEntryDetails(entryName);
assert.equal(details.type, type);
assert.equal(ts.displayPartsToString(details.displayParts), expectedText);
if (docComment != undefined) {
assert.equal(details.docComment, docComment);
}
if (fullSymbolName !== undefined) {
assert.equal(details.fullSymbolName, fullSymbolName);
if (expectedDocumentation != undefined) {
assert.equal(ts.displayPartsToString(details.documentation), expectedDocumentation);
}
if (kind !== undefined) {
@@ -758,49 +754,35 @@ module FourSlash {
return this.languageService.getImplementorsAtPosition(this.activeFile.fileName, this.currentCaretPosition);
}
public verifyQuickInfo(negative: boolean, expectedTypeName?: string, docComment?: string, symbolName?: string, kind?: string) {
[expectedTypeName, docComment, symbolName, kind].forEach(str => {
public verifyQuickInfo(negative: boolean, expectedText?: string, expectedDocumentation?: string) {
[expectedText, expectedDocumentation].forEach(str => {
if (str) {
this.scenarioActions.push('<ShowQuickInfo />');
this.scenarioActions.push('<VerifyQuickInfoTextContains IgnoreSpacing="true" Text="' + escapeXmlAttributeValue(str) + '" ' + (negative ? 'ExpectsFailure="true"' : '') + ' />');
}
});
var actualQuickInfo = this.languageService.getTypeAtPosition(this.activeFile.fileName, this.currentCaretPosition);
var actualQuickInfoMemberName = actualQuickInfo ? actualQuickInfo.memberName.toString() : "";
var actualQuickInfoDocComment = actualQuickInfo ? actualQuickInfo.docComment : "";
var actualQuickInfoSymbolName = actualQuickInfo ? actualQuickInfo.fullSymbolName : "";
var actualQuickInfoKind = actualQuickInfo ? actualQuickInfo.kind : "";
var actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition);
var actualQuickInfoText = actualQuickInfo ? ts.displayPartsToString(actualQuickInfo.displayParts) : "";
var actualQuickInfoDocumentation = actualQuickInfo ? ts.displayPartsToString(actualQuickInfo.documentation) : "";
function assertionMessage(msg: string) {
return "\nMarker: " + currentTestState.lastKnownMarker + "\nChecking: " + msg + "\n\n";
}
if (negative) {
if (expectedTypeName !== undefined) {
assert.notEqual(actualQuickInfoMemberName, expectedTypeName, assertionMessage("quick info member name"));
if (expectedText !== undefined) {
assert.notEqual(actualQuickInfoText, expectedText, assertionMessage("quick info text"));
}
if (docComment != undefined) {
assert.notEqual(actualQuickInfoDocComment, docComment, assertionMessage("quick info doc comment"));
}
if (symbolName !== undefined) {
assert.notEqual(actualQuickInfoSymbolName, symbolName, assertionMessage("quick info symbol name"));
}
if (kind !== undefined) {
assert.notEqual(actualQuickInfoKind, kind, assertionMessage("quick info kind"));
if (expectedDocumentation != undefined) {
assert.notEqual(actualQuickInfoDocumentation, expectedDocumentation, assertionMessage("quick info doc comment"));
}
} else {
if (expectedTypeName !== undefined) {
assert.equal(actualQuickInfoMemberName, expectedTypeName, assertionMessage("quick info member"));
if (expectedText !== undefined) {
assert.equal(actualQuickInfoText, expectedText, assertionMessage("quick info text"));
}
if (docComment != undefined) {
assert.equal(actualQuickInfoDocComment, docComment, assertionMessage("quick info doc"));
}
if (symbolName !== undefined) {
assert.equal(actualQuickInfoSymbolName, symbolName, assertionMessage("quick info symbol name"));
}
if (kind !== undefined) {
assert.equal(actualQuickInfoKind, kind, assertionMessage("quick info kind"));
if (expectedDocumentation != undefined) {
assert.equal(actualQuickInfoDocumentation, expectedDocumentation, assertionMessage("quick info doc"));
}
}
}
@@ -808,7 +790,7 @@ module FourSlash {
public verifyQuickInfoExists(negative: number) {
this.taoInvalidReason = 'verifyQuickInfoExists NYI';
var actualQuickInfo = this.languageService.getTypeAtPosition(this.activeFile.fileName, this.currentCaretPosition);
var actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition);
if (negative) {
if (actualQuickInfo) {
this.raiseError('verifyQuickInfoExists failed. Expected quick info NOT to exist');
@@ -826,9 +808,9 @@ module FourSlash {
var help = this.getActiveSignatureHelpItem();
assert.equal(
ts.SymbolDisplayPart.toString(help.prefixDisplayParts) +
help.parameters.map(p => ts.SymbolDisplayPart.toString(p.displayParts)).join(ts.SymbolDisplayPart.toString(help.separatorDisplayParts)) +
ts.SymbolDisplayPart.toString(help.suffixDisplayParts), expected);
ts.displayPartsToString(help.prefixDisplayParts) +
help.parameters.map(p => ts.displayPartsToString(p.displayParts)).join(ts.displayPartsToString(help.separatorDisplayParts)) +
ts.displayPartsToString(help.suffixDisplayParts), expected);
}
public verifyCurrentParameterIsVariable(isVariable: boolean) {
@@ -852,7 +834,7 @@ module FourSlash {
var activeSignature = this.getActiveSignatureHelpItem();
var activeParameter = this.getActiveParameter();
assert.equal(ts.SymbolDisplayPart.toString(activeParameter.displayParts), parameter);
assert.equal(ts.displayPartsToString(activeParameter.displayParts), parameter);
}
public verifyCurrentParameterHelpDocComment(docComment: string) {
@@ -1054,7 +1036,7 @@ module FourSlash {
}
public printCurrentQuickInfo() {
var quickInfo = this.languageService.getTypeAtPosition(this.activeFile.fileName, this.currentCaretPosition);
var quickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition);
Harness.IO.log(JSON.stringify(quickInfo));
}
@@ -1710,7 +1692,7 @@ module FourSlash {
}
for (i = 0; i < positions.length; i++) {
var nameOf = (type: ts.TypeInfo) => type ? type.fullSymbolName : '(none)';
var nameOf = (type: ts.QuickInfo) => type ? ts.displayPartsToString(type.displayParts) : '(none)';
var pullName: string, refName: string;
var anyFailed = false;
@@ -1718,7 +1700,7 @@ module FourSlash {
var errMsg = '';
try {
var pullType = this.languageService.getTypeAtPosition(this.activeFile.fileName, positions[i]);
var pullType = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, positions[i]);
pullName = nameOf(pullType);
} catch (err1) {
errMsg = 'Failed to get pull type check. Exception: ' + err1 + '\r\n';
@@ -1728,7 +1710,7 @@ module FourSlash {
}
try {
var referenceType = referenceLanguageService.getTypeAtPosition(this.activeFile.fileName, positions[i]);
var referenceType = referenceLanguageService.getQuickInfoAtPosition(this.activeFile.fileName, positions[i]);
refName = nameOf(referenceType);
} catch (err2) {
errMsg = 'Failed to get full type check. Exception: ' + err2 + '\r\n';
@@ -1980,28 +1962,25 @@ module FourSlash {
return result;
}
private assertItemInCompletionList(items: ts.CompletionEntry[], name: string, type?: string, docComment?: string, fullSymbolName?: string, kind?: string) {
private assertItemInCompletionList(items: ts.CompletionEntry[], name: string, text?: string, documentation?: string, kind?: string) {
this.scenarioActions.push('<ShowCompletionList />');
this.scenarioActions.push('<VerifyCompletionContainsItem ItemName="' + name + '"/>');
if (type || docComment || fullSymbolName || kind) {
if (text || documentation || kind) {
this.taoInvalidReason = 'assertItemInCompletionList only supports the "name" parameter';
}
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (item.name == name) {
if (docComment != undefined || type !== undefined || fullSymbolName !== undefined) {
if (documentation != undefined || text !== undefined) {
var details = this.getCompletionEntryDetails(item.name);
if (docComment != undefined) {
assert.equal(details.docComment, docComment);
if (documentation != undefined) {
assert.equal(ts.displayPartsToString(details.documentation), documentation);
}
if (type !== undefined) {
assert.equal(details.type, type);
}
if (fullSymbolName !== undefined) {
assert.equal(details.fullSymbolName, fullSymbolName);
if (text !== undefined) {
assert.equal(ts.displayPartsToString(details.displayParts), text);
}
}
@@ -2015,7 +1994,7 @@ module FourSlash {
var itemsString = items.map((item) => JSON.stringify({ name: item.name, kind: item.kind })).join(",\n");
this.raiseError('Expected "' + JSON.stringify({ name: name, type: type, docComment: docComment, fullSymbolName: fullSymbolName, kind: kind }) + '" to be in list [' + itemsString + ']');
this.raiseError('Expected "' + JSON.stringify({ name: name, text: text, documentation: documentation, kind: kind }) + '" to be in list [' + itemsString + ']');
}
private findFile(indexOrName: any) {
-1
View File
@@ -12,7 +12,6 @@
/////<reference path='base64.ts' />
/////<reference path='sourceMapping.ts' />
/////<reference path='emitter.ts' />
/////<reference path='types.ts' />
/////<reference path='pathUtils.ts' />
/////<reference path='referenceResolution.ts' />
/////<reference path='precompile.ts' />
-102
View File
@@ -1,102 +0,0 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///<reference path='references.ts' />
module TypeScript {
export class MemberName {
public prefix: string = "";
public suffix: string = "";
public isString() { return false; }
public isArray() { return false; }
public isMarker() { return !this.isString() && !this.isArray(); }
public toString(): string {
return MemberName.memberNameToString(this);
}
static memberNameToString(memberName: MemberName, markerInfo?: number[], markerBaseLength: number = 0): string {
var result = memberName.prefix;
if (memberName.isString()) {
result += (<MemberNameString>memberName).text;
}
else if (memberName.isArray()) {
var ar = <MemberNameArray>memberName;
for (var index = 0; index < ar.entries.length; index++) {
if (ar.entries[index].isMarker()) {
if (markerInfo) {
markerInfo.push(markerBaseLength + result.length);
}
continue;
}
result += MemberName.memberNameToString(ar.entries[index], markerInfo, markerBaseLength + result.length);
result += ar.delim;
}
}
result += memberName.suffix;
return result;
}
static create(text: string): MemberName;
static create(entry: MemberName, prefix: string, suffix: string): MemberName;
static create(arg1: any, arg2?: any, arg3?: any): MemberName {
if (typeof arg1 === "string") {
return new MemberNameString(arg1);
}
else {
var result = new MemberNameArray();
if (arg2)
result.prefix = arg2;
if (arg3)
result.suffix = arg3;
result.entries.push(arg1);
return result;
}
}
}
export class MemberNameString extends MemberName {
constructor(public text: string) {
super();
}
public isString() { return true; }
}
export class MemberNameArray extends MemberName {
public delim: string = "";
public entries: MemberName[] = [];
public isArray() { return true; }
public add(entry: MemberName) {
this.entries.push(entry);
}
public addAll(entries: MemberName[]) {
for (var i = 0 ; i < entries.length; i++) {
this.entries.push(entries[i]);
}
}
constructor() {
super();
}
}
}
+419 -583
View File
File diff suppressed because it is too large Load Diff
-12
View File
@@ -85,9 +85,6 @@ module ts {
getQuickInfoAtPosition(fileName: string, position: number): string;
// Obsolete. Use getQuickInfoAtPosition instead.
getTypeAtPosition(fileName: string, position: number): string;
getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): string;
getBreakpointStatementAtPosition(fileName: string, position: number): string;
@@ -577,15 +574,6 @@ module ts {
}
public getTypeAtPosition(fileName: string, position: number): string {
return this.forwardJSONCall(
"getTypeAtPosition('" + fileName + "', " + position + ")",
() => {
var typeInfo = this.languageService.getTypeAtPosition(fileName, position);
return typeInfo;
});
}
/// NAMEORDOTTEDNAMESPAN
/**
+1 -1
View File
@@ -273,7 +273,7 @@ module ts.SignatureHelp {
return {
name: p.name,
documentation: getSymbolDocumentationDisplayParts(p),
documentation: p.getDocumentationComment(),
displayParts: displayParts,
isOptional: isOptional
};