Skip to content

Commit

Permalink
feat: ✨ add show path in the file name and update folder name validat…
Browse files Browse the repository at this point in the history
…ion regex pattern
  • Loading branch information
ManuelGil committed Mar 13, 2024
1 parent 51f168c commit d51cb48
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 58 deletions.
19 changes: 17 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.6.0] - 2024-03-12

### Added

- Add Show Path In File Name setting to show the path in the file name

### Changed

- Update the `ListFileController` class to use the `showPath` setting

### Fixed

- Fix the regex pattern to match the folder name to generate the file

## [1.5.0] - 2024-02-21

### Added

- Add `covertToTS` method to `example.controller.ts` file to convert a JSON Schema to TypeScript
- Add `convertToTS` method to `example.controller.ts` file to convert a JSON Schema to TypeScript
- Add Convert to TypeScript command to convert a JSON Schema to TypeScript

### Changed
Expand Down Expand Up @@ -136,7 +150,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fix file creation issue when creating a new file

[unreleased]: https://github.com/ManuelGil/extension-starter-kit/compare/v1.5.0...HEAD
[unreleased]: https://github.com/ManuelGil/extension-starter-kit/compare/v1.6.0...HEAD
[1.6.0]: https://github.com/ManuelGil/extension-starter-kit/compare/v1.5.0...v1.6.0
[1.5.0]: https://github.com/ManuelGil/extension-starter-kit/compare/v1.4.0...v1.5.0
[1.4.0]: https://github.com/ManuelGil/extension-starter-kit/compare/v1.3.0...v1.4.0
[1.3.0]: https://github.com/ManuelGil/extension-starter-kit/compare/v1.2.0...v1.3.0
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
"scope": "resource",
"description": "Glob patterns to exclude from the package. The default is node_modules, dist, out, build, and any hidden files."
},
"extension-starter-kit.files.showPath": {
"type": "boolean",
"default": true,
"scope": "resource",
"description": "Show the path of the file in the name of the list of generated files"
},
"extension-starter-kit.openai.apiKey": {
"type": "string",
"default": "",
Expand Down
6 changes: 6 additions & 0 deletions schemas/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
"scope": "resource",
"description": "Glob patterns to exclude from the package. The default is node_modules, dist, out, build, and any hidden files."
},
"extension-starter-kit.files.showPath": {
"type": "boolean",
"default": true,
"scope": "resource",
"description": "Show the path of the file in the name of the list of generated files"
},
"extension-starter-kit.openai.apiKey": {
"type": "string",
"default": "",
Expand Down
38 changes: 26 additions & 12 deletions src/app/configs/constants.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @returns {string} - The unique identifier of the extension
*/
export const EXTENSION_ID = 'extension-starter-kit';
export const EXTENSION_ID: string = 'extension-starter-kit';

/**
* EXTENSION_NAME: The name of the extension.
Expand All @@ -20,7 +20,7 @@ export const EXTENSION_ID = 'extension-starter-kit';
*
* @returns {string} - The name of the extension
*/
export const EXTENSION_NAME = 'MyExtension';
export const EXTENSION_NAME: string = 'MyExtension';

/**
* EXTENSION_HOMEPAGE_URL: The homepage URL of the extension.
Expand All @@ -32,7 +32,7 @@ export const EXTENSION_NAME = 'MyExtension';
*
* @returns {string} - The homepage URL of the extension
*/
export const EXTENSION_HOMEPAGE_URL =
export const EXTENSION_HOMEPAGE_URL: string =
'https://github.com/ManuelGil/extension-starter-kit';

/**
Expand All @@ -45,7 +45,7 @@ export const EXTENSION_HOMEPAGE_URL =
*
* @returns {string} - The documentation URL of the extension
*/
export const EXTENSION_DOCUMENTATION_URL =
export const EXTENSION_DOCUMENTATION_URL: string =
'https://github.com/ManuelGil/extension-starter-kit';

/**
Expand All @@ -58,7 +58,7 @@ export const EXTENSION_DOCUMENTATION_URL =
*
* @returns {string} - The repository URL of the extension
*/
export const EXTENSION_REPOSITORY_URL =
export const EXTENSION_REPOSITORY_URL: string =
'https://github.com/ManuelGil/extension-starter-kit';

/**
Expand All @@ -71,7 +71,7 @@ export const EXTENSION_REPOSITORY_URL =
*
* @returns {string} - The marketplace URL of the extension
*/
export const EXTENSION_MARKETPLACE_URL =
export const EXTENSION_MARKETPLACE_URL: string =
'https://marketplace.visualstudio.com/items?itemName=imgildev.extension-starter-kit';

/**
Expand All @@ -84,7 +84,7 @@ export const EXTENSION_MARKETPLACE_URL =
*
* @returns {string} - The bugs URL of the extension
*/
export const EXTENSION_BUGS_URL =
export const EXTENSION_BUGS_URL: string =
'https://github.com/ManuelGil/extension-starter-kit/issues';

/**
Expand All @@ -97,7 +97,8 @@ export const EXTENSION_BUGS_URL =
*
* @returns {string} - The social media URL of the extension
*/
export const EXTENSION_SOCIAL_MEDIA_URL = 'https://github.com/ManuelGil';
export const EXTENSION_SOCIAL_MEDIA_URL: string =
'https://github.com/ManuelGil';

/**
* EXTENSION_SPONSOR_URL: The sponsor URL of the extension.
Expand All @@ -109,7 +110,8 @@ export const EXTENSION_SOCIAL_MEDIA_URL = 'https://github.com/ManuelGil';
*
* @returns {string} - The sponsor URL of the extension
*/
export const EXTENSION_SPONSOR_URL = 'https://github.com/sponsors/ManuelGil';
export const EXTENSION_SPONSOR_URL: string =
'https://github.com/sponsors/ManuelGil';

/**
* EXTENSION_PAYPAL_URL: The PayPal URL of the extension.
Expand All @@ -121,7 +123,7 @@ export const EXTENSION_SPONSOR_URL = 'https://github.com/sponsors/ManuelGil';
*
* @returns {string} - The PayPal URL of the extension
*/
export const EXTENSION_PAYPAL_URL =
export const EXTENSION_PAYPAL_URL: string =
'https://www.paypal.com/paypalme/ManuelFGil';

/**
Expand All @@ -134,7 +136,7 @@ export const EXTENSION_PAYPAL_URL =
*
* @returns {string[]} - The files to include
*/
export const INCLUDE = ['ts', 'html', 'css', 'scss', 'less'];
export const INCLUDE: string[] = ['ts', 'html', 'css', 'scss', 'less'];
/**
* EXCLUDE: The files to exclude.
* @type {string[]}
Expand All @@ -145,10 +147,22 @@ export const INCLUDE = ['ts', 'html', 'css', 'scss', 'less'];
*
* @returns {string[]} - The files to exclude
*/
export const EXCLUDE = [
export const EXCLUDE: string[] = [
'**/node_modules/**',
'**/dist/**',
'**/out/**',
'**/build/**',
'**/.*/**',
];

/**
* SHOW_PATH: Whether to show the path or not.
* @type {boolean}
* @public
* @memberof Constants
* @example
* console.log(SHOW_PATH);
*
* @returns {boolean} - Whether to show the path or not
*/
export const SHOW_PATH: boolean = true;
14 changes: 13 additions & 1 deletion src/app/configs/extension.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { WorkspaceConfiguration } from 'vscode';

import { EXCLUDE, INCLUDE } from './constants.config';
import { EXCLUDE, INCLUDE, SHOW_PATH } from './constants.config';

/**
* The Config class.
Expand Down Expand Up @@ -44,6 +44,16 @@ export class ExtensionConfig {
* console.log(config.exclude);
*/
exclude: string[];
/**
* Whether to show the path or not.
* @type {boolean}
* @public
* @memberof Config
* @example
* const config = new Config(workspace.getConfiguration());
* console.log(config.showPath);
*/
showPath: boolean;
/**
* The OpenAI API key.
* @type {string}
Expand Down Expand Up @@ -73,6 +83,7 @@ export class ExtensionConfig {
constructor(readonly config: WorkspaceConfiguration) {
this.include = config.get<string[]>('files.include') ?? INCLUDE;
this.exclude = config.get<string[]>('files.exclude') ?? EXCLUDE;
this.showPath = config.get<boolean>('showPath') ?? SHOW_PATH;
this.openai = {
apiKey: config.get<string>('openai.apiKey') ?? '',
model: config.get<string>('openai.model') ?? '',
Expand All @@ -98,6 +109,7 @@ export class ExtensionConfig {
update(config: WorkspaceConfiguration): void {
this.include = config.get<string[]>('files.include') ?? INCLUDE;
this.exclude = config.get<string[]>('files.exclude') ?? EXCLUDE;
this.showPath = config.get<boolean>('showPath') ?? SHOW_PATH;
this.openai = {
apiKey: config.get<string>('openai.apiKey') ?? '',
model: config.get<string>('openai.model') ?? '',
Expand Down
2 changes: 1 addition & 1 deletion src/app/controllers/example.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class ExampleController {
'Folder name',
folderPath,
(path: string) => {
if (!/^\/|([\/\w-]+)+$/.test(path)) {
if (!/^\/|([\w\d\-_]+\/?(?!\/))+$/.test(path)) {
return 'The folder name must be a valid name';
}
return;
Expand Down
11 changes: 9 additions & 2 deletions src/app/controllers/list-files.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from 'vscode';

import { ExtensionConfig } from '../configs';
import { directoryMap } from '../helpers';
import { directoryMap, getRelativePath } from '../helpers';
import { NodeModel } from '../models';

/**
Expand Down Expand Up @@ -74,9 +74,16 @@ export class ListFilesController {
for (const file of files) {
const document = await workspace.openTextDocument(file);

const path = await getRelativePath(document.fileName);
let filename = path.split('/').pop();

if (filename && this.config.showPath) {
filename += ' (' + path.split('/').slice(0, -1).join('/') + ')';
}

nodes.push(
new NodeModel(
document.fileName.replace(/\\/g, '/').split('/').pop() ?? 'unknown',
filename ?? 'Untitled',
new ThemeIcon('file'),
undefined,
document.uri,
Expand Down
4 changes: 2 additions & 2 deletions src/app/providers/chat.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class ChatProvider implements WebviewViewProvider {
* @memberof ChatProvider
* @type {string}
*/
public static readonly viewType = `${EXTENSION_ID}.chatView`;
static readonly viewType: string = `${EXTENSION_ID}.chatView`;

// Private properties
/**
Expand Down Expand Up @@ -131,7 +131,7 @@ export class ChatProvider implements WebviewViewProvider {
*
* @returns {void} - No return value
*/
public setService(service: OpenAIService): void {
setService(service: OpenAIService): void {
this.openAISservice = service;
}

Expand Down
28 changes: 14 additions & 14 deletions src/app/providers/feedback.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ export class FeedbackProvider implements TreeDataProvider<NodeModel> {
// Properties
// -----------------------------------------------------------------

// Public properties
/**
* The onDidChangeTreeData event.
* @type {Event<NodeModel | undefined | null | void>}
* @public
* @memberof FeedbackProvider
* @example
* readonly onDidChangeTreeData: Event<Node | undefined | null | void>;
* this.onDidChangeTreeData = this._onDidChangeTreeData.event;
*
* @see https://code.visualstudio.com/api/references/vscode-api#Event
*/
readonly onDidChangeTreeData: Event<NodeModel | undefined | null | void>;

// Private properties
/**
* The onDidChangeTreeData event emitter.
Expand All @@ -48,20 +62,6 @@ export class FeedbackProvider implements TreeDataProvider<NodeModel> {
NodeModel | undefined | null | void
>;

// Public properties
/**
* The onDidChangeTreeData event.
* @type {Event<NodeModel | undefined | null | void>}
* @public
* @memberof FeedbackProvider
* @example
* readonly onDidChangeTreeData: Event<Node | undefined | null | void>;
* this.onDidChangeTreeData = this._onDidChangeTreeData.event;
*
* @see https://code.visualstudio.com/api/references/vscode-api#Event
*/
readonly onDidChangeTreeData: Event<NodeModel | undefined | null | void>;

// -----------------------------------------------------------------
// Constructor
// -----------------------------------------------------------------
Expand Down
28 changes: 14 additions & 14 deletions src/app/providers/list-files.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ export class ListFilesProvider implements TreeDataProvider<NodeModel> {
// Properties
// -----------------------------------------------------------------

// Public properties
/**
* The onDidChangeTreeData event.
* @type {Event<NodeModel | undefined | null | void>}
* @public
* @memberof ListFilesProvider
* @example
* readonly onDidChangeTreeData: Event<Node | undefined | null | void>;
* this.onDidChangeTreeData = this._onDidChangeTreeData.event;
*
* @see https://code.visualstudio.com/api/references/vscode-api#Event
*/
readonly onDidChangeTreeData: Event<NodeModel | undefined | null | void>;

// Private properties
/**
* The onDidChangeTreeData event emitter.
Expand All @@ -47,20 +61,6 @@ export class ListFilesProvider implements TreeDataProvider<NodeModel> {
NodeModel | undefined | null | void
>;

// Public properties
/**
* The onDidChangeTreeData event.
* @type {Event<NodeModel | undefined | null | void>}
* @public
* @memberof ListFilesProvider
* @example
* readonly onDidChangeTreeData: Event<Node | undefined | null | void>;
* this.onDidChangeTreeData = this._onDidChangeTreeData.event;
*
* @see https://code.visualstudio.com/api/references/vscode-api#Event
*/
readonly onDidChangeTreeData: Event<NodeModel | undefined | null | void>;

// -----------------------------------------------------------------
// Constructor
// -----------------------------------------------------------------
Expand Down
18 changes: 8 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ export function activate(context: vscode.ExtensionContext) {
// Create a new ListFilesController
const listFilesController = new ListFilesController(config);

const disposableOpenFile = vscode.commands.registerCommand(
`${EXTENSION_ID}.listFiles.openFile`,
(uri) => listFilesController.openFile(uri),
);

context.subscriptions.push(disposableOpenFile);

// -----------------------------------------------------------------
// Register ListFilesProvider and list commands
// -----------------------------------------------------------------
Expand All @@ -107,16 +114,7 @@ export function activate(context: vscode.ExtensionContext) {
() => listFilesProvider.refresh(),
);

const disposableOpenFile = vscode.commands.registerCommand(
`${EXTENSION_ID}.listFiles.openFile`,
(uri) => listFilesProvider.controller.openFile(uri),
);

context.subscriptions.push(
listFilesTreeView,
disposableRefreshList,
disposableOpenFile,
);
context.subscriptions.push(listFilesTreeView, disposableRefreshList);

// -----------------------------------------------------------------
// Register ListFilesProvider and ListMethodsProvider events
Expand Down

0 comments on commit d51cb48

Please sign in to comment.