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

Minor package explorer fixes #1811

Merged
merged 3 commits into from
Aug 25, 2020
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Since 2018.1, the version numbers and release cycle match Rider's versions and r
### Fixed

- Correctly handle lambdas, actions and local functions in performance critical and Burst contexts ([#1787](https://github.com/JetBrains/resharper-unity/pull/1787))
- Rider: Correctly resolve local packages with too many parent segments in path ([#1796](https://github.com/JetBrains/resharper-unity/issues/1796), [#1811](https://github.com/JetBrains/resharper-unity/pull/1811))
- Rider: Correctly resolve embedded package where folder name does not match package name ([#1778](https://github.com/JetBrains/resharper-unity/issues/1778), [#1811](https://github.com/JetBrains/resharper-unity/pull/1811))



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,13 @@ class PackageManager(private val project: Project) {
lockDetails: LockDetails?)
: PackageData {

// Order is important here. Embedded packages in the Packages folder take precedence over everything. Registry
// packages are the most likely, and can't clash with other packages, so put them high up. The file: protocol is
// used by local and can also be a protocol for git (although I can't get it to work), so check git first
// Order is important here. A package can be listed in manifest.json, but if it also exists in Packages, that
// embedded copy takes precedence. We look for an embedded folder with the same name, but it can be under any
// name - we'll find it again and override it when we look at the other embedded packages.
// Registry packages are the most likely to match, and can't clash with other packages, so check them early. The
// file: protocol is used by local but it can also be a protocol for git, so check git before local.
return try {
getEmbeddedPackage(packagesFolder, name)
getEmbeddedPackage(packagesFolder, name, name)
?: getRegistryPackage(name, version, registry)
?: getGitPackage(name, version, lockDetails?.hash, lockDetails?.revision)
?: getLocalPackage(packagesFolder, name, version)
Expand All @@ -346,9 +348,11 @@ class PackageManager(private val project: Project) {
builtInPackagesFolder: Path?)
: PackageData {

// Embedded packages are listed in packages-lock.json with the name of the package, and the version is a file:
// spec pointing to the embedded folder in Packages
return try {
when (details.source) {
"embedded" -> getEmbeddedPackage(packagesFolder, name)
"embedded" -> getEmbeddedPackage(packagesFolder, name, details.version)
"registry" -> getRegistryPackage(name, details.version, details.url ?: DEFAULT_REGISTRY_URL)
"builtin" -> getBuiltInPackage(name, details.version, builtInPackagesFolder)
"git" -> getGitPackage(name, details.version, details.hash)
Expand All @@ -373,7 +377,7 @@ class PackageManager(private val project: Project) {
return try {
val path = version.substring(5)
val packagesPath = Paths.get(packagesFolder.path)
val filePath = packagesPath.resolve(path)
val filePath = packagesPath.resolve(path).normalize()
val packageFolder = VfsUtil.findFile(filePath, false)
when (packageFolder?.isDirectory) {
true -> getPackageDataFromFolder(name, packageFolder, PackageSource.Local)
Expand Down Expand Up @@ -454,8 +458,9 @@ class PackageManager(private val project: Project) {
}
}

private fun getEmbeddedPackage(packagesFolder: VirtualFile, name: String): PackageData? {
val packageFolder = packagesFolder.findChild(name)
private fun getEmbeddedPackage(packagesFolder: VirtualFile, name: String, filePath: String): PackageData? {
// filePath will have a file: prefix for packages-lock.json, but will be a simple package name for manifest.json
val packageFolder = packagesFolder.findChild(filePath.removePrefix("file:"))
return getPackageDataFromFolder(name, packageFolder, PackageSource.Embedded)
}

Expand Down