Skip to content
This repository was archived by the owner on Nov 6, 2018. It is now read-only.

WIP: workspace file system API #120

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

WIP: workspace file system API #120

wants to merge 5 commits into from

Conversation

sqs
Copy link
Member

@sqs sqs commented Nov 2, 2018

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.

Copy link

@felixfbecker felixfbecker left a 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?: {

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?

Copy link
Member Author

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

Copy link

@chrismwendt chrismwendt left a 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

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?

Copy link
Member Author

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:

  1. long-running operations
  2. caches
  3. external services that store a link or permission entry pointing to a Sourcegraph repository

@codecov
Copy link

codecov bot commented Nov 3, 2018

Codecov Report

Merging #120 into master will decrease coverage by 76.41%.
The diff coverage is 0%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/protocol/plainTypes.ts 0% <ø> (ø) ⬆️
src/client/environment.ts 100% <ø> (ø) ⬆️
src/client/api/roots.ts 0% <0%> (ø)
src/extension/api/roots.ts 0% <0%> (ø)
src/shared/uri.ts 0% <0%> (ø)
src/extension/workerMain.ts 0% <0%> (ø) ⬆️
src/extension/types/location.ts 0% <0%> (-65%) ⬇️
src/client/controller.ts 0% <0%> (-86.45%) ⬇️
src/extension/extensionHost.ts 0% <0%> (-87.5%) ⬇️
src/extension/api/fileSystem.ts 0% <0%> (ø)
... and 64 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f7a6d85...37aea1c. Read the comment docs.

@sqs
Copy link
Member Author

sqs commented Nov 3, 2018

@felixfbecker:

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)

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.)

@sqs
Copy link
Member Author

sqs commented Nov 3, 2018

The API looks good to me! It might be useful to expose a readDirectoryRecursive function at some point, but no need for that now.

I added a TODO in the sourcegraph.d.ts file about exposing a way to get all files matching a glob path.

sqs added 5 commits November 3, 2018 03:43
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.
@chrismwendt
Copy link

Here's how to move this PR to https://github.com/sourcegraph/sourcegraph/tree/master/packages/sourcegraph-extension-api

cd browser-extensions
git format-patch master --stdout > /tmp/patch

cd ../sourcegraph
cat /tmp/patch | git am -3 --directory=packages/sourcegraph-extension-api/
# and fixup merge conflicts

*
* new URL("https://foo/bar").pathname === "/bar"
*
* new URL("git://foo/bar").pathname === "//foo/bar" // UNDESIRABLE

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

Copy link
Member Author

@sqs sqs Nov 6, 2018

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants