From 63c68a62e65f090d1877bf648ea0027a8a8b3478 Mon Sep 17 00:00:00 2001 From: Malo Polese Date: Fri, 20 Aug 2021 12:24:56 +0200 Subject: [PATCH] fix(copy): array type --- .github/workflows/marketplace.yml | 18 ------------------ .github/workflows/update-changelog.yml | 19 ------------------- CHANGELOG.md | 9 --------- package.json | 2 +- src/commands/commands.index.ts | 2 +- src/commands/copy.command.ts | 15 ++++++++++++--- .../command.decorator.ts | 0 src/logger.service.ts | 1 - 8 files changed, 14 insertions(+), 52 deletions(-) delete mode 100644 .github/workflows/marketplace.yml delete mode 100644 .github/workflows/update-changelog.yml delete mode 100644 CHANGELOG.md rename src/{decorator => decorators}/command.decorator.ts (100%) diff --git a/.github/workflows/marketplace.yml b/.github/workflows/marketplace.yml deleted file mode 100644 index b988ca7..0000000 --- a/.github/workflows/marketplace.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: "Deploy" -on: - push: - tags: - - 'v*' - release: - types: [published] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Publish - if: success() && startsWith( github.ref, 'refs/tags/releases/') && matrix.os == 'ubuntu-latest' - run: npm run deploy - env: - VSCE_PAT: ${{ secrets.VSCE_PAT }} diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml deleted file mode 100644 index 8afcc0a..0000000 --- a/.github/workflows/update-changelog.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: "Update Changelog CI" -on: - push: - tags: - - 'v*' - release: - types: [published] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - uses: heinrichreimer/github-changelog-generator-action@v2.1.1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - - name: Create Pull Request - uses: peter-evans/create-pull-request@v3 diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 7764972..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,9 +0,0 @@ -# Change Log - -All notable changes to the "copy-json-path" extension will be documented in this file. - -Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. - -## [Unreleased] - -- Initial release \ No newline at end of file diff --git a/package.json b/package.json index 6c44758..fe7f0dc 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "repository": { "url": "https://github.com/MaloPolese/copy-json-path/tree/main" }, - "version": "1.0.0", + "version": "1.0.1", "engines": { "vscode": "^1.58.0" }, diff --git a/src/commands/commands.index.ts b/src/commands/commands.index.ts index d88e188..0abf49b 100644 --- a/src/commands/commands.index.ts +++ b/src/commands/commands.index.ts @@ -1,4 +1,4 @@ -import { commands, Disposable, window } from 'vscode'; +import { commands, Disposable } from 'vscode'; import { LoggerService } from '../logger.service'; import { Copy } from './copy.command'; diff --git a/src/commands/copy.command.ts b/src/commands/copy.command.ts index db7ff39..76920bc 100644 --- a/src/commands/copy.command.ts +++ b/src/commands/copy.command.ts @@ -1,7 +1,7 @@ -import { env, window, workspace } from 'vscode'; +import { env, window } from 'vscode'; import { LoggerService } from '../logger.service'; import * as jsonc from 'jsonc-parser'; -import { Command } from '../decorator/command.decorator'; +import { Command } from '../decorators/command.decorator'; enum FileType { JSON = 'json', @@ -32,7 +32,16 @@ export class Copy { if (offset && text) { const location = jsonc.getLocation(text, offset); - const path = location.path.join('.'); // TODO + const path: string = location.path.reduce( + (acc: string, val: any, index: number): string => { + if (Number.isInteger(val)) { + return index === 0 ? `[${val}]` : `${acc}[${val}]`; + } else { + return index === 0 ? val : `${acc}.${val}`; + } + }, + '', + ); env.clipboard .writeText(path) .then(() => this.loggerService.log('Path copied')); diff --git a/src/decorator/command.decorator.ts b/src/decorators/command.decorator.ts similarity index 100% rename from src/decorator/command.decorator.ts rename to src/decorators/command.decorator.ts diff --git a/src/logger.service.ts b/src/logger.service.ts index 15d2fb7..5fbd49c 100644 --- a/src/logger.service.ts +++ b/src/logger.service.ts @@ -6,7 +6,6 @@ enum LoggerType { WARN = 'WARN', ERROR = 'ERROR', } - export class LoggerService { private outputChannel = window.createOutputChannel('Copy Json Path - Log');