Skip to content

Commit 29af860

Browse files
feat: Updates docs, and enables Twoslash VFS (ShowEmittedFiles) (#83)
* feat: enhance documentation with TwoslashExample component and code snippets so we can dedupe code examples * fix: update includes in biome.json to exclude content snippets from linter and file processing * feat: Refactor Twoslash examples to use Tabs component for better organization - Replaced TwoslashExample component with Tabs and TabItem components in multiple documentation files for improved code sample presentation. - Updated installation documentation to reflect the support for showing emitted files. - Enhanced ESLint, TypeScript, Vue, and other Twoslashers documentation with new examples using Tabs. - Removed outdated snippet files that were previously used in examples. - Added utility functions for resolving tsconfig paths and parsing tsconfig files in the plugin code. - Updated plugin options to include cwd and tsConfigPath for better configuration flexibility. * feat: add changeset to enable Twoslash's VFS and showEmit functionality * fix: remove content snippets from linter and file processing includes in biome.json * fix: update feature links in README to use full URLs for better accessibility * fix: remove format option from tsdown configuration * feat: add cwd and tsConfigPath options to Twoslash configuration for enhanced customization
1 parent c22eaef commit 29af860

23 files changed

Lines changed: 383 additions & 225 deletions

File tree

.changeset/long-pillows-sell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"expressive-code-twoslash": minor
3+
---
4+
5+
Finally enables Twoslash's VFS and showEmit functionality!

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"recompiles",
4747
"rehype",
4848
"rgba",
49+
"seti",
4950
"shiki",
5051
"studiocms",
5152
"twocustom",

docs/astro.config.mts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ export default defineConfig({
198198
{
199199
label: "Show Emitted Files",
200200
link: "usage/show-emitted-files",
201+
badge: {
202+
text: "v0.6.0",
203+
variant: "success",
204+
},
201205
},
202206
],
203207
},

docs/src/content/docs/getting-started/basic.mdx

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,55 +13,48 @@ It leverages the compiler APIs used by text editors to offer type-driven hover i
1313
Using the homepage as an example, here is a simple code sample:
1414

1515
<Tabs>
16-
17-
<TabItem label='Before'>
18-
19-
``````md
16+
<TabItem label="Rendered Output">
2017

2118
```ts twoslash
2219
// @errors: 2540
23-
2420
console.log((1 + 2 + 3 + 4).toFixed(2));
2521
// ^|
2622

2723
/** A Basic Todo interface*/
2824
interface Todo {
29-
title: string;
25+
title: string;
3026
}
3127

3228
const todo: Readonly<Todo> = {
33-
title: 'Delete inactive users',
34-
// ^?
35-
}
29+
title: "Delete inactive users",
30+
// ^?
31+
};
3632

37-
todo.title = 'Hello';
33+
todo.title = "Hello";
3834
```
3935

40-
``````
41-
4236
</TabItem>
37+
<TabItem label="Markdown">
4338

44-
<TabItem label="After">
45-
39+
``````md
4640
```ts twoslash
4741
// @errors: 2540
48-
4942
console.log((1 + 2 + 3 + 4).toFixed(2));
5043
// ^|
5144

5245
/** A Basic Todo interface*/
5346
interface Todo {
54-
title: string;
47+
title: string;
5548
}
5649

5750
const todo: Readonly<Todo> = {
58-
title: 'Delete inactive users',
59-
// ^?
60-
}
51+
title: "Delete inactive users",
52+
// ^?
53+
};
6154

62-
todo.title = 'Hello';
55+
todo.title = "Hello";
6356
```
57+
``````
6458

6559
</TabItem>
66-
6760
</Tabs>

docs/src/content/docs/getting-started/installation.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { PackageManagers } from 'starlight-package-managers'
1919
| [Code Cutting](/usage/code-cutting) ||
2020
| [Callouts](/usage/banners/callouts) ||
2121
| [TS Compiler Overrides](/usage/ts-compiler-flags) ||
22-
| [Show Emitted Files](/usage/show-emitted-files) | ⛔️ |
22+
| [Show Emitted Files](/usage/show-emitted-files) | |
2323

2424
### Installation
2525

docs/src/content/docs/index.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ hero:
1717
icon: star
1818
---
1919

20-
import { Tabs, TabItem } from '@astrojs/starlight/components';
21-
2220
```ts twoslash
2321
// @errors: 2540
2422

docs/src/content/docs/reference/configuration.mdx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,54 @@ export default defineEcConfig({
115115
});
116116
```
117117

118+
### cwd
119+
120+
<PropertySignature>
121+
- Type: string
122+
- Default: `process.cwd()`
123+
</PropertySignature>
124+
125+
Optionally specify the current working directory for the Twoslash instances. This can be useful if you want to change the base directory from which Twoslash resolves modules and files. By default, Twoslash uses the current working directory of the process, but you can set this option to any valid directory path to customize where Twoslash looks for files and modules.
126+
127+
#### Example
128+
129+
```ts twoslash title="ec.config.mjs" {7}
130+
import { defineEcConfig } from 'astro-expressive-code';
131+
import ecTwoSlash from "expressive-code-twoslash";
132+
133+
export default defineEcConfig({
134+
plugins: [
135+
ecTwoSlash({
136+
cwd: "/path/to/your/directory", // Set the current working directory for Twoslash
137+
}),
138+
],
139+
});
140+
```
141+
142+
### tsConfigPath
143+
144+
<PropertySignature>
145+
- Type: string
146+
- Default: `undefined`
147+
</PropertySignature>
148+
149+
The `tsConfigPath` option allows you to specify the path to a custom `tsconfig.json` file that Twoslash should use when processing TypeScript code blocks. This is useful if you want to provide specific TypeScript compiler options or include/exclude certain files from the Twoslash transformations. By default, Twoslash will look for a `tsconfig.json` file in the current working directory, but you can set this option to point to any valid `tsconfig.json` file in your project.
150+
151+
#### Example
152+
153+
```ts twoslash title="ec.config.mjs" {7}
154+
import { defineEcConfig } from 'astro-expressive-code';
155+
import ecTwoSlash from "expressive-code-twoslash";
156+
157+
export default defineEcConfig({
158+
plugins: [
159+
ecTwoSlash({
160+
tsConfigPath: "tsconfig-twoslash.json", // Specify a custom tsconfig.json file for Twoslash
161+
}),
162+
],
163+
});
164+
```
165+
118166
### includeJsDoc
119167

120168
<PropertySignature>

docs/src/content/docs/twoslashers/eslint.mdx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ sidebar:
1010
variant: success
1111
---
1212

13-
import { Tabs, TabItem, Aside } from '@astrojs/starlight/components';
13+
import { Aside, TabItem, Tabs } from "@astrojs/starlight/components";
1414

1515
Included in Expressive code twoslash, [Twoslash ESLint](https://twoslash.netlify.app/packages/eslint) is a Twoslash integration that added support for Twoslash to handle ESLint code blocks. Unlike other Twoslash instances, Twoslash ESLint uses `eslint` as it's meta trigger for codeblocks, and it is designed to work with JavaScript and TypeScript code blocks that contain ESLint errors. When a code block is annotated with `eslint`, Twoslash ESLint will parse the code.
1616

@@ -25,32 +25,28 @@ npm install eslint
2525
This is an example taken from the Twoslash ESLint documentation website.
2626

2727
<Tabs>
28-
29-
<TabItem label="Output">
28+
<TabItem label="Rendered Output">
3029

3130
```ts eslint
32-
const unused = 1
31+
const unused = 1;
3332

3433
type Foo = {
35-
bar: string
36-
}
34+
bar: string;
35+
};
3736
```
38-
</TabItem>
3937

40-
<TabItem label='Markdown'>
38+
</TabItem>
39+
<TabItem label="Markdown">
4140

4241
``````md
43-
4442
```ts eslint
45-
const unused = 1
43+
const unused = 1;
4644

4745
type Foo = {
48-
bar: string
49-
}
46+
bar: string;
47+
};
5048
```
51-
5249
``````
5350

5451
</TabItem>
55-
5652
</Tabs>

docs/src/content/docs/twoslashers/typescript.mdx

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,55 @@ sidebar:
66
label: TypeScript / TSX
77
---
88

9-
import { Tabs, TabItem } from '@astrojs/starlight/components';
9+
import { TabItem, Tabs } from "@astrojs/starlight/components";
1010

1111
The primary Twoslasher integration included in Expressive Code Twoslash is the [TypeScript Twoslasher](https://twoslash.netlify.app/guide/), which adds support for Twoslash to handle TypeScript code blocks.
1212

1313
This is an example taken from the Twoslash documentation website.
1414

1515
<Tabs>
16-
17-
<TabItem label="Output">
16+
<TabItem label="Rendered Output">
1817

1918
```ts twoslash
2019
// @errors: 2540
21-
2220
console.log((1 + 2 + 3 + 4).toFixed(2));
2321
// ^|
2422

2523
/** A Basic Todo interface*/
2624
interface Todo {
27-
title: string;
25+
title: string;
2826
}
2927

3028
const todo: Readonly<Todo> = {
31-
title: 'Delete inactive users',
32-
// ^?
33-
}
29+
title: "Delete inactive users",
30+
// ^?
31+
};
3432

35-
todo.title = 'Hello';
33+
todo.title = "Hello";
3634
```
37-
</TabItem>
3835

39-
<TabItem label='Markdown'>
36+
</TabItem>
37+
<TabItem label="Markdown">
4038

4139
``````md
42-
4340
```ts twoslash
4441
// @errors: 2540
45-
4642
console.log((1 + 2 + 3 + 4).toFixed(2));
4743
// ^|
4844

4945
/** A Basic Todo interface*/
5046
interface Todo {
51-
title: string;
47+
title: string;
5248
}
5349

5450
const todo: Readonly<Todo> = {
55-
title: 'Delete inactive users',
56-
// ^?
57-
}
51+
title: "Delete inactive users",
52+
// ^?
53+
};
5854

59-
todo.title = 'Hello';
55+
todo.title = "Hello";
6056
```
61-
6257
``````
6358

6459
</TabItem>
65-
6660
</Tabs>

docs/src/content/docs/twoslashers/vue.mdx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ sidebar:
1010
variant: success
1111
---
1212

13-
import { Tabs, TabItem, Aside } from '@astrojs/starlight/components';
13+
import { Aside, TabItem, Tabs } from '@astrojs/starlight/components';
1414

1515
Included in Expressive code twoslash, [Twoslash Vue](https://twoslash.netlify.app/packages/vue) is a Twoslash integration that added support for Twoslash to handle Vue Single File Component files.
1616

@@ -25,8 +25,7 @@ npm install vue
2525
This is an example taken from the Twoslash Vue documentation website.
2626

2727
<Tabs>
28-
29-
<TabItem label="Output">
28+
<TabItem label="Rendered Output">
3029

3130
```vue twoslash
3231
<script setup>
@@ -53,12 +52,11 @@ onMounted(() => {
5352
</button>
5453
</template>
5554
```
56-
</TabItem>
5755

58-
<TabItem label='Markdown'>
56+
</TabItem>
57+
<TabItem label="Markdown">
5958

6059
``````md
61-
6260
```vue twoslash
6361
<script setup>
6462
import { onMounted, ref } from 'vue'
@@ -84,9 +82,7 @@ onMounted(() => {
8482
</button>
8583
</template>
8684
```
87-
8885
``````
8986

9087
</TabItem>
91-
9288
</Tabs>

0 commit comments

Comments
 (0)