Skip to content

Commit

Permalink
[ resolve ] Fix resolving and find usages
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Mar 30, 2019
1 parent 9e25ab6 commit a07f4f6
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 45 deletions.
32 changes: 19 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,36 @@ version = pluginVersion

plugins {
java
id("org.jetbrains.intellij") version "0.4.4"
id("org.jetbrains.intellij") version "0.4.6"
id("org.jetbrains.grammarkit") version "2018.3.1"
kotlin("jvm") version "1.2.70"
}

fun fromToolbox(path: String) = file(path).listFiles().orEmpty().filter { it.isDirectory }.maxBy {
val (major, minor, patch) = it.name.split('.')
String.format("%5s%5s%5s", major, minor, patch)
}

allprojects {
apply { plugin("org.jetbrains.grammarkit") }

intellij {
updateSinceUntilBuild = false
instrumentCode = true
val username = System.getProperty("user.name")
val root = "/home/$username/.local/share/JetBrains/Toolbox/apps"
when (username) {
"ice1000" -> {
localPath = "$root/IDEA-C/ch-0/191.6183.20"
alternativeIdePath = "$root/PyCharm-C/ch-0/191.6183.9"
}
"hoshino" -> version = "2018.2.1"
"zxj5470" -> {
version = "2018.3"
// alternativeIdePath = "$root/PyCharm-P/ch-0/183.4284.139"
val user = System.getProperty("user.name")
when (System.getProperty("os.name")) {
"Linux" -> {
val root = "/home/$user/.local/share/JetBrains/Toolbox/apps"
val intellijPath = fromToolbox("$root/IDEA-C/ch-0")
?: fromToolbox("$root/IDEA-C-JDK11/ch-0")
?: fromToolbox("$root/IDEA-U/ch-0")
?: fromToolbox("$root/IDEA-JDK11/ch-0")
intellijPath?.absolutePath?.let { localPath = it }
val pycharmPath = fromToolbox("$root/PyCharm-C/ch-0")
?: fromToolbox("$root/IDEA-C-JDK11/ch-0")
?: fromToolbox("$root/IDEA-C/ch-0")
pycharmPath?.absolutePath?.let { alternativeIdePath = it }
}
/* for CI */ else -> version = "2018.3"
}
setMarkdownDependency()
}
Expand Down
2 changes: 2 additions & 0 deletions docs/change-notes.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
0.3.13<br/>
<ul>
<li>Make find usages more stable</li>
<li>Fix reference resolving (it's utterly crushed before)</li>
</ul>
0.3.12<br/>
<ul>
Expand Down
44 changes: 14 additions & 30 deletions src/org/ice1000/julia/lang/psi/impl/julia-psi-mixin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ interface IJuliaFunctionDeclaration : PsiNameIdentifierOwner, DocStringOwner {
* Common super class for declaration
*/
abstract class JuliaDeclaration(node: ASTNode) : JuliaExprMixin(node), PsiNameIdentifierOwner {
private var refCache: Array<PsiReference>? = null
override fun setName(newName: String) = also {
references.forEach { it.handleElementRename(newName) }
nameIdentifier?.replace(JuliaTokenType.fromText(newName, project))
}

Expand All @@ -37,37 +35,25 @@ abstract class JuliaDeclaration(node: ASTNode) : JuliaExprMixin(node), PsiNameId
get() = PsiTreeUtil.getParentOfType(this, JuliaStatements::class.java) ?: parent

override fun getName() = nameIdentifier?.text.orEmpty()
override fun getReferences() = refCache
?: nameIdentifier
?.let { collectFrom(startPoint, it.text, it) }
?.also { refCache = it }
?: emptyArray()

override fun subtreeChanged() {
refCache = null
super.subtreeChanged()
}

override fun processDeclarations(
processor: PsiScopeProcessor, substitutor: ResolveState, lastParent: PsiElement?, place: PsiElement) =
nameIdentifier?.let { processor.execute(it, substitutor) }.orFalse() and
nameIdentifier?.let { processor.execute(it, substitutor) }.orTrue() &&
processDeclTrivial(processor, substitutor, lastParent, place)
}

abstract class JuliaForComprehensionMixin(node: ASTNode) : ASTWrapperPsiElement(node), JuliaForComprehension {
override fun processDeclarations(
processor: PsiScopeProcessor, state: ResolveState, lastParent: PsiElement?, place: PsiElement) =
comprehensionElementList.all { it.processDeclarations(processor, state, lastParent, place) } and
super.processDeclarations(processor, state, lastParent, place)
comprehensionElementList.all { it.processDeclarations(processor, state, lastParent, place) }

override var type: Type? = null
}

abstract class JuliaComprehensionElementMixin(node: ASTNode) : ASTWrapperPsiElement(node), JuliaComprehensionElement {
override fun processDeclarations(
processor: PsiScopeProcessor, state: ResolveState, lastParent: PsiElement?, place: PsiElement) =
singleComprehensionList.all { it.processDeclarations(processor, state, lastParent, place) } and
super.processDeclarations(processor, state, lastParent, place)
singleComprehensionList.all { it.processDeclarations(processor, state, lastParent, place) }
}

abstract class JuliaSingleComprehensionMixin(node: ASTNode) : JuliaDeclaration(node), JuliaSingleComprehension {
Expand All @@ -76,8 +62,8 @@ abstract class JuliaSingleComprehensionMixin(node: ASTNode) : JuliaDeclaration(n

override fun processDeclarations(
processor: PsiScopeProcessor, substitutor: ResolveState, lastParent: PsiElement?, place: PsiElement) =
singleIndexer?.let { processor.execute(it.firstChild, substitutor) }.orFalse() and
multiIndexer?.let { it.children.all { processor.execute(it, substitutor) } }.orFalse() and
singleIndexer?.let { processor.execute(it.firstChild, substitutor) }.orTrue() &&
multiIndexer?.let { it.children.all { processor.execute(it, substitutor) } }.orTrue() &&
super.processDeclarations(processor, substitutor, lastParent, place)
}

Expand Down Expand Up @@ -133,7 +119,7 @@ abstract class JuliaFunctionMixin(node: ASTNode) : JuliaDeclaration(node), Julia
processor: PsiScopeProcessor, substitutor: ResolveState, lastParent: PsiElement?, place: PsiElement) =
functionSignature?.run {
typedNamedVariableList.all { processor.execute(it.firstChild, substitutor) }
}.orFalse() && super.processDeclarations(processor, substitutor, lastParent, place)
}.orTrue() && super.processDeclarations(processor, substitutor, lastParent, place)

override fun toString(): String {
return "JuliaFunctionImpl(FUNCTION)"
Expand Down Expand Up @@ -244,10 +230,9 @@ abstract class JuliaTypeDeclarationMixin : StubBasedPsiElementBase<JuliaTypeDecl
override fun setName(name: String) = also { nameIdentifier?.replace(JuliaTokenType.fromText(name, project)) }
override fun getName() = nameIdentifier?.text
override fun getIcon(flags: Int): Icon? = JuliaIcons.JULIA_TYPE_ICON
// override fun processDeclarations(
// processor: PsiScopeProcessor, state: ResolveState, lastParent: PsiElement?, place: PsiElement) =
// nameIdentifier?.let { processor.execute(it, state) }.orFalse() &&
// super.processDeclarations(processor, state, lastParent, place)
override fun processDeclarations(
processor: PsiScopeProcessor, state: ResolveState, lastParent: PsiElement?, place: PsiElement) =
nameIdentifier?.let { processor.execute(it, state) }.orTrue()

override fun subtreeChanged() {
nameCache = null
Expand All @@ -268,10 +253,9 @@ abstract class JuliaAbstractTypeDeclarationMixin : StubBasedPsiElementBase<Julia
override fun setName(name: String) = also { nameIdentifier?.replace(JuliaTokenType.fromText(name, project)) }
override fun getName() = nameIdentifier?.text
override fun getIcon(flags: Int): Icon? = JuliaIcons.JULIA_ABSTRACT_TYPE_ICON
// override fun processDeclarations(
// processor: PsiScopeProcessor, state: ResolveState, lastParent: PsiElement?, place: PsiElement) =
// nameIdentifier?.let { processor.execute(it, state) }.orFalse() &&
// super.processDeclarations(processor, state, lastParent, place)
override fun processDeclarations(
processor: PsiScopeProcessor, state: ResolveState, lastParent: PsiElement?, place: PsiElement) =
nameIdentifier?.let { processor.execute(it, state) }.orTrue()

override fun subtreeChanged() {
nameCache = null
Expand Down Expand Up @@ -439,7 +423,7 @@ abstract class JuliaLambdaMixin(node: ASTNode) : JuliaDeclaration(node), JuliaLa
.asReversed()
.all { it.processDeclarations(processor, substitutor, lastParent, place) }
}
}.orFalse() && super.processDeclarations(processor, substitutor, lastParent, place)
}.orTrue() && super.processDeclarations(processor, substitutor, lastParent, place)
}

//class JuliaReferenceManager(val psiManager: PsiManager, val dumbService: DumbService) {
Expand All @@ -448,4 +432,4 @@ abstract class JuliaLambdaMixin(node: ASTNode) : JuliaDeclaration(node), JuliaLa
// return ServiceManager.getService(project, JuliaReferenceManager::class.java)
// }
// }
//}
//}
4 changes: 2 additions & 2 deletions src/org/ice1000/julia/lang/psi/julia-resolving.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ open class SymbolResolveProcessor(
constructor(ref: JuliaSymbolRef, incompleteCode: Boolean) : this(ref.canonicalText, ref.element, incompleteCode)

override val candidateSet = ArrayList<PsiElementResolveResult>(3)
protected open fun accessible(element: PsiElement) = name == element.text && isInScope(element)
protected open fun accessible(element: PsiElement) = name == element.text
override fun execute(element: PsiElement, resolveState: ResolveState) = when {
candidateSet.isNotEmpty() -> false
element is JuliaSymbol -> {
val accessible = accessible(element) && element.symbolKind.isDeclaration
val accessible = accessible(element)
if (accessible) candidateSet += PsiElementResolveResult(element, element.hasNoError)
!accessible
}
Expand Down
1 change: 1 addition & 0 deletions src/org/ice1000/julia/lang/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ fun String.splitsOf(someStr: String, expandSize: Int) = indices

fun Boolean.toYesNo() = if (this) "yes" else "no"
fun Boolean?.orFalse() = true == this
fun Boolean?.orTrue() = false != this

0 comments on commit a07f4f6

Please sign in to comment.