Hi everyone again! Sorry for my newbie question, b...
# arrow-meta
a
Hi everyone again! Sorry for my newbie question, but I can not find the place where
MessageCollector
writes the messages (the filed of
CompilerContext
). Maybe I did not understand clearly, but the
arrow meta
uses
NONE
MessageCollector, which does nothing. Can I override it? I would like to receive my logs. I tried to run the @raulraja example with
bindingContext
:
Copy code
val Meta.example: CliPlugin
    get() =
        "Hello World" {
            meta(
                analysis(
                    doAnalysis = { project, module, projectContext, files, bindingTrace, componentProvider ->
                        null
                    },
                    analysisCompleted = { project, module, bindingTrace, files ->
                        val slice: ImmutableMap<PsiElement, DeclarationDescriptor> =
                            bindingTrace.bindingContext.getSliceContents(BindingContext.DECLARATION_TO_DESCRIPTOR)
                        slice.forEach { (psi, descriptor) ->
                            if (psi is KtProperty && descriptor is PropertyDescriptor) {
                                messageCollector?.report(
                                    CompilerMessageSeverity.WARNING,
                                    "${psi.text} -> Type: ${descriptor.returnType}"
                                )
                            }
                        }
                        null
                    }
                )
            )
        }
Meta does not use the collector for any purpose than erroring in edge cases at the moment and this part is not well integrated yet.
😢 1
We got this pattern from other plugins that did the same, essentially anyone instantiating the compiler manually needed to pass in a message collector but if there is a better way to do it we are all about changing it.
a
Yes, I saw it, but it is an internal function...I am not sure how can I change it from my kotlin compiler plugin
r
We can make the
messageCollector
mutable in the CompilerContext so you can replace it or change any internals that don’t make sense. Meta is not distributed as stable until IR is stable so these are things that are fine to break bincompat for now.
If you want to suggest changes that fit what you need we will be happy to help review or make bigger changes if they make sense, this is a great time to refine these rough edges 🙂
a
I found a good way to log mesaged into file. I simple added the following code into `class MetaPlugin : Meta`:
Copy code
override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
        val file = File(filePath)
        file.createNewFile()
        configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY,
            PrintingMessageCollector(PrintStream(file.outputStream()), MessageRenderer.PLAIN_FULL_PATHS, true))
        super.registerProjectComponents(project, configuration)
    }
I use
PrintingMessageCollector
, it is the public class and I can configure it easily. Maybe it would be helpful for someone. But I don't know if it is a good way or not. @raulraja What do you think?
r
If this collector does not interfere with the IDEA plugin or gets registered as part of the lifecycle there then I think we can replace ours for this one if you’d like to contribute that as a PR 🙂
It would be just replacing what inside the
cli
block here https://github.com/arrow-kt/arrow-meta/blob/6a758274131075bd44f56cc131385d67fa279a10/compiler-plugin/src/main/kotlin/arrow/meta/internal/registry/InternalRegistry.kt#L149 for your code then you would not need to register it manually.
just checked the IDEA plugin and it uses its own custom collector unrelated to this.
a
I think I can add a possibility for using this collector instead of
NONE
, but use
NONE
by default 🙂
👍 1
There are many different collectors, but this one looks well for detecting logs, but I'm not sure
r
sounds good!
🆒 1