Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
cd99389
Add signature arguments label support
Kingwl Dec 23, 2020
ab3c937
Support rest parameters and destruction
Kingwl Dec 24, 2020
d91b2f7
make lint
Kingwl Dec 24, 2020
8388add
Fix tuple rest parameters
Kingwl Dec 24, 2020
1058fdd
Adjust name styles
Kingwl Dec 24, 2020
1517b1f
Rename to inline hints
Kingwl Dec 24, 2020
fd9b09f
Partition inline hints
Kingwl Dec 25, 2020
23afce2
Adjust range pred
Kingwl Dec 25, 2020
ee6527e
Add function expression like hints
Kingwl Dec 25, 2020
679b58d
Support configure inline hints
Kingwl Dec 25, 2020
446bee4
Display hints in single line
Kingwl Dec 25, 2020
d2fbd1e
Add test suits and tests
Kingwl Dec 27, 2020
c4abb87
Add range tests
Kingwl Dec 28, 2020
a9e007a
Support more hints
Kingwl Dec 29, 2020
df62a11
Add more options
Kingwl Dec 30, 2020
fce2619
Fix logical
Kingwl Dec 30, 2020
679f066
Add more cases
Kingwl Dec 30, 2020
eb4b4ad
Support call chains
Kingwl Dec 30, 2020
9297051
Rename options
Kingwl Dec 30, 2020
467b5cd
Match lastest protocol
Kingwl Jan 13, 2021
e5ca31b
Update protocol changes
Kingwl Jan 14, 2021
37a7089
Support context value and hover message
Kingwl Jan 16, 2021
2ccfc98
Revert "Support context value and hover message"
Kingwl Jan 21, 2021
0e5f223
Revert "Update protocol changes"
Kingwl Jan 21, 2021
7197d0d
Add hover message
Kingwl Jan 21, 2021
e785943
Accept baseline
Kingwl Jan 21, 2021
637c7f8
Update src/services/inlineHints.ts
Kingwl Feb 4, 2021
b3c3e7e
Update src/services/inlineHints.ts
Kingwl Feb 4, 2021
7948cec
Merge branch 'master' into signature_arguments_labels_support
Kingwl Feb 4, 2021
a374417
Cache across the program
Kingwl Feb 4, 2021
7ac2a35
Merge branch 'master' into signature_arguments_labels_support
Kingwl May 7, 2021
5767d7e
Fix possible undefined
Kingwl May 7, 2021
d7d72d6
Update protocol changes
Kingwl Jun 3, 2021
9306d72
Fix missing property
Kingwl Jun 3, 2021
5cab46f
Merge branch 'main' into signature_arguments_labels_support
Kingwl Jun 3, 2021
2750c6b
Make lint happy
Kingwl Jun 4, 2021
0090962
Avoid call chain hints
Kingwl Jun 10, 2021
f771afc
I'm bad
Kingwl Jun 10, 2021
67dcbb0
Add whitespace before type
Kingwl Jun 10, 2021
957756c
Add more tests
Kingwl Jun 10, 2021
db4135b
Should care about jsdoc
Kingwl Jun 10, 2021
b74af7c
Support complex rest parameter
Kingwl Jun 10, 2021
388cc6d
Avoid module symbol hints
Kingwl Jun 14, 2021
f5695a1
Care about leading comments
Kingwl Jun 14, 2021
6336803
Fix CR issues
Kingwl Jun 15, 2021
09cdf37
Avoid changes
Kingwl Jun 15, 2021
71bae5e
Simplify comments contains
Kingwl Jun 15, 2021
cba4dc3
Fix CR issues
Kingwl Jun 18, 2021
0e8cdb6
Accept baseline
Kingwl Jun 18, 2021
cc06dbc
Merge branch 'main' into signature_arguments_labels_support
Kingwl Jun 18, 2021
e8fef30
Check parameter name before create regex
Kingwl Jun 18, 2021
d8dc8f1
Rename option
Kingwl Jun 24, 2021
52c9d5c
Avoid makers
Kingwl Jun 24, 2021
7ce7a44
Skip parens for argument
Kingwl Jun 24, 2021
24e1a4a
Fix CR issues
Kingwl Jun 24, 2021
6b279e7
Fix enums
Kingwl Jun 25, 2021
8e9a8d8
Accept baseline
Kingwl Jun 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test suits and tests
  • Loading branch information
Kingwl committed Dec 27, 2020
commit d2fbd1e6e5ce39a6207f992a2bae435976cc9347
12 changes: 12 additions & 0 deletions src/harness/fourslashImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,18 @@ namespace FourSlash {
});
}

