-
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:
copyCurrentOutlinePath
! super useful for working with existin…
…g JSON structures from JS
- Loading branch information
Showing
3 changed files
with
37 additions
and
5 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
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,26 @@ | ||
import * as vscode from 'vscode' | ||
import { getActiveRegularEditor } from '@zardoy/vscode-utils' | ||
import { makeOutlineChainFromPos } from '@zardoy/vscode-utils/build/outline' | ||
import { registerExtensionCommand } from 'vscode-framework' | ||
|
||
export default () => { | ||
registerExtensionCommand('copyCurrentOutlinePath', async (_, delimeter?: string) => { | ||
const editor = getActiveRegularEditor() | ||
if (!editor) return | ||
const outlineItems: vscode.DocumentSymbol[] = await vscode.commands.executeCommand('vscode.executeDocumentSymbolProvider', editor.document.uri) | ||
if (!outlineItems) return | ||
const outlinePath = makeOutlineChainFromPos(outlineItems, editor.selection.active).map(({ name }) => name) | ||
if (outlinePath.length === 0) { | ||
void vscode.window.showInformationMessage('Outline path is empty') | ||
return | ||
} | ||
|
||
delimeter ??= await vscode.window.showInputBox({ | ||
title: 'Enter delimeter', | ||
placeHolder: 'Special values: ts', | ||
}) | ||
if (!delimeter) return | ||
const textToCopy = delimeter === 'ts' ? outlinePath.map(x => `["${x.replaceAll('"', '\\"')}"]`).join('') : outlinePath.join(delimeter) | ||
await vscode.env.clipboard.writeText(textToCopy) | ||
}) | ||
} |