Skip to content

Commit

Permalink
feat: copyCurrentOutlinePath! super useful for working with existin…
Browse files Browse the repository at this point in the history
…g JSON structures from JS
  • Loading branch information
zardoy committed Nov 18, 2022
1 parent 9c54ac6 commit 8d88d8f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,18 @@
"command": "selectOutlineItem",
"title": "Select Outline Item"
},
{
"command": "turnCommentIntoJsdoc",
"title": "Turn Comment Into Jsdoc"
},
{
"command": "copyOutlineItemName",
"title": "Copy Outline Item Name"
},
{
"command": "copyCurrentOutlinePath",
"title": "Copy Current Outline Path"
},
{
"command": "turnCommentIntoJsdoc",
"title": "Turn Comment Into Jsdoc"
},
{
"command": "applyCreatedCodeTransformers",
"title": "Apply Created Code Transformers"
Expand Down Expand Up @@ -528,7 +532,7 @@
"type": "boolean",
"default": false
},
"merge_request.merge_when_pipeline_succeeds":{
"merge_request.merge_when_pipeline_succeeds": {
"type": "boolean",
"default": false
},
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import autoRenameJsx from './features/autoRenameJsx'
import openReferencesInView from './features/openReferencesInView'
import statusbarOccurrencesCount from './features/statusbarOccurrencesCount'
import generateGitlabPush from './features/generateGitlabPush'
import copyCurrentOutlinePath from './features/copyCurrentOutlinePath'

export const activate = () => {
void initGitApi()
Expand Down Expand Up @@ -133,6 +134,7 @@ export const activate = () => {
statusbarOccurrencesCount()
generateGitlabPush()
registerRenameFileParts()
copyCurrentOutlinePath()

registerExtensionCommand('fixedTerminalMaximize', async () => {
await vscode.commands.executeCommand('workbench.action.toggleMaximizedPanel')
Expand Down
26 changes: 26 additions & 0 deletions src/features/copyCurrentOutlinePath.ts
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)
})
}

0 comments on commit 8d88d8f

Please sign in to comment.