-
Notifications
You must be signed in to change notification settings - Fork 744
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
[Improvement]: Allow passing objects to Compiler Plugin Context from Ballerina tools #42338
Comments
The basic requirement is to be able to make something available from a Ballerina Tool to compiler plugins. With recent changes, |
+1, a way to get values set to compiler plugins from the compiler plugins side is already available as: public class CustomScannerPlugin extends CompilerPlugin {
@Override
public void init(CompilerPluginContext pluginContext) {
// Access the passed object from the compiler plugin side (Feature already available)
ScannerContext scannerContext = (ScannerContext) pluginContext.userData().get("scannerContext");
// Perform analysis with scanner context and report issues
// ...
}
} However, there is no way to add something from the tool side which can then be accessed via the compiler plugin side. |
The following API is available to add data to the cache before the compilation. ballerina-lang/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilerPluginCache.java Line 59 in c7c5ee4
Usage: project.projectEnvironmentContext().getService(CompilerPluginCache.class).putData(<FQCN>, <value>) Note that the key should be the canonical name of the compiler plugin class. |
Tested this solution, and it allows passing a context from the scan tool side to be accessible from the compiler plugin side, however due to the issue #42312 it is currently not possible to cast the object back to its original type from the compiler plugins end. |
Description
Currently, it is not possible to pass context objects created from Ballerina tools to compiler plugins.
Describe your problem(s)
Having an API for passing a context from Ballerina tools to compiler plugins allows for extending the functionalities of the tools. This is particularly useful for the
bal scan
tool. By providing a single scanner context created by the scan tool, compiler plugins can directly report issues through this context. The scan tool can then seamlessly retrieve and report these analysis issues.Currently, to achieve this functionality, a write of the analysis issues to a file from the compiler plugin side and a read from the scan tool side are required.
Describe your solution(s)
Introduce an API that allows the user to pass custom arguments to the compiler plugin context from the project API.
These arguments can then be accessed via compiler plugins as follows.
This would simplify the process by eliminating unnecessary file I/O, and enable more efficient and streamlined communication between the scan tool and its compiler plugins.
Related area
-> Other Area
Related issue(s) (optional)
Issue 42121
Suggested label(s) (optional)
No response
Suggested assignee(s) (optional)
No response
The text was updated successfully, but these errors were encountered: