Closed InsertCreativityHere closed 5 months ago
Im not sure if this will work in the long term
Well sure, this exact structure won't work if we need to mutate the state in the future.
But when we get to that point, we can just move the locks inside. So, instead of OnceLock<Config>
we'd just hold a Config
, and each of it's fields would be locked individually.
Or, less elegant but even easier, we could change OnceLock
to RwLock
or Mutex
or something.
But to me, that's future work, to be done when we add workspace folders.
Right now, as of this PR's opening, I believe OnceLock
is the optimal choice.
But to me, that's future work, to be done when we add workspace folders. Right now, as of this PR's opening, I believe
OnceLock
is the optimal choice.
Right but that's work that we definitely want to do and somewhat soon. Im fine with this PR other than the root_uri
change. I would rather preemptively assume that root_uri
is going to be replaced with a mutable workspaceFolders
rather than making this change just to undo it in a month or so.
So, instead of OnceLock
we'd just hold a Config, and each of it's fields would be locked individually.
This is what I think this PR should do.
This is what I think this PR should do.
Okay, sure, that's fine with me.
@InsertCreativityHere are you still planning on working on this PR or should we draft / close it for now?
I'll know by tomorrow. Now that #35 has been merged, I think I can do what this PR does, but without adding any global state. But I haven't properly looked at that to make sure it's possible. If I'm wrong and I can't, I'll fall back to fixing this PR up.
I'm pretty sure we can do this without a global variable. Closing this in favor of a different approach I'll implement later.
This PR centralizes the server-level config into their own struct:
ServerConfig
. These fields areroot_uri
andbuilt_in_slice_path
.And places an instance of this struct in a global
OnceLock
.OnceLock
has the semantics that it can only be set once, and is set atomically.It also slightly tweaks how the
SliceConfig
caching works. Now we update the cache when it's used, instead of whenever we change a value. This should trigger less cache updates.Before this PR, we stored these fields directly in
Session
, behindRwLocks
. We also stored copies of these in everySliceConfig
, but as bare values. All of these we redundant, and removed.