-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: add support for aurelia 2 project detection #42
Changes from all commits
f32e133
e9965c1
a8b5405
0a8f991
b9987a9
26d70b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,14 +8,14 @@ repositories { | |
} | ||
|
||
intellij { | ||
pluginName = 'AureliaStorm' | ||
pluginName = 'AureliaStorm Community' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the reason to change plugin name? |
||
version = 'IU-LATEST-EAP-SNAPSHOT' | ||
plugins = ['JavaScript'] | ||
} | ||
|
||
version '1.0.231' | ||
version '1.1.2' | ||
|
||
patchPluginXml { | ||
sinceBuild = "231.0" | ||
untilBuild = "231.*" | ||
untilBuild = "233.*" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, we cannot sure that the plugin will be compatible with 233 version. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
package com.github.denofevil.aurelia | ||
|
||
import com.intellij.json.psi.JsonFile | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.roots.ProjectRootModificationTracker | ||
import com.intellij.openapi.util.IconLoader | ||
import com.intellij.openapi.vfs.VirtualFileManager | ||
import com.intellij.psi.search.FilenameIndex | ||
import com.intellij.psi.search.GlobalSearchScope | ||
import com.intellij.psi.util.CachedValueProvider | ||
import com.intellij.psi.util.CachedValuesManager | ||
import com.intellij.openapi.vfs.VfsUtilCore | ||
import com.intellij.json.psi.JsonObject | ||
import com.intellij.psi.PsiManager | ||
|
||
/** | ||
* @author Dennis.Ushakov | ||
|
@@ -19,21 +21,37 @@ object Aurelia { | |
const val REPEAT_FOR = "repeat.for" | ||
const val VIRTUAL_REPEAT_FOR = "virtual-repeat.for" | ||
const val AURELIA_APP = "aurelia-app" | ||
|
||
private val AURELIA_DETECTOR_FILES = listOf( | ||
// Aurelia is included with with module loader (from jspm_packages when using JSPM) or module bundler (from node_modules when using Webpack) | ||
"aurelia-framework.js", | ||
// project generated by aurelia-cli | ||
"aurelia-bootstrapper.js", | ||
"aurelia-bootstrapper.d.ts", | ||
// project bootstrapped with script tag (contains aurelia-framework and other essential Aurelia modules) | ||
"aurelia-core.js" | ||
) | ||
const val CASE = "case" | ||
const val REF = "ref" | ||
|
||
fun present(project: Project) = CachedValuesManager.getManager(project).getCachedValue(project) { | ||
CachedValueProvider.Result.create( | ||
AURELIA_DETECTOR_FILES.any { | ||
FilenameIndex.getFilesByName(project, it, GlobalSearchScope.allScope(project)).isNotEmpty() | ||
}, VirtualFileManager.VFS_STRUCTURE_MODIFICATIONS, ProjectRootModificationTracker.getInstance(project)) | ||
val aureliaLoaded = hasDependency(project) | ||
CachedValueProvider.Result | ||
.create(aureliaLoaded, VirtualFileManager.VFS_STRUCTURE_MODIFICATIONS, ProjectRootModificationTracker.getInstance(project)) | ||
}!! | ||
|
||
private fun hasDependency(project: Project): Boolean { | ||
var hasDependency = false | ||
|
||
VfsUtilCore.iterateChildrenRecursively(project.baseDir, null) { virtualFile -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vfs traversing is very expensive operation. Please check methods of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this comment is still relevant. VFS processing can significantly degrade performance, especially for big projects. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moreover, it looks like all usages of the method have a proper context psi element, so the best solution could be to traverse top to package.json and check its dependencies. |
||
if (!virtualFile.isDirectory && virtualFile.name == "package.json") { | ||
val jsonFile = PsiManager.getInstance(project).findFile(virtualFile) | ||
val jsonObject = (jsonFile as? JsonFile)?.topLevelValue as? JsonObject | ||
|
||
jsonObject?.findProperty("dependencies")?.let { dependenciesProp -> | ||
val dependenciesObject = dependenciesProp.value as? JsonObject | ||
val aureliaDependency = dependenciesObject?.findProperty("aurelia") | ||
val aureliaCliDependency = dependenciesObject?.findProperty("aurelia-cli") | ||
if (aureliaCliDependency != null || aureliaDependency != null) { | ||
hasDependency = true | ||
return@iterateChildrenRecursively false | ||
} | ||
} | ||
} | ||
|
||
true | ||
} | ||
|
||
return hasDependency | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, we still need to keep old behaviour for very old projects.