Skip to content
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

Custom toml files not working #20

Open
5peak2me opened this issue Apr 26, 2023 · 4 comments
Open

Custom toml files not working #20

5peak2me opened this issue Apr 26, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@5peak2me
Copy link
Contributor

5peak2me commented Apr 26, 2023

image
If we use a file named xxx.versions.toml to define our own dependency library, only the custom prompt will be displayed, and the dependency prompt of libs.versions.toml will not work.

AS:
image

@F43nd1r
Copy link
Owner

F43nd1r commented Apr 26, 2023

Unable to reproduce. Can you provide a minimal sample project?

@F43nd1r F43nd1r added the bug Something isn't working label Apr 27, 2023
@5peak2me
Copy link
Contributor Author

5peak2me commented Jul 5, 2023

hey, @F43nd1r
I'm sorry for the late reply. In the end, I found the cause of the issue. The background of this problem is as follows: In order to unify the versions of third-party dependency libraries, the configuration file in my project is pulled from the cloud. To prevent frequent commit operations due to changes in the configuration file, I chose not to track changes to this file. Therefore, I placed the standard libs.versions.toml file in the .gradle folder.

After reading the source code and debugging, I found that the main cause of this problem is the findInVersionsTomlKeyValues method in Utils.kt. This method uses the getAllFilesByExt method of FilenameIndex in the IDEA library to search for files with a specific extension. In the getVirtualFilesByNames method of FilenameIndex, the collection of VirtualFile is determined. This is where the problem lies. The Project file index does not include the contents of the ignored .gradle folder, which results in the inability to display the prompt information for the dependency libraries in .gradle/libs.versions.toml.

If we need to resolve this, we can customize the search method, but it depends on whether it aligns with your original design intentions. However, this is indeed a practical use case. Do you have any better suggestions or implementation solutions?

@F43nd1r
Copy link
Owner

F43nd1r commented Jul 5, 2023

Can you solve this by just using a different location and .gitignoring it there? Or would that also lead to intelliJ excluding it from indexing?

@5peak2me
Copy link
Contributor Author

5peak2me commented Jul 6, 2023

Finally, I found a solution. In the findInVersionsTomlKeyValues extension method of the Project, we can manually add a custom Toml file path to the VirtualFileSystem and then check if it's needed. This allows us to achieve the desired scenario. I can submit a pull request (PR) for this feature, and you can consider whether to merge it。

fun Project.findInVersionsTomlKeyValues(getKeyValues: (TomlFile) -> List<TomlKeyValue>, search: String): List<TomlKeyValue> {

    val tomlFiles = FilenameIndex.getAllFilesByExt(this, "toml").apply {
        if (basePath != null) {
            add(VfsUtil.findFile(Path.of(basePath!!, ".gradle", "libs.versions.toml"), true))
        }
    }

    return tomlFiles
        .filter { it.name.endsWith("versions.toml") }
        .map { it.toPsiFile(this) }
        .filterIsInstance<TomlFile>()
        .flatMap { file -> getKeyValues(file).filter { it.key.textMatches(search) } }
}

Here is how it turned out:
WX20230706-094454

@F43nd1r F43nd1r mentioned this issue Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants