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

Fix an off-by-one error in getBaseDirectoriesFromRootDirs #55233

Merged
merged 7 commits into from
Sep 11, 2023

Conversation

PhoebeSzmucer
Copy link
Contributor

Fixes #55232

I couldn't find where this is tested (if it even is). If someone can help me out with that I can write a test.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Aug 1, 2023
@sandersn sandersn requested a review from sheetalkamat August 11, 2023 22:20
@sheetalkamat
Copy link
Member

You would need to add test in src/testRunner/unittests/tsserver/autoImportProvider.ts following example of one of the test case there.

@PhoebeSzmucer
Copy link
Contributor Author

You would need to add test in src/testRunner/unittests/tsserver/autoImportProvider.ts following example of one of the test case there.

Isn't that for auto-import and not path completion? Or do these go through the same code path?

@PhoebeSzmucer
Copy link
Contributor Author

I added a throw statement to getBaseDirectoriesFromRootDirs and the only test that failed was tests/cases/fourslash/completionForStringLiteralRelativeImport4.ts

@PhoebeSzmucer
Copy link
Contributor Author

@microsoft-github-policy-service agree company="Palantir"

@PhoebeSzmucer
Copy link
Contributor Author

@sheetalkamat I added a fourslash test that failed before and succeeds now

src/services/stringCompletions.ts Outdated Show resolved Hide resolved
@PhoebeSzmucer
Copy link
Contributor Author

@sheetalkamat any chance this can make it to the 5.2 release?

@jakebailey
Copy link
Member

5.2 was branched off a while ago and main is now targeting 5.3; see #54298. Given this bug isn't a regression from 5.1, I wouldn't expect to see it backported unless it's causing major ecosystem pain.

src/services/stringCompletions.ts Outdated Show resolved Hide resolved
src/services/stringCompletions.ts Outdated Show resolved Hide resolved
Phoebe Szmucer added 2 commits September 10, 2023 19:07

// Determine the path to the directory containing the script relative to the root directory it is contained within
const relativeDirectory = firstDefined(rootDirs, rootDirectory => containsPath(rootDirectory, scriptDirectory, basePath, ignoreCase) ? scriptDirectory.substr(rootDirectory.length) : undefined)!; // TODO: GH#18217

// Now find a path for each potential directory that is to be merged with the one containing the script
return deduplicate<string>(
[...rootDirs.map(rootDirectory => combinePaths(rootDirectory, relativeDirectory)), scriptDirectory],
[...rootDirs.map(rootDirectory => combinePaths(rootDirectory, relativeDirectory)), scriptDirectory].map(baseDir => removeTrailingDirectorySeparator(baseDir)),
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 had to also add removeTrailingDirectorySeparator here because otherwise some tests got broken due to duplicated entries with mismatched trailing slashes. It's probably a good idea to return consistent results anyway.

@sheetalkamat sheetalkamat merged commit eb2d1f9 into microsoft:main Sep 11, 2023
19 checks passed
snovader pushed a commit to mestro-se/TypeScript that referenced this pull request Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Archived in project
4 participants