-
Notifications
You must be signed in to change notification settings - Fork 29.5k
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
URI comparisons and resources.ts #93368
Comments
I guess to really see the extend of usage we need to hunt down every single call to Changing to use the Q: the JSDoc of |
Yes - debt week. And careful changes No - |
Oh yeah, got it. |
… tree so that it will be fit for case-in-sensitive compare, #93368
@aeschli and I were wondering why all those comparisons and on-the-fly normalisations are done at all. My assumption has always been that we normalise when "uris enter the system", e.g when you call open editor for |
@jrieken @aeschli I remember I suggested that as a possible cheap solution in 2017 to #12448 by simply letting all my file editor world use case-insensitive comparators and got push back from a couple of people in the team so I reverted this again (see #12448 (comment)). See also #12448 (comment) for a more recent reply I did on that matter. One of the scenarios that break once we go down this path is:
So, we either consistently compare URIs everywhere and ignore casing on certain OS or we do not. But cannot have either or. |
Is that "make correct" logic re-usable? We could just apply it to markers as well |
Well that was basically using |
Oh, so the "make correct" logic doesn't exist and today two editors would open, right? |
@jrieken that's right, and one of the reasons for that is this line where we do
On top of that, the place where all text file models are stored is using As I said before, any place where we compare URIs (using |
I think that's the right direction. |
I like that a lot. I would opt for a dedicated service, like the I think an important piece is that such a service is non-destructive. I mean the first occurrence of a path, e.g.
I am more optimistic and I'd say the opening editors, text models, and markers are 90% here |
IMO we should not just tackle the resource equality, but also the operations (join/normalize/..). There we need to know about fs roots, rules for normalizing separators (ok to remove trailing/duplicates, which ones are required), what to do with queries and fragments. |
I am not sure that is needed on the level of the provider, I think the provider should declare its behaviour in some format (like we declare the label format) and then some service can take that and work with that information. I think I would prefer a
Yes
Not sure we can get that to work well across processes. We could end up with different forms in different processes unless we had a central authority for URIs, which of course would mean things have to be async.
Yes, definitely needs to be sync. Challenge though is that resolving the remote is async and as such you could not properly construct or compare URIs until the remote is resolved. Btw we do have a |
The editor service change is in #98795 but as I said, I would think we need to merge the adoption for text model resolvers as well. |
That's a good find. We should maybe not use the canonical uri for display purposes or find a way to re-set a canonical uris, tho that would mean we change the uri of a text model, right? |
@jrieken ideally we go with a solution that does not involve touching the model. I actually prefer the way it is now because reusing the same model has a lot of advantages (undo/redo, view state, etc). I think it would be relatively easy to do this for editors, but we may have many places in our system where we derive a label simply from its |
Listing a few things that I think should happen in June that I noticed while adopting the URI identity. I can open separate issues but we can also leave it here.
|
let canonicalResource: URI; | |
if (this.modelService?.getModel(resource)) { | |
// TODO@Ben remove this check once canonical URIs are adopted in ITextModelResolerService | |
canonicalResource = resource; | |
} else { | |
canonicalResource = this.uriIdentityService.asCanonicalUri(resource); | |
} |
There is just a lot of paths where a URI might end up to create a model, even beyond the openTextDocument
API. E.g. if you do "Peek Definition" we open an embedded editor with a URI that I think we get from extensions. If you start to edit that document inside, we would not be able to open it if it is opened with another casing.
Drop our biased checks or replace with IURIIdentityService
I think that our biased checks for isEqual
and friends are very dangerous because I think the default we assume is not good for remote scenarios. The vscode-remote
scheme will in 99% of the cases be Linux (e.g. WSL), but we ignore casing for any non-file-scheme. At the very minimum we should add a check for vscode-remote
and maybe handle that specially. For example, after we resolved the remote agent, we know exactly what target OS we are dealing with and could then do the correct thing.
Nevertheless, adopting IURIIdentityService
would solve this better.
ResourceMap
aware of file system capabilities
I am having at least one case (write queue in file service) where I would benefit from a ResourceMap
that is aware of a filesystems case sensitivity. It would be great to have a utility that would provide this.
Makes sense, but lets do it "careful"
Yeah, my plan is to drop
Agreed - we should have an overload constructor that allows to pass in a "get-key" function or a comparator (assuming we trust the SkipList). Like |
One thing I should maybe look into is to decouple the |
6a0b359 adds support for passing in a |
This allows to use the ResourceMap with case insensitive path logic etc
@bpasero fyi - I have pushed a change that allows to use the |
Done! The default uri identity utils are now unbiased and compatible with toString-usage. There is still two biased utils which 1 or 2 users only and (hopefully) very clear comments. Last, there is IUriIdentityService for the "truth" and that's adopted in the critical places. Closing |
Removed one usage of biased util in |
This is the continuation of: 7d4cd4a#r37940098.
Background: We can classify uris into two categories
file:///foo/bar.bazz
orvscode-remote://bing+bong/boo/far/fazz
, anduntitled:unitiled-1
orcommand:deleteLeft
Uris of both categories exist in our system, generally uris that represent files are posix style, e.g all file-uris and all uris from contributed file systems. However, uris for virtual documents, command uris, and others don't fall into this category.
The
URI
class knows a little about this and for instance enforces that posix style uri paths start with a slash, e.gURI.parse('file:foo').toString() === 'file:///foo'
whereas that "fixing" doesn't happen for arbitrary schemes (only file, http, https and arguably we should add vscode-remote here)Now, the following problems exist:
resources.ts
-utility which offers many convenience functions when working with uris, e.g ways to compare them. But these utilities are all written with the assumption that it works on uris with posix-paths, e.g it states thatcommand:/deleteLeft
equalscommand:deleteLeft
(which breaks compatibility withuri.toString
-usages). To make the confusion perfect it doesn't check, enforce, nor document that it work only works on a subset of uris, e.g. blind adoptions like these dc0ab50 made a perfect messResourceMap<T>
and the widespread use ofmap.set(uri.toString(), 42)
I think we need to first decide if
resources.ts
utility should only work on uris with posix-paths. That means we need at least documentation, better enforcement, and we need to review or revert @mjbvz's "adoption".resources.ts
utility be fit for all uris, esp with respect to uri comparisons. That means we need to know when posix rules apply and when not.I am strongly suggesting to use variant 2 because anything else will be confusing.
As a next step we need to use the same URI-equivalence checks, e.g it's bad that the renderer uses a different identity for documents then the extension host. The
ResourcesMap<T>
also uses a different identity than for instance users ofgetComparisonKey
. We should align that and ideally have them all rootgetComparsionKey
and/orisEqual
. So, this is what I think needs to be donegetComparisonKey
inResourceMap<T>
@bpaseroResourceMap
whenever storing something by URITernarySearchTree@forPaths
which actually isforUris
@jriekenThe text was updated successfully, but these errors were encountered: