Skip to content

Support both baseUrl and relative paths when adding missing import #19724

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
4 commits merged into from
Nov 28, 2017

Conversation

ghost
Copy link

@ghost ghost commented Nov 3, 2017

Fixes #15888 and #19920

@mjbvz CompletionEntryDetails has a CodeAction[], how are you handling this in the user interface if there is more than one? For example an export from a particular source could have multiple ways to be imported.

@ghost ghost requested a review from sheetalkamat November 3, 2017 21:05
if (!options.baseUrl) {
return undefined;
function getRelativePathLength(relativePath: string): number {
if (startsWith(relativePath, "../")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

use directorySeparator here instead

}

// Prefer a relative import over a baseUrl import if it doesn't traverse up to baseUrl.
const relativeFirst = getRelativePathNParents(relativePath) < getRelativePathLength(getRelativePath(sourceDirectory, baseUrl, getCanonicalFileName));
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure i understand this condition..
should not this just be getRelativePathNParents(getRelativePath(sourceDirectory, baseUrl, getCanonicalFileName)) ?

Copy link
Author

Choose a reason for hiding this comment

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

Added a comment, tell me if this could be done in some simpler way.

}

/*
Prefer a relative import over a baseUrl import if it doesn't traverse up to baseUrl.
Copy link
Contributor

Choose a reason for hiding this comment

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

assuming that both source file and module file are under the baseUrl, would not it be sufficient to sort based on the number of levels u need to go up (getRelativePathLength) between (source, baseUrl) and (source, module)?

Copy link
Contributor

Choose a reason for hiding this comment

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

or what am i missing..?

@mjbvz
Copy link
Contributor

mjbvz commented Nov 15, 2017

@Andy-MS We currently try to apply all the returned code actions. After this change, we would need to change our logic to instead show a selector. We originally tried to avoid this UX because it breaks up the typing flow

@mhegazy
Copy link
Contributor

mhegazy commented Nov 20, 2017

@Andy-MS we should make sure completion always has one code action..

@ghost ghost merged commit 185f15d into master Nov 28, 2017
@ghost ghost deleted the importNameCodeFixBaseUrl branch November 28, 2017 19:01
@ghost
Copy link
Author

ghost commented Nov 28, 2017

We will only use one code action, from the shorter choice of baseUrl or relative path.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
This pull request was closed.
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.

2 participants