public verifyInlineHints(expected: readonly FourSlashInterface.VerifyInlineHintsOptions[], span: ts.TextSpan = { start: 0, length: this.activeFile.content.length }, preference?: ts.InlineHintsOptions) {
const hints = this.languageService.provideInlineHints(this.activeFile.fileName, span, preference);
assert.equal(hints.length, expected.length, "Number of hints");
const sortHints = (a: ts.InlineHint, b: ts.InlineHint) => a.position - b.position;
ts.zipWith(hints.sort(sortHints), [...expected].sort(sortHints), (actual, expected) => {
assert.equal(actual.text, expected.text, "Text");
assert.equal(actual.position, expected.position, "Position");
assert.equal(actual.whitespaceBefore, expected.whitespaceBefore, "whitespaceBefore");
assert.equal(actual.whitespaceAfter, expected.whitespaceAfter, "whitespaceAfter");
});
}

public verifyCompletions(options: FourSlashInterface.VerifyCompletionsOptions) {
if (options.marker === undefined) {
this.verifyCompletionsWorker(options);
Expand Down
11 changes: 11 additions & 0 deletions src/harness/fourslashInterfaceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ namespace FourSlashInterface {
}
}

public getInlineHints(expected: readonly VerifyInlineHintsOptions[], span: ts.TextSpan, preference?: ts.InlineHintsOptions) {
this.state.verifyInlineHints(expected, span, preference);
}

public quickInfoIs(expectedText: string, expectedDocumentation?: string) {
this.state.verifyQuickInfoString(expectedText, expectedDocumentation);
}
Expand Down Expand Up @@ -1645,6 +1649,13 @@ namespace FourSlashInterface {
readonly containerKind?: ts.ScriptElementKind;
}

export interface VerifyInlineHintsOptions {
text: string;
position: number
whitespaceBefore?: boolean;
whitespaceAfter?: boolean;
}

export type ArrayOrSingle<T> = T | readonly T[];

export interface VerifyCompletionListContainsOptions extends ts.UserPreferences {
Expand Down
2 changes: 1 addition & 1 deletion src/services/inlineHints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ts.InlineHints {
whitespaceAfter?: boolean;
}

const maxHintsLength = 20;
const maxHintsLength = 30;

export function provideInlineHints(context: InlineHintsContext): HintInfo[] {
const { file, program, span, cancellationToken, preferences } = context;
Expand Down
14 changes: 14 additions & 0 deletions tests/cases/fourslash/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ declare namespace FourSlashInterface {
start: number;
length: number;
}, displayParts: ts.SymbolDisplayPart[], documentation: ts.SymbolDisplayPart[], tags: { name: string, text?: string }[] | undefined): void;
getInlineHints(expected: readonly VerifyInlineHintsOptions[], span?: TextSpan, preference?: InlineHintsOptions);
getSyntacticDiagnostics(expected: ReadonlyArray<Diagnostic>): void;
getSemanticDiagnostics(expected: ReadonlyArray<Diagnostic>): void;
getSuggestionDiagnostics(expected: ReadonlyArray<Diagnostic>): void;
Expand Down Expand Up @@ -614,6 +615,11 @@ declare namespace FourSlashInterface {
readonly importModuleSpecifierPreference?: "shortest" | "project-relative" | "relative" | "non-relative";
readonly importModuleSpecifierEnding?: "minimal" | "index" | "js";
}
interface InlineHintsOptions extends UserPreferences {
readonly includeInlineParameterName?: boolean;
readonly includeInlineFunctionParameterType?: boolean;
readonly includeInlineVariableType?: boolean;
}
interface CompletionsOptions {
readonly marker?: ArrayOrSingle<string | Marker>;
readonly isNewIdentifierLocation?: boolean;
Expand Down Expand Up @@ -711,6 +717,14 @@ declare namespace FourSlashInterface {
readonly commands?: ReadonlyArray<{}>;
}

export interface VerifyInlineHintsOptions {
text: string;
position: number
whitespaceBefore?: boolean;
whitespaceAfter?: boolean;
}


interface VerifyNavigateToOptions {
readonly pattern: string;
readonly fileName?: string;
Expand Down
20 changes: 20 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// <reference path="fourslash.ts" />

//// function foo (a: number, b: number) {}
//// foo(/*a*/1, /*b*/2);

const markers = test.markers();
verify.getInlineHints([
{
text: 'a:',
position: markers[0].position,
whitespaceAfter: true
},
{
text: 'b:',
position: markers[1].position,
whitespaceAfter: true
}
], undefined, {
includeInlineParameterName: true
});
9 changes: 9 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork10.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference path="fourslash.ts" />

//// declare const unknownCall: any;
//// unknownCall();

const markers = test.markers();
verify.getInlineHints([], undefined, {
includeInlineParameterName: true
});
24 changes: 24 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork11.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// <reference path="fourslash.ts" />

//// function foo(a: number) {
//// return (b: number) => {
//// return a + b
//// }
//// }
//// foo(/*a*/1)(/*b*/2);

const markers = test.markers();
verify.getInlineHints([
{
text: 'a:',
position: markers[0].position,
whitespaceAfter: true
},
{
text: 'b:',
position: markers[1].position,
whitespaceAfter: true
},
], undefined, {
includeInlineParameterName: true
});
23 changes: 23 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork12.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// <reference path="fourslash.ts" />

//// function foo(a: (b: number) => number) {
//// return a(/*a*/1) + 2
//// }

//// foo(/*b*/(c: number) => c + 1);

const markers = test.markers();
verify.getInlineHints([
{
text: 'b:',
position: markers[0].position,
whitespaceAfter: true
},
{
text: 'a:',
position: markers[1].position,
whitespaceAfter: true
},
], undefined, {
includeInlineParameterName: true
});
16 changes: 16 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork13.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />

//// function foo (a: number, b: number) {}
//// declare const a: 1;
//// foo(a, /*b*/2);

const markers = test.markers();
verify.getInlineHints([
{
text: 'b:',
position: markers[0].position,
whitespaceAfter: true
},
], undefined, {
includeInlineParameterName: true
});
8 changes: 8 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork14.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// <reference path="fourslash.ts" />

//// function foo (a: number, b: number) {}
//// foo(1, 2);

verify.getInlineHints([], undefined, {
includeInlineParameterName: false
});
14 changes: 14 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork15.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference path="fourslash.ts" />

//// const a/*a*/ = 123;

const markers = test.markers();
verify.getInlineHints([
{
text: ':123',
position: markers[0].position,
whitespaceBefore: true
},
], undefined, {
includeInlineVariableType: true
});
14 changes: 14 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork16.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference path="fourslash.ts" />

//// const a/*a*/ = 123;

const markers = test.markers();
verify.getInlineHints([
{
text: ':123',
position: markers[0].position,
whitespaceBefore: true
},
], undefined, {
includeInlineVariableType: true
});
14 changes: 14 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork17.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference path="fourslash.ts" />

//// const a/*a*/ = { a: 123 };

const markers = test.markers();
verify.getInlineHints([
{
text: ':{ a: number; }',
position: markers[0].position,
whitespaceBefore: true
},
], undefined, {
includeInlineVariableType: true
});
15 changes: 15 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork18.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />

//// class Class {}
//// const a/*a*/ = new Class();

const markers = test.markers();
verify.getInlineHints([
{
text: ':Class',
position: markers[0].position,
whitespaceBefore: true
},
], undefined, {
includeInlineVariableType: true
});
14 changes: 14 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork19.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference path="fourslash.ts" />

//// const a/*a*/ = () => 123;

const markers = test.markers();
verify.getInlineHints([
{
text: ':() => number',
position: markers[0].position,
whitespaceBefore: true
},
], undefined, {
includeInlineVariableType: true
});
15 changes: 15 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />

//// function foo (a: number, { c }: any) {}
//// foo(/*a*/1, { c: 1});

const markers = test.markers();
verify.getInlineHints([
{
text: 'a:',
position: markers[0].position,
whitespaceAfter: true
}
], undefined, {
includeInlineParameterName: true
});
7 changes: 7 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork20.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference path="fourslash.ts" />

//// const a = 123;

verify.getInlineHints([], undefined, {
includeInlineVariableType: false
});
7 changes: 7 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork21.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference path="fourslash.ts" />

//// const a;

verify.getInlineHints([], undefined, {
includeInlineVariableType: true
});
14 changes: 14 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork22.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference path="fourslash.ts" />

//// const a/*a*/ = "I'm very very very very very very very very very long";

const markers = test.markers();
verify.getInlineHints([
{
text: `:"I'm very very very very ve...`,
position: markers[0].position,
whitespaceBefore: true
},
], undefined, {
includeInlineVariableType: true
});
15 changes: 15 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork23.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />

//// function foo (Im_very_very_very_very_very_very_very_long: number) {}
//// foo(/*a*/1);

const markers = test.markers();
verify.getInlineHints([
{
text: 'Im_very_very_very_very_very...:',
position: markers[0].position,
whitespaceAfter: true
}
], undefined, {
includeInlineParameterName: true
});
20 changes: 20 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork24.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// <reference path="fourslash.ts" />

//// type F = (a: string, b: number) => void
//// const f: F = (a/*a*/, b/*b*/) => { }

const markers = test.markers();
verify.getInlineHints([
{
text: ':string',
position: markers[0].position,
whitespaceBefore: true
},
{
text: ':number',
position: markers[1].position,
whitespaceBefore: true
}
], undefined, {
includeInlineFunctionParameterType: true
});
15 changes: 15 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork25.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />

//// function foo (cb: (a: string) => void) {}
//// foo((a/*a*/) => { })

const markers = test.markers();
verify.getInlineHints([
{
text: ':string',
position: markers[0].position,
whitespaceBefore: true
}
], undefined, {
includeInlineFunctionParameterType: true
});
15 changes: 15 additions & 0 deletions tests/cases/fourslash/inlineHintsShouldWork26.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />

//// function foo (cb: (a: Exclude<1 | 2 | 3, 1>) => void) {}
//// foo((a/*a*/) => { })

const markers = test.markers();
verify.getInlineHints([
{
text: ':Exclude<1 | 2 | 3, 1>',
position: markers[0].position,
whitespaceBefore: true
}
], undefined, {
includeInlineFunctionParameterType: true
});
Loading