Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add commit characters to protocol #59339

Merged
merged 4 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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 commit character properties to fourslash tests
  • Loading branch information
gabritto committed Jul 18, 2024
commit cdf160e4044cd6bd4c1cc210f553a8033bde5c3f
17 changes: 16 additions & 1 deletion src/harness/fourslashImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 1024,7 @@ export class TestState {
}

if (ts.hasProperty(options, "isGlobalCompletion") && actualCompletions.isGlobalCompletion !== options.isGlobalCompletion) {
this.raiseError(`Expected 'isGlobalCompletion to be ${options.isGlobalCompletion}, got ${actualCompletions.isGlobalCompletion}`);
this.raiseError(`Expected 'isGlobalCompletion' to be ${options.isGlobalCompletion}, got ${actualCompletions.isGlobalCompletion}`);
}

if (ts.hasProperty(options, "optionalReplacementSpan")) {
Expand All @@ -1035,6 1035,14 @@ export class TestState {
);
}

if (ts.hasProperty(options, "defaultCommitCharacters")) {
assert.deepEqual(
actualCompletions.defaultCommitCharacters?.sort(),
options.defaultCommitCharacters?.sort(),
"Expected 'defaultCommitCharacters' properties to match",
);
}

const nameToEntries = new Map<string, ts.CompletionEntry[]>();
const nameAndSourceToData = new Map<string, ts.CompletionEntryData | false>();
for (const entry of actualCompletions.entries) {
Expand Down Expand Up @@ -1181,6 1189,13 @@ export class TestState {
assert.equal(actual.isSnippet, expected.isSnippet, `At entry ${actual.name}: Expected 'isSnippet' properties to match`);
assert.equal(actual.source, expected.source, `At entry ${actual.name}: Expected 'source' values to match`);
assert.equal(actual.sortText, expected.sortText || ts.Completions.SortText.LocationPriority, `At entry ${actual.name}: Expected 'sortText' properties to match`);
if (ts.hasProperty(expected, "commitCharacters")) {
assert.deepEqual(
actual.commitCharacters?.sort(),
expected.commitCharacters?.sort(),
`At entry ${actual.name}: Expected 'commitCharacters' values to match`,
);
}
if (expected.sourceDisplay && actual.sourceDisplay) {
assert.equal(ts.displayPartsToString(actual.sourceDisplay), expected.sourceDisplay, `At entry ${actual.name}: Expected 'sourceDisplay' properties to match`);
}
Expand Down
2 changes: 2 additions & 0 deletions src/harness/fourslashInterfaceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 1797,7 @@ export interface ExpectedCompletionEntryObject {
readonly labelDetails?: ExpectedCompletionEntryLabelDetails;
readonly tags?: readonly ts.JSDocTagInfo[];
readonly sortText?: ts.Completions.SortText;
readonly commitCharacters?: string[]; // If not specified, won't assert about this
}

export interface ExpectedCompletionEntryLabelDetails {
Expand All @@ -1820,6 1821,7 @@ export interface VerifyCompletionsOptions {
readonly excludes?: ArrayOrSingle<string>;
readonly preferences?: ts.UserPreferences;
readonly triggerCharacter?: ts.CompletionsTriggerCharacter;
readonly defaultCommitCharacters?: string[]; // Only tested if set
}

export interface VerifySignatureHelpOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 4,4 @@
////
//// test({ type: /*ts*/ })

verify.completions({ marker: ["ts"], includes: ['"a"', '"b"'], isNewIdentifierLocation: false });
verify.completions({ marker: ["ts"], includes: ['"a"', '"b"'], isNewIdentifierLocation: false, defaultCommitCharacters: [".", ",", ";"] });
12 changes: 6 additions & 6 deletions tests/cases/fourslash/completionForStringLiteral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 8,13 @@

verify.completions(
{ marker: "1", exact: [
{ name: "Option 1", replacementSpan: test.ranges()[0] },
{ name: "Option 2", replacementSpan: test.ranges()[0] },
{ name: "Option 3", replacementSpan: test.ranges()[0] }
{ name: "Option 1", replacementSpan: test.ranges()[0], commitCharacters: [] },
{ name: "Option 2", replacementSpan: test.ranges()[0], commitCharacters: [] },
{ name: "Option 3", replacementSpan: test.ranges()[0], commitCharacters: [] }
] },
{ marker: "2", exact: [
{ name: "Option 1", replacementSpan: test.ranges()[1] },
{ name: "Option 2", replacementSpan: test.ranges()[1] },
{ name: "Option 3", replacementSpan: test.ranges()[1] }
{ name: "Option 1", replacementSpan: test.ranges()[1], commitCharacters: [] },
{ name: "Option 2", replacementSpan: test.ranges()[1], commitCharacters: [] },
{ name: "Option 3", replacementSpan: test.ranges()[1], commitCharacters: [] }
] }
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 8,5 @@ verify.completions({
marker: "1",
exact: completion.typeKeywords,
isNewIdentifierLocation: true,
defaultCommitCharacters: [],
});
2 changes: 2 additions & 0 deletions tests/cases/fourslash/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 719,7 @@ declare namespace FourSlashInterface {
readonly excludes?: ArrayOrSingle<string>;
readonly preferences?: UserPreferences;
readonly triggerCharacter?: string;
readonly defaultCommitCharacters?: string[];
}
type ExpectedCompletionEntry = string | ExpectedCompletionEntryObject;
interface ExpectedCompletionEntryObject {
Expand All @@ -735,6 736,7 @@ declare namespace FourSlashInterface {
readonly sortText?: completion.SortText;
readonly isPackageJsonImport?: boolean;
readonly isSnippet?: boolean;
readonly commitCharacters?: string[];

// details
readonly text?: string;
Expand Down