Skip to content

Commit

Permalink
Refactor: simplify ITypedDirectory to interface
Browse files Browse the repository at this point in the history
  • Loading branch information
maxisam committed Oct 25, 2024
1 parent b8e498e commit d902e2d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/operator/DirectoryOperator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import * as vscode from 'vscode';
import { MY_FOLDER_DIRECTORY_CONTEXT } from '../core/constants';
import type { IConfiguration } from '../types/Configuration';
import type { FileSystemObject } from '../types/FileSystemObject';
import type { TypedDirectory } from '../types/TypedDirectory';
import { buildTypedDirectory, createFileSystemObject, focusFileExplorer } from '../utils';
import type { ITypedDirectory } from '../types/TypedDirectory';
import { getConfigurationAsync, updateConfigurationAsync } from '../utils/configUtils';
import { buildTypedDirectory, createFileSystemObject, focusFileExplorer } from '../utils/utils';

export class DirectoryOperator {
readonly myFolderDirContextValue: string = MY_FOLDER_DIRECTORY_CONTEXT;
private bookmarkedDirectories: TypedDirectory[] = [];
private bookmarkedDirectories: ITypedDirectory[] = [];
private hideContent: boolean = false;

constructor(
Expand Down Expand Up @@ -91,7 +91,7 @@ export class DirectoryOperator {
});
}

private async createEntries(bookmarkedDirectories: TypedDirectory[]) {
private async createEntries(bookmarkedDirectories: ITypedDirectory[]) {
const fileSystem: FileSystemObject[] = [];

for (const dir of bookmarkedDirectories) {
Expand Down
4 changes: 2 additions & 2 deletions src/types/Configuration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { TypedDirectory } from './TypedDirectory';
import type { ITypedDirectory } from './TypedDirectory';

export interface IConfiguration {
bookmarkedDirectories: TypedDirectory[];
bookmarkedDirectories: ITypedDirectory[];
hideContent: boolean;
/**
* Allow users to specify a custom path for the settings file, so it will be useful if the users
Expand Down
10 changes: 1 addition & 9 deletions src/types/TypedDirectory.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import * as filePath from 'path';

import type * as vscode from 'vscode';

export class TypedDirectory {
export interface ITypedDirectory {
name: string;
path: string;
type: vscode.FileType;

constructor(path: string, type: vscode.FileType, name?: string | undefined) {
this.path = path;
this.type = type;
this.name = name || filePath.basename(path) || path;
}
}
14 changes: 10 additions & 4 deletions src/utils.ts → src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import * as path from 'path';

import * as vscode from 'vscode';

import { FileSystemObject } from './types/FileSystemObject';
import { TypedDirectory } from './types/TypedDirectory';
import { FileSystemObject } from '../types/FileSystemObject';
import type { ITypedDirectory } from '../types/TypedDirectory';

export async function buildTypedDirectory(uri: vscode.Uri, name?: string | undefined) {
export async function buildTypedDirectory(
uri: vscode.Uri,
name?: string,
): Promise<ITypedDirectory> {
const type = (await vscode.workspace.fs.stat(uri)).type;
return new TypedDirectory(uri.path, type, name);
const _name = name || path.basename(uri.path) || uri.path;
return { name: _name, path: uri.path, type };
}

export function createFileSystemObject(
Expand Down

0 comments on commit d902e2d

Please sign in to comment.