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 string literal completions for package.json imports field #57718

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Mar 11, 2024

closes #52460
closes #57680
closes #57777

Currently, this only has tests based on #55015 but I still have to add more

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Mar 11, 2024
@@ -6288,6 6290,21 @@ export function getPossibleOriginalInputExtensionForExtension(path: string) {
[Extension.Tsx, Extension.Ts, Extension.Jsx, Extension.Js];
}

/** @internal */
export function getPossibleOriginalInputPathWithoutChangingExt(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is kinda a reverse of getOutputPathWithoutChangingExt:

function getOutputPathWithoutChangingExt(
inputFileName: string,
ignoreCase: boolean,
outputDir: string | undefined,
getCommonSourceDirectory: () => string,
): string {
return outputDir ?
resolvePath(
outputDir,
getRelativePathFromDirectory(getCommonSourceDirectory(), inputFileName, ignoreCase),
) :
inputFileName;
}

}
if (!seenPackageScope) {
const packageFile = combinePaths(ancestor, "package.json");
if (seenPackageScope = tryFileExists(host, packageFile)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: this has to be heavily deduplicated with the existing branch that handles exports

@@ -938,10 951,41 @@ function getCompletionEntriesForNonRelativeModules(
}
}
if (!foundGlobal) {
let seenPackageScope = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: add a test case that will show that it's needed

@@ -1072,9 1153,11 @@ function getModulesForPathsPattern(

const normalizedSuffix = normalizePath(parsed.suffix);
const declarationExtension = normalizedSuffix && getDeclarationEmitExtensionForPath("_" normalizedSuffix);
const matchingSuffixes = declarationExtension ? [changeExtension(normalizedSuffix, declarationExtension), normalizedSuffix] : [normalizedSuffix];
const inputExtension = isImports && normalizedSuffix ? getPossibleOriginalInputExtensionForExtension("_" normalizedSuffix) : undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the logic in this function assumes the same extensions between potential inputs and outputs and stuff. This can impact the used globs but I think it's largely fine right now - unless somebody would come up with a compelling test case that should work differently.

@Andarist
Copy link
Contributor Author

@andrewbranch I opened this as a draft because there are some minor cleanups to be done here. I'd appreciate an early review here though - in case there is something fundamentally wrong with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need more test cases like this but with a pattern. Atm, I didn't add any special logic for declarationDir - this "exact" match works solely based on the fact that it's exact. It doesn't even need to check if the corresponding file exists on the disk or not so it doesn't perform any output->input mapping etc. This has to be fixed.

@DanielRosenwasser
Copy link
Member

@Andarist did you still want to pursue this? We're looking to get this done in the TS 5.7 timeframe.

@Andarist
Copy link
Contributor Author

@DanielRosenwasser yes, it would be great if @andrewbranch could give this a quick look to check if im not doing anything overly wrong so I dont spend too much time on cleaning up things that will turn out to be wrong in the end ;p

Copy link
Member

@andrewbranch andrewbranch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this looks on the right track to me, thanks!

@Andarist
Copy link
Contributor Author

@andrewbranch thanks for the review! I’ll try to clean this up asap

…letions

# Conflicts:
#	src/compiler/utilities.ts
#	src/services/stringCompletions.ts
@Andarist Andarist marked this pull request as ready for review October 10, 2024 09:40
@typescript-bot
Copy link
Collaborator

The TypeScript team hasn't accepted the linked issue #52460. If you can get it accepted, this PR will have a better chance of being reviewed.

@Andarist
Copy link
Contributor Author

I have been busy the last 2 weeks, I've done some progress on this in the past days but I hope to get everything done till the end of this week 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
None yet
4 participants