Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 38 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
"command": "slingr-vscode-extension.changeFieldType",
"title": "Change type"
},
{
"command": "slingr-vscode-extension.changeFieldToArray",
"title": "Change to array"
},
{
"command": "slingr-vscode-extension.changeFieldToSingleValue",
"title": "Change to single value"
},
{
"command": "slingr.runInfraUpdate",
"title": "Run infrastructure update"
Expand Down Expand Up @@ -187,19 +195,29 @@
},
{
"command": "slingr-vscode-extension.renameField",
"when": "view == slingrExplorer && viewItem == 'field'",
"when": "view == slingrExplorer && viewItem =~ /field(Single|Array)/",
"group": "0_modification@1"
},
{
"command": "slingr-vscode-extension.changeFieldType",
"when": "view == slingrExplorer && viewItem == 'field'",
"when": "view == slingrExplorer && viewItem =~ /field(Single|Array)/",
"group": "0_modification@2"
},
{
"command": "slingr-vscode-extension.deleteField",
"when": "view == slingrExplorer && viewItem == 'field'",
"command": "slingr-vscode-extension.changeFieldToArray",
"when": "view == slingrExplorer && viewItem == 'fieldSingle'",
"group": "0_modification@3"
},
{
"command": "slingr-vscode-extension.changeFieldToSingleValue",
"when": "view == slingrExplorer && viewItem == 'fieldArray'",
"group": "0_modification@4"
},
{
"command": "slingr-vscode-extension.deleteField",
"when": "view == slingrExplorer && viewItem =~ /field(Single|Array)/",
"group": "0_modification@5"
},
{
"command": "slingr-vscode-extension.newFolder",
"when": "view == slingrExplorer && viewItem == 'folder'",
Expand Down Expand Up @@ -301,17 +319,27 @@
},
{
"command": "slingr-vscode-extension.renameField",
"when": "view == slingrExplorer && viewItem == 'field'",
"when": "view == slingrExplorer && viewItem =~ /field(Single|Array)/",
"group": "1_modification@4"
},
{
"command": "slingr-vscode-extension.changeFieldType",
"when": "view == slingrExplorer && viewItem == 'field'",
"when": "view == slingrExplorer && viewItem =~ /field(Single|Array)/",
"group": "1_modification@5"
},
{
"command": "slingr-vscode-extension.changeFieldToArray",
"when": "view == slingrExplorer && viewItem == 'fieldSingle'",
"group": "1_modification@6"
},
{
"command": "slingr-vscode-extension.changeFieldToSingleValue",
"when": "view == slingrExplorer && viewItem == 'fieldArray'",
"group": "1_modification@7"
},
{
"command": "slingr-vscode-extension.deleteField",
"when": "view == slingrExplorer && viewItem == 'field'",
"when": "view == slingrExplorer && viewItem =~ /field(Single|Array)/",
"group": "2_modification@3"
}
]
Expand All @@ -330,7 +358,7 @@
{
"id": "slingrExplorer",
"name": "Slingr Explorer",
"icon": "resources/slingr-icon.jpg"
"icon": "resources/slingr-icon.jpg"
},
{
"id": "slingrQuickInfo",
Expand All @@ -352,6 +380,7 @@
"devDependencies": {
"@types/mocha": "^10.0.10",
"@types/node": "22.x",
"@types/pluralize": "^0.0.33",
"@types/vscode": "^1.103.0",
"@typescript-eslint/eslint-plugin": "^8.39.0",
"@typescript-eslint/parser": "^8.39.0",
Expand All @@ -361,6 +390,7 @@
"typescript": "^5.9.2"
},
"dependencies": {
"pluralize": "^8.0.0",
"ts-morph": "^26.0.0"
}
}
6 changes: 3 additions & 3 deletions src/cache/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,16 +721,16 @@ export class MetadataCache {
/**
* Gets a clean, human-readable name for a ts-morph Type object.
* This method correctly handles imported types, removing the "import(...)" part,
* and properly extracts element types from arrays.
* and preserves array notation for array types.
* @param type The ts-morph Type object.
* @returns The clean type name as a string.
*/
private getCleanTypeName(type: Type): string {
// Handle array types by extracting the element type
// Handle array types by preserving the array notation
if (type.isArray()) {
const elementType = type.getArrayElementType();
if (elementType) {
return this.getCleanTypeName(elementType);
return this.getCleanTypeName(elementType) + '[]';
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/explorer/appTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,19 @@ export class AppTreeItem extends vscode.TreeItem {
folderPath?: string
) {
super(label, collapsibleState);
this.contextValue = itemType;
this.folderPath = folderPath;

let finalContextValue = itemType;
if (itemType === 'field' && metadata && 'type' in metadata) {
const propMetadata = metadata as PropertyMetadata;
if (propMetadata.type.endsWith('[]')) {
finalContextValue = 'fieldArray';
} else {
finalContextValue = 'fieldSingle';
}
}
this.contextValue = finalContextValue;

// Icon logic
if (!this.extensionUri) {
console.warn(`[MyTreeItem] Extension URI not provided for item: "${label}". Local icons will not be loaded.`);
Expand Down Expand Up @@ -47,6 +57,8 @@ export class AppTreeItem extends vscode.TreeItem {
iconFileName = "database.svg";
break;
case "field":
case "fieldSingle":
case "fieldArray":
iconFileName = "field.svg";
break;
case "modelActionsFolder":
Expand Down
4 changes: 4 additions & 0 deletions src/refactor/refactorDisposables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { PropertyMetadata } from '../cache/cache';
import { fieldTypeConfig } from '../utils/fieldTypes';
import { RenameDataSourceTool } from './tools/renameDataSource';
import { DeleteDataSourceTool } from './tools/deleteDataSource';
import { ChangeFieldToArrayTool } from './tools/changeFieldToArray';
import { ChangeFieldToSingleValueTool } from './tools/changeFieldToSingleValue';

/**
* Returns an array of all available refactor tools for the application.
Expand All @@ -38,6 +40,8 @@ export function getAllRefactorTools(): IRefactorTool[] {
new RenameFieldTool(),
new DeleteFieldTool(),
new ChangeFieldTypeTool(),
new ChangeFieldToArrayTool(),
new ChangeFieldToSingleValueTool(),
new AddDecoratorTool(),
new RenameDataSourceTool(),
new DeleteDataSourceTool(),
Expand Down
12 changes: 12 additions & 0 deletions src/refactor/refactorInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ export interface DeleteDataSourcePayload extends BasePayload {
urisToDelete: vscode.Uri[];
}

export interface ChangeFieldToArrayPayload extends BasePayload {
field: PropertyMetadata;
modelName: string;
}

export interface ChangeFieldToSingleValuePayload extends BasePayload {
field: PropertyMetadata;
modelName: string;
}

// --- Discriminated Union for ChangeObject ---

/**
Expand All @@ -82,6 +92,8 @@ export type ChangePayloadMap = {
'ADD_DECORATOR': AddDecoratorPayload;
'RENAME_DATA_SOURCE': RenameDataSourcePayload;
'DELETE_DATA_SOURCE': DeleteDataSourcePayload;
'CHANGE_FIELD_TO_ARRAY': ChangeFieldToArrayPayload;
'CHANGE_FIELD_TO_SINGLE_VALUE': ChangeFieldToSingleValuePayload;
};

/**
Expand Down
Loading