Custom persistence... Follow
Once there was a support of custom persistence, but I cannot find it now in MPS sources... Was it removed?
I'd like to use MPS to edit my existing models, and these models are stored in a set of files in my format.
Custom persistence would solve the problem..
Please sign in to leave a comment.
You can go to module properties-> model roots. For every model root, a "manager" class can be specified. It is used for storing/reading models (look at solutions MPS.Classpath and JDK).
But this functionality will be deprecated, because it was introduced for our internal purposes and is very hard to use. We are working now on re-implementing it as MPS language aspect (so that every language could have a kind of "persistence" aspect). There is a chance that it will be available in version 1.2.
I'm trying to implement my own persistence adapter, and something is apparently missing in my code.
Could you help me out, please?
Let's say my language is:
property root: true
child others: PersonReference 0..n
reference person: Person 1
So, I've implemented a simple ModelRootManager that should create the SModel programmatically.
This ModelRootManage, I think, I can use the generated classes for my language.
Then, in the method loadModel, I am constructing the SModel, and populate it with my data.
I use generated methods Person.newInstance(), PersonReference.newInstance(), addOthers(Person)
Finally, I add all Person instances as roots to the model:
That seems to work, but not very good.
First, as I use generated classes in my ModelRootManager, I must tell MPS to use them for my solution.
I've tried adding the reference to generated classes directory to Solution Properties|Classpath, but MPS doesn't find classes when loading the solution.
The solution uses my language, also.
So I've added the reference to generated classes right into mps.bat (I guess it's bad..)
MPS was able to load the solution, and I can see Persons, each with references to other persons, but these references are red cells.
However, I'm able to navigate thru these references. Searching for references to given Person does not find anything, however.
Could you advise, how do I specify the classpath to use with my solution in this case? Hopefully, it will solve the problem with red cell and search.
MPS 1.1 loads ModelRootManagers with system classloader, so there's no "correct" way to use classes, that are not inside of MPS in your MRM (if they are not found in system classpath, MPS will not be able to load them). The situation will be fixed in the release that will contain custom persistence feature.
I think that red references is not the same problem. If you could send me your project, I would take a look at it and try to help you with this.
I've attached my project
This happens because you create not valid model - modelId for it is not specified.
For this code to work, create your model like this:
SModelReference modelReference = new SModelReference(new SModelFqName("persons", ""), SModelId.generate());
After this change, it works well.
The code that shows error is here:
It helped, thanks!
I suspected that SModel is bad, but I don't know how to use it yet.
One thing that still does not work is search. Do you have any idea why is it not working?
One more remark - when you'll use it in real project, model id should be the same on diffirent loads (because it is used in MPS references).
I've changed model id to SModelId.foreign ("persons"), I guess it will be the same between reloads + removed all mps caches, but it does not help with search.
If I search for some Person that is in 'friends' of other Person, nothing is found...
I've found out that if default find usages manager is used (fast one), that search does not work for me. With default search manager, it works (but quite slow..).
Is there some magic method to be called (like refresh() or reindex()..) that I can call to make fast searcher work?
For now, "fast" find usages will not work, because it requires building caches, that are file-based (and you need custom model load before building caches from a file), so it can't be done without changing MPS source code.
Thanks for report, we haven't noticed this case even in the new framework yet (thought it's quite simple to implement)
I've noticed another problem with search (most likely I'm using APIs incorrectly again..)
When I load my project, search does not work. After I run Rebuild All, the search works.
And another problem: Go to Symbol does not work, although nodes have 'name' property and inherit from INamedConcept.
It's very inconvenient without Go To Symbol
Actually, we were using these mangers to deal with java stubs, so it may work not very good with real models, which require most MPS functionality. Now this feedback is very valuable, because it will help us to write the new framework more accurately.
Btw, do you often use "Go to symbol" (which is ctrl-alt-shift-N)?
In trunc, we've disabled this action, because building caches for it consumes about 70% time of building all caches, and we don't use this action at all. If it's often used by some reasons, we could enable it again.
Well, that was the feedback from my customers (other developers).
I've build the root manager that constructs a model from a set of files in the filesystem.
Let's say its structure is:
the total number of nodes is already big (hundreds), and the model is changed sometimes some child can be moved to another root.
One thing the customer (and I) want to do is to quickly locate the certain ChildNode, given its name,
because nobody remembers, where exactly the particular ChildNode is placed at the moment. But everybody knows the name.
So, even though the customer had MPS and rich model in it, there was still a problem to find the node no edit,
and the customer had to search exhaustively thru all the root nodes.
For us, "Go to node by name" is quite important. Speed is not that important. Actually, instead of Go To, there could be Search by name (or by attribute value)
In that case, you can write an action for your language yourself (because the speed of the search is not very important for you, as I understood). The main thing there is that you don't actually need caches. That was the question - because you can't enable them without changing MPS source code now, so if they are needed, we must enable them while writing MPS.
Btw, we now have some ideas about implementing caching abilities in MPS (so that custom caches for your languages are available). Regretully, this idea is quite immature, so maybe the feature will be available in some later releases, not now.
Well, "Go to node by name" could be used in many languages, would be nice to support it in MPS...
Regarding custom action:
It seems that I cannot access many MPS classes from the action's body, like SearchResults...
Can I define a finder and "invoke" it from action (So that "Find usages" tool will appear, etc)?
>Well, "Go to node by name" could be used in many languages, would be nice to support it in MPS...
Ok, we'll discuss it here in MPS. Maybe we'll return the action back.
>It seems that I cannot access many MPS classes from the action's body, like SearchResults...
You need to import "java_stub" that contain those classes from Java you want to use.
To use SearchResults class, you should import "jetbrains.mps.ide.findusages.model@java_stub" model.
You can also use "Import model by root" action for these purposes (ctrl-R)
>Can I define a finder and "invoke" it from action (So that "Find usages" tool will appear, etc)?
You can define a finder, but now there is no DSL construct to invoke it (this task is in our bugtracker and we are working on it), but you can invoke it natively. See how it's done in "GoToOverridingMethods" action in baseLanguage.
I've just found that "Go to Node" and "Go to symbol" works for me, if I switch "Go To Node" to "Use default go to root node and named node" - just never noticed that.
Please, don't remove it :-)