Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/minimum line count #94

Merged
merged 2 commits into from
Mar 8, 2024
Merged
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# What's new in Separators 2.5

* Adds new option to draw separators above comments
* Adds new setting to define the minimum number of lines for symbols
* Adds new setting to choose separator's location
* Adds **Localization** support
* Adds **Web** support
Expand Down Expand Up @@ -107,6 +108,16 @@ You can customize the appearance of each kind of Symbol.
}
```

* Specifies the minimum number of lines that a symbol must have to draw separators _(default is `0` - unlimited)_
```json
"separators.minimumLineCount": 2

// per-language setting
"[javascript]": {
"separators.minimumLineCount": 2
}
```

* Defines the border width _(in `px`)_
```json
"separators.classes.borderWidth": 1,
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@
}
},
"scope": "window"
},
"separators.minimumLineCount": {
"type": "integer",
"default": 0,
"description": "%separators.configuration.minimumLineCount.description%",
"scope": "language-overridable"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"separators.configuration.aboveComments.rules.rules.multiLine.description": "Specifies the list of patterns to match multi line comments",
"separators.configuration.aboveComments.rules.rules.multiLine.start.description": "Specifies the glob pattern to match multi line comments start",
"separators.configuration.aboveComments.rules.rules.multiLine.end.description": "Specifies the glob pattern to match multi line comments end",
"separators.configuration.minimumLineCount.description": "Specifies the minimum number of lines that a symbol must have to draw separators",
"separators.configuration.functions.ignoreCallbackInline.description": "Controls whether callback/inline Functions should be ignored",
"separators.configuration.maxDepth.description": "Indicates the maximum depth (level) which the separators should be rendered. Any value below 1 means there is no limit.",
"separators.configuration.useOriginalGreenishSeparator.description": "Use the original greenish separator for Methods, Functions and Constructors",
Expand Down
1 change: 1 addition & 0 deletions package.nls.pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"separators.configuration.aboveComments.rules.rules.multiLine.description": "Especifica a lista de padrões para comentário de múltiplas linha",
"separators.configuration.aboveComments.rules.rules.multiLine.start.description": "Especifica o padrão glob para início de comentário de múltiplas linhas",
"separators.configuration.aboveComments.rules.rules.multiLine.end.description": "Especifica o padrão glob para fim de comentário de múltiplas linhas",
"separators.configuration.minimumLineCount.description": "Especifica o número mínimo de linhas que um símbolo deve ter para desenhar separadores",
"separators.configuration.functions.ignoreCallbackInline.description": "Controla se funções callback/inline Functions devem ser ignoradas",
"separators.configuration.maxDepth.description": "Indica a profundidade máxima (nível) na qual separadores devem ser desenhados. Qualquer valor abaixo de 1 significa que não tem limite.",
"separators.configuration.useOriginalGreenishSeparator.description": "Usar a cor de separador verde original para Métodos, Funções e Construtores",
Expand Down
6 changes: 6 additions & 0 deletions src/decoration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { window, ThemeColor, TextEditor, Range, TextEditorDecorationType, Decora
import { DEFAULT_GREENISH_COLOR, } from "./constants";
import { Location, shouldHaveSeparatorAbove, shouldHaveSeparatorBelow } from "./location";
import { shiftTopLineAboveComment } from "./comments/comments";
import { symbolHasAtLeastNLines } from "./symbols";

export interface TextEditorDecorationTypePair {
above: TextEditorDecorationType;
Expand Down Expand Up @@ -82,13 +83,18 @@ export async function updateDecorationsInActiveEditor(activeEditor: TextEditor |
}

const location = workspace.getConfiguration("separators").get<string>("location", Location.aboveTheSymbol);
const minimumLineCount = workspace.getConfiguration("separators", window.activeTextEditor?.document).get<number>("minimumLineCount", 0);

const rangesAbove: Range[] = [];
const rangesBelow: Range[] = [];

for (let i = 0; i < symbols.length; i++) {
const element = symbols[i];
const elementAbove = i === 0 ? undefined : symbols[i - 1];

if (!symbolHasAtLeastNLines(element, minimumLineCount)) {
continue;
}

if (shouldHaveSeparatorAbove(location)) {
const topLine = await shiftTopLineAboveComment(activeEditor, element, elementAbove);
Expand Down
6 changes: 5 additions & 1 deletion src/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,8 @@ export async function findSymbols(symbolsToFind: SymbolKind[]): Promise<Document
: undefined;

return docSymbolsFunctionsMethods;
}
}

export function symbolHasAtLeastNLines(element: DocumentSymbol, minimunLineCount: number) {
return minimunLineCount <= 0 || (element.range.end.line - element.range.start.line >= minimunLineCount);
}
Loading