-
Notifications
You must be signed in to change notification settings - Fork 64
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
Spec gotcha: directory entry must end with /
#76
Comments
The "directory ends with slash" convention was borrowed from
I don't feel strongly about this however. |
any opinion @jvican ? |
I like this convention and I think there's no benefit in splitting up the entities to represent files and directories. You make a good point that we should improve this invariant in the specification so that implementors and clients know about it. I would get the contents of that comment and put it in an independent paragraph. |
Okay with me. My concern is that ideally the spec wouldn't need to be referred to much while implementing. But this may not be a major issue here. |
Just ran into this actually. Java |
even the bsp API has this issue:
So the only way to check if an uri is intended as directory is to check the string of the uri. I think this is unelegant and error-prone |
Yes that’s expected, you need to add the trailing slash yourself, we do that in bloop |
You expect it, but I expect this to cost most people implementing this a few hours of debugging :( |
@jastice can you give an example where this situation causes issues? I haven't had issues with this so far in Metals, I work with the plain bsp4j data structures I parse URIs into paths with |
The issue is, on client side I need to know if a path is intended to be a directory or a regular file, especially if this path doesn't exist (yet). With the way this information is encoded, I think it is likely that server implementors will just forget to do that, because the trailing The most straightforward approach:
will lead to the wrong encoding:
Which in itself is easy enough (albeit a bit ugly) to fix once you know the problem, but it's kind of subtle to figure out what's wrong in the first place when items aren't imported into the client correctly. I wouldn't rely solely on documentation to guide correct implementation. Therefore I suggest creating a |
I agree this is a likely pitfall for server implementations (but less so for clients). How about we introduce an an optional |
I did have the same issue implementing it as client, then forgot about it when implementing the mock server and had the same issue again :) I think the optional |
Sounds good, if you open a PR I'm happy to LGTM 👍 |
This would be a breaking change for existing servers that don't set the directory field in servers. Everyone would need to migrate to the new API. It's a shame that the Java NIO APIs strip the trailing path separator by default for directories and that, when the file doesn't exist, clients need to check with I see why @jastice would want that and if this is really an imperative for him we can do it. But I would strongly suggest having a consistent API that relies on URIs instead of replacing every instance of a path with our own abstraction. The more BSP looks like LSP, the better IMO. |
In the case that a server uses URIs to encode plain files, yes. Are there servers besides bloop?
Yet another pitfall: In the URI it's always
Plain URIs would be more elegant in some way, but relying on an implicit string encoding of an important property is just too error prone.
Agree, but as far as I see, LSP doesn't use URIs in a way where it's ambiguous whether they are a file or diectory |
That's a good point! It looks like the only place where they use URI to mean a directory is in the OK, I'm good with this change 👍 |
URIs are system-independent, they use |
For file watching I don't think it matters: You watch what's there, whether it's a file or directory.. But I've looked into the spec more closely and there's more cases, only they call directories folders.
There is a |
Good.
Note that it does matter because you don't file watch a directory in the same way you would file watch a file. If you have a non-existing URI and you start to file watch it as a file, the file watcher could fail whenever it is created afterwards as a directory. |
So it seems on LSP side they simply haven't thought much about file/directory. See eg microsoft/language-server-protocol#272 (comment) I'll go ahead with the change then. |
URI assumes that some protocol portion is expected. I think that building remote workspace is fantasy |
Indeed, Opened workspace can be represented by URI which is mapped to some place in the storage by workspace run-time LSP servers and builders are parts of workspace runtime. Every resource inside workspace can be addressed relatively to workspace URI. Relative path which contains protocol is meaningless. |
Regardless of my previous comment, I think that designation of folder resource by trailing / is consistent |
Solved via #83 |
SourceItem
specifies that a directory entry must end with/
. This is a detail that is likely to be missed by implementors of the spec, both client and server and requires looking at the string to determine if something is a directory. I suggest making it an explicit field inSourceItem
(and probablyDependencySourceItem
as well.The text was updated successfully, but these errors were encountered: