Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ lib
dist
out
node_modules
.worktrees/
12 changes: 6 additions & 6 deletions extensions/github1s/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@
"resourceLabelFormatters": [
{
"scheme": "github1s",
"authority": "**/*+?*",
"authority": "?*/**",
"formatting": {
"label": "${path} (${authoritySuffix:7})",
"label": "${path} (${authoritySuffix})",
"separator": "/"
}
},
{
"scheme": "gitlab1s",
"authority": "**/*+?*",
"authority": "?*/**",
"formatting": {
"label": "${path} (${authoritySuffix:7})",
"label": "${path} (${authoritySuffix})",
"separator": "/"
}
},
{
"scheme": "bitbucket1s",
"authority": "**/*+?*",
"authority": "?*/**",
"formatting": {
"label": "${path} (${authoritySuffix:7})",
"label": "${path} (${authoritySuffix})",
"separator": "/"
}
}
Expand Down
4 changes: 2 additions & 2 deletions extensions/github1s/src/providers/file-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ export class GitHub1sFileSearchProvider implements FileSearchProvider, Disposabl
*/
getFileUris = reuseable(async (): Promise<Uri[]> => {
const { repo, ref } = router.getState();
const cacheKey = `${repo}+${ref}`;
const cacheKey = `${repo}@${ref}`;

if (this.fileUrisMap.has(cacheKey)) {
return this.fileUrisMap.get(cacheKey)!;
}

const dataSource = await getAdapter().resolveDataSource();
const rootDirectoryData = await dataSource.provideDirectory(repo, ref, '/', true);
const rootDirectoryUri = router.buildUri({ repo, ref, path: '/' });
const rootDirectoryUri = router.buildUri({ path: '/' });

// the number of items in the tree array maybe exceeded maximum limit, only
// insert the data to fileSystemProvider's cache if `treeData.truncated` is false
Expand Down
6 changes: 3 additions & 3 deletions extensions/github1s/src/providers/file-system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class GitHub1sFileSystemProvider implements FileSystemProvider, Disposabl
public async lookup(uri: Uri, silent: boolean): Promise<Entry | null> {
const parts = uri.path.split('/').filter(Boolean);
const { scheme, repo, ref } = router.parseUri(uri);
const lookupKey = `${scheme}:${repo}+${ref}`;
const lookupKey = `${scheme}:${repo}@${ref}`;
if (!this.root.has(lookupKey)) {
this.root.set(lookupKey, createEntry(adapterTypes.FileType.Directory, uri.with({ path: '/' }), ''));
}
Expand Down Expand Up @@ -172,7 +172,7 @@ export class GitHub1sFileSystemProvider implements FileSystemProvider, Disposabl
}
const subRef = directory.sha || 'HEAD';
const [subScheme, subRepo] = await parseSubmoduleUrl(gitmoduleData.url);
const lookupKey = `${subScheme}:${subRepo}+${subRef}`;
const lookupKey = `${subScheme}:${subRepo}@${subRef}`;
directory.name = ''; // update the name field to '' to indicated it is an root directory
// update the uri field to indicated it is belong the `submodule repository`
directory.uri = router.buildUri({ scheme: subScheme, repo: subRepo, ref: subRef, path: '/' });
Expand Down Expand Up @@ -215,7 +215,7 @@ export class GitHub1sFileSystemProvider implements FileSystemProvider, Disposabl
uri = Uri.joinPath(file.uri, file.name);
}
const { scheme, repo, ref, path } = router.parseUri(uri);
const cacheKey = `${scheme}:${repo}+${ref}${path}`;
const cacheKey = `${scheme}:${repo}@${ref}${path}`;
if (!this.contentCache.has(cacheKey)) {
const dataSource = await getAdapter(scheme).resolveDataSource();
const data = await dataSource.provideFile(repo, ref, path);
Expand Down
24 changes: 24 additions & 0 deletions extensions/github1s/src/router/authority.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @file URI authority helpers
* @author netcon
*/

export const buildAuthority = (repo: string, ref: string): string => {
// label is using for display in resourceLabelFormatters
const label = ref.length >= 32 ? ref.slice(0, 7) : ref;
return repo && ref ? `${repo}@${ref}+${label}` : '';
};

export const parseAuthority = (authority: string): { repo: string; ref: string } | undefined => {
// repo name may starts with @, so we skip the first character
const atIndex = authority.slice(1).indexOf('@') + 1;
if (atIndex <= 0) {
// compatible with old format, remove in the future
const [repo, ref] = authority.split('+');
return repo && ref ? { repo, ref } : undefined;
}
const repo = authority.slice(0, atIndex);
const plusIndex = authority.lastIndexOf('+');
const ref = plusIndex > 0 ? authority.slice(atIndex + 1, plusIndex) : '';
return repo && ref ? { repo, ref } : undefined;
};
10 changes: 5 additions & 5 deletions extensions/github1s/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as vscode from 'vscode';
import { getAdapter } from '@/adapters';
import { History, createMemoryHistory, parsePath, Action } from 'history';
import { RouterParser, RouterState } from '@/adapters/types';
import { buildAuthority, parseAuthority } from './authority';
import { EventEmitter } from './events';

export interface UrlManager {
Expand Down Expand Up @@ -93,9 +94,8 @@ export class Router extends EventEmitter<RouterState> {
}

public parseUri(uri: vscode.Uri): UriState {
const scheme = uri.scheme;
const [repo, ref] = uri.authority ? uri.authority.split('+') : [this._state!.repo, this._state!.ref];
return { scheme, repo, ref, path: uri.path || '/' };
const { repo, ref } = parseAuthority(uri.authority) || this._state!;
return { scheme: uri.scheme, repo, ref, path: uri.path || '/' };
}

public buildUri(state?: Partial<UriState>, base?: vscode.Uri): vscode.Uri {
Expand All @@ -108,8 +108,8 @@ export class Router extends EventEmitter<RouterState> {
throw new Error('ref is required when repo is provided');
}
if (state?.hasOwnProperty('ref')) {
const repo = state.repo || base?.authority.split('+')[0] || this._state!.repo;
mergedState.authority = repo && state.ref ? `${repo}+${state.ref}` : '';
const repo = state.repo || parseAuthority(base?.authority || '')?.repo || this._state!.repo;
mergedState.authority = buildAuthority(repo, state.ref || '');
}
if (state?.hasOwnProperty('path')) {
mergedState.path = `/${state.path?.split('/').filter(Boolean).join('/') || ''}`;
Expand Down
Loading