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

Kotlin: not detecting a function in a specific case #4175

Closed
amgdev9 opened this issue Jan 11, 2025 · 6 comments
Closed

Kotlin: not detecting a function in a specific case #4175

amgdev9 opened this issue Jan 11, 2025 · 6 comments

Comments

@amgdev9
Copy link

amgdev9 commented Jan 11, 2025

The name of the parser: Kotlin

The command line you used to run ctags:

$ ctags -R --languages=kotlin .

The content of input file:

package com.example.myapplication.ui.theme

import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext

private val DarkColorScheme =
    darkColorScheme(primary = Purple80, secondary = PurpleGrey80, tertiary = Pink80)

private val LightColorScheme =
    lightColorScheme(
        primary = Purple40,
        secondary = PurpleGrey40,
        tertiary = Pink40,

        /* Other default colors to override
        background = Color(0xFFFFFBFE),
        surface = Color(0xFFFFFBFE),
        onPrimary = Color.White,
        onSecondary = Color.White,
        onTertiary = Color.White,
        onBackground = Color(0xFF1C1B1F),
        onSurface = Color(0xFF1C1B1F),
        */
    )

@Composable
fun MyApplicationTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    // Dynamic color is available on Android 12+
    dynamicColor: Boolean = true,
    content: @Composable () -> Unit,
) {
    val colorScheme =
        when {
            dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
                val context = LocalContext.current
                if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
            }

            darkTheme -> DarkColorScheme
            else -> LightColorScheme
        }

    MaterialTheme(colorScheme = colorScheme, typography = Typography, content = content)
}

The tags output you are not satisfied with:

(no output for MyApplicationTheme)
...

The tags output you expect:

MyApplicationTheme	./app/src/main/java/com/example/myapplication/ui/theme/Theme.kt	/^fun MyApplicationTheme($/;"	m	package:com.example.myapplication.ui.theme
...

The version of ctags:

Universal Ctags 6.1.0(v6.1.0), Copyright (C) 2015-2023 Universal Ctags Team
Universal Ctags is derived from Exuberant Ctags.
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Mar 17 2024, 12:18:39
  URL: https://ctags.io/
  Output version: 0.0
  Optional compiled features: +wildcards, +regex, +iconv, +option-directory, +xpath, +json, +interactive, +sandbox, +yaml, +packcc, +optscript, +pcre2

How do you get ctags binary:

pacman -S ctags

@masatake
Copy link
Member

@dolik-rce Could you look into this one?

@dolik-rce
Copy link
Contributor

There seems to be a problem with parsing of the annotation in function the type in content: @Composable () -> Unit.
It is possible to use parenthesized type content: @Composable (() -> Unit) as a workaround. I'll try to submit a PR with fix soon.

@dolik-rce
Copy link
Contributor

The problem was that the parenthesis after annotation name were parsed as part of the annotation, as if it was @Composable() and the rest of the statement ( -> Unit) didn't make any sense. PR #4176 should fix this.

dolik-rce added a commit to dolik-rce/ctags that referenced this issue Jan 13, 2025
@masatake
Copy link
Member

#4176 fixes this.
@dolik-rce Thank you.

@masatake
Copy link
Member

@amgdev9 Thank you for reporting.

@amgdev9
Copy link
Author

amgdev9 commented Jan 14, 2025

@dolik-rce @masatake Thanks to you for solving it! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants