diff --git a/CHANGELOG.md b/CHANGELOG.md index 01b57a4..7b25f81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/package.json b/package.json index 2c0957c..23d4d6a 100644 --- a/package.json +++ b/package.json @@ -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": "", diff --git a/schemas/config.schema.json b/schemas/config.schema.json index aece607..59461e2 100644 --- a/schemas/config.schema.json +++ b/schemas/config.schema.json @@ -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": "", diff --git a/src/app/configs/constants.config.ts b/src/app/configs/constants.config.ts index 45e9b6a..f88c8f5 100644 --- a/src/app/configs/constants.config.ts +++ b/src/app/configs/constants.config.ts @@ -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. @@ -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. @@ -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'; /** @@ -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'; /** @@ -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'; /** @@ -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'; /** @@ -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'; /** @@ -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. @@ -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. @@ -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'; /** @@ -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[]} @@ -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; diff --git a/src/app/configs/extension.config.ts b/src/app/configs/extension.config.ts index 626e602..9bebbe7 100644 --- a/src/app/configs/extension.config.ts +++ b/src/app/configs/extension.config.ts @@ -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. @@ -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} @@ -73,6 +83,7 @@ export class ExtensionConfig { constructor(readonly config: WorkspaceConfiguration) { this.include = config.get('files.include') ?? INCLUDE; this.exclude = config.get('files.exclude') ?? EXCLUDE; + this.showPath = config.get('showPath') ?? SHOW_PATH; this.openai = { apiKey: config.get('openai.apiKey') ?? '', model: config.get('openai.model') ?? '', @@ -98,6 +109,7 @@ export class ExtensionConfig { update(config: WorkspaceConfiguration): void { this.include = config.get('files.include') ?? INCLUDE; this.exclude = config.get('files.exclude') ?? EXCLUDE; + this.showPath = config.get('showPath') ?? SHOW_PATH; this.openai = { apiKey: config.get('openai.apiKey') ?? '', model: config.get('openai.model') ?? '', diff --git a/src/app/controllers/example.controller.ts b/src/app/controllers/example.controller.ts index d037afe..3c3d46d 100644 --- a/src/app/controllers/example.controller.ts +++ b/src/app/controllers/example.controller.ts @@ -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; diff --git a/src/app/controllers/list-files.controller.ts b/src/app/controllers/list-files.controller.ts index 171bbb8..faad1aa 100644 --- a/src/app/controllers/list-files.controller.ts +++ b/src/app/controllers/list-files.controller.ts @@ -9,7 +9,7 @@ import { } from 'vscode'; import { ExtensionConfig } from '../configs'; -import { directoryMap } from '../helpers'; +import { directoryMap, getRelativePath } from '../helpers'; import { NodeModel } from '../models'; /** @@ -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, diff --git a/src/app/providers/chat.provider.ts b/src/app/providers/chat.provider.ts index d0ccff6..95489c6 100644 --- a/src/app/providers/chat.provider.ts +++ b/src/app/providers/chat.provider.ts @@ -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 /** @@ -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; } diff --git a/src/app/providers/feedback.provider.ts b/src/app/providers/feedback.provider.ts index 86f06c4..fb2a278 100644 --- a/src/app/providers/feedback.provider.ts +++ b/src/app/providers/feedback.provider.ts @@ -32,6 +32,20 @@ export class FeedbackProvider implements TreeDataProvider { // Properties // ----------------------------------------------------------------- + // Public properties + /** + * The onDidChangeTreeData event. + * @type {Event} + * @public + * @memberof FeedbackProvider + * @example + * readonly onDidChangeTreeData: Event; + * this.onDidChangeTreeData = this._onDidChangeTreeData.event; + * + * @see https://code.visualstudio.com/api/references/vscode-api#Event + */ + readonly onDidChangeTreeData: Event; + // Private properties /** * The onDidChangeTreeData event emitter. @@ -48,20 +62,6 @@ export class FeedbackProvider implements TreeDataProvider { NodeModel | undefined | null | void >; - // Public properties - /** - * The onDidChangeTreeData event. - * @type {Event} - * @public - * @memberof FeedbackProvider - * @example - * readonly onDidChangeTreeData: Event; - * this.onDidChangeTreeData = this._onDidChangeTreeData.event; - * - * @see https://code.visualstudio.com/api/references/vscode-api#Event - */ - readonly onDidChangeTreeData: Event; - // ----------------------------------------------------------------- // Constructor // ----------------------------------------------------------------- diff --git a/src/app/providers/list-files.providers.ts b/src/app/providers/list-files.providers.ts index 2b31893..e4eba95 100644 --- a/src/app/providers/list-files.providers.ts +++ b/src/app/providers/list-files.providers.ts @@ -31,6 +31,20 @@ export class ListFilesProvider implements TreeDataProvider { // Properties // ----------------------------------------------------------------- + // Public properties + /** + * The onDidChangeTreeData event. + * @type {Event} + * @public + * @memberof ListFilesProvider + * @example + * readonly onDidChangeTreeData: Event; + * this.onDidChangeTreeData = this._onDidChangeTreeData.event; + * + * @see https://code.visualstudio.com/api/references/vscode-api#Event + */ + readonly onDidChangeTreeData: Event; + // Private properties /** * The onDidChangeTreeData event emitter. @@ -47,20 +61,6 @@ export class ListFilesProvider implements TreeDataProvider { NodeModel | undefined | null | void >; - // Public properties - /** - * The onDidChangeTreeData event. - * @type {Event} - * @public - * @memberof ListFilesProvider - * @example - * readonly onDidChangeTreeData: Event; - * this.onDidChangeTreeData = this._onDidChangeTreeData.event; - * - * @see https://code.visualstudio.com/api/references/vscode-api#Event - */ - readonly onDidChangeTreeData: Event; - // ----------------------------------------------------------------- // Constructor // ----------------------------------------------------------------- diff --git a/src/extension.ts b/src/extension.ts index 63d1117..2c21b41 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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 // ----------------------------------------------------------------- @@ -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