diff --git a/CHANGELOG.md b/CHANGELOG.md index 972b44b..02caf22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to the "magento-toolbox" extension will be documented in thi Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. ## [Unreleased] +- Fixed: Generated plugin class arguments contain an incorrect namespace + +## [1.3.0] - 2025-03-17 - Added: Jump to module command - Changed: All dropdown inputs now support searching diff --git a/package-lock.json b/package-lock.json index 5d3bf45..dc40875 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "magebit-magento-toolbox", - "version": "1.2.0", + "version": "1.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "magebit-magento-toolbox", - "version": "1.2.0", + "version": "1.3.0", "dependencies": { "@types/handlebars": "^4.1.0", "@vscode-elements/elements": "^1.11.0", diff --git a/package.json b/package.json index f596acc..6b02ad5 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Magento 2 code generation, inspection and utility tools", "publisher": "magebit", "icon": "resources/logo.jpg", - "version": "1.2.0", + "version": "1.3.0", "engines": { "vscode": "^1.93.1" }, diff --git a/src/generator/plugin/PluginClassGenerator.ts b/src/generator/plugin/PluginClassGenerator.ts index cf25460..471a4fc 100644 --- a/src/generator/plugin/PluginClassGenerator.ts +++ b/src/generator/plugin/PluginClassGenerator.ts @@ -89,9 +89,22 @@ export default class PluginClassGenerator extends FileGenerator { return type; } - const namespace = this.subjectClass.namespace; - const typeName = type.startsWith('\\') ? type.slice(1) : type; + if (type.startsWith('\\')) { + return type; + } + + if (type === this.subjectClass.name) { + return `${this.subjectClass.namespace}\\${type}`; + } + + const useItems = this.subjectClass.parent.useItems; + + for (const useItem of useItems) { + if (useItem.name === type) { + return useItem.fullName; + } + } - return `${namespace}\\${typeName}`; + return type; } } diff --git a/src/parser/php/PhpUseItem.ts b/src/parser/php/PhpUseItem.ts index 575d798..4f0bbe8 100644 --- a/src/parser/php/PhpUseItem.ts +++ b/src/parser/php/PhpUseItem.ts @@ -13,18 +13,15 @@ export class PhpUseItem extends PhpNode { } public get fullName() { - if (this.ast.alias) { - return this.ast.alias.name; - } return this.ast.name; } public get name() { - if (this.ast.alias) { - return this.ast.alias.name; - } - const parts = this.ast.name.split('\\'); return last(parts)!; } + + public get alias() { + return this.ast.alias?.name; + } }