Skip to content

Commit

Permalink
Adds & enforces module boundary types
Browse files Browse the repository at this point in the history
 - For improved type performance
  • Loading branch information
eamodio committed Jan 27, 2025
1 parent cbd6de9 commit b881fcd
Show file tree
Hide file tree
Showing 410 changed files with 1,794 additions and 1,553 deletions.
5 changes: 5 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ export default ts.config(
},
],
'@typescript-eslint/consistent-type-imports': ['error', { disallowTypeAnnotations: false }],
'@typescript-eslint/explicit-module-boundary-types': [
'error',
{ allowArgumentsExplicitlyTypedAsAny: true },
],
'@typescript-eslint/naming-convention': [
'error',
{
Expand Down Expand Up @@ -414,6 +418,7 @@ export default ts.config(
},
},
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-restricted-imports': [
'error',
{
Expand Down
12 changes: 6 additions & 6 deletions src/ai/aiProviderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ export class AIProviderService implements Disposable {

constructor(private readonly container: Container) {}

dispose() {
dispose(): void {
this._provider?.dispose();
}

get currentProviderId() {
get currentProviderId(): AIProviders | undefined {
return this._provider?.id;
}

Expand Down Expand Up @@ -486,7 +486,7 @@ export class AIProviderService implements Disposable {
}
}

async reset(all?: boolean) {
async reset(all?: boolean): Promise<void> {
let { _provider: provider } = this;
if (provider == null) {
// If we have no provider, try to get the current model (which will load the provider)
Expand Down Expand Up @@ -540,11 +540,11 @@ export class AIProviderService implements Disposable {
}
}

supports(provider: AIProviders | string) {
supports(provider: AIProviders | string): boolean {
return _supportedProviderTypes.has(provider as AIProviders);
}

async switchModel() {
async switchModel(): Promise<void> {
void (await this.getModel({ force: true }));
}
}
Expand Down Expand Up @@ -702,7 +702,7 @@ function splitMessageIntoSummaryAndBody(message: string): AIResult {
};
}

export function showDiffTruncationWarning(maxCodeCharacters: number, model: AIModel) {
export function showDiffTruncationWarning(maxCodeCharacters: number, model: AIModel): void {
void window.showWarningMessage(
`The diff of the changes had to be truncated to ${maxCodeCharacters} characters to fit within the ${getPossessiveForm(
model.provider.name,
Expand Down
3 changes: 2 additions & 1 deletion src/ai/geminiProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { CancellationToken } from 'vscode';
import type { Response } from '@env/fetch';
import type { AIModel } from './aiProviderService';
import { OpenAICompatibleProvider } from './openAICompatibleProvider';

Expand Down Expand Up @@ -71,7 +72,7 @@ export class GeminiProvider extends OpenAICompatibleProvider<typeof provider.id>
apiKey: string,
request: object,
cancellation: CancellationToken | undefined,
) {
): Promise<Response> {
if ('max_completion_tokens' in request) {
const { max_completion_tokens: _, ...rest } = request;
request = rest;
Expand Down
5 changes: 3 additions & 2 deletions src/ai/openAICompatibleProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { CancellationToken } from 'vscode';
import type { Response } from '@env/fetch';
import { fetch } from '@env/fetch';
import type { AIProviders } from '../constants.ai';
import type { TelemetryEvents } from '../constants.telemetry';
Expand Down Expand Up @@ -30,7 +31,7 @@ export interface AIProviderConfig {
export abstract class OpenAICompatibleProvider<T extends AIProviders> implements AIProvider<T> {
constructor(protected readonly container: Container) {}

dispose() {}
dispose(): void {}

abstract readonly id: T;
abstract readonly name: string;
Expand Down Expand Up @@ -261,7 +262,7 @@ export abstract class OpenAICompatibleProvider<T extends AIProviders> implements
apiKey: string,
request: object,
cancellation: CancellationToken | undefined,
) {
): Promise<Response> {
let aborter: AbortController | undefined;
if (cancellation != null) {
aborter = new AbortController();
Expand Down
4 changes: 2 additions & 2 deletions src/ai/vscodeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export class VSCodeAIProvider implements AIProvider<typeof provider.id> {
readonly id = provider.id;

private _name: string | undefined;
get name() {
get name(): string {
return this._name ?? provider.name;
}

constructor(private readonly container: Container) {}

dispose() {}
dispose(): void {}

async getModels(): Promise<readonly AIModel<typeof provider.id>[]> {
const models = await lm.selectChatModels();
Expand Down
10 changes: 5 additions & 5 deletions src/annotations/annotationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export abstract class AnnotationProviderBase<TContext extends AnnotationContext
);
}

dispose() {
dispose(): void {
void this.clear();

this.disposable.dispose();
Expand Down Expand Up @@ -102,7 +102,7 @@ export abstract class AnnotationProviderBase<TContext extends AnnotationContext
return true;
}

async clear() {
async clear(): Promise<void> {
if (this._computing?.pending) {
await this._computing.promise;
}
Expand Down Expand Up @@ -156,7 +156,7 @@ export abstract class AnnotationProviderBase<TContext extends AnnotationContext

protected abstract onProvideAnnotation(context?: TContext, state?: AnnotationState): Promise<boolean>;

refresh(replaceDecorationTypes: Map<TextEditorDecorationType, TextEditorDecorationType | null>) {
refresh(replaceDecorationTypes: Map<TextEditorDecorationType, TextEditorDecorationType | null>): void {
if (this.editor == null || !this.decorations?.length) return;

const decorations = [];
Expand All @@ -175,7 +175,7 @@ export abstract class AnnotationProviderBase<TContext extends AnnotationContext
this.setDecorations(this.decorations);
}

restore(editor: TextEditor, recompute?: boolean) {
restore(editor: TextEditor, recompute?: boolean): void {
// If the editor isn't disposed then we don't need to do anything
// Explicitly check for `false`
if ((this.editor as any)._disposed === false) return;
Expand All @@ -201,7 +201,7 @@ export abstract class AnnotationProviderBase<TContext extends AnnotationContext
selection?(selection?: TContext['selection']): Promise<void>;
validate?(): boolean | Promise<boolean>;

protected setDecorations(decorations: Decoration[]) {
protected setDecorations(decorations: Decoration[]): void {
if (this.decorations?.length) {
// If we have no new decorations, just completely clear the old ones
if (!decorations?.length) {
Expand Down
12 changes: 8 additions & 4 deletions src/annotations/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ const defaultHeatmapColors = [
'#0a60f6',
];

let heatmapColors: { hot: string[]; cold: string[] } | undefined;
export function getHeatmapColors() {
interface HeatmapColors {
hot: string[];
cold: string[];
}
let heatmapColors: HeatmapColors | undefined;
export function getHeatmapColors(): HeatmapColors {
if (heatmapColors == null) {
const { coldColor, hotColor } = configuration.get('heatmap');

Expand All @@ -91,7 +95,7 @@ export function getHeatmapColors() {
return heatmapColors;
}

export function applyHeatmap(decoration: Partial<DecorationOptions>, date: Date, heatmap: ComputedHeatmap) {
export function applyHeatmap(decoration: Partial<DecorationOptions>, date: Date, heatmap: ComputedHeatmap): void {
const [r, g, b, a] = getHeatmapColor(date, heatmap);
decoration.renderOptions!.before!.borderColor = `rgba(${r},${g},${b},${a})`;
}
Expand All @@ -101,7 +105,7 @@ export function addOrUpdateGutterHeatmapDecoration(
heatmap: ComputedHeatmap,
range: Range,
map: Map<string, Decoration<Range[]>>,
) {
): TextEditorDecorationType {
const [r, g, b, a] = getHeatmapColor(date, heatmap);

const { fadeLines, locations } = configuration.get('heatmap');
Expand Down
4 changes: 2 additions & 2 deletions src/annotations/blameAnnotationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase
}
}

override clear() {
override clear(): Promise<void> {
if (this.hoverProviderDisposable != null) {
this.hoverProviderDisposable.dispose();
this.hoverProviderDisposable = undefined;
Expand Down Expand Up @@ -140,7 +140,7 @@ export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase
};
}

registerHoverProviders(providers: { details: boolean; changes: boolean }) {
registerHoverProviders(providers: { details: boolean; changes: boolean }): void {
const cfg = configuration.get('hovers');
if (!cfg.enabled || !cfg.annotations.enabled || (!providers.details && !providers.changes)) {
return;
Expand Down
15 changes: 9 additions & 6 deletions src/annotations/fileAnnotationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class FileAnnotationController implements Disposable {
this._toggleModes = new Map<FileAnnotationType, AnnotationsToggleMode>();
}

dispose() {
dispose(): void {
void this.clearAll();

Decorations.gutterBlameAnnotation?.dispose();
Expand Down Expand Up @@ -280,15 +280,15 @@ export class FileAnnotationController implements Disposable {
}

@log<FileAnnotationController['clear']>({ args: { 0: e => e?.document.uri.toString(true) } })
clear(editor: TextEditor | undefined) {
clear(editor: TextEditor | undefined): Promise<void> | undefined {
if (this.isInWindowToggle()) return this.clearAll();
if (editor == null) return;

return this.clearCore(getEditorCorrelationKey(editor), true);
}

@log()
async clearAll() {
async clearAll(): Promise<void> {
this._windowAnnotationType = undefined;

for (const [key] of this._annotationProviders) {
Expand Down Expand Up @@ -335,7 +335,10 @@ export class FileAnnotationController implements Disposable {
private readonly _annotatedUris = new UriSet();
private readonly _computingUris = new UriSet();

async onProviderEditorStatusChanged(editor: TextEditor | undefined, status: AnnotationStatus | undefined) {
async onProviderEditorStatusChanged(
editor: TextEditor | undefined,
status: AnnotationStatus | undefined,
): Promise<void> {
if (editor == null) return;

let changed = false;
Expand Down Expand Up @@ -530,13 +533,13 @@ export class FileAnnotationController implements Disposable {
}

@log()
nextChange() {
nextChange(): void {
const provider = this.getProvider(window.activeTextEditor);
provider?.nextChange?.();
}

@log()
previousChange() {
previousChange(): void {
const provider = this.getProvider(window.activeTextEditor);
provider?.previousChange?.();
}
Expand Down
2 changes: 1 addition & 1 deletion src/annotations/gutterBlameAnnotationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class GutterBlameAnnotationProvider extends BlameAnnotationProviderBase {
super(container, onDidChangeStatus, 'blame', editor, trackedDocument);
}

override async clear() {
override async clear(): Promise<void> {
await super.clear();

if (Decorations.gutterBlameHighlight != null) {
Expand Down
8 changes: 4 additions & 4 deletions src/annotations/gutterChangesAnnotationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class GutterChangesAnnotationProvider extends AnnotationProviderBase<Chan
return !(this.annotationContext?.sha !== context?.sha || this.annotationContext?.only !== context?.only);
}

override clear() {
override clear(): Promise<void> {
this.state = undefined;
if (this.hoverProviderDisposable != null) {
this.hoverProviderDisposable.dispose();
Expand All @@ -49,7 +49,7 @@ export class GutterChangesAnnotationProvider extends AnnotationProviderBase<Chan
return super.clear();
}

override nextChange() {
override nextChange(): void {
if (this.sortedHunkStarts == null) return;

let nextLine = -1;
Expand All @@ -74,7 +74,7 @@ export class GutterChangesAnnotationProvider extends AnnotationProviderBase<Chan
}
}

override previousChange() {
override previousChange(): void {
if (this.sortedHunkStarts == null) return;

let previousLine = -1;
Expand Down Expand Up @@ -261,7 +261,7 @@ export class GutterChangesAnnotationProvider extends AnnotationProviderBase<Chan
return true;
}

registerHoverProvider() {
registerHoverProvider(): void {
const cfg = configuration.get('hovers');
if (!cfg.enabled || !cfg.annotations.enabled) return;

Expand Down
12 changes: 6 additions & 6 deletions src/annotations/lineAnnotationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class LineAnnotationController implements Disposable {
);
}

dispose() {
dispose(): void {
this.clearAnnotations(this._editor);

this.container.lineTracker.unsubscribe(this);
Expand Down Expand Up @@ -72,12 +72,12 @@ export class LineAnnotationController implements Disposable {
}

private _suspended: boolean = false;
get suspended() {
get suspended(): boolean {
return !this._enabled || this._suspended;
}

@log()
resume() {
resume(): boolean {
this.setLineTracker(true);

if (this._suspended) {
Expand All @@ -89,7 +89,7 @@ export class LineAnnotationController implements Disposable {
}

@log()
suspend() {
suspend(): boolean {
this.setLineTracker(false);

if (!this._suspended) {
Expand Down Expand Up @@ -123,7 +123,7 @@ export class LineAnnotationController implements Disposable {
}

@debug({ args: false, singleLine: true })
clear(editor: TextEditor | undefined) {
clear(editor: TextEditor | undefined): void {
this._cancellation?.cancel();
if (this._editor !== editor && this._editor != null) {
this.clearAnnotations(this._editor);
Expand All @@ -132,7 +132,7 @@ export class LineAnnotationController implements Disposable {
}

@log({ args: false })
async toggle(editor: TextEditor | undefined) {
async toggle(editor: TextEditor | undefined): Promise<void> {
this._enabled = !(this._enabled && !this.suspended);

if (this._enabled) {
Expand Down
6 changes: 3 additions & 3 deletions src/api/actionRunners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class RegisteredActionRunner<T extends ActionContext = ActionContext> implements
this.id = runnerIdGenerator.next();
}

dispose() {
dispose(): void {
this.unregister();
}

Expand Down Expand Up @@ -146,7 +146,7 @@ export class ActionRunners implements Disposable {
this._disposable = Disposable.from(...subscriptions);
}

dispose() {
dispose(): void {
this._disposable.dispose();

for (const runners of this._actionRunners.values()) {
Expand Down Expand Up @@ -238,7 +238,7 @@ export class ActionRunners implements Disposable {
);
}

async run<T extends ActionContext>(context: T, runnerId?: number) {
async run<T extends ActionContext>(context: T, runnerId?: number): Promise<void> {
let runners = this.get(context.type);
if (runners == null || runners.length === 0) return;

Expand Down
Loading

0 comments on commit b881fcd

Please sign in to comment.