From 5542e56724d46d30b3a2ce0252361667f4a4bff0 Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Wed, 28 Feb 2024 01:00:22 -0300 Subject: [PATCH 01/21] Add first steps to shift separator above comments (WIP) --- src/comments.ts | 28 ++++++++++++++++++++++++++++ src/decoration.ts | 6 ++++-- 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/comments.ts diff --git a/src/comments.ts b/src/comments.ts new file mode 100644 index 0000000..2858fb8 --- /dev/null +++ b/src/comments.ts @@ -0,0 +1,28 @@ +/*--------------------------------------------------------------------------------------------- +* Copyright (c) Alessandro Fragnani. All rights reserved. +* Licensed under the GPLv3 License. See License.md in the project root for license information. +*--------------------------------------------------------------------------------------------*/ + +import { DocumentSymbol, TextDocument, TextEditor } from "vscode"; +import { LanguageFactory } from "./language/factory"; + +export function shiftTopLineAboveComment(activeEditor: TextEditor, documentSymbol: DocumentSymbol): number { + + if (!languageSupportsComments(activeEditor.document)) { + return documentSymbol.range.start.line; + } + + const lineAbove = documentSymbol.range.start.line - 1; + const lineTextAbove = activeEditor.document.lineAt(lineAbove).text; + const commentIndex = lineTextAbove.indexOf("//"); + if (commentIndex > 0) { + return lineAbove; + } + return documentSymbol.range.start.line; +} + +function languageSupportsComments(textDocument: TextDocument) { + + const language = LanguageFactory.getLanguage(textDocument?.languageId); + return language !== undefined; +} diff --git a/src/decoration.ts b/src/decoration.ts index fed7742..04cc24c 100644 --- a/src/decoration.ts +++ b/src/decoration.ts @@ -5,6 +5,7 @@ import { window, ThemeColor, TextEditor, Range, TextEditorDecorationType, DecorationRenderOptions, DocumentSymbol, workspace } from "vscode"; import { DEFAULT_GREENISH_COLOR, Location } from "./constants"; +import { shiftTopLineAboveComment } from "./comments"; export interface TextEditorDecorationTypePair { above: TextEditorDecorationType; @@ -86,7 +87,8 @@ export function updateDecorationsInActiveEditor(activeEditor: TextEditor | undef for (const element of symbols) { if (location === Location.aboveTheSymbol || location === Location.surroundingTheSymbol) { - const decorationAbove = new Range(element.range.start.line, 0, element.range.start.line, 0); + const topLine = shiftTopLineAboveComment(activeEditor, element) + const decorationAbove = new Range(topLine, 0, topLine, 0); rangesAbove.push(decorationAbove); } @@ -98,4 +100,4 @@ export function updateDecorationsInActiveEditor(activeEditor: TextEditor | undef activeEditor.setDecorations(decorationType.above, rangesAbove); activeEditor.setDecorations(decorationType.below, rangesBelow); -} \ No newline at end of file +} From 5ab6a0f4e13ceb2b348a8ffefe353411ef8ac54f Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Wed, 28 Feb 2024 01:19:31 -0300 Subject: [PATCH 02/21] Add generic support for single line comments // --- src/comments.ts | 23 ++++++++++------------- src/language/javaScriptTypeScript.ts | 5 +++++ src/language/language.ts | 1 + src/language/lua.ts | 5 +++++ 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/comments.ts b/src/comments.ts index 2858fb8..e9d1772 100644 --- a/src/comments.ts +++ b/src/comments.ts @@ -3,26 +3,23 @@ * Licensed under the GPLv3 License. See License.md in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { DocumentSymbol, TextDocument, TextEditor } from "vscode"; +import { DocumentSymbol, TextEditor } from "vscode"; import { LanguageFactory } from "./language/factory"; export function shiftTopLineAboveComment(activeEditor: TextEditor, documentSymbol: DocumentSymbol): number { - if (!languageSupportsComments(activeEditor.document)) { + const language = LanguageFactory.getLanguage(activeEditor.document?.languageId); + if (!language?.supportsComments()) { return documentSymbol.range.start.line; } - const lineAbove = documentSymbol.range.start.line - 1; - const lineTextAbove = activeEditor.document.lineAt(lineAbove).text; - const commentIndex = lineTextAbove.indexOf("//"); - if (commentIndex > 0) { - return lineAbove; + let lineAbove = documentSymbol.range.start.line - 1; + let lineTextAbove = activeEditor.document.lineAt(lineAbove).text; + while (lineTextAbove.trim().startsWith("//")) { + lineAbove--; + lineTextAbove = activeEditor.document.lineAt(lineAbove).text; } - return documentSymbol.range.start.line; -} + return lineAbove + 1; -function languageSupportsComments(textDocument: TextDocument) { - - const language = LanguageFactory.getLanguage(textDocument?.languageId); - return language !== undefined; } + diff --git a/src/language/javaScriptTypeScript.ts b/src/language/javaScriptTypeScript.ts index 1ef0f89..6651e82 100644 --- a/src/language/javaScriptTypeScript.ts +++ b/src/language/javaScriptTypeScript.ts @@ -7,6 +7,11 @@ import { DocumentSymbol } from "vscode"; import { Language } from "./language"; export class JavaScriptTypeScriptLanguage implements Language { + + supportsComments(): boolean { + return true; + } + isCallback(symbol: DocumentSymbol): boolean { return symbol.name.endsWith(' callback'); } diff --git a/src/language/language.ts b/src/language/language.ts index a88b68c..98b17b6 100644 --- a/src/language/language.ts +++ b/src/language/language.ts @@ -6,5 +6,6 @@ import { DocumentSymbol } from "vscode"; export interface Language { + supportsComments(): boolean; isCallback(symbol: DocumentSymbol): boolean; } diff --git a/src/language/lua.ts b/src/language/lua.ts index c8644fa..8f8fd6e 100644 --- a/src/language/lua.ts +++ b/src/language/lua.ts @@ -7,6 +7,11 @@ import { DocumentSymbol } from "vscode"; import { Language } from "./language"; export class LuaLanguage implements Language { + + supportsComments(): boolean { + return false; + } + isCallback(symbol: DocumentSymbol): boolean { return symbol.name === "" && symbol.detail.includes("-> function"); } From 72188845c271fa55057f6c28a636ac0834c44b26 Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Wed, 28 Feb 2024 08:12:54 -0300 Subject: [PATCH 03/21] Add generic support for multiline comments /* .. */ (JS/TS and Lua) --- src/comments.ts | 18 ++++++++++++++++-- src/language/javaScriptTypeScript.ts | 11 +++++++++++ src/language/language.ts | 3 +++ src/language/lua.ts | 11 +++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/comments.ts b/src/comments.ts index e9d1772..2f47035 100644 --- a/src/comments.ts +++ b/src/comments.ts @@ -15,11 +15,25 @@ export function shiftTopLineAboveComment(activeEditor: TextEditor, documentSymbo let lineAbove = documentSymbol.range.start.line - 1; let lineTextAbove = activeEditor.document.lineAt(lineAbove).text; - while (lineTextAbove.trim().startsWith("//")) { + + if (language.isSingleLineComment(lineTextAbove)) { + while (language.isSingleLineComment(lineTextAbove)) { + lineAbove--; + lineTextAbove = activeEditor.document.lineAt(lineAbove).text; + } + return lineAbove + 1; + } + + if (language.isMultiLineCommentEnd(lineTextAbove)) { lineAbove--; lineTextAbove = activeEditor.document.lineAt(lineAbove).text; + while (!language.isMultiLineCommentStart(lineTextAbove)) { + lineAbove--; + lineTextAbove = activeEditor.document.lineAt(lineAbove).text; + } + return lineAbove; } + return lineAbove + 1; - } diff --git a/src/language/javaScriptTypeScript.ts b/src/language/javaScriptTypeScript.ts index 6651e82..56f1ad2 100644 --- a/src/language/javaScriptTypeScript.ts +++ b/src/language/javaScriptTypeScript.ts @@ -8,6 +8,17 @@ import { Language } from "./language"; export class JavaScriptTypeScriptLanguage implements Language { + isMultiLineCommentStart(lineText: string): boolean { + return lineText.trim().startsWith("/*") || lineText.trim().startsWith("/**"); + } + isMultiLineCommentEnd(lineText: string): boolean { + return lineText.trim().endsWith("*/"); + } + + isSingleLineComment(lineText: string): boolean { + return lineText.trim().startsWith("//"); + } + supportsComments(): boolean { return true; } diff --git a/src/language/language.ts b/src/language/language.ts index 98b17b6..7bff164 100644 --- a/src/language/language.ts +++ b/src/language/language.ts @@ -6,6 +6,9 @@ import { DocumentSymbol } from "vscode"; export interface Language { + isMultiLineCommentStart(lineText: string): boolean; + isMultiLineCommentEnd(lineText: string): boolean; + isSingleLineComment(lineText: string): boolean; supportsComments(): boolean; isCallback(symbol: DocumentSymbol): boolean; } diff --git a/src/language/lua.ts b/src/language/lua.ts index 8f8fd6e..63791ed 100644 --- a/src/language/lua.ts +++ b/src/language/lua.ts @@ -8,6 +8,17 @@ import { Language } from "./language"; export class LuaLanguage implements Language { + isMultiLineCommentStart(lineText: string): boolean { + return lineText.trim().startsWith("--[["); + } + isMultiLineCommentEnd(lineText: string): boolean { + return lineText.trim().endsWith("]]"); + } + + isSingleLineComment(lineText: string): boolean { + return lineText.trim().startsWith("--"); + } + supportsComments(): boolean { return false; } From 4f2524baa29770dcc1a8459efd66d27fc7e31557 Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Wed, 28 Feb 2024 17:23:48 -0300 Subject: [PATCH 04/21] Improve multiline and handle edge cases --- src/comments.ts | 35 +++++++++++++++++++++------- src/language/javaScriptTypeScript.ts | 8 +++++-- src/language/language.ts | 4 ++-- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/comments.ts b/src/comments.ts index 2f47035..9e6536c 100644 --- a/src/comments.ts +++ b/src/comments.ts @@ -12,28 +12,47 @@ export function shiftTopLineAboveComment(activeEditor: TextEditor, documentSymbo if (!language?.supportsComments()) { return documentSymbol.range.start.line; } - + let lineAbove = documentSymbol.range.start.line - 1; - let lineTextAbove = activeEditor.document.lineAt(lineAbove).text; + let lineTextAbove = getLineTextAbove(activeEditor, lineAbove); + + if (lineAbove < 0) return 0; if (language.isSingleLineComment(lineTextAbove)) { while (language.isSingleLineComment(lineTextAbove)) { lineAbove--; - lineTextAbove = activeEditor.document.lineAt(lineAbove).text; + lineTextAbove = getLineTextAbove(activeEditor, lineAbove); } return lineAbove + 1; } - + if (language.isMultiLineCommentEnd(lineTextAbove)) { lineAbove--; - lineTextAbove = activeEditor.document.lineAt(lineAbove).text; - while (!language.isMultiLineCommentStart(lineTextAbove)) { + lineTextAbove = getLineTextAbove(activeEditor, lineAbove); + let didFoundMultiLineCommentStart = language.isMultiLineCommentStart(lineTextAbove); + while (!didFoundMultiLineCommentStart) { lineAbove--; - lineTextAbove = activeEditor.document.lineAt(lineAbove).text; - } + lineTextAbove = getLineTextAbove(activeEditor, lineAbove); + + if (!lineTextAbove) break; + + didFoundMultiLineCommentStart = language.isMultiLineCommentStart(lineTextAbove); + } + + if (!didFoundMultiLineCommentStart) { + return documentSymbol.range.start.line; + } + return lineAbove; } return lineAbove + 1; } +function getLineTextAbove(activeEditor: TextEditor, lineAbove: number): string | undefined { + if (lineAbove < 0) { + return undefined; + } + return activeEditor.document.lineAt(lineAbove).text; +} + diff --git a/src/language/javaScriptTypeScript.ts b/src/language/javaScriptTypeScript.ts index 56f1ad2..0516d66 100644 --- a/src/language/javaScriptTypeScript.ts +++ b/src/language/javaScriptTypeScript.ts @@ -11,11 +11,15 @@ export class JavaScriptTypeScriptLanguage implements Language { isMultiLineCommentStart(lineText: string): boolean { return lineText.trim().startsWith("/*") || lineText.trim().startsWith("/**"); } - isMultiLineCommentEnd(lineText: string): boolean { + isMultiLineCommentEnd(lineText: string | undefined): boolean { + if (!lineText) return false; + return lineText.trim().endsWith("*/"); } - isSingleLineComment(lineText: string): boolean { + isSingleLineComment(lineText: string | undefined): boolean { + if (!lineText) return false; + return lineText.trim().startsWith("//"); } diff --git a/src/language/language.ts b/src/language/language.ts index 7bff164..1c72e92 100644 --- a/src/language/language.ts +++ b/src/language/language.ts @@ -7,8 +7,8 @@ import { DocumentSymbol } from "vscode"; export interface Language { isMultiLineCommentStart(lineText: string): boolean; - isMultiLineCommentEnd(lineText: string): boolean; - isSingleLineComment(lineText: string): boolean; + isMultiLineCommentEnd(lineText: string | undefined): boolean; + isSingleLineComment(lineText: string | undefined): boolean; supportsComments(): boolean; isCallback(symbol: DocumentSymbol): boolean; } From 95ef84e6f8adc74ceb76e1562d5857b919299e28 Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Wed, 28 Feb 2024 17:29:02 -0300 Subject: [PATCH 05/21] Enable comments support for Lua --- src/language/lua.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/language/lua.ts b/src/language/lua.ts index 63791ed..c48083d 100644 --- a/src/language/lua.ts +++ b/src/language/lua.ts @@ -20,7 +20,7 @@ export class LuaLanguage implements Language { } supportsComments(): boolean { - return false; + return true; } isCallback(symbol: DocumentSymbol): boolean { From f00b80a76874943b63ece64092b934bd65fdacad Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Thu, 29 Feb 2024 01:25:23 -0300 Subject: [PATCH 06/21] Add first steps for a generic language --- src/language/factory.ts | 3 ++- src/language/generic.ts | 26 ++++++++++++++++++++++++++ src/symbols.ts | 3 ++- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/language/generic.ts diff --git a/src/language/factory.ts b/src/language/factory.ts index d17124f..3cccca8 100644 --- a/src/language/factory.ts +++ b/src/language/factory.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { JAVASCRIPT_TYPESCRIPT_LANGUAGE_IDS, LUA_LANGUAGE_IDS } from "../constants"; +import { GenericLanguage } from "./generic"; import { JavaScriptTypeScriptLanguage } from "./javaScriptTypeScript"; import { Language } from "./language"; import { LuaLanguage } from "./lua"; @@ -16,7 +17,7 @@ export class LanguageFactory { } else if (LUA_LANGUAGE_IDS.includes(languageId)) { return new LuaLanguage(); } else { - return undefined + return new GenericLanguage(); } } } \ No newline at end of file diff --git a/src/language/generic.ts b/src/language/generic.ts new file mode 100644 index 0000000..53aa7a3 --- /dev/null +++ b/src/language/generic.ts @@ -0,0 +1,26 @@ +/*--------------------------------------------------------------------------------------------- +* Copyright (c) Alessandro Fragnani. All rights reserved. +* Licensed under the GPLv3 License. See License.md in the project root for license information. +*--------------------------------------------------------------------------------------------*/ + +import { DocumentSymbol } from "vscode"; +import { Language } from "./language"; + +export class GenericLanguage implements Language { + + isMultiLineCommentStart(lineText: string): boolean { + return /^\s*\/\*/.test(lineText); + } + isMultiLineCommentEnd(lineText: string): boolean { + return /\*\/\s*$/.test(lineText); + } + isSingleLineComment(lineText: string): boolean { + return /^\s*\/\//.test(lineText); + } + supportsComments(): boolean { + return true; + } + isCallback(symbol: DocumentSymbol): boolean { + return false; + } +} \ No newline at end of file diff --git a/src/symbols.ts b/src/symbols.ts index 105e753..97dda44 100644 --- a/src/symbols.ts +++ b/src/symbols.ts @@ -5,6 +5,7 @@ import { commands, DocumentSymbol, SymbolKind, TextDocument, window, workspace } from "vscode"; import { LanguageFactory } from "./language/factory"; +import { GenericLanguage } from "./language/generic"; function getSymbolsFrom(symbol: DocumentSymbol, level: number): DocumentSymbol[] { @@ -41,7 +42,7 @@ function shouldIgnore(symbol: DocumentSymbol, textDocument: TextDocument | undef } const language = LanguageFactory.getLanguage(textDocument?.languageId); - if (!language) { + if (language instanceof GenericLanguage) { return false; } From e7b7867c999e2dc6bef056705d6ff78de59441bd Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Thu, 29 Feb 2024 01:27:04 -0300 Subject: [PATCH 07/21] Add settings that expose regexes for generic language --- package.json | 20 ++++++++++++++++++++ src/comments.ts | 7 ++++++- src/language/generic.ts | 18 ++++++++++++++---- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 9fc6d97..795e5fa 100644 --- a/package.json +++ b/package.json @@ -154,6 +154,26 @@ "Two separators surrounding the symbol" ], "description": "%separators.configuration.location.description%" + }, + "separators.aboveComments.enabled": { + "type": "boolean", + "default": false, + "description": "%separators.configuration.aboveComments.enabled.description%" + }, + "separators.aboveComments.singleLineCommentRegex": { + "type": "string", + "default": "^\\s*\/\/", + "description": "%separators.configuration.aboveComments.singleLineCommentRegex.description%" + }, + "separators.aboveComments.multiLineCommentStartRegex": { + "type": "string", + "default": "^\\s*\\/\\*", + "description": "%separators.configuration.aboveComments.multiLineCommentStartRegex.description%" + }, + "separators.aboveComments.multiLineCommentEndRegex": { + "type": "string", + "default": "\\*\\/\\s*$", + "description": "%separators.configuration.aboveComments.multiLineCommentEndRegex.description%" } } }, diff --git a/src/comments.ts b/src/comments.ts index 9e6536c..f4bd66e 100644 --- a/src/comments.ts +++ b/src/comments.ts @@ -3,11 +3,16 @@ * Licensed under the GPLv3 License. See License.md in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { DocumentSymbol, TextEditor } from "vscode"; +import { DocumentSymbol, TextEditor, workspace } from "vscode"; import { LanguageFactory } from "./language/factory"; export function shiftTopLineAboveComment(activeEditor: TextEditor, documentSymbol: DocumentSymbol): number { + const isEnabled = workspace.getConfiguration('separators.aboveComments').get('enabled', false); + if (!isEnabled) { + return documentSymbol.range.start.line; + } + const language = LanguageFactory.getLanguage(activeEditor.document?.languageId); if (!language?.supportsComments()) { return documentSymbol.range.start.line; diff --git a/src/language/generic.ts b/src/language/generic.ts index 53aa7a3..cd3d1b3 100644 --- a/src/language/generic.ts +++ b/src/language/generic.ts @@ -3,23 +3,33 @@ * Licensed under the GPLv3 License. See License.md in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { DocumentSymbol } from "vscode"; +import { DocumentSymbol, workspace } from "vscode"; import { Language } from "./language"; export class GenericLanguage implements Language { isMultiLineCommentStart(lineText: string): boolean { - return /^\s*\/\*/.test(lineText); + const config = workspace.getConfiguration('separators.aboveComments').get('multiLineCommentStartRegex', "^\\s*/*"); + const multiLineCommentStartRegex = new RegExp(config); + return multiLineCommentStartRegex.test(lineText); } + isMultiLineCommentEnd(lineText: string): boolean { - return /\*\/\s*$/.test(lineText); + const config = workspace.getConfiguration('separators.aboveComments').get('multiLineCommentEndRegex', "\\*\\/\\s*$"); + const multiLineCommentEndRegex = new RegExp(config); + return multiLineCommentEndRegex.test(lineText); } + isSingleLineComment(lineText: string): boolean { - return /^\s*\/\//.test(lineText); + const config = workspace.getConfiguration('separators.aboveComments').get('singleLineCommentRegex', "^\\s*//"); + const singleLineCommentRegex = new RegExp(config); + return singleLineCommentRegex.test(lineText); } + supportsComments(): boolean { return true; } + isCallback(symbol: DocumentSymbol): boolean { return false; } From d5d3c822b9d0fee8a197abb517c3739ebd4f7e6d Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Fri, 1 Mar 2024 01:04:11 -0300 Subject: [PATCH 08/21] Expand settings to structured list of comments --- package.json | 63 ++++++++++++++++++++++++++++ rules.json | 40 ++++++++++++++++++ src/comments.ts | 55 ++++--------------------- src/comments/config.ts | 20 +++++++++ src/comments/regexComment.ts | 77 +++++++++++++++++++++++++++++++++++ src/comments/rulesProvider.ts | 28 +++++++++++++ src/decoration.ts | 4 +- src/extension.ts | 2 +- 8 files changed, 240 insertions(+), 49 deletions(-) create mode 100644 rules.json create mode 100644 src/comments/config.ts create mode 100644 src/comments/regexComment.ts create mode 100644 src/comments/rulesProvider.ts diff --git a/package.json b/package.json index 795e5fa..752d3e0 100644 --- a/package.json +++ b/package.json @@ -160,6 +160,69 @@ "default": false, "description": "%separators.configuration.aboveComments.enabled.description%" }, + "separators.aboveComments.rules": { + "type": "array", + "default": [], + "items": { + "type": "object", + "required": [ + "name", + "languageIds", + "rules" + ], + "properties": { + "name": { + "type": "string", + "description": "Specifies the name of the rule" + }, + "languageIds": { + "type": "array", + "items": { + "type": "string", + "uniqueItems": true + }, + "description": "Specifies the list of language IDs to which this rule applies" + }, + "rules": { + "type": "object", + "items": { + "type": "object", + "required": [ + "singleLine", + "multiLine" + ], + "properties": { + "singleLine": { + "type": "string", + "description": "Specifies the glob pattern to match single line comments" + }, + "multiLine": { + "type": "object", + "required": [ + "start", + "end" + ], + "properties": { + "start": { + "type": "string", + "description": "Specifies the glob pattern to match multi line comments start" + }, + "end": { + "type": "string", + "description": "Specifies the glob pattern to match multi line comments end" + } + } + } + }, + "uniqueItems": true + }, + "description": "Specifies the list of rules to match comments" + } + } + }, + "markdownDescription": "%separators.configuration.aboveComments.rules.description%", + "scope": "window" + }, "separators.aboveComments.singleLineCommentRegex": { "type": "string", "default": "^\\s*\/\/", diff --git a/rules.json b/rules.json new file mode 100644 index 0000000..384e72e --- /dev/null +++ b/rules.json @@ -0,0 +1,40 @@ +[ + { + "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": "Lua", + "languageIds": [ + "lua" + ], + "rules": { + "singleLine": "^\\s*--", + "multiLine": { + "start": "^\\s*\\-\\-\\[\\[", + "end": "\\]\\]\\s*$" + } + } + } +] \ No newline at end of file diff --git a/src/comments.ts b/src/comments.ts index f4bd66e..d8fcef1 100644 --- a/src/comments.ts +++ b/src/comments.ts @@ -4,60 +4,23 @@ *--------------------------------------------------------------------------------------------*/ import { DocumentSymbol, TextEditor, workspace } from "vscode"; -import { LanguageFactory } from "./language/factory"; +import { RulesProvider } from "./comments/rulesProvider"; +import { RegexComment } from "./comments/regexComment"; -export function shiftTopLineAboveComment(activeEditor: TextEditor, documentSymbol: DocumentSymbol): number { +export async function shiftTopLineAboveComment(activeEditor: TextEditor, documentSymbol: DocumentSymbol): Promise { const isEnabled = workspace.getConfiguration('separators.aboveComments').get('enabled', false); if (!isEnabled) { return documentSymbol.range.start.line; } - const language = LanguageFactory.getLanguage(activeEditor.document?.languageId); - if (!language?.supportsComments()) { - return documentSymbol.range.start.line; - } - - let lineAbove = documentSymbol.range.start.line - 1; - let lineTextAbove = getLineTextAbove(activeEditor, lineAbove); - - if (lineAbove < 0) return 0; - - if (language.isSingleLineComment(lineTextAbove)) { - while (language.isSingleLineComment(lineTextAbove)) { - lineAbove--; - lineTextAbove = getLineTextAbove(activeEditor, lineAbove); - } - return lineAbove + 1; + const ruleProvider = new RulesProvider(); + const ruleConfig = await ruleProvider.getRuleConfigForLanguage(activeEditor.document?.languageId); + if (ruleConfig) { + const regexComment = new RegexComment(ruleConfig); + return regexComment.shiftTopLineAboveComment(activeEditor, documentSymbol); } - - if (language.isMultiLineCommentEnd(lineTextAbove)) { - lineAbove--; - lineTextAbove = getLineTextAbove(activeEditor, lineAbove); - let didFoundMultiLineCommentStart = language.isMultiLineCommentStart(lineTextAbove); - while (!didFoundMultiLineCommentStart) { - lineAbove--; - lineTextAbove = getLineTextAbove(activeEditor, lineAbove); - - if (!lineTextAbove) break; - - didFoundMultiLineCommentStart = language.isMultiLineCommentStart(lineTextAbove); - } - - if (!didFoundMultiLineCommentStart) { - return documentSymbol.range.start.line; - } - return lineAbove; - } - - return lineAbove + 1; -} - -function getLineTextAbove(activeEditor: TextEditor, lineAbove: number): string | undefined { - if (lineAbove < 0) { - return undefined; - } - return activeEditor.document.lineAt(lineAbove).text; + return documentSymbol.range.start.line; } diff --git a/src/comments/config.ts b/src/comments/config.ts new file mode 100644 index 0000000..da56dae --- /dev/null +++ b/src/comments/config.ts @@ -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; +} diff --git a/src/comments/regexComment.ts b/src/comments/regexComment.ts new file mode 100644 index 0000000..c08bd9f --- /dev/null +++ b/src/comments/regexComment.ts @@ -0,0 +1,77 @@ +/*--------------------------------------------------------------------------------------------- +* Copyright (c) Alessandro Fragnani. All rights reserved. +* Licensed under the GPLv3 License. See License.md in the project root for license information. +*--------------------------------------------------------------------------------------------*/ + +import { TextEditor, DocumentSymbol } from "vscode"; +import { RuleConfig } from "./config"; + +export class RegexComment { + private _config: RuleConfig; + + constructor(config: RuleConfig) { + this._config = config + } + + public shiftTopLineAboveComment(activeEditor: TextEditor, documentSymbol: DocumentSymbol): number { + let lineAbove = documentSymbol.range.start.line - 1; + let lineTextAbove = getLineTextAbove(activeEditor, lineAbove); + + if (lineAbove < 0) return 0; + + if (this.isSingleLineComment(lineTextAbove)) { + while (this.isSingleLineComment(lineTextAbove)) { + lineAbove--; + lineTextAbove = getLineTextAbove(activeEditor, lineAbove); + } + return lineAbove + 1; + } + + if (this.isMultiLineCommentEnd(lineTextAbove)) { + lineAbove--; + lineTextAbove = getLineTextAbove(activeEditor, lineAbove); + let didFoundMultiLineCommentStart = this.isMultiLineCommentStart(lineTextAbove); + while (!didFoundMultiLineCommentStart) { + lineAbove--; + lineTextAbove = getLineTextAbove(activeEditor, lineAbove); + + if (!lineTextAbove) break; + + didFoundMultiLineCommentStart = this.isMultiLineCommentStart(lineTextAbove); + } + + if (!didFoundMultiLineCommentStart) { + return documentSymbol.range.start.line; + } + + return lineAbove; + } + + return lineAbove + 1; + } + + + private isSingleLineComment(lineText: string): boolean { + const singleLineCommentRegex = new RegExp(this._config.rules.singleLine); + return singleLineCommentRegex.test(lineText); + } + + + private isMultiLineCommentStart(lineText: string): boolean { + const multiLineCommentStartRegex = new RegExp(this._config.rules.multiLine.start); + return multiLineCommentStartRegex.test(lineText); + } + + private isMultiLineCommentEnd(lineText: string): boolean { + const multiLineCommentStartRegex = new RegExp(this._config.rules.multiLine.end); + return multiLineCommentStartRegex.test(lineText); + } +} + +function getLineTextAbove(activeEditor: TextEditor, lineAbove: number): string | undefined { + if (lineAbove < 0) { + return undefined; + } + return activeEditor.document.lineAt(lineAbove).text; +} + diff --git a/src/comments/rulesProvider.ts b/src/comments/rulesProvider.ts new file mode 100644 index 0000000..d40f802 --- /dev/null +++ b/src/comments/rulesProvider.ts @@ -0,0 +1,28 @@ +/*--------------------------------------------------------------------------------------------- +* Copyright (c) Alessandro Fragnani. All rights reserved. +* Licensed under the GPLv3 License. See License.md in the project root for license information. +*--------------------------------------------------------------------------------------------*/ + +import { Uri, workspace } from "vscode"; +import { RuleConfig } from "./config"; +import { Container } from "../container"; + +const textDecoder = new TextDecoder('utf8'); + +export class RulesProvider { + + private _builtinRules: Thenable; + private _userRules: RuleConfig[]; + + constructor() { + this._builtinRules = workspace.fs.readFile(Uri.joinPath(Container.context.extensionUri, './rules.json')).then(bytes => JSON.parse(textDecoder.decode(bytes))); + this._userRules = workspace.getConfiguration("separators.aboveComments").get("rules", []); + } + + public async getRuleConfigForLanguage(languageId: string): Promise { + const rules = await this._builtinRules; + rules.push(...this._userRules); + + return rules.find(c => c.languageIds.includes(languageId)); + } +} \ No newline at end of file diff --git a/src/decoration.ts b/src/decoration.ts index 04cc24c..e0e4236 100644 --- a/src/decoration.ts +++ b/src/decoration.ts @@ -66,7 +66,7 @@ export function createTextEditorDecoration(symbolKind: string): TextEditorDecora } } -export function updateDecorationsInActiveEditor(activeEditor: TextEditor | undefined, +export async function updateDecorationsInActiveEditor(activeEditor: TextEditor | undefined, symbols: DocumentSymbol[] | undefined, decorationType: TextEditorDecorationTypePair) { if (!activeEditor) { @@ -87,7 +87,7 @@ export function updateDecorationsInActiveEditor(activeEditor: TextEditor | undef for (const element of symbols) { if (location === Location.aboveTheSymbol || location === Location.surroundingTheSymbol) { - const topLine = shiftTopLineAboveComment(activeEditor, element) + const topLine = await shiftTopLineAboveComment(activeEditor, element) const decorationAbove = new Range(topLine, 0, topLine, 0); rangesAbove.push(decorationAbove); } diff --git a/src/extension.ts b/src/extension.ts index e98e8b4..f1c1b75 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -64,7 +64,7 @@ export async function activate(context: vscode.ExtensionContext) { } for (const symbol of DEFAULT_ENABLED_SYMBOLS) { - updateDecorationsInActiveEditor( + await updateDecorationsInActiveEditor( vscode.window.activeTextEditor, symbols.filter(s => s.kind === getSymbolKindAsKind(symbol)), // eslint-disable-next-line @typescript-eslint/no-non-null-assertion From 2c3ef8aac925777175c5527da0c94e15d0eaf84e Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Fri, 1 Mar 2024 08:09:45 -0300 Subject: [PATCH 09/21] Move RulesProvider to Container object --- src/comments.ts | 6 +++--- src/comments/rulesProvider.ts | 14 ++++++++++---- src/container.ts | 10 ++++++++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/comments.ts b/src/comments.ts index d8fcef1..7d72c40 100644 --- a/src/comments.ts +++ b/src/comments.ts @@ -4,8 +4,8 @@ *--------------------------------------------------------------------------------------------*/ import { DocumentSymbol, TextEditor, workspace } from "vscode"; -import { RulesProvider } from "./comments/rulesProvider"; import { RegexComment } from "./comments/regexComment"; +import { Container } from "./container"; export async function shiftTopLineAboveComment(activeEditor: TextEditor, documentSymbol: DocumentSymbol): Promise { @@ -14,8 +14,8 @@ export async function shiftTopLineAboveComment(activeEditor: TextEditor, documen return documentSymbol.range.start.line; } - const ruleProvider = new RulesProvider(); - const ruleConfig = await ruleProvider.getRuleConfigForLanguage(activeEditor.document?.languageId); + // const ruleProvider = new RulesProvider(Container.context); + const ruleConfig = await Container.rulesProvider.getRuleConfigForLanguage(activeEditor.document?.languageId); if (ruleConfig) { const regexComment = new RegexComment(ruleConfig); return regexComment.shiftTopLineAboveComment(activeEditor, documentSymbol); diff --git a/src/comments/rulesProvider.ts b/src/comments/rulesProvider.ts index d40f802..2e4064e 100644 --- a/src/comments/rulesProvider.ts +++ b/src/comments/rulesProvider.ts @@ -3,7 +3,7 @@ * Licensed under the GPLv3 License. See License.md in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Uri, workspace } from "vscode"; +import { ExtensionContext, Uri, workspace } from "vscode"; import { RuleConfig } from "./config"; import { Container } from "../container"; @@ -14,15 +14,21 @@ export class RulesProvider { private _builtinRules: Thenable; private _userRules: RuleConfig[]; - constructor() { - this._builtinRules = workspace.fs.readFile(Uri.joinPath(Container.context.extensionUri, './rules.json')).then(bytes => JSON.parse(textDecoder.decode(bytes))); + constructor(context: ExtensionContext) { + this._builtinRules = workspace.fs.readFile(Uri.joinPath(context.extensionUri, './rules.json')).then(bytes => JSON.parse(textDecoder.decode(bytes))); this._userRules = workspace.getConfiguration("separators.aboveComments").get("rules", []); + + context.subscriptions.push(workspace.onDidChangeConfiguration(cfg => { + if (cfg.affectsConfiguration("separators.aboveComments.rules")) { + this._userRules = workspace.getConfiguration("separators.aboveComments").get("rules", []); + } + })); } public async getRuleConfigForLanguage(languageId: string): Promise { const rules = await this._builtinRules; rules.push(...this._userRules); - + return rules.find(c => c.languageIds.includes(languageId)); } } \ No newline at end of file diff --git a/src/container.ts b/src/container.ts index 6f93fe0..baa6c57 100644 --- a/src/container.ts +++ b/src/container.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { ExtensionContext } from "vscode"; +import { RulesProvider } from "./comments/rulesProvider"; export class Container { private static _extContext: ExtensionContext; @@ -15,5 +16,14 @@ export class Container { public static set context(ec: ExtensionContext) { this._extContext = ec; } + + private static _rulesProvider: RulesProvider; + static get rulesProvider() { + if (!this._rulesProvider) { + this._rulesProvider = new RulesProvider(this.context); + } + + return this._rulesProvider; + } } \ No newline at end of file From 14550b186806d957bd99ee1684c640f4d1b1c886 Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Fri, 1 Mar 2024 21:06:12 -0300 Subject: [PATCH 10/21] Update ruleConfig on change of active file --- src/comments.ts | 6 ++---- src/comments/rulesProvider.ts | 1 - src/container.ts | 10 ++++++++++ src/extension.ts | 4 +++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/comments.ts b/src/comments.ts index 7d72c40..d141466 100644 --- a/src/comments.ts +++ b/src/comments.ts @@ -14,10 +14,8 @@ export async function shiftTopLineAboveComment(activeEditor: TextEditor, documen return documentSymbol.range.start.line; } - // const ruleProvider = new RulesProvider(Container.context); - const ruleConfig = await Container.rulesProvider.getRuleConfigForLanguage(activeEditor.document?.languageId); - if (ruleConfig) { - const regexComment = new RegexComment(ruleConfig); + if (Container.ruleConfig) { + const regexComment = new RegexComment(Container.ruleConfig); return regexComment.shiftTopLineAboveComment(activeEditor, documentSymbol); } diff --git a/src/comments/rulesProvider.ts b/src/comments/rulesProvider.ts index 2e4064e..ecc45ab 100644 --- a/src/comments/rulesProvider.ts +++ b/src/comments/rulesProvider.ts @@ -5,7 +5,6 @@ import { ExtensionContext, Uri, workspace } from "vscode"; import { RuleConfig } from "./config"; -import { Container } from "../container"; const textDecoder = new TextDecoder('utf8'); diff --git a/src/container.ts b/src/container.ts index baa6c57..55239bf 100644 --- a/src/container.ts +++ b/src/container.ts @@ -5,9 +5,11 @@ import { ExtensionContext } from "vscode"; import { RulesProvider } from "./comments/rulesProvider"; +import { RuleConfig } from "./comments/config"; export class Container { private static _extContext: ExtensionContext; + private static _ruleConfig: RuleConfig; public static get context(): ExtensionContext { return this._extContext; @@ -25,5 +27,13 @@ export class Container { return this._rulesProvider; } + + public static get ruleConfig(): RuleConfig { + return this._ruleConfig; + } + + public static set ruleConfig(config: RuleConfig) { + this._ruleConfig = config; + } } \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index f1c1b75..1b56b17 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -31,6 +31,7 @@ export async function activate(context: vscode.ExtensionContext) { let isVisible = context.workspaceState.get('separators.visible', true); if (activeEditor) { + Container.ruleConfig = await Container.rulesProvider.getRuleConfigForLanguage(activeEditor.document?.languageId); triggerUpdateDecorations(); } @@ -72,9 +73,10 @@ export async function activate(context: vscode.ExtensionContext) { } } - vscode.window.onDidChangeActiveTextEditor(editor => { + vscode.window.onDidChangeActiveTextEditor(async editor => { if (editor) { activeEditor = editor; + Container.ruleConfig = await Container.rulesProvider.getRuleConfigForLanguage(activeEditor.document?.languageId); triggerUpdateDecorations(); } }, null, context.subscriptions); From e5c7e2e57e177b49999a772d3d77d1e41f7a25cf Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Fri, 1 Mar 2024 21:06:53 -0300 Subject: [PATCH 11/21] Add support to multiple multiLine comments --- rules.json | 41 +++++++++++++++++++++++++++++------- src/comments/config.ts | 2 +- src/comments/regexComment.ts | 17 ++++++++++++--- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/rules.json b/rules.json index 384e72e..6467bac 100644 --- a/rules.json +++ b/rules.json @@ -18,10 +18,33 @@ ], "rules": { "singleLine": "^\\s*\/\/", - "multiLine": { - "start": "^\\s*\\/\\*", - "end": "\\*\\/\\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*$" + } + ] } }, { @@ -31,10 +54,12 @@ ], "rules": { "singleLine": "^\\s*--", - "multiLine": { - "start": "^\\s*\\-\\-\\[\\[", - "end": "\\]\\]\\s*$" - } + "multiLine": [ + { + "start": "^\\s*\\-\\-\\[\\[", + "end": "\\]\\]\\s*$" + } + ] } } ] \ No newline at end of file diff --git a/src/comments/config.ts b/src/comments/config.ts index da56dae..c318030 100644 --- a/src/comments/config.ts +++ b/src/comments/config.ts @@ -11,7 +11,7 @@ export interface RuleConfig { export interface Rules { singleLine: string; - multiLine: MultiLineRule; + multiLine: MultiLineRule[]; } export interface MultiLineRule { diff --git a/src/comments/regexComment.ts b/src/comments/regexComment.ts index c08bd9f..89ffd88 100644 --- a/src/comments/regexComment.ts +++ b/src/comments/regexComment.ts @@ -8,6 +8,7 @@ import { RuleConfig } from "./config"; export class RegexComment { private _config: RuleConfig; + private _currentMultilineRule = 0; constructor(config: RuleConfig) { this._config = config @@ -58,13 +59,23 @@ export class RegexComment { private isMultiLineCommentStart(lineText: string): boolean { - const multiLineCommentStartRegex = new RegExp(this._config.rules.multiLine.start); + const multiLineCommentStartRegex = new RegExp(this._config.rules.multiLine[this._currentMultilineRule].start); return multiLineCommentStartRegex.test(lineText); } private isMultiLineCommentEnd(lineText: string): boolean { - const multiLineCommentStartRegex = new RegExp(this._config.rules.multiLine.end); - return multiLineCommentStartRegex.test(lineText); + let isEndOfMultilineComment = false; + + for (let index = 0; index < this._config.rules.multiLine.length; index++) { + const multiLineCommentStartRegex = new RegExp(this._config.rules.multiLine[index].end); + isEndOfMultilineComment = multiLineCommentStartRegex.test(lineText); + if (isEndOfMultilineComment) { + this._currentMultilineRule = index; + break; + } + } + + return isEndOfMultilineComment; } } From 06e26bc9c480b084aa18b9987d62bcf06024048f Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Fri, 1 Mar 2024 23:56:17 -0300 Subject: [PATCH 12/21] Revert the changes made for per language command support - RulesProvider is the winner --- package.json | 15 ------------ src/language/factory.ts | 3 +-- src/language/generic.ts | 36 ---------------------------- src/language/javaScriptTypeScript.ts | 19 --------------- src/language/language.ts | 4 ---- src/language/lua.ts | 15 ------------ src/symbols.ts | 3 +-- 7 files changed, 2 insertions(+), 93 deletions(-) delete mode 100644 src/language/generic.ts diff --git a/package.json b/package.json index 752d3e0..2d2d9d3 100644 --- a/package.json +++ b/package.json @@ -222,21 +222,6 @@ }, "markdownDescription": "%separators.configuration.aboveComments.rules.description%", "scope": "window" - }, - "separators.aboveComments.singleLineCommentRegex": { - "type": "string", - "default": "^\\s*\/\/", - "description": "%separators.configuration.aboveComments.singleLineCommentRegex.description%" - }, - "separators.aboveComments.multiLineCommentStartRegex": { - "type": "string", - "default": "^\\s*\\/\\*", - "description": "%separators.configuration.aboveComments.multiLineCommentStartRegex.description%" - }, - "separators.aboveComments.multiLineCommentEndRegex": { - "type": "string", - "default": "\\*\\/\\s*$", - "description": "%separators.configuration.aboveComments.multiLineCommentEndRegex.description%" } } }, diff --git a/src/language/factory.ts b/src/language/factory.ts index 3cccca8..e5b8312 100644 --- a/src/language/factory.ts +++ b/src/language/factory.ts @@ -4,7 +4,6 @@ *--------------------------------------------------------------------------------------------*/ import { JAVASCRIPT_TYPESCRIPT_LANGUAGE_IDS, LUA_LANGUAGE_IDS } from "../constants"; -import { GenericLanguage } from "./generic"; import { JavaScriptTypeScriptLanguage } from "./javaScriptTypeScript"; import { Language } from "./language"; import { LuaLanguage } from "./lua"; @@ -17,7 +16,7 @@ export class LanguageFactory { } else if (LUA_LANGUAGE_IDS.includes(languageId)) { return new LuaLanguage(); } else { - return new GenericLanguage(); + return undefined; } } } \ No newline at end of file diff --git a/src/language/generic.ts b/src/language/generic.ts deleted file mode 100644 index cd3d1b3..0000000 --- a/src/language/generic.ts +++ /dev/null @@ -1,36 +0,0 @@ -/*--------------------------------------------------------------------------------------------- -* Copyright (c) Alessandro Fragnani. All rights reserved. -* Licensed under the GPLv3 License. See License.md in the project root for license information. -*--------------------------------------------------------------------------------------------*/ - -import { DocumentSymbol, workspace } from "vscode"; -import { Language } from "./language"; - -export class GenericLanguage implements Language { - - isMultiLineCommentStart(lineText: string): boolean { - const config = workspace.getConfiguration('separators.aboveComments').get('multiLineCommentStartRegex', "^\\s*/*"); - const multiLineCommentStartRegex = new RegExp(config); - return multiLineCommentStartRegex.test(lineText); - } - - isMultiLineCommentEnd(lineText: string): boolean { - const config = workspace.getConfiguration('separators.aboveComments').get('multiLineCommentEndRegex', "\\*\\/\\s*$"); - const multiLineCommentEndRegex = new RegExp(config); - return multiLineCommentEndRegex.test(lineText); - } - - isSingleLineComment(lineText: string): boolean { - const config = workspace.getConfiguration('separators.aboveComments').get('singleLineCommentRegex', "^\\s*//"); - const singleLineCommentRegex = new RegExp(config); - return singleLineCommentRegex.test(lineText); - } - - supportsComments(): boolean { - return true; - } - - isCallback(symbol: DocumentSymbol): boolean { - return false; - } -} \ No newline at end of file diff --git a/src/language/javaScriptTypeScript.ts b/src/language/javaScriptTypeScript.ts index 0516d66..ea2f868 100644 --- a/src/language/javaScriptTypeScript.ts +++ b/src/language/javaScriptTypeScript.ts @@ -8,25 +8,6 @@ import { Language } from "./language"; export class JavaScriptTypeScriptLanguage implements Language { - isMultiLineCommentStart(lineText: string): boolean { - return lineText.trim().startsWith("/*") || lineText.trim().startsWith("/**"); - } - isMultiLineCommentEnd(lineText: string | undefined): boolean { - if (!lineText) return false; - - return lineText.trim().endsWith("*/"); - } - - isSingleLineComment(lineText: string | undefined): boolean { - if (!lineText) return false; - - return lineText.trim().startsWith("//"); - } - - supportsComments(): boolean { - return true; - } - isCallback(symbol: DocumentSymbol): boolean { return symbol.name.endsWith(' callback'); } diff --git a/src/language/language.ts b/src/language/language.ts index 1c72e92..a88b68c 100644 --- a/src/language/language.ts +++ b/src/language/language.ts @@ -6,9 +6,5 @@ import { DocumentSymbol } from "vscode"; export interface Language { - isMultiLineCommentStart(lineText: string): boolean; - isMultiLineCommentEnd(lineText: string | undefined): boolean; - isSingleLineComment(lineText: string | undefined): boolean; - supportsComments(): boolean; isCallback(symbol: DocumentSymbol): boolean; } diff --git a/src/language/lua.ts b/src/language/lua.ts index c48083d..f6b9e65 100644 --- a/src/language/lua.ts +++ b/src/language/lua.ts @@ -8,21 +8,6 @@ import { Language } from "./language"; export class LuaLanguage implements Language { - isMultiLineCommentStart(lineText: string): boolean { - return lineText.trim().startsWith("--[["); - } - isMultiLineCommentEnd(lineText: string): boolean { - return lineText.trim().endsWith("]]"); - } - - isSingleLineComment(lineText: string): boolean { - return lineText.trim().startsWith("--"); - } - - supportsComments(): boolean { - return true; - } - isCallback(symbol: DocumentSymbol): boolean { return symbol.name === "" && symbol.detail.includes("-> function"); } diff --git a/src/symbols.ts b/src/symbols.ts index 97dda44..105e753 100644 --- a/src/symbols.ts +++ b/src/symbols.ts @@ -5,7 +5,6 @@ import { commands, DocumentSymbol, SymbolKind, TextDocument, window, workspace } from "vscode"; import { LanguageFactory } from "./language/factory"; -import { GenericLanguage } from "./language/generic"; function getSymbolsFrom(symbol: DocumentSymbol, level: number): DocumentSymbol[] { @@ -42,7 +41,7 @@ function shouldIgnore(symbol: DocumentSymbol, textDocument: TextDocument | undef } const language = LanguageFactory.getLanguage(textDocument?.languageId); - if (language instanceof GenericLanguage) { + if (!language) { return false; } From bff7554ddb1098e76c7664a1f519a561a9b31ebb Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Sat, 2 Mar 2024 00:32:27 -0300 Subject: [PATCH 13/21] Add TODOs --- src/comments/regexComment.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/comments/regexComment.ts b/src/comments/regexComment.ts index 89ffd88..8bb8ba9 100644 --- a/src/comments/regexComment.ts +++ b/src/comments/regexComment.ts @@ -14,6 +14,8 @@ export class RegexComment { this._config = config } + // TODO: Multiline comments on the same line are not supported + // TODO: Multiline comments with empty lines are not supported public shiftTopLineAboveComment(activeEditor: TextEditor, documentSymbol: DocumentSymbol): number { let lineAbove = documentSymbol.range.start.line - 1; let lineTextAbove = getLineTextAbove(activeEditor, lineAbove); From 21b0836c74d9aace0b1cb5296788e0144e49a1bb Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Sat, 2 Mar 2024 00:37:52 -0300 Subject: [PATCH 14/21] Fix multiline comments on the same line --- src/comments/regexComment.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/comments/regexComment.ts b/src/comments/regexComment.ts index 8bb8ba9..90ff266 100644 --- a/src/comments/regexComment.ts +++ b/src/comments/regexComment.ts @@ -14,7 +14,7 @@ export class RegexComment { this._config = config } - // TODO: Multiline comments on the same line are not supported + // TODO [OK]: Multiline comments on the same line are not supported // TODO: Multiline comments with empty lines are not supported public shiftTopLineAboveComment(activeEditor: TextEditor, documentSymbol: DocumentSymbol): number { let lineAbove = documentSymbol.range.start.line - 1; @@ -31,6 +31,10 @@ export class RegexComment { } if (this.isMultiLineCommentEnd(lineTextAbove)) { + if (this.isMultiLineCommentStart(lineTextAbove)) { + return lineAbove; + } + lineAbove--; lineTextAbove = getLineTextAbove(activeEditor, lineAbove); let didFoundMultiLineCommentStart = this.isMultiLineCommentStart(lineTextAbove); @@ -69,8 +73,8 @@ export class RegexComment { let isEndOfMultilineComment = false; for (let index = 0; index < this._config.rules.multiLine.length; index++) { - const multiLineCommentStartRegex = new RegExp(this._config.rules.multiLine[index].end); - isEndOfMultilineComment = multiLineCommentStartRegex.test(lineText); + const multiLineCommentEndRegex = new RegExp(this._config.rules.multiLine[index].end); + isEndOfMultilineComment = multiLineCommentEndRegex.test(lineText); if (isEndOfMultilineComment) { this._currentMultilineRule = index; break; From dbb2dc9d31bb015db2197fcbffd2ea1accdaaa86 Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Sat, 2 Mar 2024 01:00:42 -0300 Subject: [PATCH 15/21] Fix multiline comments with empty lines --- src/comments/regexComment.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/comments/regexComment.ts b/src/comments/regexComment.ts index 90ff266..6cc5790 100644 --- a/src/comments/regexComment.ts +++ b/src/comments/regexComment.ts @@ -42,7 +42,7 @@ export class RegexComment { lineAbove--; lineTextAbove = getLineTextAbove(activeEditor, lineAbove); - if (!lineTextAbove) break; + if (lineTextAbove === undefined) break; didFoundMultiLineCommentStart = this.isMultiLineCommentStart(lineTextAbove); } From 9c1f0c07ebf4a7af15915c1a79f5a45362f136a8 Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Sat, 2 Mar 2024 01:02:12 -0300 Subject: [PATCH 16/21] Fix multiline comments with no start --- src/comments.ts | 4 ++-- src/comments/regexComment.ts | 9 ++++++--- src/decoration.ts | 6 ++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/comments.ts b/src/comments.ts index d141466..2b9353a 100644 --- a/src/comments.ts +++ b/src/comments.ts @@ -7,7 +7,7 @@ import { DocumentSymbol, TextEditor, workspace } from "vscode"; import { RegexComment } from "./comments/regexComment"; import { Container } from "./container"; -export async function shiftTopLineAboveComment(activeEditor: TextEditor, documentSymbol: DocumentSymbol): Promise { +export async function shiftTopLineAboveComment(activeEditor: TextEditor, documentSymbol: DocumentSymbol, documentSymbolAbove: DocumentSymbol): Promise { const isEnabled = workspace.getConfiguration('separators.aboveComments').get('enabled', false); if (!isEnabled) { @@ -16,7 +16,7 @@ export async function shiftTopLineAboveComment(activeEditor: TextEditor, documen if (Container.ruleConfig) { const regexComment = new RegexComment(Container.ruleConfig); - return regexComment.shiftTopLineAboveComment(activeEditor, documentSymbol); + return regexComment.shiftTopLineAboveComment(activeEditor, documentSymbol, documentSymbolAbove); } return documentSymbol.range.start.line; diff --git a/src/comments/regexComment.ts b/src/comments/regexComment.ts index 6cc5790..4c73d3d 100644 --- a/src/comments/regexComment.ts +++ b/src/comments/regexComment.ts @@ -15,8 +15,9 @@ export class RegexComment { } // TODO [OK]: Multiline comments on the same line are not supported - // TODO: Multiline comments with empty lines are not supported - public shiftTopLineAboveComment(activeEditor: TextEditor, documentSymbol: DocumentSymbol): number { + // TODO [OK]: Multiline comments with empty lines are not supported + // TODO [OK]: Multiline comments with no start are not supported + public shiftTopLineAboveComment(activeEditor: TextEditor, documentSymbol: DocumentSymbol, documentSymbolAbove: DocumentSymbol): number { let lineAbove = documentSymbol.range.start.line - 1; let lineTextAbove = getLineTextAbove(activeEditor, lineAbove); @@ -38,13 +39,15 @@ export class RegexComment { lineAbove--; lineTextAbove = getLineTextAbove(activeEditor, lineAbove); let didFoundMultiLineCommentStart = this.isMultiLineCommentStart(lineTextAbove); - while (!didFoundMultiLineCommentStart) { + let didFoundSymbolAbove = false; + while (!didFoundMultiLineCommentStart && !didFoundSymbolAbove) { lineAbove--; lineTextAbove = getLineTextAbove(activeEditor, lineAbove); if (lineTextAbove === undefined) break; didFoundMultiLineCommentStart = this.isMultiLineCommentStart(lineTextAbove); + didFoundSymbolAbove = documentSymbolAbove?.range.end.line === lineAbove; } if (!didFoundMultiLineCommentStart) { diff --git a/src/decoration.ts b/src/decoration.ts index e0e4236..9b47968 100644 --- a/src/decoration.ts +++ b/src/decoration.ts @@ -85,9 +85,11 @@ export async function updateDecorationsInActiveEditor(activeEditor: TextEditor | const rangesAbove: Range[] = []; const rangesBelow: Range[] = []; - for (const element of symbols) { + for (let i = 0; i < symbols.length; i++) { + const element = symbols[i]; + const elementAbove = i === 0 ? undefined : symbols[i - 1]; if (location === Location.aboveTheSymbol || location === Location.surroundingTheSymbol) { - const topLine = await shiftTopLineAboveComment(activeEditor, element) + const topLine = await shiftTopLineAboveComment(activeEditor, element, elementAbove); const decorationAbove = new Range(topLine, 0, topLine, 0); rangesAbove.push(decorationAbove); } From 0c2c4c532fcf5593f35f59676d817dceee8ef151 Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Sat, 2 Mar 2024 18:10:21 -0300 Subject: [PATCH 17/21] Update config rules (package.json) to support multiple multiLine comments; Localize new settings --- package.json | 46 +++++++++++++++++++++++----------------------- package.nls.json | 8 ++++++++ 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 2d2d9d3..eb8c555 100644 --- a/package.json +++ b/package.json @@ -158,11 +158,12 @@ "separators.aboveComments.enabled": { "type": "boolean", "default": false, - "description": "%separators.configuration.aboveComments.enabled.description%" + "description": "separators.configuration.aboveComments.enabled.description" }, "separators.aboveComments.rules": { "type": "array", "default": [], + "description": "%separators.configuration.aboveComments.rules.description%", "items": { "type": "object", "required": [ @@ -173,7 +174,7 @@ "properties": { "name": { "type": "string", - "description": "Specifies the name of the rule" + "description": "%separators.configuration.aboveComments.rules.name.description%" }, "languageIds": { "type": "array", @@ -181,22 +182,24 @@ "type": "string", "uniqueItems": true }, - "description": "Specifies the list of language IDs to which this rule applies" + "description": "%separators.configuration.aboveComments.rules.languageIds.description%" }, "rules": { "type": "object", - "items": { - "type": "object", - "required": [ - "singleLine", - "multiLine" - ], - "properties": { - "singleLine": { - "type": "string", - "description": "Specifies the glob pattern to match single line comments" - }, - "multiLine": { + "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", @@ -205,22 +208,19 @@ "properties": { "start": { "type": "string", - "description": "Specifies the glob pattern to match multi line comments start" + "description": "%separators.configuration.aboveComments.rules.rules.multiLine.start.description%" }, - "end": { + "end": { "type": "string", - "description": "Specifies the glob pattern to match multi line comments end" + "description": "%separators.configuration.aboveComments.rules.rules.multiLine.end.description%" } } } - }, - "uniqueItems": true - }, - "description": "Specifies the list of rules to match comments" + } + } } } }, - "markdownDescription": "%separators.configuration.aboveComments.rules.description%", "scope": "window" } } diff --git a/package.nls.json b/package.nls.json index 96fb8ca..8e60864 100644 --- a/package.nls.json +++ b/package.nls.json @@ -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", From 7a9371d16c40031f452a5a85fe247ab89e09e228 Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Mon, 4 Mar 2024 20:45:50 -0300 Subject: [PATCH 18/21] Update to use separators.location setting instead of separators.aboveComments.enabled --- package.json | 7 ++----- src/comments.ts | 3 ++- src/constants.ts | 9 +++++++++ src/decoration.ts | 7 ++++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index eb8c555..4624889 100644 --- a/package.json +++ b/package.json @@ -145,21 +145,18 @@ "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.enabled": { - "type": "boolean", - "default": false, - "description": "separators.configuration.aboveComments.enabled.description" - }, "separators.aboveComments.rules": { "type": "array", "default": [], diff --git a/src/comments.ts b/src/comments.ts index 2b9353a..a02bb20 100644 --- a/src/comments.ts +++ b/src/comments.ts @@ -6,10 +6,11 @@ import { DocumentSymbol, TextEditor, workspace } from "vscode"; import { RegexComment } from "./comments/regexComment"; import { Container } from "./container"; +import { Location } from "./constants"; export async function shiftTopLineAboveComment(activeEditor: TextEditor, documentSymbol: DocumentSymbol, documentSymbolAbove: DocumentSymbol): Promise { - const isEnabled = workspace.getConfiguration('separators.aboveComments').get('enabled', false); + const isEnabled = workspace.getConfiguration("separators").get("location", Location.aboveTheSymbol) === Location.aboveTheComment; if (!isEnabled) { return documentSymbol.range.start.line; } diff --git a/src/constants.ts b/src/constants.ts index 30bba29..74b6ca7 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -13,6 +13,15 @@ export const LUA_LANGUAGE_IDS = ["lua"]; export enum Location { aboveTheSymbol = "aboveTheSymbol", + aboveTheComment = "aboveTheComment", belowTheSymbol = "belowTheSymbol", surroundingTheSymbol = "surroundingTheSymbol" +} + +export function shouldHaveSeparatorAbove(location: string): boolean { + return location === Location.aboveTheSymbol || location === Location.aboveTheComment || location === Location.surroundingTheSymbol; +} + +export function shouldHaveSeparatorBelow(location: string): boolean { + return location === Location.belowTheSymbol || location === Location.surroundingTheSymbol; } \ No newline at end of file diff --git a/src/decoration.ts b/src/decoration.ts index 9b47968..8c4bece 100644 --- a/src/decoration.ts +++ b/src/decoration.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { window, ThemeColor, TextEditor, Range, TextEditorDecorationType, DecorationRenderOptions, DocumentSymbol, workspace } from "vscode"; -import { DEFAULT_GREENISH_COLOR, Location } from "./constants"; +import { DEFAULT_GREENISH_COLOR, Location, shouldHaveSeparatorAbove, shouldHaveSeparatorBelow } from "./constants"; import { shiftTopLineAboveComment } from "./comments"; export interface TextEditorDecorationTypePair { @@ -88,13 +88,14 @@ export async function updateDecorationsInActiveEditor(activeEditor: TextEditor | for (let i = 0; i < symbols.length; i++) { const element = symbols[i]; const elementAbove = i === 0 ? undefined : symbols[i - 1]; - if (location === Location.aboveTheSymbol || location === Location.surroundingTheSymbol) { + + if (shouldHaveSeparatorAbove(location)) { const topLine = await shiftTopLineAboveComment(activeEditor, element, elementAbove); const decorationAbove = new Range(topLine, 0, topLine, 0); rangesAbove.push(decorationAbove); } - if (location === Location.belowTheSymbol || location === Location.surroundingTheSymbol) { + if (shouldHaveSeparatorBelow(location)) { const decorationBelow = new Range(element.range.end.line, 0, element.range.end.line, 0); rangesBelow.push(decorationBelow); } From be7a333feedeabba5aca23b9720bdcb3d32d3264 Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Mon, 4 Mar 2024 20:56:02 -0300 Subject: [PATCH 19/21] Extract location and move comments --- src/{ => comments}/comments.ts | 6 +++--- src/constants.ts | 15 --------------- src/decoration.ts | 5 +++-- src/location.ts | 19 +++++++++++++++++++ 4 files changed, 25 insertions(+), 20 deletions(-) rename src/{ => comments}/comments.ts (88%) create mode 100644 src/location.ts diff --git a/src/comments.ts b/src/comments/comments.ts similarity index 88% rename from src/comments.ts rename to src/comments/comments.ts index a02bb20..b45720a 100644 --- a/src/comments.ts +++ b/src/comments/comments.ts @@ -4,9 +4,9 @@ *--------------------------------------------------------------------------------------------*/ import { DocumentSymbol, TextEditor, workspace } from "vscode"; -import { RegexComment } from "./comments/regexComment"; -import { Container } from "./container"; -import { Location } from "./constants"; +import { RegexComment } from "./regexComment"; +import { Container } from "../container"; +import { Location } from "../location"; export async function shiftTopLineAboveComment(activeEditor: TextEditor, documentSymbol: DocumentSymbol, documentSymbolAbove: DocumentSymbol): Promise { diff --git a/src/constants.ts b/src/constants.ts index 74b6ca7..22d14ac 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -10,18 +10,3 @@ export const DEFAULT_GREENISH_COLOR = "#65EAB9"; export const JAVASCRIPT_TYPESCRIPT_LANGUAGE_IDS = ["javascript", "javascripreact", "typescript", "typescriptreact"]; export const LUA_LANGUAGE_IDS = ["lua"]; - -export enum Location { - aboveTheSymbol = "aboveTheSymbol", - aboveTheComment = "aboveTheComment", - belowTheSymbol = "belowTheSymbol", - surroundingTheSymbol = "surroundingTheSymbol" -} - -export function shouldHaveSeparatorAbove(location: string): boolean { - return location === Location.aboveTheSymbol || location === Location.aboveTheComment || location === Location.surroundingTheSymbol; -} - -export function shouldHaveSeparatorBelow(location: string): boolean { - return location === Location.belowTheSymbol || location === Location.surroundingTheSymbol; -} \ No newline at end of file diff --git a/src/decoration.ts b/src/decoration.ts index 8c4bece..1cbfd67 100644 --- a/src/decoration.ts +++ b/src/decoration.ts @@ -4,8 +4,9 @@ *--------------------------------------------------------------------------------------------*/ import { window, ThemeColor, TextEditor, Range, TextEditorDecorationType, DecorationRenderOptions, DocumentSymbol, workspace } from "vscode"; -import { DEFAULT_GREENISH_COLOR, Location, shouldHaveSeparatorAbove, shouldHaveSeparatorBelow } from "./constants"; -import { shiftTopLineAboveComment } from "./comments"; +import { DEFAULT_GREENISH_COLOR, } from "./constants"; +import { Location, shouldHaveSeparatorAbove, shouldHaveSeparatorBelow } from "./location"; +import { shiftTopLineAboveComment } from "./comments/comments"; export interface TextEditorDecorationTypePair { above: TextEditorDecorationType; diff --git a/src/location.ts b/src/location.ts new file mode 100644 index 0000000..c4231fc --- /dev/null +++ b/src/location.ts @@ -0,0 +1,19 @@ +/*--------------------------------------------------------------------------------------------- +* Copyright (c) Alessandro Fragnani. All rights reserved. +* Licensed under the GPLv3 License. See License.md in the project root for license information. +*--------------------------------------------------------------------------------------------*/ + +export enum Location { + aboveTheSymbol = "aboveTheSymbol", + aboveTheComment = "aboveTheComment", + belowTheSymbol = "belowTheSymbol", + surroundingTheSymbol = "surroundingTheSymbol" +} + +export function shouldHaveSeparatorAbove(location: string): boolean { + return location === Location.aboveTheSymbol || location === Location.aboveTheComment || location === Location.surroundingTheSymbol; +} + +export function shouldHaveSeparatorBelow(location: string): boolean { + return location === Location.belowTheSymbol || location === Location.surroundingTheSymbol; +} \ No newline at end of file From aaedbdc5b1d29c4be02eb7d77e1e3357f97e15e3 Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Tue, 5 Mar 2024 00:01:12 -0300 Subject: [PATCH 20/21] Update pt-br translation --- package.nls.pt-br.json | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/package.nls.pt-br.json b/package.nls.pt-br.json index 9d8b844..8d67773 100644 --- a/package.nls.pt-br.json +++ b/package.nls.pt-br.json @@ -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", From eca248abcb4821b8b6f7e5aaf4040e310f1c33af Mon Sep 17 00:00:00 2001 From: Alessandro Fragnani Date: Tue, 5 Mar 2024 00:23:26 -0300 Subject: [PATCH 21/21] Update docs --- README.md | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e0844cc..a77f108 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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).