Skip to content

Commit 743046b

Browse files
committed
Use SymbolDisplayParts api
1 parent d1a09da commit 743046b

File tree

10 files changed

+597
-905
lines changed

10 files changed

+597
-905
lines changed

src/compiler/checker.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ module ts {
4545
string(): string;
4646
}
4747

48+
// TODO this should go back in services
49+
export function getSymbolDisplayPart(text: string, kind: SymbolDisplayPartKind, symbol?: Symbol): SymbolDisplayPart {
50+
return <SymbolDisplayPart> {
51+
text: text,
52+
kind: kind
53+
};
54+
}
55+
4856
/// fullTypeCheck denotes if this instance of the typechecker will be used to get semantic diagnostics.
4957
/// If fullTypeCheck === true, then the typechecker should do every possible check to produce all errors
5058
/// If fullTypeCheck === false, the typechecker can take shortcuts and skip checks that only produce errors.
@@ -931,7 +939,7 @@ module ts {
931939
var displayParts: SymbolDisplayPart[] = [];
932940
return {
933941
displayParts: () => displayParts,
934-
writeKind: (text, kind) => displayParts.push(new SymbolDisplayPart(text, kind, undefined)),
942+
writeKind: (text, kind) => displayParts.push(getSymbolDisplayPart(text, kind)),
935943
writeSymbol: (text, symbol) => displayParts.push(symbolPart(text, symbol)),
936944

937945
// Completely ignore indentation for display part writers. And map newlines to
@@ -7699,27 +7707,27 @@ module ts {
76997707
}
77007708

77017709
export function spacePart() {
7702-
return new SymbolDisplayPart(" ", SymbolDisplayPartKind.space, undefined);
7710+
return getSymbolDisplayPart(" ", SymbolDisplayPartKind.space, undefined);
77037711
}
77047712

77057713
export function keywordPart(kind: SyntaxKind) {
7706-
return new SymbolDisplayPart(tokenToString(kind), SymbolDisplayPartKind.keyword, undefined);
7714+
return getSymbolDisplayPart(tokenToString(kind), SymbolDisplayPartKind.keyword, undefined);
77077715
}
77087716

77097717
export function punctuationPart(kind: SyntaxKind) {
7710-
return new SymbolDisplayPart(tokenToString(kind), SymbolDisplayPartKind.punctuation, undefined);
7718+
return getSymbolDisplayPart(tokenToString(kind), SymbolDisplayPartKind.punctuation, undefined);
77117719
}
77127720

77137721
export function operatorPart(kind: SyntaxKind) {
7714-
return new SymbolDisplayPart(tokenToString(kind), SymbolDisplayPartKind.operator, undefined);
7722+
return getSymbolDisplayPart(tokenToString(kind), SymbolDisplayPartKind.operator, undefined);
77157723
}
77167724

77177725
export function textPart(text: string) {
7718-
return new SymbolDisplayPart(text, SymbolDisplayPartKind.text, undefined);
7726+
return getSymbolDisplayPart(text, SymbolDisplayPartKind.text, undefined);
77197727
}
77207728

77217729
export function symbolPart(text: string, symbol: Symbol) {
7722-
return new SymbolDisplayPart(text, displayPartKind(symbol), symbol)
7730+
return getSymbolDisplayPart(text, displayPartKind(symbol), symbol)
77237731
}
77247732

77257733
function displayPartKind(symbol: Symbol): SymbolDisplayPartKind {

src/compiler/types.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,22 +1190,9 @@ module ts {
11901190
verticalTab = 0x0B, // \v
11911191
}
11921192

1193-
export class SymbolDisplayPart {
1194-
constructor(public text: string,
1195-
public kind: SymbolDisplayPartKind,
1196-
public symbol: Symbol) {
1197-
}
1198-
1199-
public toJSON() {
1200-
return {
1201-
text: this.text,
1202-
kind: SymbolDisplayPartKind[this.kind]
1203-
};
1204-
}
1205-
1206-
public static toString(parts: SymbolDisplayPart[]) {
1207-
return parts.map(p => p.text).join("");
1208-
}
1193+
export interface SymbolDisplayPart {
1194+
text: string;
1195+
kind: SymbolDisplayPartKind;
12091196
}
12101197

12111198
export enum SymbolDisplayPartKind {
@@ -1215,20 +1202,17 @@ module ts {
12151202
fieldName,
12161203
interfaceName,
12171204
keyword,
1218-
labelName,
12191205
lineBreak,
12201206
numericLiteral,
12211207
stringLiteral,
12221208
localName,
12231209
methodName,
12241210
moduleName,
1225-
namespaceName,
12261211
operator,
12271212
parameterName,
12281213
propertyName,
12291214
punctuation,
12301215
space,
1231-
anonymousTypeIndicator,
12321216
text,
12331217
typeParameterName,
12341218
enumMemberName,

src/harness/fourslash.ts

Lines changed: 39 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -523,17 +523,17 @@ module FourSlash {
523523
}
524524
}
525525

526-
public verifyMemberListContains(symbol: string, type?: string, docComment?: string, fullSymbolName?: string, kind?: string) {
526+
public verifyMemberListContains(symbol: string, text?: string, documentation?: string, kind?: string) {
527527
this.scenarioActions.push('<ShowCompletionList />');
528528
this.scenarioActions.push('<VerifyCompletionContainsItem ItemName="' + symbol + '"/>');
529529

530-
if (type || docComment || fullSymbolName || kind) {
530+
if (text || documentation || kind) {
531531
this.taoInvalidReason = 'verifyMemberListContains only supports the "symbol" parameter';
532532
}
533533

534534
var members = this.getMemberListAtCaret();
535535
if (members) {
536-
this.assertItemInCompletionList(members.entries, symbol, type, docComment, fullSymbolName, kind);
536+
this.assertItemInCompletionList(members.entries, symbol, text, documentation, kind);
537537
}
538538
else {
539539
this.raiseError("Expected a member list, but none was provided");
@@ -632,9 +632,9 @@ module FourSlash {
632632
}
633633
}
634634

635-
public verifyCompletionListContains(symbol: string, type?: string, docComment?: string, fullSymbolName?: string, kind?: string) {
635+
public verifyCompletionListContains(symbol: string, text?: string, documentation?: string, kind?: string) {
636636
var completions = this.getCompletionListAtCaret();
637-
this.assertItemInCompletionList(completions.entries, symbol, type, docComment, fullSymbolName, kind);
637+
this.assertItemInCompletionList(completions.entries, symbol, text, documentation, kind);
638638
}
639639

640640
public verifyCompletionListDoesNotContain(symbol: string) {
@@ -647,19 +647,15 @@ module FourSlash {
647647
}
648648
}
649649

650-
public verifyCompletionEntryDetails(entryName: string, type: string, docComment?: string, fullSymbolName?: string, kind?: string) {
650+
public verifyCompletionEntryDetails(entryName: string, expectedText: string, expectedDocumentation?: string, kind?: string) {
651651
this.taoInvalidReason = 'verifyCompletionEntryDetails NYI';
652652

653653
var details = this.getCompletionEntryDetails(entryName);
654654

655-
assert.equal(details.type, type);
655+
assert.equal(ts.displayPartsToString(details.displayParts), expectedText);
656656

657-
if (docComment != undefined) {
658-
assert.equal(details.docComment, docComment);
659-
}
660-
661-
if (fullSymbolName !== undefined) {
662-
assert.equal(details.fullSymbolName, fullSymbolName);
657+
if (expectedDocumentation != undefined) {
658+
assert.equal(ts.displayPartsToString(details.documentation), expectedDocumentation);
663659
}
664660

665661
if (kind !== undefined) {
@@ -758,57 +754,43 @@ module FourSlash {
758754
return this.languageService.getImplementorsAtPosition(this.activeFile.fileName, this.currentCaretPosition);
759755
}
760756

761-
public verifyQuickInfo(negative: boolean, expectedTypeName?: string, docComment?: string, symbolName?: string, kind?: string) {
762-
[expectedTypeName, docComment, symbolName, kind].forEach(str => {
757+
public verifyQuickInfo(negative: boolean, expectedText?: string, expectedDocumentation?: string) {
758+
[expectedText, expectedDocumentation].forEach(str => {
763759
if (str) {
764760
this.scenarioActions.push('<ShowQuickInfo />');
765761
this.scenarioActions.push('<VerifyQuickInfoTextContains IgnoreSpacing="true" Text="' + escapeXmlAttributeValue(str) + '" ' + (negative ? 'ExpectsFailure="true"' : '') + ' />');
766762
}
767763
});
768764

769-
var actualQuickInfo = this.languageService.getTypeAtPosition(this.activeFile.fileName, this.currentCaretPosition);
770-
var actualQuickInfoMemberName = actualQuickInfo ? actualQuickInfo.memberName.toString() : "";
771-
var actualQuickInfoDocComment = actualQuickInfo ? actualQuickInfo.docComment : "";
772-
var actualQuickInfoSymbolName = actualQuickInfo ? actualQuickInfo.fullSymbolName : "";
773-
var actualQuickInfoKind = actualQuickInfo ? actualQuickInfo.kind : "";
765+
var actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition);
766+
var actualQuickInfoText = actualQuickInfo ? ts.displayPartsToString(actualQuickInfo.displayParts) : "";
767+
var actualQuickInfoDocumentation = actualQuickInfo ? ts.displayPartsToString(actualQuickInfo.documentation) : "";
774768

775769
function assertionMessage(msg: string) {
776770
return "\nMarker: " + currentTestState.lastKnownMarker + "\nChecking: " + msg + "\n\n";
777771
}
778772

779773
if (negative) {
780-
if (expectedTypeName !== undefined) {
781-
assert.notEqual(actualQuickInfoMemberName, expectedTypeName, assertionMessage("quick info member name"));
782-
}
783-
if (docComment != undefined) {
784-
assert.notEqual(actualQuickInfoDocComment, docComment, assertionMessage("quick info doc comment"));
785-
}
786-
if (symbolName !== undefined) {
787-
assert.notEqual(actualQuickInfoSymbolName, symbolName, assertionMessage("quick info symbol name"));
774+
if (expectedText !== undefined) {
775+
assert.notEqual(actualQuickInfoText, expectedText, assertionMessage("quick info text"));
788776
}
789-
if (kind !== undefined) {
790-
assert.notEqual(actualQuickInfoKind, kind, assertionMessage("quick info kind"));
777+
if (expectedDocumentation != undefined) {
778+
assert.notEqual(actualQuickInfoDocumentation, expectedDocumentation, assertionMessage("quick info doc comment"));
791779
}
792780
} else {
793-
if (expectedTypeName !== undefined) {
794-
assert.equal(actualQuickInfoMemberName, expectedTypeName, assertionMessage("quick info member"));
781+
if (expectedText !== undefined) {
782+
assert.equal(actualQuickInfoText, expectedText, assertionMessage("quick info text"));
795783
}
796-
if (docComment != undefined) {
797-
assert.equal(actualQuickInfoDocComment, docComment, assertionMessage("quick info doc"));
798-
}
799-
if (symbolName !== undefined) {
800-
assert.equal(actualQuickInfoSymbolName, symbolName, assertionMessage("quick info symbol name"));
801-
}
802-
if (kind !== undefined) {
803-
assert.equal(actualQuickInfoKind, kind, assertionMessage("quick info kind"));
784+
if (expectedDocumentation != undefined) {
785+
assert.equal(actualQuickInfoDocumentation, expectedDocumentation, assertionMessage("quick info doc"));
804786
}
805787
}
806788
}
807789

808790
public verifyQuickInfoExists(negative: number) {
809791
this.taoInvalidReason = 'verifyQuickInfoExists NYI';
810792

811-
var actualQuickInfo = this.languageService.getTypeAtPosition(this.activeFile.fileName, this.currentCaretPosition);
793+
var actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition);
812794
if (negative) {
813795
if (actualQuickInfo) {
814796
this.raiseError('verifyQuickInfoExists failed. Expected quick info NOT to exist');
@@ -826,9 +808,9 @@ module FourSlash {
826808

827809
var help = this.getActiveSignatureHelpItem();
828810
assert.equal(
829-
ts.SymbolDisplayPart.toString(help.prefixDisplayParts) +
830-
help.parameters.map(p => ts.SymbolDisplayPart.toString(p.displayParts)).join(ts.SymbolDisplayPart.toString(help.separatorDisplayParts)) +
831-
ts.SymbolDisplayPart.toString(help.suffixDisplayParts), expected);
811+
ts.displayPartsToString(help.prefixDisplayParts) +
812+
help.parameters.map(p => ts.displayPartsToString(p.displayParts)).join(ts.displayPartsToString(help.separatorDisplayParts)) +
813+
ts.displayPartsToString(help.suffixDisplayParts), expected);
832814
}
833815

834816
public verifyCurrentParameterIsVariable(isVariable: boolean) {
@@ -852,7 +834,7 @@ module FourSlash {
852834

853835
var activeSignature = this.getActiveSignatureHelpItem();
854836
var activeParameter = this.getActiveParameter();
855-
assert.equal(ts.SymbolDisplayPart.toString(activeParameter.displayParts), parameter);
837+
assert.equal(ts.displayPartsToString(activeParameter.displayParts), parameter);
856838
}
857839

858840
public verifyCurrentParameterHelpDocComment(docComment: string) {
@@ -1054,7 +1036,7 @@ module FourSlash {
10541036
}
10551037

10561038
public printCurrentQuickInfo() {
1057-
var quickInfo = this.languageService.getTypeAtPosition(this.activeFile.fileName, this.currentCaretPosition);
1039+
var quickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition);
10581040
Harness.IO.log(JSON.stringify(quickInfo));
10591041
}
10601042

@@ -1710,15 +1692,15 @@ module FourSlash {
17101692
}
17111693

17121694
for (i = 0; i < positions.length; i++) {
1713-
var nameOf = (type: ts.TypeInfo) => type ? type.fullSymbolName : '(none)';
1695+
var nameOf = (type: ts.QuickInfo) => type ? ts.displayPartsToString(type.displayParts) : '(none)';
17141696

17151697
var pullName: string, refName: string;
17161698
var anyFailed = false;
17171699

17181700
var errMsg = '';
17191701

17201702
try {
1721-
var pullType = this.languageService.getTypeAtPosition(this.activeFile.fileName, positions[i]);
1703+
var pullType = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, positions[i]);
17221704
pullName = nameOf(pullType);
17231705
} catch (err1) {
17241706
errMsg = 'Failed to get pull type check. Exception: ' + err1 + '\r\n';
@@ -1728,7 +1710,7 @@ module FourSlash {
17281710
}
17291711

17301712
try {
1731-
var referenceType = referenceLanguageService.getTypeAtPosition(this.activeFile.fileName, positions[i]);
1713+
var referenceType = referenceLanguageService.getQuickInfoAtPosition(this.activeFile.fileName, positions[i]);
17321714
refName = nameOf(referenceType);
17331715
} catch (err2) {
17341716
errMsg = 'Failed to get full type check. Exception: ' + err2 + '\r\n';
@@ -1980,28 +1962,25 @@ module FourSlash {
19801962
return result;
19811963
}
19821964

1983-
private assertItemInCompletionList(items: ts.CompletionEntry[], name: string, type?: string, docComment?: string, fullSymbolName?: string, kind?: string) {
1965+
private assertItemInCompletionList(items: ts.CompletionEntry[], name: string, text?: string, documentation?: string, kind?: string) {
19841966
this.scenarioActions.push('<ShowCompletionList />');
19851967
this.scenarioActions.push('<VerifyCompletionContainsItem ItemName="' + name + '"/>');
19861968

1987-
if (type || docComment || fullSymbolName || kind) {
1969+
if (text || documentation || kind) {
19881970
this.taoInvalidReason = 'assertItemInCompletionList only supports the "name" parameter';
19891971
}
19901972

19911973
for (var i = 0; i < items.length; i++) {
19921974
var item = items[i];
19931975
if (item.name == name) {
1994-
if (docComment != undefined || type !== undefined || fullSymbolName !== undefined) {
1976+
if (documentation != undefined || text !== undefined) {
19951977
var details = this.getCompletionEntryDetails(item.name);
19961978

1997-
if (docComment != undefined) {
1998-
assert.equal(details.docComment, docComment);
1999-
}
2000-
if (type !== undefined) {
2001-
assert.equal(details.type, type);
1979+
if (documentation != undefined) {
1980+
assert.equal(ts.displayPartsToString(details.documentation), documentation);
20021981
}
2003-
if (fullSymbolName !== undefined) {
2004-
assert.equal(details.fullSymbolName, fullSymbolName);
1982+
if (text !== undefined) {
1983+
assert.equal(ts.displayPartsToString(details.displayParts), text);
20051984
}
20061985
}
20071986

@@ -2015,7 +1994,7 @@ module FourSlash {
20151994

20161995
var itemsString = items.map((item) => JSON.stringify({ name: item.name, kind: item.kind })).join(",\n");
20171996

2018-
this.raiseError('Expected "' + JSON.stringify({ name: name, type: type, docComment: docComment, fullSymbolName: fullSymbolName, kind: kind }) + '" to be in list [' + itemsString + ']');
1997+
this.raiseError('Expected "' + JSON.stringify({ name: name, text: text, documentation: documentation, kind: kind }) + '" to be in list [' + itemsString + ']');
20191998
}
20201999

20212000
private findFile(indexOrName: any) {

src/services/compiler/references.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
/////<reference path='base64.ts' />
1313
/////<reference path='sourceMapping.ts' />
1414
/////<reference path='emitter.ts' />
15-
/////<reference path='types.ts' />
1615
/////<reference path='pathUtils.ts' />
1716
/////<reference path='referenceResolution.ts' />
1817
/////<reference path='precompile.ts' />

0 commit comments

Comments
 (0)