generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(devins-lang): improve file lookup logic in AutoCommand #101
The file lookup logic in `FileAutoCommand.kt` has been refactored to use the `lookupFile` method from `AutoCommand.kt`, which simplifies the code and improves readability. The old implementation used `guessProjectDir` and `VirtualFileManager` directly, which was
- Loading branch information
Showing
2 changed files
with
19 additions
and
7 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/AutoCommand.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 |
---|---|---|
@@ -1,5 +1,20 @@ | ||
package cc.unitmesh.devti.language.compiler | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.project.guessProjectDir | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.openapi.vfs.VirtualFileManager | ||
|
||
interface AutoCommand { | ||
fun execute(): String? | ||
} | ||
|
||
fun Project.lookupFile(path: String): VirtualFile? { | ||
val projectPath = this.guessProjectDir()?.toNioPath() | ||
val realpath = projectPath?.resolve(path) | ||
|
||
val virtualFile = | ||
VirtualFileManager.getInstance().findFileByUrl("file://${realpath?.toAbsolutePath()}") | ||
return virtualFile | ||
} | ||
|
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