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

Auto-complete for accessing resource files #64

Open
aSemy opened this issue Jun 6, 2023 · 2 comments
Open

Auto-complete for accessing resource files #64

aSemy opened this issue Jun 6, 2023 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@aSemy
Copy link

aSemy commented Jun 6, 2023

I would like for my IDE to be able to recommend suggestions so that I can quickly access resources when I'm writing the tests, without having to refer to the resources directory.

I have two suggestions:

  1. Implement the @Language tag that the Resources() class can inject languages, specifically the file-reference injection.

    IntelliJ will then automatically suggest file paths

    image

    Unfortunately @Language isn't a Kotlin annotation, so it isn't suitable for Kotlin Multiplatform out of the box. But it can be converted to work for Kotlin Multiplatform projects, as demonstrated in Kotlinx Serialization.

  2. Generate code so that I can access the files via variables.

    For example, given that resources contains

    .
    └── resources/
        └── test-data/
            └── some-test-file.json

    Then the kotlinx-resources plugin could generate the following code:

    // build/generated/src/main/kotlin/ResourcesAccessors.kt
    
    object Resource {
      /** `test-data/ directory */
      object testData {
        /** Load the file `test-data/some-test-file.json */
        val someTestFileJson = Resource("test-data/some-test-file.json")
      }
    }

    I could then quickly access the file in my test:

    // src/commonTest/MyResourcesTests.kt
    class MyResourcesTests {
      @Test
      fun `test json`() {
          val someTestData = Resource.testData.someTestFileJson.readText()
          // ...
      }
    }
@goncalossilva
Copy link
Owner

Thanks, that's a great suggestion! I favor the approach using @Language, similar to what kotlinx.serialization is doing. It's something I was unaware of before, but I'll explore it unless someone submits PR before I get to it.

@goncalossilva goncalossilva added enhancement New feature or request help wanted Extra attention is needed labels Jun 9, 2023
@goncalossilva goncalossilva changed the title Feature request: auto-complete for accessing resource files Auto-complete for accessing resource files Jun 9, 2023
@jbruchanov
Copy link

I'd suggest the 2nd option, basically what android does with the R class.
In case there is a change/removal it's being caught right away during compile time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants