• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kenhowardpdx / vscode-gist / 328

pending completion
328

push

travis-ci-com

web-flow
chore(deps): bump json5 from 2.2.0 to 2.2.3

Bumps [json5](https://github.com/json5/json5) from 2.2.0 to 2.2.3.
- [Release notes](https://github.com/json5/json5/releases)
- [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md)
- [Commits](https://github.com/json5/json5/compare/v2.2.0...v2.2.3)

---
updated-dependencies:
- dependency-name: json5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

158 of 235 branches covered (67.23%)

Branch coverage included in aggregate %.

580 of 644 relevant lines covered (90.06%)

3.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.31
/src/commands/gists/utils.ts
1
import {
6✔
2
  commands,
3
  Position,
4
  Range,
5
  Selection,
6
  // TextEdit,
7
  TextEditor,
8
  window,
9
  workspace,
10
  WorkspaceEdit
11
} from 'vscode';
12

13
import * as utils from '../../utils';
6✔
14

15
const _openDocument = async (file: string): Promise<void> => {
6✔
16
  const doc = await workspace.openTextDocument(file);
6✔
17
  await window.showTextDocument(doc);
6✔
18
  commands.executeCommand('workbench.action.keepEditor');
6✔
19
};
20

21
const selectFile = async (gist: {
6✔
22
  files: { [name: string]: { content: string } };
23
}): Promise<{ content: string; filename: string } | undefined> => {
7✔
24
  const files = Object.keys(gist.files).map((key) => ({
14✔
25
    description: '',
26
    [key]: gist.files[key],
27
    label: key
28
  }));
29
  const selectedFile =
30
    files.length > 1
7✔
31
      ? await window.showQuickPick(files)
7!
32
      : await Promise.resolve(files[0]);
33

34
  return selectedFile
7✔
35
    ? {
7✔
36
        content: gist.files[selectedFile.label].content,
37
        filename: selectedFile.label
38
      }
39
    : undefined;
40
};
41

42
const openGist = async (
6✔
43
  gist: Gist,
44
  maxFiles = 10
5✔
45
): Promise<{
46
  fileCount: number;
47
  files: { [x: string]: { content: string } };
48
  id: string;
49
}> => {
6✔
50
  const { id, files, fileCount } = gist;
6✔
51

52
  if (fileCount > maxFiles) {
6✔
53
    const file = await selectFile(gist);
1✔
54
    if (!file) {
1!
55
      throw new Error('File not found');
×
56
    }
57
    const filePath = utils.files.fileSync(id, file.filename, file.content);
1✔
58
    await _openDocument(filePath);
1✔
59
  } else {
60
    const filePaths = utils.files.filesSync(id, files);
5✔
61

62
    // await is not available not available in forEach
63
    for (const filePath of filePaths) {
5✔
64
      await _openDocument(filePath);
5✔
65
    }
66
  }
67

68
  return { id, files, fileCount };
6✔
69
};
70

71
const insertText = async (
6✔
72
  editor: TextEditor,
73
  text: string
74
): Promise<boolean> => {
×
75
  const document = editor.document;
×
76
  const workspaceEdit = new WorkspaceEdit();
×
77
  const range = new Range(editor.selection.start, editor.selection.end);
×
78
  workspaceEdit.replace(document.uri, range, text);
×
79

80
  return workspace.applyEdit(workspaceEdit).then((applied: boolean) => {
×
81
    if (applied) {
×
82
      const lines = text.trim().split('\n');
×
83
      const endPosition = new Position(
×
84
        lines.length + range.start.line - 1,
85
        lines[lines.length - 1].length
86
      );
87

88
      const selection = new Selection(range.start, endPosition);
×
89
      editor.selection = selection;
×
90
    }
91

92
    return applied;
×
93
  });
94
};
95

96
export { insertText, openGist, selectFile };
6✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc