Skip to content

Commit 04c6da5

Browse files
committed
Update settings and types
1 parent 8939c96 commit 04c6da5

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@
4242
"configuration": {
4343
"title": "Snippet Copy",
4444
"properties": {
45-
"snippet-copy.markdownCodeBlock.flavor": {
45+
"snippet-copy.markdownCodeBlock.includeLanguageIdentifier": {
4646
"type": "string",
4747
"default": "prompt",
48-
"markdownDescription": "Flavor of the generated [fenced Markdown code block](https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks). By default, prompts every time a snippet is copied as a Markdown code block.",
48+
"markdownDescription": "Style of the generated [fenced Markdown code block](https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks). By default, prompts every time a snippet is copied as a Markdown code block.",
4949
"enum": [
50-
"plain",
51-
"includeLanguageIdentifier",
50+
"never",
51+
"always",
5252
"prompt"
5353
],
5454
"markdownEnumDescriptions": [
55-
"Copy a plain fenced Markdown code block.",
56-
"Copy a fenced Markdown code block that includes the language identifier of the current document.\nThis enables [automatic syntax highlighting](https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting) on e.g. GitHub or StackOverflow but isn't compatible with some apps, for example Slack.",
55+
"Copy a regular fenced Markdown code block without language identifier.",
56+
"Copy a fenced Markdown code block that includes the language identifier of the current document. \nThis enables [automatic syntax highlighting](https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting) on e.g. GitHub or StackOverflow but isn't compatible with some apps, for example Slack.",
5757
"Always prompt when copying a snippet as a Markdown code block whether to include the language identifier or not."
5858
]
5959
}

src/lib/textHelpers.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { QuickPickItem, Selection, TextDocument, window, workspace } from "vscode";
2-
import { ExtensionConfig, MarkdownCodeBlockFlavor } from "../types/config";
2+
import { ExtensionConfig, IncludeLanguageIdentifier } from "../types/config";
33
import { contentOfLinesWithAdjustedIndentation, endOfLineCharacter, languageId, minimumIndentationForLineIndexes } from "./documentHelpers";
44
import { lineIndexesForSelection } from "./selectionHelpers";
55

66
type MarkdownCodeBlockFlavorQuickPickItems = QuickPickItem & {
7-
detail: MarkdownCodeBlockFlavor;
7+
detail: IncludeLanguageIdentifier;
88
};
99

1010
export async function generateSnippet(document: TextDocument, selections: Selection[], wrapInMarkdownCodeBlock = false): Promise<string> {
@@ -47,27 +47,27 @@ export function wrapTextInMarkdownCodeBlock(document: TextDocument, text: string
4747
}
4848

4949
export async function includeLanguageIdentifier(config: ExtensionConfig): Promise<boolean> {
50-
let markdownCodeBlockFlavor = config.markdownCodeBlock.flavor;
50+
let includeLanguageIdentifier = config.markdownCodeBlock.includeLanguageIdentifier;
5151

52-
if (markdownCodeBlockFlavor === 'prompt') {
52+
if (includeLanguageIdentifier === 'prompt') {
5353
const prompt = await promptForMarkdownCodeBlockFlavor();
5454

5555
if (prompt && isMarkdownCodeBlockFlavor(prompt.detail)) {
56-
markdownCodeBlockFlavor = prompt.detail;
56+
includeLanguageIdentifier = prompt.detail;
5757
}
5858
}
59-
return markdownCodeBlockFlavor === 'includeLanguageIdentifier';
59+
return includeLanguageIdentifier === 'always';
6060
}
6161

6262
export async function promptForMarkdownCodeBlockFlavor(): Promise<MarkdownCodeBlockFlavorQuickPickItems | undefined> {
6363
const quickPickItems: MarkdownCodeBlockFlavorQuickPickItems[] = [
6464
{
6565
label: 'Plain fenced Markdown code block',
66-
detail: 'plain',
67-
description: 'Copy a plain, default Markdown code block'
66+
detail: 'never',
67+
description: 'Copy a regular fenced Markdown code block without language identifier'
6868
}, {
6969
label: 'Include Markdown language identifier',
70-
detail: 'includeLanguageIdentifier',
70+
detail: 'always',
7171
description: "Copy a Markdown code block that includes the language identifier of the current document"
7272
}
7373
];
@@ -76,7 +76,7 @@ export async function promptForMarkdownCodeBlockFlavor(): Promise<MarkdownCodeBl
7676
});
7777
}
7878

79-
export function isMarkdownCodeBlockFlavor(value: string | undefined): value is MarkdownCodeBlockFlavor {
80-
const validValues: MarkdownCodeBlockFlavor[] = ['plain', 'includeLanguageIdentifier'];
81-
return !!value && validValues.includes(value as MarkdownCodeBlockFlavor);
79+
export function isMarkdownCodeBlockFlavor(value: string | undefined): value is IncludeLanguageIdentifier {
80+
const validValues: IncludeLanguageIdentifier[] = ['never', 'always'];
81+
return !!value && validValues.includes(value as IncludeLanguageIdentifier);
8282
}

src/test/suite/lib/textHelpers.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,31 +88,31 @@ describe('Text Helpers', () => {
8888

8989
context('includeLanguageIdentifier', () => {
9090
it('returns true if setting is "includeLanguageIdentifier"', async () => {
91-
const config: unknown = td.object({ markdownCodeBlock: { flavor: 'includeLanguageIdentifier' } });
91+
const config: unknown = td.object({ markdownCodeBlock: { includeLanguageIdentifier: 'always' } });
9292

9393
assert.strictEqual(await includeLanguageIdentifier(config as ExtensionConfig), true);
9494
});
9595

9696
it('returns false if setting is "plain"', async () => {
97-
const config: unknown = td.object({ markdownCodeBlock: { flavor: 'plain' } });
97+
const config: unknown = td.object({ markdownCodeBlock: { includeLanguageIdentifier: 'never' } });
9898

9999
assert.strictEqual(await includeLanguageIdentifier(config as ExtensionConfig), false);
100100
});
101101

102102
it('returns false if setting is true', async () => {
103-
const config: unknown = td.object({ markdownCodeBlock: { flavor: true } });
103+
const config: unknown = td.object({ markdownCodeBlock: { includeLanguageIdentifier: true } });
104104

105105
assert.strictEqual(await includeLanguageIdentifier(config as ExtensionConfig), false);
106106
});
107107
});
108108

109109
context('isMarkdownCodeBlockFlavor', () => {
110-
it('returns true if value is "plain"', () => {
111-
assert.equal(isMarkdownCodeBlockFlavor('plain'), true);
110+
it('returns true if value is "never"', () => {
111+
assert.equal(isMarkdownCodeBlockFlavor('never'), true);
112112
});
113113

114-
it('returns true if value is "includeLanguageIdentifier"', () => {
115-
assert.equal(isMarkdownCodeBlockFlavor('plain'), true);
114+
it('returns true if value is "always"', () => {
115+
assert.equal(isMarkdownCodeBlockFlavor('always'), true);
116116
});
117117

118118
it('returns false if value is any other string', () => {

src/types/config.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { WorkspaceConfiguration } from "vscode";
22

3-
export type MarkdownCodeBlockFlavor = 'plain' | 'includeLanguageIdentifier';
3+
export type IncludeLanguageIdentifier = 'always' | 'never';
44

55
export type ExtensionConfig = WorkspaceConfiguration & {
66
markdownCodeBlock: {
7-
flavor: MarkdownCodeBlockFlavor | 'prompt'
7+
includeLanguageIdentifier: IncludeLanguageIdentifier | 'prompt'
88
};
99
addLanguageIdentifierToMarkdownBlock?: boolean;
1010
};

0 commit comments

Comments
 (0)