Skip to content

Commit

Permalink
Reorganizes code structure
Browse files Browse the repository at this point in the history
 - Splits models & utils into separate files to reduce coupling
 - Relocates VS Code-specific utilities into system/-webview/
  • Loading branch information
eamodio committed Jan 20, 2025
1 parent 61e07e0 commit 6c3356a
Show file tree
Hide file tree
Showing 451 changed files with 4,641 additions and 4,479 deletions.
26 changes: 13 additions & 13 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export default ts.config(
{
name: 'extension:node',
files: ['src/**/*'],
ignores: ['src/webviews/apps/**/*', 'src/env/browser/**/*'],
ignores: ['**/webview/**/*', 'src/test/**/*', 'src/webviews/apps/**/*', 'src/env/browser/**/*'],
languageOptions: {
globals: {
...globals.node,
Expand Down Expand Up @@ -358,7 +358,7 @@ export default ts.config(
{
name: 'extension:browser',
files: ['src/**/*'],
ignores: ['src/webviews/apps/**/*', 'src/env/node/**/*'],
ignores: ['**/webview/**/*', 'src/test/**/*', 'src/webviews/apps/**/*', 'src/env/node/**/*'],
languageOptions: {
globals: {
...globals.worker,
Expand All @@ -381,19 +381,19 @@ export default ts.config(
// Keep in sync with `src/webviews/apps/tsconfig.json`
files: [
'src/webviews/apps/**/*',
'src/@types/**/*',
'src/env/browser/**/*',
'src/plus/gk/account/promos.ts',
'src/plus/gk/account/subscription.ts',
'src/webviews/**/protocol.ts',
'src/**/models/**/*.ts',
'src/**/utils/**/*.ts',
'src/@types/**/*',
'src/config.ts',
'src/constants.ts',
'src/constants.*.ts',
'src/env/browser/**/*',
'src/features.ts',
'src/subscription.ts',
'src/system/*.ts',
'src/system/decorators/log.ts',
'src/system/**/*.ts',
'**/webview/**/*',
],
ignores: ['**/-webview/**/*'],
languageOptions: {
globals: {
...globals.browser,
Expand All @@ -414,13 +414,13 @@ export default ts.config(
{
patterns: [
{
group: ['react-dom'],
importNames: ['Container'],
message: 'Use our Container instead',
group: ['Container'],
message: "Can't use `Container` in webviews",
allowTypeImports: true,
},
{
group: ['vscode'],
message: "Can't use vscode in webviews",
message: "Can't use `vscode` in webviews",
allowTypeImports: true,
},
],
Expand Down
9 changes: 5 additions & 4 deletions src/ai/aiProviderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import type { AIGenerateDraftEventData, Sources, TelemetryEvents } from '../cons
import type { Container } from '../container';
import { CancellationError } from '../errors';
import type { GitCommit } from '../git/models/commit';
import { assertsCommitHasFullDetails, isCommit } from '../git/models/commit';
import { isCommit } from '../git/models/commit';
import type { GitRevisionReference } from '../git/models/reference';
import type { Repository } from '../git/models/repository';
import { isRepository } from '../git/models/repository';
import { uncommitted, uncommittedStaged } from '../git/models/revision';
import { assertsCommitHasFullDetails } from '../git/utils/commit.utils';
import { showAIModelPicker } from '../quickpicks/aiModelPicker';
import { configuration } from '../system/-webview/configuration';
import type { Storage } from '../system/-webview/storage';
import { supportedInVSCodeVersion } from '../system/-webview/utils';
import { getSettledValue } from '../system/promise';
import { getPossessiveForm } from '../system/string';
import { configuration } from '../system/vscode/configuration';
import type { Storage } from '../system/vscode/storage';
import { supportedInVSCodeVersion } from '../system/vscode/utils';
import type { TelemetryService } from '../telemetry/telemetry';
import { AnthropicProvider } from './anthropicProvider';
import { GeminiProvider } from './geminiProvider';
Expand Down
2 changes: 1 addition & 1 deletion src/ai/openAICompatibleProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { AIProviders } from '../constants.ai';
import type { TelemetryEvents } from '../constants.telemetry';
import type { Container } from '../container';
import { CancellationError } from '../errors';
import { configuration } from '../system/-webview/configuration';
import { sum } from '../system/iterable';
import { interpolate } from '../system/string';
import { configuration } from '../system/vscode/configuration';
import type { AIModel, AIProvider } from './aiProviderService';
import { getMaxCharacters, getOrPromptApiKey, showDiffTruncationWarning } from './aiProviderService';
import {
Expand Down
2 changes: 1 addition & 1 deletion src/ai/openaiProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { configuration } from '../system/vscode/configuration';
import { configuration } from '../system/-webview/configuration';
import type { AIModel } from './aiProviderService';
import { OpenAICompatibleProvider } from './openAICompatibleProvider';

Expand Down
2 changes: 1 addition & 1 deletion src/ai/vscodeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type { CancellationToken, LanguageModelChat, LanguageModelChatSelector }
import { CancellationTokenSource, LanguageModelChatMessage, lm } from 'vscode';
import type { TelemetryEvents } from '../constants.telemetry';
import type { Container } from '../container';
import { configuration } from '../system/-webview/configuration';
import { sum } from '../system/iterable';
import { capitalize, getPossessiveForm, interpolate } from '../system/string';
import { configuration } from '../system/vscode/configuration';
import type { AIModel, AIProvider } from './aiProviderService';
import { getMaxCharacters, showDiffTruncationWarning } from './aiProviderService';
import {
Expand Down
2 changes: 1 addition & 1 deletion src/annotations/annotationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Disposable, window } from 'vscode';
import type { FileAnnotationType } from '../config';
import type { AnnotationStatus } from '../constants';
import type { Container } from '../container';
import { getTabUri } from '../system/-webview/utils';
import { Logger } from '../system/logger';
import type { Deferred } from '../system/promise';
import { defer } from '../system/promise';
import { getTabUri } from '../system/vscode/utils';
import type { TrackedGitDocument } from '../trackers/trackedDocument';
import type { Decoration } from './annotations';

Expand Down
2 changes: 1 addition & 1 deletion src/annotations/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import type { Colors } from '../constants.colors';
import type { CommitFormatOptions } from '../git/formatters/commitFormatter';
import { CommitFormatter } from '../git/formatters/commitFormatter';
import type { GitCommit } from '../git/models/commit';
import { configuration } from '../system/-webview/configuration';
import { scale, toRgba } from '../system/color';
import { getWidth, interpolate, pad } from '../system/string';
import { configuration } from '../system/vscode/configuration';
import type { BlameFontOptions } from './gutterBlameAnnotationProvider';

export interface ComputedHeatmap {
Expand Down
2 changes: 1 addition & 1 deletion src/annotations/blameAnnotationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { GitUri } from '../git/gitUri';
import type { GitBlame } from '../git/models/blame';
import type { GitCommit } from '../git/models/commit';
import { changesMessage, detailsMessage } from '../hovers/hovers';
import { configuration } from '../system/-webview/configuration';
import { log } from '../system/decorators/log';
import { configuration } from '../system/vscode/configuration';
import type { TrackedGitDocument } from '../trackers/trackedDocument';
import type { DidChangeStatusCallback } from './annotationProvider';
import { AnnotationProviderBase } from './annotationProvider';
Expand Down
12 changes: 6 additions & 6 deletions src/annotations/fileAnnotationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ import type { AnnotationsToggleMode, FileAnnotationType } from '../config';
import type { AnnotationStatus } from '../constants';
import type { Colors, CoreColors } from '../constants.colors';
import type { Container } from '../container';
import { registerCommand } from '../system/-webview/command';
import { configuration } from '../system/-webview/configuration';
import { setContext } from '../system/-webview/context';
import type { KeyboardScope } from '../system/-webview/keyboard';
import { UriSet } from '../system/-webview/uriMap';
import { isTrackableTextEditor } from '../system/-webview/utils';
import { debug, log } from '../system/decorators/log';
import { once } from '../system/event';
import type { Deferrable } from '../system/function';
import { debounce } from '../system/function';
import { find } from '../system/iterable';
import { basename } from '../system/path';
import { registerCommand } from '../system/vscode/command';
import { configuration } from '../system/vscode/configuration';
import { setContext } from '../system/vscode/context';
import type { KeyboardScope } from '../system/vscode/keyboard';
import { UriSet } from '../system/vscode/uriMap';
import { isTrackableTextEditor } from '../system/vscode/utils';
import type {
DocumentBlameStateChangeEvent,
DocumentDirtyIdleTriggerEvent,
Expand Down
2 changes: 1 addition & 1 deletion src/annotations/gutterBlameAnnotationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import type { Container } from '../container';
import type { CommitFormatOptions } from '../git/formatters/commitFormatter';
import { CommitFormatter } from '../git/formatters/commitFormatter';
import type { GitCommit } from '../git/models/commit';
import { configuration } from '../system/-webview/configuration';
import { filterMap } from '../system/array';
import { log } from '../system/decorators/log';
import { first } from '../system/iterable';
import { getLogScope } from '../system/logger.scope';
import { maybeStopWatch } from '../system/stopwatch';
import type { TokenOptions } from '../system/string';
import { getTokensFromTemplate, getWidth } from '../system/string';
import { configuration } from '../system/vscode/configuration';
import type { TrackedGitDocument } from '../trackers/trackedDocument';
import type { AnnotationContext, AnnotationState, DidChangeStatusCallback } from './annotationProvider';
import { applyHeatmap, getGutterDecoration, getGutterRenderOptions } from './annotations';
Expand Down
2 changes: 1 addition & 1 deletion src/annotations/gutterChangesAnnotationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import type { Container } from '../container';
import type { GitCommit } from '../git/models/commit';
import type { GitDiffFile } from '../git/models/diff';
import { localChangesMessage } from '../hovers/hovers';
import { configuration } from '../system/-webview/configuration';
import { log } from '../system/decorators/log';
import { getLogScope } from '../system/logger.scope';
import { getSettledValue } from '../system/promise';
import { maybeStopWatch } from '../system/stopwatch';
import { configuration } from '../system/vscode/configuration';
import type { TrackedGitDocument } from '../trackers/trackedDocument';
import type { AnnotationContext, AnnotationState, DidChangeStatusCallback } from './annotationProvider';
import { AnnotationProviderBase } from './annotationProvider';
Expand Down
4 changes: 2 additions & 2 deletions src/annotations/lineAnnotationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import type { Container } from '../container';
import { CommitFormatter } from '../git/formatters/commitFormatter';
import type { PullRequest } from '../git/models/pullRequest';
import { detailsMessage } from '../hovers/hovers';
import { configuration } from '../system/-webview/configuration';
import { isTrackableTextEditor } from '../system/-webview/utils';
import { debug, log } from '../system/decorators/log';
import { once } from '../system/event';
import { debounce } from '../system/function';
import { Logger } from '../system/logger';
import { getLogScope, setLogScopeExit } from '../system/logger.scope';
import type { MaybePausedResult } from '../system/promise';
import { getSettledValue, pauseOnCancelOrTimeoutMap } from '../system/promise';
import { configuration } from '../system/vscode/configuration';
import { isTrackableTextEditor } from '../system/vscode/utils';
import type { LinesChangeEvent, LineState } from '../trackers/lineTracker';
import { getInlineDecoration } from './annotations';
import type { BlameFontOptions } from './gutterBlameAnnotationProvider';
Expand Down
8 changes: 4 additions & 4 deletions src/api/actionRunners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { Disposable, EventEmitter, window } from 'vscode';
import type { Config } from '../config';
import { actionCommandPrefix } from '../constants.commands';
import type { Container } from '../container';
import { registerCommand } from '../system/-webview/command';
import { configuration } from '../system/-webview/configuration';
import { setContext } from '../system/-webview/context';
import { getQuickPickIgnoreFocusOut } from '../system/-webview/utils';
import { getScopedCounter } from '../system/counter';
import { sortCompare } from '../system/string';
import { registerCommand } from '../system/vscode/command';
import { configuration } from '../system/vscode/configuration';
import { setContext } from '../system/vscode/context';
import { getQuickPickIgnoreFocusOut } from '../system/vscode/utils';
import type { Action, ActionContext, ActionRunner } from './gitlens';

type Actions = ActionContext['type'];
Expand Down
4 changes: 2 additions & 2 deletions src/autolinks/autolinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import type { IntegrationId } from '../constants.integrations';
import { IssueIntegrationId } from '../constants.integrations';
import type { Container } from '../container';
import type { GitRemote } from '../git/models/remote';
import { getIssueOrPullRequestHtmlIcon, getIssueOrPullRequestMarkdownIcon } from '../git/utils/vscode/icons';
import { getIssueOrPullRequestHtmlIcon, getIssueOrPullRequestMarkdownIcon } from '../git/utils/-webview/icons';
import type { HostingIntegration, IssueIntegration } from '../plus/integrations/integration';
import { configuration } from '../system/-webview/configuration';
import { fromNow } from '../system/date';
import { debug } from '../system/decorators/log';
import { encodeUrl } from '../system/encoding';
Expand All @@ -15,7 +16,6 @@ import { Logger } from '../system/logger';
import { escapeMarkdown } from '../system/markdown';
import { getSettledValue, isPromise } from '../system/promise';
import { capitalize, encodeHtmlWeak, getSuperscript } from '../system/string';
import { configuration } from '../system/vscode/configuration';
import type {
Autolink,
CacheableAutolinkReference,
Expand Down
2 changes: 1 addition & 1 deletion src/autolinks/autolinks.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IssueIntegrationId } from '../constants.integrations';
import type { IssueOrPullRequest } from '../git/models/issue';
import type { IssueOrPullRequest } from '../git/models/issueOrPullRequest';
import type { ProviderReference } from '../git/models/remoteProvider';
import type { ResourceDescriptor } from '../plus/integrations/integration';
import { escapeMarkdown } from '../system/markdown';
Expand Down
4 changes: 2 additions & 2 deletions src/avatars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import type { StoredAvatar } from './constants.storage';
import { Container } from './container';
import type { CommitAuthor } from './git/models/author';
import { getGitHubNoReplyAddressParts } from './git/remotes/github';
import { configuration } from './system/-webview/configuration';
import { getContext } from './system/-webview/context';
import { debounce } from './system/function';
import { filterMap } from './system/iterable';
import { base64, equalsIgnoreCase } from './system/string';
import { configuration } from './system/vscode/configuration';
import { getContext } from './system/vscode/context';
import type { ContactPresenceStatus } from './vsls/vsls';

const maxSmallIntegerV8 = 2 ** 30 - 1; // Max number that can be stored in V8's smis (small integers)
Expand Down
3 changes: 2 additions & 1 deletion src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import type { Disposable } from './api/gitlens';
import type { Container } from './container';
import type { Account } from './git/models/author';
import type { DefaultBranch } from './git/models/defaultBranch';
import type { Issue, IssueOrPullRequest } from './git/models/issue';
import type { Issue } from './git/models/issue';
import type { IssueOrPullRequest } from './git/models/issueOrPullRequest';
import type { PullRequest } from './git/models/pullRequest';
import type { RepositoryMetadata } from './git/models/repositoryMetadata';
import type { HostingIntegration, IntegrationBase, ResourceDescriptor } from './plus/integrations/integration';
Expand Down
4 changes: 2 additions & 2 deletions src/codelens/codeLensController.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { ConfigurationChangeEvent } from 'vscode';
import { Disposable, languages } from 'vscode';
import type { Container } from '../container';
import { configuration } from '../system/-webview/configuration';
import { setContext } from '../system/-webview/context';
import { log } from '../system/decorators/log';
import { once } from '../system/event';
import { getLoggableName, Logger } from '../system/logger';
import { getLogScope, setLogScopeExit, startLogScope } from '../system/logger.scope';
import { configuration } from '../system/vscode/configuration';
import { setContext } from '../system/vscode/context';
import type { DocumentBlameStateChangeEvent, DocumentDirtyIdleTriggerEvent } from '../trackers/documentTracker';
import type { GitCodeLensProvider } from './codeLensProvider';

Expand Down
6 changes: 3 additions & 3 deletions src/codelens/codeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import type { GitUri } from '../git/gitUri';
import type { GitBlame } from '../git/models/blame';
import type { GitCommit } from '../git/models/commit';
import { RemoteResourceType } from '../git/models/remoteResource';
import { createCommand, executeCoreCommand } from '../system/-webview/command';
import { configuration } from '../system/-webview/configuration';
import { isVirtualUri } from '../system/-webview/utils';
import { is, once } from '../system/function';
import { filterMap, find, first, join, map } from '../system/iterable';
import { getLoggableName, Logger } from '../system/logger';
import { startLogScope } from '../system/logger.scope';
import { pluralize } from '../system/string';
import { createCommand, executeCoreCommand } from '../system/vscode/command';
import { configuration } from '../system/vscode/configuration';
import { isVirtualUri } from '../system/vscode/utils';

class GitRecentChangeCodeLens extends CodeLens {
constructor(
Expand Down
4 changes: 2 additions & 2 deletions src/commands/addAuthors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { SourceControl } from 'vscode';
import { GlCommand } from '../constants.commands';
import type { Container } from '../container';
import { executeGitCommand } from '../git/actions';
import { command } from '../system/vscode/command';
import { GlCommandBase } from './base';
import { command } from '../system/-webview/command';
import { GlCommandBase } from './commandBase';

@command()
export class AddAuthorsCommand extends GlCommandBase {
Expand Down
13 changes: 7 additions & 6 deletions src/commands/browseRepoAtRevision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { GlCommand } from '../constants.commands';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { showGenericErrorMessage } from '../messages';
import { command, executeCoreCommand } from '../system/-webview/command';
import { openWorkspace } from '../system/-webview/utils';
import { Logger } from '../system/logger';
import { basename } from '../system/path';
import { command, executeCoreCommand } from '../system/vscode/command';
import { openWorkspace } from '../system/vscode/utils';
import type { CommandContext } from './base';
import { ActiveEditorCommand, getCommandUri } from './base';
import { ActiveEditorCommand } from './commandBase';
import { getCommandUri } from './commandBase.utils';
import type { CommandContext } from './commandContext';

export interface BrowseRepoAtRevisionCommandArgs {
uri?: Uri;
Expand Down Expand Up @@ -41,10 +42,10 @@ export class BrowseRepoAtRevisionCommand extends ActiveEditorCommand {
break;
}

return this.execute(context.editor!, context.uri, args);
return this.execute(context.editor, context.uri, args);
}

async execute(editor: TextEditor, uri?: Uri, args?: BrowseRepoAtRevisionCommandArgs) {
async execute(editor: TextEditor | undefined, uri?: Uri, args?: BrowseRepoAtRevisionCommandArgs) {
args = { ...args };

try {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/closeUnchangedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { GlCommand } from '../constants.commands';
import type { Container } from '../container';
import { showGenericErrorMessage } from '../messages';
import { getRepositoryOrShowPicker } from '../quickpicks/repositoryPicker';
import { command } from '../system/-webview/command';
import { UriComparer } from '../system/comparers';
import { Logger } from '../system/logger';
import { command } from '../system/vscode/command';
import { GlCommandBase } from './base';
import { GlCommandBase } from './commandBase';

export interface CloseUnchangedFilesCommandArgs {
uris?: Uri[];
Expand Down
4 changes: 2 additions & 2 deletions src/commands/cloudIntegrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { GlCommand } from '../constants.commands';
import type { SupportedCloudIntegrationIds } from '../constants.integrations';
import type { Source } from '../constants.telemetry';
import type { Container } from '../container';
import { command } from '../system/-webview/command';
import { createMarkdownCommandLink } from '../system/commands';
import { command } from '../system/vscode/command';
import { GlCommandBase } from './base';
import { GlCommandBase } from './commandBase';

export interface ManageCloudIntegrationsCommandArgs extends Source {}

Expand Down
Loading

0 comments on commit 6c3356a

Please sign in to comment.