-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add fold other platforms command
feat: add fold other platforms command
- Loading branch information
Showing
8 changed files
with
107 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
playground/**/*.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import type { ExtensionContext } from 'vscode' | ||
import { Position, Range, commands, window } from 'vscode' | ||
import { PLATFORM_LIST } from './constants' | ||
import { CommentFoldingRangeProvider } from './CommentFoldingRangeProvider' | ||
|
||
export async function foldOtherPlatformComment(_context: ExtensionContext) { | ||
const platform = await window.showQuickPick([ | ||
...PLATFORM_LIST, | ||
]) | ||
|
||
if (!platform) | ||
return | ||
|
||
const editor = window.activeTextEditor | ||
const document = editor?.document | ||
|
||
if (document) { | ||
const c = new CommentFoldingRangeProvider() | ||
const ranges = c.provideFoldingRanges(document, undefined as any, undefined as any) | ||
if (Array.isArray(ranges)) { | ||
const comments = ranges.map((v) => { | ||
const text = document.getText(lineNumberToRange(v.start)) | ||
return { | ||
start: v.start, | ||
flag: !text?.includes(platform), | ||
} | ||
}) | ||
const fold = comments.filter(v => v.flag).map(v => v.start) | ||
const unfold = comments.filter(v => !v.flag).map(v => v.start) | ||
await commands.executeCommand('editor.unfold', { | ||
levels: 1, | ||
direction: 'up', | ||
selectionLines: unfold, | ||
}) | ||
await commands.executeCommand('editor.fold', { | ||
levels: 1, | ||
direction: 'up', | ||
selectionLines: fold, | ||
}) | ||
} | ||
} | ||
|
||
function lineNumberToRange(line: number): Range { | ||
// Convert the line number to a position | ||
const startPosition = new Position(line, 0) | ||
const endPosition = new Position(line, Number.MAX_SAFE_INTEGER) | ||
|
||
// Create a range using the start and end positions | ||
const range = new Range(startPosition, endPosition) | ||
|
||
return range | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters