Skip to content

Commit a05e8e3

Browse files
authored
Merge pull request #98 from 1nVitr0:develop
Fix code lenses
2 parents a4f4d08 + 744b8a2 commit a05e8e3

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/constants/comments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const commentRegex: Record<string, string> = {
6666

6767
export const commentMarkers: Record<string, TextBlockDefinition[]> = {
6868
default: [
69-
{ start: '//' },
69+
{ start: '(?://|#)' },
7070
{ start: '/\\*', end: '\\*/' },
7171
],
7272
// abap: [],

src/providers/BlockSortFormattingProvider.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ export default class BlockSortFormattingProvider
9393
public getBlockSortMarkerAtRange(document: TextDocument, range: Range): BlockSortMarker | undefined {
9494
const markers = this.getBlockSortMarkers(document);
9595

96-
return markers.find(({ line }) => range.intersection(line.range) !== undefined);
96+
return markers.find(
97+
({ range: markerRange }) => markerRange && markerRange.intersection(range) !== undefined
98+
);
9799
}
98100

99101
public preComputeLineMeta(document: TextDocument, ranges?: Range[], token?: CancellationToken) {
@@ -233,13 +235,14 @@ export default class BlockSortFormattingProvider
233235
): BlockSortMarker[] {
234236
const markers: TextLine[] = [];
235237
const comments = commentMarkers[document.languageId] ?? commentMarkers.default;
236-
const markerPrefixes = comments.map((comment) => `${comment.start} ${BlockSortFormattingProvider.blockSortMarker}`);
238+
const escapedBlockSortMarker = this.escapeRegExp(BlockSortFormattingProvider.blockSortMarker);
239+
const markerPrefixes = comments.map((comment) => new RegExp(`^${comment.start} ${escapedBlockSortMarker}`));
237240

238241
for (let i = range.start.line; i <= range.end.line; i++) {
239242
if (token?.isCancellationRequested) return [];
240243

241244
const line = document.lineAt(i);
242-
if (markerPrefixes.some((prefix) => line.text.trim().startsWith(prefix))) markers.push(line);
245+
if (markerPrefixes.some((prefix) => prefix.test(line.text.trim()))) markers.push(line);
243246
}
244247

245248
const expandRange = this.expandSelection.bind(this, document);
@@ -254,4 +257,8 @@ export default class BlockSortFormattingProvider
254257

255258
return result;
256259
}
260+
261+
private escapeRegExp(input: string) {
262+
return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
263+
}
257264
}

0 commit comments

Comments
 (0)