Skip to content

Commit 50b625d

Browse files
authored
Merge pull request #111 from 1nVitr0/develop
2 parents e5b1ee3 + 369f04b commit 50b625d

File tree

10 files changed

+222
-77
lines changed

10 files changed

+222
-77
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ The blocks are sorted purely by their content, so while decorators are supported
6464
`Expand current Selection to surrounding Block`: Expand curren selection locally to surrounding lines in block.
6565

6666
`Expand current Selection fully (including separating Newlines) to the surrounding Block`: Expand curren selection to complete surrounding block.
67+
68+
`Quick Sort`: Shows a configurable list of sort commands, can be used to bind a keyboard shortcut.
6769
</details>
6870

6971
***
@@ -250,6 +252,43 @@ some:
250252
"indentationComplete": true
251253
}
252254
```
255+
- `quickSortCommands`: Commands to show when the quick sort is opened
256+
- Default:
257+
```json
258+
[
259+
{
260+
"command": "blocksort.sortBlocksAsc",
261+
"label": "$(sort-asc) Sort Blocks Ascending",
262+
"description": "Expand Selection and sort blocks in ascending order",
263+
"picked": true
264+
},
265+
{
266+
"command": "blocksort.sortBlocksDesc",
267+
"label": "$(sort-desc) Sort Blocks Descending",
268+
"description": "Expand Selection and sort blocks in descending order"
269+
},
270+
{
271+
"command": "blocksort.sortBlocksShuffle",
272+
"label": "$(arrow-switch) Shuffle Blocks",
273+
"description": "Expand Selection and shuffle blocks"
274+
},
275+
{
276+
"command": "editor.action.sortLinesAscending",
277+
"label": "$(sort-asc) Sort Lines Ascending",
278+
"description": "Sort selected lines in ascending order"
279+
},
280+
{
281+
"command": "editor.action.sortLinesDescending",
282+
"label": "$(sort-desc) Sort Lines Descending",
283+
"description": "Sort selected lines in descending order"
284+
},
285+
{
286+
"command": "blocksort.expandSelectionLocally",
287+
"label": "$(unfold) Expand Selection",
288+
"description": "Expand current Selection to surrounding Block"
289+
}
290+
]
291+
```
253292

254293
Settings marked as *Language Overridable* can be specified on a per-language basis using the notation:
255294

package.json

Lines changed: 111 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"onCommand:blocksort.sortInnerBlocksDesc",
3838
"onCommand:blocksort.sortInnerBlocksShuffle",
3939
"onCommand:blocksort.expandSelectionLocally",
40-
"onCommand:blocksort.expandSelectionFull"
40+
"onCommand:blocksort.expandSelectionFull",
41+
"onCommand:blocksort.quickSort"
4142
],
4243
"main": "./dist/extension.js",
4344
"contributes": {
@@ -140,6 +141,11 @@
140141
"dark": "resources/icon_expand_dark.svg",
141142
"light": "resources/icon_expand.svg"
142143
}
144+
},
145+
{
146+
"command": "blocksort.quickSort",
147+
"title": "Quick Sort",
148+
"category": "Sort"
143149
}
144150
],
145151
"configuration": [
@@ -572,42 +578,112 @@
572578
"foldingComplete": true,
573579
"indentationComplete": true
574580
}
575-
}
576-
},
577-
"blocksort.expandCursor": {
578-
"oneOf": [
579-
{
580-
"type": "boolean"
581-
},
582-
{
583-
"type": "object",
584-
"minProperties": 1,
585-
"properties": {
586-
"expandLocally": {
587-
"type": "boolean",
588-
"description": "Expand selection locally while in the same blocks (stopping at empty lines)"
589-
},
590-
"expandOverEmptyLines": {
591-
"type": "boolean",
592-
"description": "Expand selection over empty lines"
593-
},
594-
"foldingComplete": {
595-
"type": "boolean",
596-
"description": "Expand selection, so that all folding markers are closed"
597-
},
598-
"indentationComplete": {
599-
"type": "boolean",
600-
"description": "Expand selection, so that all indentation is complete"
581+
},
582+
"blocksort.expandCursor": {
583+
"oneOf": [
584+
{
585+
"type": "boolean"
586+
},
587+
{
588+
"type": "object",
589+
"minProperties": 1,
590+
"properties": {
591+
"expandLocally": {
592+
"type": "boolean",
593+
"description": "Expand selection locally while in the same blocks (stopping at empty lines)"
594+
},
595+
"expandOverEmptyLines": {
596+
"type": "boolean",
597+
"description": "Expand selection over empty lines"
598+
},
599+
"foldingComplete": {
600+
"type": "boolean",
601+
"description": "Expand selection, so that all folding markers are closed"
602+
},
603+
"indentationComplete": {
604+
"type": "boolean",
605+
"description": "Expand selection, so that all indentation is complete"
606+
}
601607
}
602608
}
609+
],
610+
"description": "Expand cursor to selection when sorting blocks",
611+
"default": {
612+
"expandLocally": true,
613+
"expandOverEmptyLines": false,
614+
"foldingComplete": true,
615+
"indentationComplete": true
603616
}
604-
],
605-
"description": "Expand cursor to selection when sorting blocks",
606-
"default": {
607-
"expandLocally": true,
608-
"expandOverEmptyLines": false,
609-
"foldingComplete": true,
610-
"indentationComplete": true
617+
},
618+
"blocksort.quickSortCommands": {
619+
"type": "object",
620+
"default": [
621+
{
622+
"command": "blocksort.sortBlocksAsc",
623+
"label": "$(sort-asc) Sort Blocks Ascending",
624+
"description": "Expand Selection and sort blocks in ascending order",
625+
"picked": true
626+
},
627+
{
628+
"command": "blocksort.sortBlocksDesc",
629+
"label": "$(sort-desc) Sort Blocks Descending",
630+
"description": "Expand Selection and sort blocks in descending order"
631+
},
632+
{
633+
"command": "blocksort.sortBlocksShuffle",
634+
"label": "$(arrow-switch) Shuffle Blocks",
635+
"description": "Expand Selection and shuffle blocks"
636+
},
637+
{
638+
"command": "editor.action.sortLinesAscending",
639+
"label": "$(sort-asc) Sort Lines Ascending",
640+
"description": "Sort selected lines in ascending order"
641+
},
642+
{
643+
"command": "editor.action.sortLinesDescending",
644+
"label": "$(sort-desc) Sort Lines Descending",
645+
"description": "Sort selected lines in descending order"
646+
},
647+
{
648+
"command": "blocksort.expandSelectionLocally",
649+
"label": "$(unfold) Expand Selection",
650+
"description": "Expand current Selection to surrounding Block"
651+
}
652+
],
653+
"properties": {
654+
"command": {
655+
"type": "string",
656+
"description": "The command to execute"
657+
},
658+
"args": {
659+
"type": "array",
660+
"description": "The arguments to pass to the command"
661+
},
662+
"label": {
663+
"type": "string",
664+
"description": "A human-readable string which is rendered prominent"
665+
},
666+
"description": {
667+
"type": "string",
668+
"description": "A human-readable string which is rendered less prominent in the same line"
669+
},
670+
"detail": {
671+
"type": "string",
672+
"description": "A human-readable string which is rendered less prominent in a separate line"
673+
},
674+
"picked": {
675+
"type": "boolean",
676+
"description": "Optional flag indicating if this item is picked initially"
677+
},
678+
"alwaysShow": {
679+
"type": "boolean",
680+
"description": "Always show this item"
681+
}
682+
},
683+
"required": [
684+
"command",
685+
"label"
686+
]
611687
}
612688
}
613689
}
@@ -715,4 +791,4 @@
715791
]
716792
]
717793
}
718-
}
794+
}

src/commands/blockSort.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { commands, InputBoxOptions, Selection, Range, TextEditor, TextEditorEdit, window } from "vscode";
2-
import ConfigurationProvider, { BlockSortCollatorOptions } from "../providers/ConfigurationProvider";
1+
import { Selection, Range, TextEditor, TextEditorEdit, window } from "vscode";
2+
import ConfigurationProvider from "../providers/ConfigurationProvider";
33
import BlockSortFormattingProvider from "../providers/BlockSortFormattingProvider";
44
import { BlockSortOptions } from "../types/BlockSortOptions";
55
import { showNumberQuickPick } from "../helpers/showNumberQuickPick";

src/commands/quickSort.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { commands, window } from "vscode";
2+
import ConfigurationProvider from "../providers/ConfigurationProvider";
3+
4+
export async function quickSort() {
5+
const options = ConfigurationProvider.getQuickSortCommands();
6+
const { command, args = [] } = (await window.showQuickPick(options)) ?? {};
7+
8+
if (command) commands.executeCommand(command, ...args);
9+
}

src/contribute/commands.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from "../commands/blockSort";
1212
import { expandSelectionFull, expandSelectionLocally } from "../commands/expandSelection";
1313
import BlockSortFormattingProvider from "../providers/BlockSortFormattingProvider";
14+
import { quickSort } from "../commands/quickSort";
1415

1516
export default function contributeCommands(b: BlockSortFormattingProvider) {
1617
return [
@@ -26,5 +27,6 @@ export default function contributeCommands(b: BlockSortFormattingProvider) {
2627
commands.registerTextEditorCommand("blocksort.sortInnerBlocksShuffle", blockSortShuffle.bind(null, b)),
2728
commands.registerTextEditorCommand("blocksort.expandSelectionLocally", expandSelectionLocally.bind(null, b)),
2829
commands.registerTextEditorCommand("blocksort.expandSelectionFull", expandSelectionFull.bind(null, b)),
30+
commands.registerTextEditorCommand("blocksort.quickSort", quickSort),
2931
];
3032
}

src/providers/ConfigurationProvider.ts

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import {
1111
} from "vscode";
1212
import { ExpandSelectionOptions } from "../types/BlockSortOptions";
1313
import { FoldingMarkerDefault, FoldingMarkerList } from "./StringProcessingProvider";
14+
import {
15+
BlockSortCollatorOptions,
16+
BlockSortConfiguration,
17+
NaturalSortOptions,
18+
SortCommandOptions,
19+
} from "../types/BlockSortConfiguration";
1420

1521
const defaultFoldingMarkers: FoldingMarkerList<FoldingMarkerDefault> = {
1622
"()": { start: "\\(", end: "\\)" },
@@ -28,43 +34,6 @@ const defaultIndentIgnoreMarkers = [
2834
"esac|fi",
2935
];
3036

31-
/** @deprecated Will no longer be applied. Use collatorOptions instead */
32-
export interface NaturalSortOptions {
33-
padding: number;
34-
omitUuids: boolean;
35-
sortNegativeValues: boolean;
36-
}
37-
38-
export interface BlockSortCollatorOptions extends Omit<Intl.CollatorOptions, "usage"> {
39-
locales?: string;
40-
customSortOrder?: string;
41-
customIgnoreCharacters?: string;
42-
}
43-
44-
export interface BlockSortConfiguration {
45-
defaultMultilevelDepth: number;
46-
defaultSkipParents: number;
47-
askForMultilevelDepth: boolean;
48-
askForSkipParents: boolean;
49-
indentIgnoreMarkers: string[];
50-
completeBlockMarkers: string[];
51-
foldingMarkers: FoldingMarkerList;
52-
/** @deprecated Use collatorOptions.numeric instead */
53-
enableNaturalSorting: boolean;
54-
/** @deprecated Will no longer be applied. Use collatorOptions instead */
55-
naturalSorting: NaturalSortOptions;
56-
collatorOptions: BlockSortCollatorOptions;
57-
sortConsecutiveBlockHeaders: boolean;
58-
enableCodeLens: DocumentSelector | boolean;
59-
enableCodeActions: DocumentSelector | boolean;
60-
enableDocumentFormatting: DocumentSelector | boolean;
61-
enableRangeFormatting: DocumentSelector | boolean;
62-
forceBlockHeaderFirstRegex: string;
63-
forceBlockHeaderLastRegex: string;
64-
multiBlockHeaderRegex: string;
65-
incompleteBlockRegex: string;
66-
}
67-
6837
export default class ConfigurationProvider {
6938
public static readonly invalidatingConfigurationKeys: string[] = [
7039
"enableNaturalSorting",
@@ -209,6 +178,11 @@ export default class ConfigurationProvider {
209178
return typeof tabSize === "string" ? 4 : tabSize ?? 4;
210179
}
211180

181+
public static getQuickSortCommands(): SortCommandOptions[] {
182+
const quickSortCommands: SortCommandOptions[] = ConfigurationProvider.getConfiguration().quickSortCommands || [];
183+
return quickSortCommands;
184+
}
185+
212186
public static onConfigurationChanged(): void {
213187
ConfigurationProvider.configuration.clear();
214188
}

src/providers/StringSortProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BlockSortCollatorOptions } from "./ConfigurationProvider";
1+
import { BlockSortCollatorOptions } from "../types/BlockSortConfiguration";
22

33
export class StringSortProvider extends Intl.Collator {
44
public readonly customSortOrder?: string;

src/test/suite/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CodeActionKind, Position, Range } from "vscode";
22
import { ExpandSelectionOptions } from "../../types/BlockSortOptions";
3-
import { BlockSortCollatorOptions } from "../../providers/ConfigurationProvider";
3+
import { BlockSortCollatorOptions } from "../../types/BlockSortConfiguration";
44

55
export interface BaseTest {
66
file: string;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { DocumentSelector, QuickPickItem } from "vscode";
2+
import { FoldingMarkerList } from "../providers/StringProcessingProvider";
3+
4+
/** @deprecated Will no longer be applied. Use collatorOptions instead */
5+
export interface NaturalSortOptions {
6+
padding: number;
7+
omitUuids: boolean;
8+
sortNegativeValues: boolean;
9+
}
10+
11+
export interface BlockSortCollatorOptions extends Omit<Intl.CollatorOptions, "usage"> {
12+
locales?: string;
13+
customSortOrder?: string;
14+
customIgnoreCharacters?: string;
15+
}
16+
17+
export interface SortCommandOptions extends QuickPickItem {
18+
command: string;
19+
args: any[];
20+
}
21+
22+
export interface BlockSortConfiguration {
23+
defaultMultilevelDepth: number;
24+
defaultSkipParents: number;
25+
askForMultilevelDepth: boolean;
26+
askForSkipParents: boolean;
27+
indentIgnoreMarkers: string[];
28+
completeBlockMarkers: string[];
29+
foldingMarkers: FoldingMarkerList;
30+
/** @deprecated Use collatorOptions.numeric instead */
31+
enableNaturalSorting: boolean;
32+
/** @deprecated Will no longer be applied. Use collatorOptions instead */
33+
naturalSorting: NaturalSortOptions;
34+
collatorOptions: BlockSortCollatorOptions;
35+
sortConsecutiveBlockHeaders: boolean;
36+
enableCodeLens: DocumentSelector | boolean;
37+
enableCodeActions: DocumentSelector | boolean;
38+
enableDocumentFormatting: DocumentSelector | boolean;
39+
enableRangeFormatting: DocumentSelector | boolean;
40+
forceBlockHeaderFirstRegex: string;
41+
forceBlockHeaderLastRegex: string;
42+
multiBlockHeaderRegex: string;
43+
incompleteBlockRegex: string;
44+
quickSortCommands: SortCommandOptions[];
45+
}

src/types/BlockSortOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TextEdit } from "vscode";
2-
import { BlockSortCollatorOptions } from "../providers/ConfigurationProvider";
2+
import { BlockSortCollatorOptions } from "./BlockSortConfiguration";
33

44
export interface ExpandSelectionOptions {
55
expandLocally?: boolean;

0 commit comments

Comments
 (0)