Skip to content

Commit a07f4f6

Browse files
committed
[ resolve ] Fix resolving and find usages
1 parent 9e25ab6 commit a07f4f6

File tree

5 files changed

+38
-45
lines changed

5 files changed

+38
-45
lines changed

build.gradle.kts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,36 @@ version = pluginVersion
3030

3131
plugins {
3232
java
33-
id("org.jetbrains.intellij") version "0.4.4"
33+
id("org.jetbrains.intellij") version "0.4.6"
3434
id("org.jetbrains.grammarkit") version "2018.3.1"
3535
kotlin("jvm") version "1.2.70"
3636
}
3737

38+
fun fromToolbox(path: String) = file(path).listFiles().orEmpty().filter { it.isDirectory }.maxBy {
39+
val (major, minor, patch) = it.name.split('.')
40+
String.format("%5s%5s%5s", major, minor, patch)
41+
}
42+
3843
allprojects {
3944
apply { plugin("org.jetbrains.grammarkit") }
4045

4146
intellij {
4247
updateSinceUntilBuild = false
4348
instrumentCode = true
44-
val username = System.getProperty("user.name")
45-
val root = "/home/$username/.local/share/JetBrains/Toolbox/apps"
46-
when (username) {
47-
"ice1000" -> {
48-
localPath = "$root/IDEA-C/ch-0/191.6183.20"
49-
alternativeIdePath = "$root/PyCharm-C/ch-0/191.6183.9"
50-
}
51-
"hoshino" -> version = "2018.2.1"
52-
"zxj5470" -> {
53-
version = "2018.3"
54-
// alternativeIdePath = "$root/PyCharm-P/ch-0/183.4284.139"
49+
val user = System.getProperty("user.name")
50+
when (System.getProperty("os.name")) {
51+
"Linux" -> {
52+
val root = "/home/$user/.local/share/JetBrains/Toolbox/apps"
53+
val intellijPath = fromToolbox("$root/IDEA-C/ch-0")
54+
?: fromToolbox("$root/IDEA-C-JDK11/ch-0")
55+
?: fromToolbox("$root/IDEA-U/ch-0")
56+
?: fromToolbox("$root/IDEA-JDK11/ch-0")
57+
intellijPath?.absolutePath?.let { localPath = it }
58+
val pycharmPath = fromToolbox("$root/PyCharm-C/ch-0")
59+
?: fromToolbox("$root/IDEA-C-JDK11/ch-0")
60+
?: fromToolbox("$root/IDEA-C/ch-0")
61+
pycharmPath?.absolutePath?.let { alternativeIdePath = it }
5562
}
56-
/* for CI */ else -> version = "2018.3"
5763
}
5864
setMarkdownDependency()
5965
}

docs/change-notes.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
0.3.13<br/>
22
<ul>
3+
<li>Make find usages more stable</li>
4+
<li>Fix reference resolving (it's utterly crushed before)</li>
35
</ul>
46
0.3.12<br/>
57
<ul>

src/org/ice1000/julia/lang/psi/impl/julia-psi-mixin.kt

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ interface IJuliaFunctionDeclaration : PsiNameIdentifierOwner, DocStringOwner {
2626
* Common super class for declaration
2727
*/
2828
abstract class JuliaDeclaration(node: ASTNode) : JuliaExprMixin(node), PsiNameIdentifierOwner {
29-
private var refCache: Array<PsiReference>? = null
3029
override fun setName(newName: String) = also {
31-
references.forEach { it.handleElementRename(newName) }
3230
nameIdentifier?.replace(JuliaTokenType.fromText(newName, project))
3331
}
3432

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

3937
override fun getName() = nameIdentifier?.text.orEmpty()
40-
override fun getReferences() = refCache
41-
?: nameIdentifier
42-
?.let { collectFrom(startPoint, it.text, it) }
43-
?.also { refCache = it }
44-
?: emptyArray()
45-
46-
override fun subtreeChanged() {
47-
refCache = null
48-
super.subtreeChanged()
49-
}
5038

5139
override fun processDeclarations(
5240
processor: PsiScopeProcessor, substitutor: ResolveState, lastParent: PsiElement?, place: PsiElement) =
53-
nameIdentifier?.let { processor.execute(it, substitutor) }.orFalse() and
41+
nameIdentifier?.let { processor.execute(it, substitutor) }.orTrue() &&
5442
processDeclTrivial(processor, substitutor, lastParent, place)
5543
}
5644

5745
abstract class JuliaForComprehensionMixin(node: ASTNode) : ASTWrapperPsiElement(node), JuliaForComprehension {
5846
override fun processDeclarations(
5947
processor: PsiScopeProcessor, state: ResolveState, lastParent: PsiElement?, place: PsiElement) =
60-
comprehensionElementList.all { it.processDeclarations(processor, state, lastParent, place) } and
61-
super.processDeclarations(processor, state, lastParent, place)
48+
comprehensionElementList.all { it.processDeclarations(processor, state, lastParent, place) }
6249

6350
override var type: Type? = null
6451
}
6552

6653
abstract class JuliaComprehensionElementMixin(node: ASTNode) : ASTWrapperPsiElement(node), JuliaComprehensionElement {
6754
override fun processDeclarations(
6855
processor: PsiScopeProcessor, state: ResolveState, lastParent: PsiElement?, place: PsiElement) =
69-
singleComprehensionList.all { it.processDeclarations(processor, state, lastParent, place) } and
70-
super.processDeclarations(processor, state, lastParent, place)
56+
singleComprehensionList.all { it.processDeclarations(processor, state, lastParent, place) }
7157
}
7258

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

7763
override fun processDeclarations(
7864
processor: PsiScopeProcessor, substitutor: ResolveState, lastParent: PsiElement?, place: PsiElement) =
79-
singleIndexer?.let { processor.execute(it.firstChild, substitutor) }.orFalse() and
80-
multiIndexer?.let { it.children.all { processor.execute(it, substitutor) } }.orFalse() and
65+
singleIndexer?.let { processor.execute(it.firstChild, substitutor) }.orTrue() &&
66+
multiIndexer?.let { it.children.all { processor.execute(it, substitutor) } }.orTrue() &&
8167
super.processDeclarations(processor, substitutor, lastParent, place)
8268
}
8369

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

138124
override fun toString(): String {
139125
return "JuliaFunctionImpl(FUNCTION)"
@@ -244,10 +230,9 @@ abstract class JuliaTypeDeclarationMixin : StubBasedPsiElementBase<JuliaTypeDecl
244230
override fun setName(name: String) = also { nameIdentifier?.replace(JuliaTokenType.fromText(name, project)) }
245231
override fun getName() = nameIdentifier?.text
246232
override fun getIcon(flags: Int): Icon? = JuliaIcons.JULIA_TYPE_ICON
247-
// override fun processDeclarations(
248-
// processor: PsiScopeProcessor, state: ResolveState, lastParent: PsiElement?, place: PsiElement) =
249-
// nameIdentifier?.let { processor.execute(it, state) }.orFalse() &&
250-
// super.processDeclarations(processor, state, lastParent, place)
233+
override fun processDeclarations(
234+
processor: PsiScopeProcessor, state: ResolveState, lastParent: PsiElement?, place: PsiElement) =
235+
nameIdentifier?.let { processor.execute(it, state) }.orTrue()
251236

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

276260
override fun subtreeChanged() {
277261
nameCache = null
@@ -439,7 +423,7 @@ abstract class JuliaLambdaMixin(node: ASTNode) : JuliaDeclaration(node), JuliaLa
439423
.asReversed()
440424
.all { it.processDeclarations(processor, substitutor, lastParent, place) }
441425
}
442-
}.orFalse() && super.processDeclarations(processor, substitutor, lastParent, place)
426+
}.orTrue() && super.processDeclarations(processor, substitutor, lastParent, place)
443427
}
444428

445429
//class JuliaReferenceManager(val psiManager: PsiManager, val dumbService: DumbService) {
@@ -448,4 +432,4 @@ abstract class JuliaLambdaMixin(node: ASTNode) : JuliaDeclaration(node), JuliaLa
448432
// return ServiceManager.getService(project, JuliaReferenceManager::class.java)
449433
// }
450434
// }
451-
//}
435+
//}

src/org/ice1000/julia/lang/psi/julia-resolving.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ open class SymbolResolveProcessor(
9898
constructor(ref: JuliaSymbolRef, incompleteCode: Boolean) : this(ref.canonicalText, ref.element, incompleteCode)
9999

100100
override val candidateSet = ArrayList<PsiElementResolveResult>(3)
101-
protected open fun accessible(element: PsiElement) = name == element.text && isInScope(element)
101+
protected open fun accessible(element: PsiElement) = name == element.text
102102
override fun execute(element: PsiElement, resolveState: ResolveState) = when {
103103
candidateSet.isNotEmpty() -> false
104104
element is JuliaSymbol -> {
105-
val accessible = accessible(element) && element.symbolKind.isDeclaration
105+
val accessible = accessible(element)
106106
if (accessible) candidateSet += PsiElementResolveResult(element, element.hasNoError)
107107
!accessible
108108
}

src/org/ice1000/julia/lang/utils.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,4 @@ fun String.splitsOf(someStr: String, expandSize: Int) = indices
103103

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

0 commit comments

Comments
 (0)