redhat-developer / vscode-rsp-ui

A unified UI for all RSP servers and RSP server-providers to integrate with
Eclipse Public License 2.0
38 stars 21 forks source link

Keep the order of servers in the Servers view #300

Closed pbodnar closed 4 months ago

pbodnar commented 4 months ago

Problem

Right now, when you add new servers into the Servers view, they are simply put to the end of the list. On the VS Code restart though, their order is randomized.

I've tracked the cause of this problem down to the rsp-server project, where the server instances that are returned to the UI on startup via /getServerHandles are A) kept in a plain HashMap, B) loaded from the file system via java.io.File#listFiles() - see ServerModel.java. Both A and B on their own can cause the list being randomly shuffled.

Solution?

I think the "best" solution would be to let the users order their servers as they like, but that would require extending the data model (there is no notion of ordering so far) and to implement corresponding UI actions.

A "good-enough" solution could be to at least sort the servers by their label ("Server Name" in the New Server wizard; stored as id in the underlying model; BTW one cannot change the server name later on, because the id is immutable and used for the name of the file holding the server JSON definition). Not sure whether to do this on the server, or on the client (UI) side. Doing it in the UI could be probably preferable, as we can control it "more closely" there and possibly improve it in the future?

Apart from this, I think it wouldn't break anything if LinkedHashMap was used instead of HashMap on the server side, so that at least the servers are kept in insertion order there.

Note that I'm new to the code base of these projects, so I won't be surprised if someone comes with some better approach... :)

robstryker commented 4 months ago

Working on a fix to keep them organized alphabetically via the UI side. If you have other clients that want them pre-sorted, please open a bug on rsp-server or on the other extensions ;)

pbodnar commented 4 months ago

@robstryker, thank you for the quick fix, I hope it is good enough for now! :)