Skip to content

Commit

Permalink
fix(copy): array type
Browse files Browse the repository at this point in the history
  • Loading branch information
MaloPolese committed Aug 20, 2021
1 parent b715ddd commit 63c68a6
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 52 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/marketplace.yml

This file was deleted.

19 changes: 0 additions & 19 deletions .github/workflows/update-changelog.yml

This file was deleted.

9 changes: 0 additions & 9 deletions CHANGELOG.md

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion src/commands/commands.index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
15 changes: 12 additions & 3 deletions src/commands/copy.command.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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'));
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion src/logger.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ enum LoggerType {
WARN = 'WARN',
ERROR = 'ERROR',
}

export class LoggerService {
private outputChannel = window.createOutputChannel('Copy Json Path - Log');

Expand Down

0 comments on commit 63c68a6

Please sign in to comment.