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

[typescript-language-features] Update importModuleSpecifierPreference values #110536

Merged

Conversation

andrewbranch
Copy link
Member

Counterpart of microsoft/TypeScript#40637.

@@ -561,7 +561,7 @@ class TypeScriptCompletionItemProvider implements vscode.CompletionItemProvider<
type: response?.type ?? 'unknown',
count: response?.type === 'response' && response.body ? response.body.entries.length : 0,
updateGraphDurationMs: response?.type === 'response' ? response.performanceData?.updateGraphDurationMs : undefined,
createAutoImportProviderProgramDurationMs: response?.type === 'response' ? (response.performanceData as Proto.PerformanceData & { createAutoImportProviderProgramDurationMs?: number })?.createAutoImportProviderProgramDurationMs : undefined,
createAutoImportProviderProgramDurationMs: response?.type === 'response' ? response.performanceData?.createAutoImportProviderProgramDurationMs : undefined,
Copy link
Member Author

Choose a reason for hiding this comment

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

Drive-by fix now that the API is updated

"typescript.preferences.importModuleSpecifier.shortest": "Prefers using a non-relative import only if one is available that has fewer path segments than a relative import.",
"typescript.preferences.importModuleSpecifier.relative": "Prefers using a relative path to the imported file location.",
"typescript.preferences.importModuleSpecifier.nonRelative": "Prefers using a non-relative import based on the `baseUrl` or `paths` configured in your `jsconfig.json` / `tsconfig.json`.",
"typescript.preferences.importModuleSpecifier.projectRelative": "Prefers using a non-relative import only if the relative import path would leave the package or project directory.",
Copy link
Member Author

Choose a reason for hiding this comment

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

/cc @DanielRosenwasser on the copy update; I know we’ve talked about these before

Copy link
Member Author

Choose a reason for hiding this comment

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

I also sort of considered adding “Useful for monorepos.” at the end of this one; do you think that would be worthwhile?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe instead of "Prefers using" you could switch to "Prefer a"

Copy link
Member

Choose a reason for hiding this comment

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

"Useful for monorepos" might be helpful, but I feel like maybe this should be the new default?

How does it know when you've "left' a package? And how surprising is it when you've left a "project directory"?

Copy link
Member Author

Choose a reason for hiding this comment

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

I also suspect this might be a better default, but we normally try not to shove unproven changes to defaults on people 🤷.

The implementation details are in microsoft/TypeScript#40637. Briefly, this setting will try to use a non-relative path if the nearest ancestor package.json of the importing file and the nearest ancestor package.json of the imported file are not the same, or if the imported file is outside the directory of the imported file’s tsconfig.json.

Copy link
Collaborator

@mjbvz mjbvz left a comment

Choose a reason for hiding this comment

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

Thanks! I'll merge once Daniel provides feedback and you tell me it's ready

"typescript.preferences.importModuleSpecifier.shortest": "Prefers using a non-relative import only if one is available that has fewer path segments than a relative import.",
"typescript.preferences.importModuleSpecifier.relative": "Prefers using a relative path to the imported file location.",
"typescript.preferences.importModuleSpecifier.nonRelative": "Prefers using a non-relative import based on the `baseUrl` or `paths` configured in your `jsconfig.json` / `tsconfig.json`.",
"typescript.preferences.importModuleSpecifier.projectRelative": "Prefers using a non-relative import only if the relative import path would leave the package or project directory.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

If projectRelative is a new setting, could you also note which TS version is required to use it?

@andrewbranch
Copy link
Member Author

@mjbvz ready to merge, thanks!

@mjbvz mjbvz added this to the November 2020 milestone Nov 16, 2020
@mjbvz mjbvz merged commit 00fa5d3 into microsoft:master Nov 16, 2020
@mjbvz
Copy link
Collaborator

mjbvz commented Nov 16, 2020

Thanks!

@andrewbranch andrewbranch deleted the feature/importModuleSpecifierPreference branch November 16, 2020 21:14
meganrogge pushed a commit that referenced this pull request Nov 18, 2020
… values (#110536)

* Update importModuleSpecifierPreference values

* -using

* Add minimum version message
@github-actions github-actions bot locked and limited conversation to collaborators Dec 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants