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/shift separator above comments #91

Merged
merged 21 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5542e56
Add first steps to shift separator above comments (WIP)
alefragnani Feb 28, 2024
5ab6a0f
Add generic support for single line comments //
alefragnani Feb 28, 2024
7218884
Add generic support for multiline comments /* .. */ (JS/TS and Lua)
alefragnani Feb 28, 2024
4f2524b
Improve multiline and handle edge cases
alefragnani Feb 28, 2024
95ef84e
Enable comments support for Lua
alefragnani Feb 28, 2024
f00b80a
Add first steps for a generic language
alefragnani Feb 29, 2024
e7b7867
Add settings that expose regexes for generic language
alefragnani Feb 29, 2024
d5d3c82
Expand settings to structured list of comments
alefragnani Mar 1, 2024
2c3ef8a
Move RulesProvider to Container object
alefragnani Mar 1, 2024
14550b1
Update ruleConfig on change of active file
alefragnani Mar 2, 2024
e5c7e2e
Add support to multiple multiLine comments
alefragnani Mar 2, 2024
06e26bc
Revert the changes made for per language command support - RulesProvi…
alefragnani Mar 2, 2024
bff7554
Add TODOs
alefragnani Mar 2, 2024
21b0836
Fix multiline comments on the same line
alefragnani Mar 2, 2024
dbb2dc9
Fix multiline comments with empty lines
alefragnani Mar 2, 2024
9c1f0c0
Fix multiline comments with no start
alefragnani Mar 2, 2024
0c2c4c5
Update config rules (package.json) to support multiple multiLine comm…
alefragnani Mar 2, 2024
7a9371d
Update to use separators.location setting instead of separators.above…
alefragnani Mar 4, 2024
be7a333
Extract location and move comments
alefragnani Mar 4, 2024
aaedbdc
Update pt-br translation
alefragnani Mar 5, 2024
eca248a
Update docs
alefragnani Mar 5, 2024
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
66 changes: 63 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

# What's new in Separators 2.5

* Adds new option to draw separators above comments
* Adds new setting to choose separator's location
* Adds **Localization** support
* Adds **Web** support
* Adds separators for `Struct` symbol
* Adds **Virtual Workspaces** support

## Support

Expand Down Expand Up @@ -132,11 +131,72 @@ You can customize the appearance of each kind of Symbol.
"separators.structs.borderStyle": "solid",
```

* Indicates the locations (relative to the symbols) where the separators will be drawn _(choose between `aboveTheSymbol`, `belowTheSymbol` and `surroundingTheSymbol`)
* Indicates the locations (relative to the symbols) where the separators will be drawn _(default `aboveTheSymbol`)

| Option | Behavior |
|------------------------|------------------------------------------------------------|
| `aboveTheSymbol` | A single separator located above the symbol |
| `aboveTheComment` | A single separator located above the comment of the symbol |
| `belowTheSymbol` | A single separator located below the symbol |
| `surroundingTheSymbol` | A pair of separators located above and below the symbol |

```json
"separators.location": "aboveTheSymbol"
```

* Indicates the comment rules to draw separators above comments

Out of the box, the extension supports three _patterns_ of comments:
* **Slash based comments**: Like those found in JavaScript, TypeScript, C, C++, C#, Java, etc
```javascript
// this is a single line comment

/* this is a multi line comment
this is a multi line comment */
```
* **Pascal based comments**: Like those found in Pascal, Object Pascal, etc
```pascal
// this is a single line comment

{ this is a multi line comment
this is a multi line comment }

(* this is an old school multi line comment
this is an old school multi line comment *)
```
* **Lua based comments**: Like those found in Lua
```lua
-- this is a single line comment

--[[ this is a multi line comment
this is a multi line comment ]]
```

If you want to add support for a custom language, you can add a new rule to the `separators.aboveComments.rules` setting. Here is an example for Lua:
```json
"separators.aboveComments.rules": [
{
"name": "Lua",
"languageIds": [
"lua"
],
"rules": {
"singleLine": "^\\s*--",
"multiLine": [
{
"start": "^\\s*\\-\\-\\[\\[",
"end": "\\]\\]\\s*$"
}
]
}
}
],
```

Or you can open a PR, an contribute to the built in rules in the extension. These are located in the `./rules.json` file

> Be aware that regex must be escaped, so `\\` is used instead of `\`

## Available colors

For more information about customizing colors in VSCode, see [Theme Color](https://code.visualstudio.com/api/references/theme-color).
Expand Down
65 changes: 65 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,80 @@
"default": "aboveTheSymbol",
"enum": [
"aboveTheSymbol",
"aboveTheComment",
"belowTheSymbol",
"surroundingTheSymbol"
],
"enumDescriptions": [
"A single separator located above the symbol",
"A single separator located above the comments of the symbol",
"A single separator located below the symbol",
"Two separators surrounding the symbol"
],
"description": "%separators.configuration.location.description%"
},
"separators.aboveComments.rules": {
"type": "array",
"default": [],
"description": "%separators.configuration.aboveComments.rules.description%",
"items": {
"type": "object",
"required": [
"name",
"languageIds",
"rules"
],
"properties": {
"name": {
"type": "string",
"description": "%separators.configuration.aboveComments.rules.name.description%"
},
"languageIds": {
"type": "array",
"items": {
"type": "string",
"uniqueItems": true
},
"description": "%separators.configuration.aboveComments.rules.languageIds.description%"
},
"rules": {
"type": "object",
"required": [
"singleLine",
"multiLine"
],
"description": "%separators.configuration.aboveComments.rules.rules.description%",
"properties": {
"singleLine": {
"type": "string",
"description": "%separators.configuration.aboveComments.rules.rules.singleLine.description%"
},
"multiLine": {
"type": "array",
"description": "%separators.configuration.aboveComments.rules.rules.multiLine.description%",
"items": {
"type": "object",
"required": [
"start",
"end"
],
"properties": {
"start": {
"type": "string",
"description": "%separators.configuration.aboveComments.rules.rules.multiLine.start.description%"
},
"end": {
"type": "string",
"description": "%separators.configuration.aboveComments.rules.rules.multiLine.end.description%"
}
}
}
}
}
}
}
},
"scope": "window"
}
}
},
Expand Down
8 changes: 8 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
"separators.configuration.title": "Separators",
"separators.configuration.enabledSymbols.description": "List of symbols in which the separators will be drawn",
"separators.configuration.location.description": "Indicates the locations (relative to the symbols) where the separators will be drawn",
"separators.configuration.aboveComments.rules.description": "Indicates the comment rules to draw separators above comments",
"separators.configuration.aboveComments.rules.name.description": "Specifies the name of the rule",
"separators.configuration.aboveComments.rules.languageIds.description": "Specifies the list of language IDs to which this rule applies",
"separators.configuration.aboveComments.rules.rules.description": "Specifies the rules to match comments",
"separators.configuration.aboveComments.rules.rules.singleLine.description": "Specifies the glob pattern to match single line comments",
"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.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
12 changes: 10 additions & 2 deletions package.nls.pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
"separators.commands.whatsNew#contextMenu.title": "Novidades",
"separators.configuration.title": "Separators",
"separators.configuration.enabledSymbols.description": "Lista de símbolos nos quais os separadores serão desenhados",
"separators.configuration.location.description": "Indicata a localização (relativa aos símbolos) onde os separadores serão desenhados",
"separators.configuration.location.description": "Indica a localização (relativa aos símbolos) onde os separadores serão desenhados",
"separators.configuration.aboveComments.rules.description": "Indica as regras de comentário para desenhar os separadores sobre comentários",
"separators.configuration.aboveComments.rules.name.description": "Especifica o nome da regra",
"separators.configuration.aboveComments.rules.languageIds.description": "Especifica a lista de IDs de linguagem ao qual a regra se aplica",
"separators.configuration.aboveComments.rules.rules.description": "Especifica as regras de comentário",
"separators.configuration.aboveComments.rules.rules.singleLine.description": "Especifica o padrão glob para comentários de uma linha",
"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.functions.ignoreCallbackInline.description": "Controla se funções callback/inline Functions devem ser ignoradas",
"separators.configuration.maxDepth.description": "Indicata 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.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",
"separators.configuration.methods.borderWidth.description": "Largura da borda em Métodos (em px)",
"separators.configuration.methods.borderStyle.description": "Estilo da borda em Métodos",
Expand Down
65 changes: 65 additions & 0 deletions rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[
{
"name": "Slash based comments",
"languageIds": [
"c",
"cpp",
"csharp",
"go",
"java",
"javascript",
"kotlin",
"php",
"rust",
"scala",
"swift",
"typescript",
"zig"
],
"rules": {
"singleLine": "^\\s*\/\/",
"multiLine": [
{
"start": "^\\s*\\/\\*",
"end": "\\*\\/\\s*$"
}
]
}
},
{
"name": "Pascal based comments",
"languageIds": [
"pascal",
"objectpascal",
"delphi"
],
"rules": {
"singleLine": "^\\s*\/\/",
"multiLine": [
{
"start": "^\\s*\\{",
"end": "}\\s*$"
},
{
"start": "^\\s*\\(\\*",
"end": "\\*\\)\\s*$"
}
]
}
},
{
"name": "Lua",
"languageIds": [
"lua"
],
"rules": {
"singleLine": "^\\s*--",
"multiLine": [
{
"start": "^\\s*\\-\\-\\[\\[",
"end": "\\]\\]\\s*$"
}
]
}
}
]
25 changes: 25 additions & 0 deletions src/comments/comments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Alessandro Fragnani. All rights reserved.
* Licensed under the GPLv3 License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { DocumentSymbol, TextEditor, workspace } from "vscode";
import { RegexComment } from "./regexComment";
import { Container } from "../container";
import { Location } from "../location";

export async function shiftTopLineAboveComment(activeEditor: TextEditor, documentSymbol: DocumentSymbol, documentSymbolAbove: DocumentSymbol): Promise<number> {

const isEnabled = workspace.getConfiguration("separators").get<string>("location", Location.aboveTheSymbol) === Location.aboveTheComment;
if (!isEnabled) {
return documentSymbol.range.start.line;
}

if (Container.ruleConfig) {
const regexComment = new RegexComment(Container.ruleConfig);
return regexComment.shiftTopLineAboveComment(activeEditor, documentSymbol, documentSymbolAbove);
}

return documentSymbol.range.start.line;
}

20 changes: 20 additions & 0 deletions src/comments/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Alessandro Fragnani. All rights reserved.
* Licensed under the GPLv3 License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

export interface RuleConfig {
name: string;
languageIds: string[];
rules: Rules;
}

export interface Rules {
singleLine: string;
multiLine: MultiLineRule[];
}

export interface MultiLineRule {
start: string;
end: string;
}
Loading
Loading