Skip to content

Commit

Permalink
Refactors shared location storage
Browse files Browse the repository at this point in the history
 - Uses XDG env vars on all OSs
 - Avoids singleton & adds to container
 - Avoids empty implementations for web
 - Renames files and methods for better clarity
 - Removes dependency on xdg-basedir package
Adds new Lazy<T> type & lazy method
Adds new UnifiedDisposable & UnifiedAsyncDisposable
  • Loading branch information
eamodio committed Jan 26, 2025
1 parent 0f4c914 commit c39ec45
Show file tree
Hide file tree
Showing 23 changed files with 541 additions and 525 deletions.
18 changes: 1 addition & 17 deletions ThirdPartyNotices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ This project incorporates components from the projects listed below.
28. signal-utils version 0.21.1 (https://github.com/proposal-signals/signal-utils)
29. slug version 10.0.0 (https://github.com/Trott/slug)
30. sortablejs version 1.15.0 (https://github.com/SortableJS/Sortable)
31. xdg-basedir version 5.1.0 (https://github.com/sindresorhus/xdg-basedir)

%% @gk-nzaytsev/fast-string-truncated-width NOTICES AND INFORMATION BEGIN HERE
=========================================
Expand Down Expand Up @@ -2245,19 +2244,4 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

=========================================
END OF sortablejs NOTICES AND INFORMATION

%% xdg-basedir NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License

Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

=========================================
END OF xdg-basedir NOTICES AND INFORMATION
END OF sortablejs NOTICES AND INFORMATION
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20147,8 +20147,7 @@
"react-dom": "16.8.4",
"signal-utils": "0.21.1",
"slug": "10.0.0",
"sortablejs": "1.15.0",
"xdg-basedir": "5.1.0"
"sortablejs": "1.15.0"
},
"devDependencies": {
"@eamodio/eslint-lite-webpack-plugin": "0.2.0",
Expand Down
9 changes: 0 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 43 additions & 16 deletions src/container.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import type { ConfigurationChangeEvent, Disposable, Event, ExtensionContext } from 'vscode';
import { EventEmitter, ExtensionMode, Uri } from 'vscode';
import { getSupportedGitProviders, getSupportedRepositoryPathMappingProvider } from '@env/providers';
import {
getSharedGKStorageLocationProvider,
getSupportedGitProviders,
getSupportedRepositoryLocationProvider,
getSupportedWorkspacesStorageProvider,
} from '@env/providers';
import type { AIProviderService } from './ai/aiProviderService';
import { FileAnnotationController } from './annotations/fileAnnotationController';
import { LineAnnotationController } from './annotations/lineAnnotationController';
Expand All @@ -18,7 +23,7 @@ import { GlCommand } from './constants.commands';
import { EventBus } from './eventBus';
import { GitFileSystemProvider } from './git/fsProvider';
import { GitProviderService } from './git/gitProviderService';
import type { RepositoryPathMappingProvider } from './git/pathMapping/repositoryPathMappingProvider';
import type { RepositoryLocationProvider } from './git/location/repositorylocationProvider';
import { LineHoverController } from './hovers/lineHoverController';
import { DraftService } from './plus/drafts/draftsService';
import { AccountAuthenticationProvider } from './plus/gk/authenticationProvider';
Expand All @@ -35,6 +40,8 @@ import { EnrichmentService } from './plus/launchpad/enrichmentService';
import { LaunchpadIndicator } from './plus/launchpad/launchpadIndicator';
import { LaunchpadProvider } from './plus/launchpad/launchpadProvider';
import { RepositoryIdentityService } from './plus/repos/repositoryIdentityService';
import type { SharedGkStorageLocationProvider } from './plus/repos/sharedGkStorageLocationProvider';
import { WorkspacesApi } from './plus/workspaces/workspacesApi';
import { scheduleAddMissingCurrentWorkspaceRepos, WorkspacesService } from './plus/workspaces/workspacesService';
import { StatusBarController } from './statusbar/statusBarController';
import { executeCommand } from './system/-webview/command';
Expand Down Expand Up @@ -404,14 +411,6 @@ export class Container {
return this._drafts;
}

private _repositoryIdentity: RepositoryIdentityService | undefined;
get repositoryIdentity(): RepositoryIdentityService {
if (this._repositoryIdentity == null) {
this._disposables.push((this._repositoryIdentity = new RepositoryIdentityService(this, this._connection)));
}
return this._repositoryIdentity;
}

private readonly _codeLensController: GitCodeLensController;
get codeLens(): GitCodeLensController {
return this._codeLensController;
Expand Down Expand Up @@ -587,12 +586,33 @@ export class Container {
return this._rebaseEditor;
}

private _repositoryPathMapping: RepositoryPathMappingProvider | undefined;
get repositoryPathMapping(): RepositoryPathMappingProvider {
if (this._repositoryPathMapping == null) {
this._disposables.push((this._repositoryPathMapping = getSupportedRepositoryPathMappingProvider(this)));
private _repositoryIdentity: RepositoryIdentityService | undefined;
get repositoryIdentity(): RepositoryIdentityService {
if (this._repositoryIdentity == null) {
this._disposables.push(
(this._repositoryIdentity = new RepositoryIdentityService(this, this.repositoryLocator)),
);
}
return this._repositoryIdentity;
}

private _repositoryLocator: RepositoryLocationProvider | null | undefined;
get repositoryLocator(): RepositoryLocationProvider | undefined {
if (this._repositoryLocator === undefined) {
this._repositoryLocator = getSupportedRepositoryLocationProvider(this, this.sharedGkStorage!) ?? null;
if (this._repositoryLocator != null) {
this._disposables.push(this._repositoryLocator);
}
}
return this._repositoryLocator ?? undefined;
}

private _sharedGkStorage: SharedGkStorageLocationProvider | null | undefined;
private get sharedGkStorage(): SharedGkStorageLocationProvider | undefined {
if (this._sharedGkStorage === undefined) {
this._sharedGkStorage = getSharedGKStorageLocationProvider(this) ?? null;
}
return this._repositoryPathMapping;
return this._sharedGkStorage ?? undefined;
}

private readonly _statusBarController: StatusBarController;
Expand Down Expand Up @@ -648,7 +668,14 @@ export class Container {
private _workspaces: WorkspacesService | undefined;
get workspaces(): WorkspacesService {
if (this._workspaces == null) {
this._disposables.push((this._workspaces = new WorkspacesService(this, this._connection)));
this._disposables.push(
(this._workspaces = new WorkspacesService(
this,
new WorkspacesApi(this, this._connection),
getSupportedWorkspacesStorageProvider(this, this.sharedGkStorage!),
this.repositoryLocator,
)),
);
}
return this._workspaces;
}
Expand Down
21 changes: 0 additions & 21 deletions src/env/browser/pathMapping/repositoryWebPathMappingProvider.ts

This file was deleted.

50 changes: 0 additions & 50 deletions src/env/browser/pathMapping/workspacesWebPathMappingProvider.ts

This file was deleted.

23 changes: 17 additions & 6 deletions src/env/browser/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import type { GitCommandOptions } from '../../git/commandOptions';
// Force import of GitHub since dynamic imports are not supported in the WebWorker ExtensionHost
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import { GitProvider } from '../../git/gitProvider';
import type { RepositoryLocationProvider } from '../../git/location/repositorylocationProvider';
import { GitHubGitProvider } from '../../plus/integrations/providers/github/githubGitProvider';
import { RepositoryWebPathMappingProvider } from './pathMapping/repositoryWebPathMappingProvider';
import { WorkspacesWebPathMappingProvider } from './pathMapping/workspacesWebPathMappingProvider';
import type { SharedGkStorageLocationProvider } from '../../plus/repos/sharedGkStorageLocationProvider';
import type { GkWorkspacesSharedStorageProvider } from '../../plus/workspaces/workspacesSharedStorageProvider';

export function git(_options: GitCommandOptions, ..._args: any[]): Promise<string | Buffer> {
return Promise.resolve('');
Expand All @@ -25,10 +26,20 @@ export function getSupportedGitProviders(container: Container): Promise<GitProvi
return Promise.resolve([new GitHubGitProvider(container)]);
}

export function getSupportedRepositoryPathMappingProvider(container: Container) {
return new RepositoryWebPathMappingProvider(container);
export function getSharedGKStorageLocationProvider(_container: Container): SharedGkStorageLocationProvider | undefined {
return undefined;
}

export function getSupportedWorkspacesPathMappingProvider() {
return new WorkspacesWebPathMappingProvider();
export function getSupportedRepositoryLocationProvider(
_container: Container,
_sharedStorage: SharedGkStorageLocationProvider | undefined,
): RepositoryLocationProvider | undefined {
return undefined;
}

export function getSupportedWorkspacesStorageProvider(
_container: Container,
_sharedStorage: SharedGkStorageLocationProvider | undefined,
): GkWorkspacesSharedStorageProvider | undefined {
return undefined;
}
Loading

0 comments on commit c39ec45

Please sign in to comment.