Skip to content

Commit

Permalink
nested sorting and misc sorting added
Browse files Browse the repository at this point in the history
  • Loading branch information
HYP3R00T committed Aug 10, 2024
1 parent 11626d0 commit 2e09ce3
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,31 @@ function categorizeSettings(settings: any) {
"remote",
];

// Helper function to recursively sort objects
function sortObject(obj: any): any {
if (typeof obj !== "object" || obj === null) {
return obj;
}

if (Array.isArray(obj)) {
return obj.map(sortObject);
}

const sorted: { [key: string]: any } = {};
Object.keys(obj)
.sort()
.forEach((key) => {
sorted[key] = sortObject(obj[key]);
});

return sorted;
}

// Sort settings based on categories
categoriesOrder.forEach((category) => {
for (const key in settings) {
if (key.startsWith(category)) {
sortedSettings[key] = settings[key];
sortedSettings[key] = sortObject(settings[key]);
}
}
});
Expand All @@ -126,21 +146,28 @@ function categorizeSettings(settings: any) {
}
}

// Sort language-specific settings alphabetically
// Sort language-specific settings alphabetically and their nested objects
const sortedLanguageSettingsKeys = Object.keys(languageSettings).sort();
sortedLanguageSettingsKeys.forEach((key) => {
sortedSettings[key] = languageSettings[key];
sortedSettings[key] = sortObject(languageSettings[key]);
});

// Add any miscellaneous settings that don't fit into categories
const miscellaneousSettings: { [key: string]: any } = {};
for (const key in settings) {
if (
!categoriesOrder.some((category) => key.startsWith(category)) &&
!(key.startsWith("[") && key.endsWith("]"))
) {
sortedSettings[key] = settings[key];
miscellaneousSettings[key] = settings[key];
}
}

// Sort miscellaneous settings alphabetically
const sortedMiscellaneousKeys = Object.keys(miscellaneousSettings).sort();
sortedMiscellaneousKeys.forEach((key) => {
sortedSettings[key] = miscellaneousSettings[key];
});

return sortedSettings;
}

0 comments on commit 2e09ce3

Please sign in to comment.