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

[Proposal] Add Namespace Source Literals #1354

Merged

Conversation

addison-adler
Copy link
Contributor

I'd like to add two source literals: SOURCE_NAMESPACE and SOURCE_NAMESPACE_ROOT

  • These are complimentary to the existing SOURCE_FUNCTION_NAME literal
  • These are very useful for trace logging
  • for developers that use a logger with filtering, enables filtering logs based on the namespace they originate from
    • alternative right now is to use PKG_PATH, but that changes every file, whereas a namespace can span multiple files

Live Transpile Preview (pulled from VSCode)

Brighterscript:

Sub ComponentScope ()
    ' Component Scope
    sourceFunction = source_function_name
    sourceNamespace = source_namespace
    sourceNamespaceRoot = source_namespace_root
End Sub

Namespace NamespaceA

    ' Namespace Scope
    Sub ScopeA ()
        sourceFunction = source_function_name
        sourceNamespace = source_namespace
        sourceNamespaceRoot = source_namespace_root
    End Sub

    ' Nested Namespace Scope
    Namespace NamespaceB.NamespaceC

        Sub ScopeB ()
            sourceFunction = source_function_name
            sourceNamespace = source_namespace
            sourceNamespaceRoot = source_namespace_root
        End Sub

    End Namespace
End Namespace

Transpiled

Sub ComponentScope()
    ' Component Scope
    sourceFunction = "ComponentScope"
    sourceNamespace = ""
    sourceNamespaceRoot = ""
End Sub
' Namespace Scope
Sub NamespaceA_ScopeA()
    sourceFunction = "NamespaceA.ScopeA"
    sourceNamespace = "NamespaceA"
    sourceNamespaceRoot = "NamespaceA"
End Sub
' Nested Namespace Scope
Sub NamespaceA_NamespaceB_NamespaceC_ScopeB()
    sourceFunction = "NamespaceA.NamespaceB.NamespaceC.ScopeB"
    sourceNamespace = "NamespaceA.NamespaceB.NamespaceC"
    sourceNamespaceRoot = "NamespaceA"
End Sub

Example Use Case

for debugging & log filtering

Namespace SpaceA
    Sub MyFunction ()
        LoggerUtil.Trace(SOURCE_FUNCTION_NAME, [SOURCE_NAMESPACE_ROOT]) 
    End Sub

    Namespace PrivateA
        Sub PrivateFunc ()
            LoggerUtil.Trace(SOURCE_FUNCTION_NAME, [SOURCE_NAMESPACE_ROOT])
        End Sub
    End Namespace
End Namespace

' Trace(text, filters)
' for filtering logs based on namespace, which may span multiple files
Namespace SpaceA
    Sub MyFunction ()
        LoggerUtil.Trace("MyFunction", ["SpaceA"]) 
    End Sub

    Namespace PrivateA
        Sub PrivateFunc ()
            LoggerUtil.Trace("PrivateFunc", ["SpaceA"])
        End Sub
    End Namespace
End Namespace

Copy link
Member

@TwitchBronBron TwitchBronBron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me! Nice work.

@TwitchBronBron TwitchBronBron enabled auto-merge (squash) November 25, 2024 16:22
Copy link
Member

@TwitchBronBron TwitchBronBron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, on second thought, I wanted to have a quick discussion about the variable names. Would appreciate your thoughts.

src/astUtils/creators.ts Outdated Show resolved Hide resolved
@TwitchBronBron TwitchBronBron enabled auto-merge (squash) November 25, 2024 18:25
@TwitchBronBron
Copy link
Member

@addison-adler can you fix the failing unit test?

image

auto-merge was automatically disabled November 25, 2024 18:31

Head branch was pushed to by a user without write access

@addison-adler
Copy link
Contributor Author

Test failure caused by a casing mismatch; re-testing now

@TwitchBronBron TwitchBronBron enabled auto-merge (squash) November 25, 2024 18:32
@addison-adler
Copy link
Contributor Author

addison-adler commented Nov 25, 2024

@TwitchBronBron

@addison-adler can you fix the failing unit test?

Test failure caused by a casing mismatch; re-testing now

already on it and fixed! 😁
it was a small casing mismatch

@addison-adler
Copy link
Contributor Author

Oh, it doesn't like variables that use snakecase.. okay lemme make those hash keys into strings again 😅

auto-merge was automatically disabled November 25, 2024 18:36

Head branch was pushed to by a user without write access

@addison-adler
Copy link
Contributor Author

@TwitchBronBron all good now!

@TwitchBronBron TwitchBronBron merged commit bc54435 into rokucommunity:master Nov 25, 2024
6 checks passed
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

Successfully merging this pull request may close these issues.

4 participants