Skip to content

Commit 08adc30

Browse files
committed
feat: jump to module command; added basic cursorrule for command generation
1 parent 053b92c commit 08adc30

File tree

5 files changed

+113
-29
lines changed

5 files changed

+113
-29
lines changed

.cursor/rules/commands.mdc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
description: Describes how to create and register new commands
3+
globs:
4+
alwaysApply: false
5+
---
6+
- Commands are located in src/command directory
7+
- Commands must extend the [Command.ts](mdc:src/command/Command.ts) abstract class or any other class that inherits it
8+
- New commands must be added to [index.ts](mdc:src/command/index.ts) file so that they are loaded. Commands also need to be added to [package.json](mdc:package.json) under contributes -> commands
9+
- Commands that only generate files based on a pre-defined template can extend the [SimpleTemplateGeneratorCommand.ts](mdc:src/command/SimpleTemplateGeneratorCommand.ts) class

package.json

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,111 +57,143 @@
5757
"commands": [
5858
{
5959
"command": "magento-toolbox.generateModule",
60-
"title": "Magento Toolbox: Generate Module"
60+
"title": "Generate Module",
61+
"category": "Magento Toolbox"
6162
},
6263
{
6364
"command": "magento-toolbox.generateBlock",
64-
"title": "Magento Toolbox: Generate Block"
65+
"title": "Generate Block",
66+
"category": "Magento Toolbox"
6567
},
6668
{
6769
"command": "magento-toolbox.indexWorkspace",
68-
"title": "Magento Toolbox: Index Workspace"
70+
"title": "Index Workspace",
71+
"category": "Magento Toolbox"
6972
},
7073
{
7174
"command": "magento-toolbox.generateContextPlugin",
72-
"title": "Magento Toolbox: Generate Plugin"
75+
"title": "Generate Plugin",
76+
"category": "Magento Toolbox"
7377
},
7478
{
7579
"command": "magento-toolbox.copyMagentoPath",
76-
"title": "Magento Toolbox: Copy Magento Path"
80+
"title": "Copy Magento Path",
81+
"category": "Magento Toolbox"
7782
},
7883
{
7984
"command": "magento-toolbox.generateXmlCatalog",
80-
"title": "Magento Toolbox: Generate XML URN Catalog"
85+
"title": "Generate XML URN Catalog",
86+
"category": "Magento Toolbox"
8187
},
8288
{
8389
"command": "magento-toolbox.generateObserver",
84-
"title": "Magento Toolbox: Generate Observer"
90+
"title": "Generate Observer",
91+
"category": "Magento Toolbox"
8592
},
8693
{
8794
"command": "magento-toolbox.generateEventsXml",
88-
"title": "Magento Toolbox: Generate Events XML"
95+
"title": "Generate Events XML",
96+
"category": "Magento Toolbox"
8997
},
9098
{
9199
"command": "magento-toolbox.generateGraphqlSchemaFile",
92-
"title": "Magento Toolbox: Generate GraphQL Schema File"
100+
"title": "Generate GraphQL Schema File",
101+
"category": "Magento Toolbox"
93102
},
94103
{
95104
"command": "magento-toolbox.generateRoutesXmlFile",
96-
"title": "Magento Toolbox: Generate Routes XML"
105+
"title": "Generate Routes XML",
106+
"category": "Magento Toolbox"
97107
},
98108
{
99109
"command": "magento-toolbox.generateAclXmlFile",
100-
"title": "Magento Toolbox: Generate ACL XML"
110+
"title": "Generate ACL XML",
111+
"category": "Magento Toolbox"
101112
},
102113
{
103114
"command": "magento-toolbox.generateDiXmlFile",
104-
"title": "Magento Toolbox: Generate DI XML"
115+
"title": "Generate DI XML",
116+
"category": "Magento Toolbox"
105117
},
106118
{
107119
"command": "magento-toolbox.generateWebapiXmlFile",
108-
"title": "Magento Toolbox: Generate Webapi XML"
120+
"title": "Generate Webapi XML",
121+
"category": "Magento Toolbox"
109122
},
110123
{
111124
"command": "magento-toolbox.generatePreference",
112-
"title": "Magento Toolbox: Generate Preference"
125+
"title": "Generate Preference",
126+
"category": "Magento Toolbox"
113127
},
114128
{
115129
"command": "magento-toolbox.generateLayoutXmlFile",
116-
"title": "Magento Toolbox: Generate Layout XML"
130+
"title": "Generate Layout XML",
131+
"category": "Magento Toolbox"
117132
},
118133
{
119134
"command": "magento-toolbox.generatePageTypesXmlFile",
120-
"title": "Magento Toolbox: Generate Page Types XML"
135+
"title": "Generate Page Types XML",
136+
"category": "Magento Toolbox"
121137
},
122138
{
123139
"command": "magento-toolbox.generateCrontabXmlFile",
124-
"title": "Magento Toolbox: Generate Crontab XML"
140+
"title": "Generate Crontab XML",
141+
"category": "Magento Toolbox"
125142
},
126143
{
127144
"command": "magento-toolbox.generateEmailTemplatesXmlFile",
128-
"title": "Magento Toolbox: Generate Email Templates XML"
145+
"title": "Generate Email Templates XML",
146+
"category": "Magento Toolbox"
129147
},
130148
{
131149
"command": "magento-toolbox.generateSectionsXmlFile",
132-
"title": "Magento Toolbox: Generate Sections XML"
150+
"title": "Generate Sections XML",
151+
"category": "Magento Toolbox"
133152
},
134153
{
135154
"command": "magento-toolbox.generateFieldsetXmlFile",
136-
"title": "Magento Toolbox: Generate Fieldset XML"
155+
"title": "Generate Fieldset XML",
156+
"category": "Magento Toolbox"
137157
},
138158
{
139159
"command": "magento-toolbox.generateViewXmlFile",
140-
"title": "Magento Toolbox: Generate View XML"
160+
"title": "Generate View XML",
161+
"category": "Magento Toolbox"
141162
},
142163
{
143164
"command": "magento-toolbox.generateIndexerXmlFile",
144-
"title": "Magento Toolbox: Generate Indexer XML"
165+
"title": "Generate Indexer XML",
166+
"category": "Magento Toolbox"
145167
},
146168
{
147169
"command": "magento-toolbox.generateMviewXmlFile",
148-
"title": "Magento Toolbox: Generate MVIEW XML"
170+
"title": "Generate MVIEW XML",
171+
"category": "Magento Toolbox"
149172
},
150173
{
151174
"command": "magento-toolbox.generateWidgetXmlFile",
152-
"title": "Magento Toolbox: Generate Widget XML"
175+
"title": "Generate Widget XML",
176+
"category": "Magento Toolbox"
153177
},
154178
{
155179
"command": "magento-toolbox.generateExtensionAttributesXmlFile",
156-
"title": "Magento Toolbox: Generate Extension Attributes XML"
180+
"title": "Generate Extension Attributes XML",
181+
"category": "Magento Toolbox"
157182
},
158183
{
159184
"command": "magento-toolbox.generateSystemXmlFile",
160-
"title": "Magento Toolbox: Generate System XML"
185+
"title": "Generate System XML",
186+
"category": "Magento Toolbox"
161187
},
162188
{
163189
"command": "magento-toolbox.generateConfigXmlFile",
164-
"title": "Magento Toolbox: Generate Config XML"
190+
"title": "Generate Config XML",
191+
"category": "Magento Toolbox"
192+
},
193+
{
194+
"command": "magento-toolbox.jumpToModule",
195+
"title": "Jump to Module",
196+
"category": "Magento Toolbox"
165197
}
166198
],
167199
"menus": {

src/command/JumpToModuleCommand.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Command } from 'command/Command';
2+
import { window } from 'vscode';
3+
import IndexManager from 'indexer/IndexManager';
4+
import ModuleIndexer from 'indexer/module/ModuleIndexer';
5+
import { Uri } from 'vscode';
6+
7+
export default class JumpToModuleCommand extends Command {
8+
constructor() {
9+
super('magento-toolbox.jumpToModule');
10+
}
11+
12+
public async execute(...args: any[]): Promise<void> {
13+
const moduleIndexData = IndexManager.getIndexData(ModuleIndexer.KEY);
14+
15+
if (!moduleIndexData) {
16+
window.showErrorMessage('Module index data not found');
17+
return;
18+
}
19+
20+
const moduleName = await window.showInputBox({
21+
placeHolder: 'Enter module name (e.g. Magento_Catalog)',
22+
prompt: 'Enter the name of the module to jump to',
23+
});
24+
25+
if (!moduleName) {
26+
return;
27+
}
28+
29+
const module = moduleIndexData.getModule(moduleName);
30+
31+
if (!module) {
32+
window.showErrorMessage(`Module ${moduleName} not found`);
33+
return;
34+
}
35+
36+
const moduleXmlPath = Uri.file(`${module.path}/etc/module.xml`);
37+
38+
const document = await window.showTextDocument(moduleXmlPath);
39+
}
40+
}

src/command/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ export { default as GenerateWidgetXmlFileCommand } from './GenerateWidgetXmlFile
2525
export { default as GenerateExtensionAttributesXmlFileCommand } from './GenerateExtensionAttributesXmlFileCommand';
2626
export { default as GenerateSystemXmlFileCommand } from './GenerateSystemXmlFileCommand';
2727
export { default as GenerateConfigXmlFileCommand } from './GenerateConfigXmlFileCommand';
28+
export { default as JumpToModuleCommand } from './JumpToModuleCommand';

src/indexer/module/ModuleIndexData.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ export class ModuleIndexData extends AbstractIndexData<Module> {
1313
}));
1414
}
1515

16-
public getModule(name: string): Module | undefined {
17-
return this.getValues().find(module => module.name === name);
16+
public getModule(name: string, caseSensitive = false): Module | undefined {
17+
return this.getValues().find(module =>
18+
caseSensitive ? module.name === name : module.name.toLowerCase() === name.toLowerCase()
19+
);
1820
}
1921

2022
public getModuleByUri(uri: Uri, appOnly = true): Module | undefined {

0 commit comments

Comments
 (0)