Skip to content

Add completion property to identify completions from unchecked files #36063

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 9 additions & 3 deletions src/harness/fourslashImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,8 @@ namespace FourSlash {
}

private verifyCompletionEntry(actual: ts.CompletionEntry, expected: FourSlashInterface.ExpectedCompletionEntry) {
const { insertText, replacementSpan, hasAction, isRecommended, kind, kindModifiers, text, documentation, tags, source, sourceDisplay, sortText } = typeof expected === "string"
? { insertText: undefined, replacementSpan: undefined, hasAction: undefined, isRecommended: undefined, kind: undefined, kindModifiers: undefined, text: undefined, documentation: undefined, tags: undefined, source: undefined, sourceDisplay: undefined, sortText: undefined }
const { insertText, replacementSpan, hasAction, isRecommended, isFromUncheckedFile, kind, kindModifiers, text, documentation, tags, source, sourceDisplay, sortText } = typeof expected === "string"
? { insertText: undefined, replacementSpan: undefined, hasAction: undefined, isRecommended: undefined, isFromUncheckedFile: undefined, kind: undefined, kindModifiers: undefined, text: undefined, documentation: undefined, tags: undefined, source: undefined, sourceDisplay: undefined, sortText: undefined }
: expected;

if (actual.insertText !== insertText) {
Expand All @@ -867,8 +867,14 @@ namespace FourSlash {
}
}

if (isFromUncheckedFile !== undefined) {
if (actual.isFromUncheckedFile !== isFromUncheckedFile) {
this.raiseError(`Expected 'isFromUncheckedFile' value '${actual.isFromUncheckedFile}' to equal '${isFromUncheckedFile}'`);
}
}

assert.equal(actual.hasAction, hasAction, `Expected 'hasAction' value '${actual.hasAction}' to equal '${hasAction}'`);
assert.equal(actual.isRecommended, isRecommended, `Expected 'isRecommended' value '${actual.source}' to equal '${isRecommended}'`);
assert.equal(actual.isRecommended, isRecommended, `Expected 'isRecommended' value '${actual.isRecommended}' to equal '${isRecommended}'`);
assert.equal(actual.source, source, `Expected 'source' value '${actual.source}' to equal '${source}'`);
assert.equal(actual.sortText, sortText || ts.Completions.SortText.LocationPriority, this.messageAtLastKnownMarker(`Actual entry: ${JSON.stringify(actual)}`));

Expand Down
1 change: 1 addition & 0 deletions src/harness/fourslashInterfaceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,7 @@ namespace FourSlashInterface {
readonly replacementSpan?: FourSlash.Range;
readonly hasAction?: boolean; // If not specified, will assert that this is false.
readonly isRecommended?: boolean; // If not specified, will assert that this is false.
readonly isFromUncheckedFile?: boolean; // If not specified, won't assert about this
readonly kind?: string; // If not specified, won't assert about this
readonly kindModifiers?: string; // Must be paired with 'kind'
readonly text?: string;
Expand Down
5 changes: 5 additions & 0 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2086,6 +2086,11 @@ namespace ts.server.protocol {
* Then either that enum/class or a namespace containing it will be the recommended symbol.
*/
isRecommended?: true;
/**
* If true, this completion was generated from traversing the name table of an unchecked JS file,
* and therefore may not be accurate.
*/
isFromUncheckedFile?: true;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ namespace ts.Completions {
name: realName,
kind: ScriptElementKind.warning,
kindModifiers: "",
sortText: SortText.JavascriptIdentifiers
sortText: SortText.JavascriptIdentifiers,
isFromUncheckedFile: true
});
}
});
Expand Down
1 change: 1 addition & 0 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,7 @@ namespace ts {
hasAction?: true;
source?: string;
isRecommended?: true;
isFromUncheckedFile?: true;
}

export interface CompletionEntryDetails {
Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5652,6 +5652,7 @@ declare namespace ts {
hasAction?: true;
source?: string;
isRecommended?: true;
isFromUncheckedFile?: true;
}
interface CompletionEntryDetails {
name: string;
Expand Down Expand Up @@ -7644,6 +7645,11 @@ declare namespace ts.server.protocol {
* Then either that enum/class or a namespace containing it will be the recommended symbol.
*/
isRecommended?: true;
/**
* If true, this completion was generated from traversing the name table of an unchecked JS file,
* and therefore may not be accurate.
*/
isFromUncheckedFile?: true;
}
/**
* Additional completion entry details, available on demand
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5652,6 +5652,7 @@ declare namespace ts {
hasAction?: true;
source?: string;
isRecommended?: true;
isFromUncheckedFile?: true;
}
interface CompletionEntryDetails {
name: string;
Expand Down
28 changes: 28 additions & 0 deletions tests/cases/fourslash/completionInUncheckedJSFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/// <reference path="fourslash.ts" />

// @allowJs: true
// @checkJs: false
// @Filename: index.js
////function hello() {
////
////}
////
////const goodbye = 5;
////
////console./*0*/

verify.completions({
marker: "0",
includes: [
{
name: "hello",
sortText: completion.SortText.JavascriptIdentifiers,
isFromUncheckedFile: true
},
{
name: "goodbye",
sortText: completion.SortText.JavascriptIdentifiers,
isFromUncheckedFile: true
}
]
});
1 change: 1 addition & 0 deletions tests/cases/fourslash/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ declare namespace FourSlashInterface {
readonly replacementSpan?: Range;
readonly hasAction?: boolean;
readonly isRecommended?: boolean;
readonly isFromUncheckedFile?: boolean;
readonly kind?: string;
readonly kindModifiers?: string;
readonly sortText?: completion.SortText;
Expand Down