Accessing preferences from other plugins
Hi,
I have two custom MPS plugins. Plugin A defines a preference component with a single preference page. This is were I set a path to a project specific file.
Now Plugin B defines a Tool that needs to access the file via the path specified in the preference component of Plugin A.
I tried to achieve this with the following snipped inside the Tool of Plugin B with the following snippet that is also referred to in the MPS plugin documentation https://confluence.jetbrains.com/display/MPSD32/Plugin#Plugin-PreferenceComponentexpression:
This, however, produces an error:
The dependencies look fine to me but the generator seems not able to resolve the references. So my question is if what I want to achieve is possible and if so what am I doing wrong?
I have two custom MPS plugins. Plugin A defines a preference component with a single preference page. This is were I set a path to a project specific file.
Now Plugin B defines a Tool that needs to access the file via the path specified in the preference component of Plugin A.
I tried to achieve this with the following snipped inside the Tool of Plugin B with the following snippet that is also referred to in the MPS plugin documentation https://confluence.jetbrains.com/display/MPSD32/Plugin#Plugin-PreferenceComponentexpression:
init(project)->void {
string path = project.preferenceComponent<CustomPrefences>.myFilepath
}
This, however, produces an error:
couldn't resolve reference 'baseMethodDeclaration' from getStateObject -- cannot resolve reference by string: 'getStateObject' -- was input: 034ff76b-1ae8-4bb0-823c-a3f81ff1996a/r:c0217f7d-91e8-4a13-bd95-b21cbfc313df(B@transient18/B.plugin@0)/8159339663038184236 -- was template: r:00000000-0000-4000-0000-011c89590369(jetbrains.mps.lang.plugin.generator.baseLanguage.template.main@generator)/5891355986060395731 Failed to replace dynamic reference 'baseMethodDeclaration' with static counterpart: no target; resolveInfo=getStateObject. Dynamic reference is left intact. broken reference 'fieldDeclaration' in [operation] FieldReferenceOperation null[8159339663038196662] in B.plugin@1_0 (target model is null) -- -- was input node: [operation] FieldReferenceOperation null[8159339663038196662] in B.plugin@1_0 broken reference 'classifier' in [actualArgument] ClassifierClassExpression null[8159339663038196670] in B.plugin@1_0 (target model is null) -- -- was input node: [actualArgument] ClassifierClassExpression null[8159339663038196670] in B.plugin@1_0 model "B.plugin@1_0" has been generated with errors generation completed with errors in 245 ms Error executing target jetbrains.mps.lang.core.Generate.generate "generate" target execution time: 246 ms Other targets execution time: 1 ms; configure: 1 ms, preloadModels: 0 ms, checkParameters: 0 ms Make failed. See previous messages for details.
The dependencies look fine to me but the generator seems not able to resolve the references. So my question is if what I want to achieve is possible and if so what am I doing wrong?
Please sign in to leave a comment.
Vaclav
I have uploaded a examlple project here https://www.dropbox.com/s/a2sa16mf7vk3gdg/PreferencePluginTest.tar.gz?dl=1
Thank you for your help.
Phillipp
you've discovered a limitation of the MPS plugin language generator, which prevents it from correctly generating PreferencesComponent references pointing to other models (https://youtrack.jetbrains.com/issue/MPS-21996). I recommend to put the tool as well as the preferences component both in a single model for now.
Vaclav
thank you for looking into this issue. For now I will try the work around you proposed and hope that there will be a fix for this in one of the next MPS releases since this would support a more modular approach in creating MPS plugins.
Best regards,
Phillipp