generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Alaanor/rust-integration
Rust integration
- Loading branch information
Showing
33 changed files
with
512 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 11 additions & 3 deletions
14
src/main/kotlin/com/github/alaanor/candid/CandidFindUsageProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/com/github/alaanor/candid/inspection/CandidUnusedMethodInspection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.github.alaanor.candid.inspection | ||
|
||
import com.github.alaanor.candid.project.DfxJson | ||
import com.github.alaanor.candid.psi.CandidMethodType | ||
import com.intellij.codeInspection.* | ||
import com.intellij.psi.PsiFile | ||
import com.intellij.psi.util.PsiTreeUtil | ||
|
||
class CandidUnusedMethodInspection : LocalInspectionTool() { | ||
override fun checkFile(file: PsiFile, manager: InspectionManager, isOnTheFly: Boolean): Array<ProblemDescriptor>? { | ||
if (!DfxJson.isRustCanister(file.project, file.virtualFile)) | ||
return null | ||
|
||
val problemsHolder = ProblemsHolder(manager, file, isOnTheFly) | ||
val methods = PsiTreeUtil.findChildrenOfType(file, CandidMethodType::class.java) | ||
|
||
methods.forEach { method -> | ||
if (method.reference?.resolve() != null) | ||
return@forEach | ||
|
||
problemsHolder.registerProblem( | ||
method.originalElement, | ||
"No matching rust method found for this candid method", | ||
ProblemHighlightType.LIKE_UNUSED_SYMBOL | ||
) | ||
} | ||
|
||
return problemsHolder.resultsArray | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/com/github/alaanor/candid/listener/DfxFileListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.github.alaanor.candid.listener | ||
|
||
import com.github.alaanor.candid.project.DfxJson | ||
import com.intellij.openapi.vfs.AsyncFileListener | ||
import com.intellij.openapi.vfs.newvfs.events.VFileEvent | ||
|
||
class DfxFileListener : AsyncFileListener { | ||
override fun prepareChange(events: MutableList<out VFileEvent>): AsyncFileListener.ChangeApplier? { | ||
var hasInterestingEvent = false | ||
|
||
for (event in events) | ||
if (event.path.endsWith("dfx.json")) | ||
hasInterestingEvent = true | ||
|
||
if (!hasInterestingEvent) return null | ||
|
||
return object : AsyncFileListener.ChangeApplier { | ||
override fun afterVfsChange() { | ||
DfxJson.updateCache() | ||
} | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/kotlin/com/github/alaanor/candid/marker/CandidMethodRsLineMarkerProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.github.alaanor.candid.marker | ||
|
||
import com.github.alaanor.candid.icon.CandidIcons | ||
import com.github.alaanor.candid.project.DfxJson | ||
import com.github.alaanor.candid.psi.CandidMethodType | ||
import com.github.alaanor.candid.psi.stub.index.CandidStubMethodIndex | ||
import com.github.alaanor.candid.util.CandidRustIcCdkUtil | ||
import com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo | ||
import com.intellij.codeInsight.daemon.RelatedItemLineMarkerProvider | ||
import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.search.GlobalSearchScope | ||
import com.intellij.psi.stubs.StubIndex | ||
import org.rust.lang.core.psi.RsFunction | ||
|
||
class CandidMethodRsLineMarkerProvider : RelatedItemLineMarkerProvider() { | ||
|
||
override fun collectNavigationMarkers( | ||
element: PsiElement, | ||
result: MutableCollection<in RelatedItemLineMarkerInfo<*>> | ||
) { | ||
val rsFunction = element as? RsFunction ?: return | ||
val name = CandidRustIcCdkUtil.getName(rsFunction) ?: return | ||
val candidFile = DfxJson.getCandidFileFromRustFile(element.containingFile) ?: return | ||
|
||
val candidMethod = StubIndex.getElements( | ||
CandidStubMethodIndex.Key, | ||
name, | ||
element.project, | ||
GlobalSearchScope.fileScope(element.project, candidFile), | ||
CandidMethodType::class.java | ||
).firstOrNull() ?: return | ||
|
||
// we found a matching rust method and candid method | ||
|
||
val builder = NavigationGutterIconBuilder.create(CandidIcons.FileType) | ||
.setTarget(candidMethod) | ||
.setTooltipText("Navigate to the corresponding candid method") | ||
|
||
result.add(builder.createLineMarkerInfo(element.identifier)) | ||
} | ||
} |
Oops, something went wrong.