-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: contribute configuration for natural sorting
- Loading branch information
Showing
7 changed files
with
111 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,90 @@ | ||
import { workspace } from 'vscode'; | ||
import { FoldingMarkerDefault, FoldingMarkerList } from './StringProcessingProvider'; | ||
import { workspace } from "vscode"; | ||
import { FoldingMarkerDefault, FoldingMarkerList } from "./StringProcessingProvider"; | ||
|
||
const defaultFoldingMarkers: FoldingMarkerList<FoldingMarkerDefault> = { | ||
'()': { start: '\\(', end: '\\)' }, | ||
'[]': { start: '\\[', end: '\\]' }, | ||
'{}': { start: '\\{', end: '\\}' }, | ||
'<>': { start: '<[a-zA-Z0-9\\-_=\\s]+', end: '<\\/[a-zA-Z0-9\\-_=\\s]+' }, | ||
"()": { start: "\\(", end: "\\)" }, | ||
"[]": { start: "\\[", end: "\\]" }, | ||
"{}": { start: "\\{", end: "\\}" }, | ||
"<>": { start: "<[a-zA-Z0-9\\-_=\\s]+", end: "<\\/[a-zA-Z0-9\\-_=\\s]+" }, | ||
}; | ||
|
||
const defaultCompleteBlockMarkers = ['\\}', '<\\/[a-zA-Z0-9\\-_=\\s]+']; | ||
const defaultCompleteBlockMarkers = ["\\}", "<\\/[a-zA-Z0-9\\-_=\\s]+"]; | ||
|
||
const defaultIndentIgnoreMarkers = [ | ||
'{', | ||
"{", | ||
// eslint-disable-next-line quotes | ||
"end(?:for(?:each)?|if|while|case|def)?\\s*?([\\.\\[\\->\\|\\s]\\s*(?:[$A-Za-z0-9_+\\-\\*\\/\\^\\%\\<\\>\\=\\!\\?\\:]*|'[^']*?'|'[']*?'|\"[^\"]*?\"|`[^`]*?`)\\s*[\\]\\|]?\\s*)*", | ||
'esac|fi', | ||
"esac|fi", | ||
]; | ||
|
||
export interface NaturalSortOptions { | ||
enabled: boolean; | ||
padding: number; | ||
omitUuids: boolean; | ||
sortNegativeValues: boolean; | ||
} | ||
|
||
export default class ConfigurationProvider { | ||
public static getFoldingMarkers(): FoldingMarkerList { | ||
const additional: FoldingMarkerList = workspace.getConfiguration('blocksort').get('foldingMarkers') || {}; | ||
const additional: FoldingMarkerList = workspace.getConfiguration("blocksort").get("foldingMarkers") || {}; | ||
return { ...additional, ...defaultFoldingMarkers }; | ||
} | ||
|
||
public static getCompleteBlockMarkers(): string[] { | ||
const additional: string[] = workspace.getConfiguration('blocksort').get('completeBlockMarkers') || []; | ||
const additional: string[] = workspace.getConfiguration("blocksort").get("completeBlockMarkers") || []; | ||
return [...additional, ...defaultCompleteBlockMarkers]; | ||
} | ||
|
||
public static getSortConsecutiveBlockHeaders(): boolean { | ||
const configuration: boolean | undefined = workspace | ||
.getConfiguration('blocksort') | ||
.get('sortConsecutiveBlockHeaders'); | ||
.getConfiguration("blocksort") | ||
.get("sortConsecutiveBlockHeaders"); | ||
return configuration === undefined ? true : configuration; | ||
} | ||
|
||
public static getDefaultMultilevelDepth(): number { | ||
const configuration: number | undefined = workspace.getConfiguration('blocksort').get('defaultMultilevelDepth'); | ||
const configuration: number | undefined = workspace.getConfiguration("blocksort").get("defaultMultilevelDepth"); | ||
return configuration === undefined ? -1 : configuration; | ||
} | ||
|
||
public static getAskForMultilevelDepth(): boolean { | ||
const configuration: boolean | undefined = workspace.getConfiguration('blocksort').get('askForMultilevelDepth'); | ||
const configuration: boolean | undefined = workspace.getConfiguration("blocksort").get("askForMultilevelDepth"); | ||
return configuration === undefined ? true : configuration; | ||
} | ||
|
||
public static getForceBlockHeaderFirstRegex(): string { | ||
return '$^'; | ||
return "$^"; | ||
} | ||
|
||
public static getForceBlockHeaderLastRegex(): string { | ||
return '(default|else)\\s*(\'([^\']|(?<=\\\\)\')*\'|"([^"]|(?<=\\\\)")*"|`([^`]|(?<=\\\\)`)*`|[A-Za-z_+\\-*/%<>d.,s]*)*\\s*(.*:)?(\r?\n|$)'; | ||
return "(default|else)\\s*('([^']|(?<=\\\\)')*'|\"([^\"]|(?<=\\\\)\")*\"|`([^`]|(?<=\\\\)`)*`|[A-Za-z_+\\-*/%<>d.,s]*)*\\s*(.*:)?(\r?\n|$)"; | ||
} | ||
|
||
public static getMultiBlockHeaderRegex(): string { | ||
return '(when|case|else|default)\\s*(\'([^\']|(?<=\\\\)\')*\'|"([^"]|(?<=\\\\)")*"|`([^`]|(?<=\\\\)`)*`|[A-Za-z_+\\-*/%<>d.,s]*)*\\s*(.*:)?$'; | ||
return "(when|case|else|default)\\s*('([^']|(?<=\\\\)')*'|\"([^\"]|(?<=\\\\)\")*\"|`([^`]|(?<=\\\\)`)*`|[A-Za-z_+\\-*/%<>d.,s]*)*\\s*(.*:)?$"; | ||
} | ||
|
||
public static getIncompleteBlockRegex(): string { | ||
return '(if|when|else|case|for|foreach|else|elsif|while|def|then)\\s*(\'([^\']|(?<=\\\\)\')*\'|"([^"]|(?<=\\\\)")*"|`([^`]|(?<=\\\\)`)*`|[A-Za-z_+\\-*/%<>d.,s]*)*\\s*(.*:)?$'; | ||
return "(if|when|else|case|for|foreach|else|elsif|while|def|then)\\s*('([^']|(?<=\\\\)')*'|\"([^\"]|(?<=\\\\)\")*\"|`([^`]|(?<=\\\\)`)*`|[A-Za-z_+\\-*/%<>d.,s]*)*\\s*(.*:)?$"; | ||
} | ||
|
||
public static getIndentIgnoreMarkers(): string[] { | ||
const additional: string[] = workspace.getConfiguration('blocksort').get('indentIgnoreMarkers') || []; | ||
const additional: string[] = workspace.getConfiguration("blocksort").get("indentIgnoreMarkers") || []; | ||
return [...additional, ...defaultIndentIgnoreMarkers]; | ||
} | ||
|
||
public static getNaturalSortOptions(): NaturalSortOptions { | ||
const configuration: Partial<NaturalSortOptions> = workspace.getConfiguration("blocksort").get("naturalSorting") || {}; | ||
return { | ||
enabled: false, | ||
padding: 9, | ||
omitUuids: false, | ||
sortNegativeValues: true, | ||
...configuration | ||
}; | ||
} | ||
|
||
public static getEnableNaturalSorting(): boolean { | ||
return !!workspace.getConfiguration("blocksort").get("enableNaturalSorting"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,11 @@ port 22 | |
port 80 | ||
port 443 | ||
port 8080 | ||
|
||
-3456 | ||
-12 | ||
2 | ||
19 | ||
60 | ||
145 | ||
1837 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,11 @@ port 443 | |
port 80 | ||
port 8080 | ||
port 22 | ||
|
||
145 | ||
2 | ||
19 | ||
-12 | ||
1837 | ||
60 | ||
-3456 |