-
Notifications
You must be signed in to change notification settings - Fork 2
WIP: workspace file system API #120
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was to design/name this API I would avoid the concept of a "file system" and not use syscall-like names, because that seems like an implementation detail (and doesn't actually match the implementation, since it is backed by GraphQL API and git show
/git ls-files
). As a user, I don't care about "reading a file" I care about "getting the content".
I said the same back in the day about "vfs" in LSP :)
* | ||
* @todo Document what happens when the root is a subdirectory of a repository. | ||
*/ | ||
readonly repository?: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the root has multiple repos?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the root is itself not in a repository, then this would be undefined (even if it had subdirs that were repositories). This only describes "where the workspace root comes from, from the POV of the client application". It is not a general "all repository information that might be relevant for this root" because that:
- can change at any time
- is difficult to define minimally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API looks good to me! It might be useful to expose a readDirectoryRecursive
function at some point, but no need for that now.
* | ||
* This is equivalent to Repository.id in the Sourcegraph GraphQL API schema. | ||
*/ | ||
readonly id: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering, what would the id
here be used for? Perhaps renaming a repository via the Sourcegraph GraphQL API? Where does an extension get an id
from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an extension needs a stable reference identifier for the repository, it can use this value. Handling renames/deletions for any operation is one case where this is useful. In general, if the extension stores other data that is attached to the repository itself and not just the name, then it should use this identifier. Other cases of that are:
- long-running operations
- caches
- external services that store a link or permission entry pointing to a Sourcegraph repository
Codecov Report
@@ Coverage Diff @@
## master #120 +/- ##
==========================================
- Coverage 77.62% 1.21% -76.42%
==========================================
Files 67 71 +4
Lines 2632 2808 +176
Branches 534 558 +24
==========================================
- Hits 2043 34 -2009
- Misses 589 2774 +2185
Continue to review full report at Codecov.
|
Are you thinking of changes other than the names? What specific changes do you have in mind? (This implementation is backed by GraphQL, but other implementations, such as in the editor or when the extension is itself a file system provider (e.g., for vendored or codegenned files) would be more appropriately called "file systems". So I think the name fits, but I am interested to hear your alternatives.) |
I added a TODO in the sourcegraph.d.ts file about exposing a way to get all files matching a glob path. |
The enhanced sourcegraph.URI class (and its implementation, which is shared by the client and extension) is a full URI parser. Previously it only wrapped a string.
Here's how to move this PR to https://github.com/sourcegraph/sourcegraph/tree/master/packages/sourcegraph-extension-api
|
* | ||
* new URL("https://foo/bar").pathname === "/bar" | ||
* | ||
* new URL("git://foo/bar").pathname === "//foo/bar" // UNDESIRABLE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not how WHATWG URL behaves: https://runkit.com/felixfbecker/5be0d65fa5064900123995f4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I think it's not spec compliant (and so soon will change, or will have different behavior in different browsers). Try it in the browser and read the https://url.spec.whatwg.org/#special-scheme doc.
I made an attempt at an extension API for reading dirs and files from a repository.
The code is WIP, so don't bother reviewing it for implementation feedback. But API feedback would be helpful.