Skip to content

Commit 3a25f12

Browse files
authored
Merge pull request #98 from zardoy/develop
2 parents e2a60c7 + da7bb72 commit 3a25f12

38 files changed

+1434
-361
lines changed

CONTRIBUTING.MD

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!-- https://github.com/vitest-dev/vitest/blob/main/CONTRIBUTING.md -->
2+
# TypeScript Essential Plugins Contributing Guide
3+
4+
Hi! Thank you so much for contributing to TypeScript Essential Plugins VS Code extension! We are really excited to bring high quality features and stability and we really appreciate any interest in it!
5+
Let us give you some high-level overview for you.
6+
7+
## Repo Setup
8+
9+
> Quick Tip: You can use [ni](https://github.com/antfu/ni) to help switching between repos using different package managers.
10+
> `ni` is equivalent to `pnpm install` and `nr script` is equivalent to `pnpm script`
11+
12+
### Start in Development
13+
14+
To start the VS Code plugin extension locally for developing:
15+
16+
0. Ensure you have pnpm installed (minimum v6): `npm i -g pnpm`
17+
18+
1. Run `pnpm install` in root folder
19+
20+
2. Run `pnpm start` to build extension and typescript plugin in watch mode. After initial build you can open VS Code window in development by pressing F5 to **start debugging session** (or by running `> Debug: Select and Start Debugging` and selecting *Extension + TS Plugin*).
21+
22+
- Note, that window will *be reloaded after each change in `src/*` automatically*. Note that each development window reload most probably cause erase of unsaved files/data. Also if you frequently change files in `src/*` you can uncomment `--disable-extensions` in launch.json for faster window reloads.
23+
24+
### Files Structure Overview
25+
26+
- `src/*` - VS Code extension code, that is specific to VS Code extension API only. Most probably you don't need to change it. (For now there is a limitation from vscode-framework so folder name cannot be changed to something like `extension` or `vscode`.)
27+
- `src/configurationType.ts` - Extension configuration live here. Add / change settings here. It is used to generate `out/package.json`'s `contributes.configuration`.
28+
- `typescript/*` - TypeScript plugin code, that integrates into TypeScript language service. After you change code in it, you need run to `> TypeScript: Restart TS server` to see changes (or `> Volar: Restart Vue server` for Vue files). Thats why it is useful to bind it to a shortcut.
29+
30+
### Running Tests
31+
32+
#### Unit Tests
33+
34+
They are in `typescript/test` and using vitest, so they faster than integration. Feel free to add new tests here. But note that most of tests are completion tests, but I do hope to add more types tests in the future.
35+
36+
To launch them run `pnpm test-plugin`.
37+
38+
#### Integration Tests
39+
40+
They are in `integration`. This type of tests launches VSCode. For now I don't recommend either running or adding new tests here, use unit tests.
41+
> Note that while running this script, you must also keep `pnpm start` running in the background. However, changing a file in `src/`, won't relaunch integration tests. If this is your case, you should edit the script.

README.MD

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ This also makes plugin work in Volar's takeover mode!
102102

103103
### Web Support
104104

105-
> Note: when you open TS/JS file in the web for the first time you currently need to switch editors to make everything work!
105+
> Note: when you open TS/JS file in the web for the first time you currently need to switch between editors to make plugin work.
106106
107-
Web-only feature: `import` path resolution
107+
There is web-only feature: fix clicking on relative `import` paths.
108108

109109
### `in` Keyword Suggestions
110110

@@ -149,9 +149,9 @@ Appends *space* to almost all keywords e.g. `const `, like WebStorm does.
149149

150150
(*enabled by default*)
151151

152-
Patches `toString()` insert function snippet on number types to remove tabStop.
152+
Patches `toString()` insert function snippet on number types to remove annoying tab stop.
153153

154-
### Enforce Properties Sorting
154+
### Restore Properties Sorting
155155

156156
(*disabled by default*) enable with `tsEssentialPlugins.fixSuggestionsSorting`
157157

@@ -162,11 +162,7 @@ Try to restore [original](https://github.com/microsoft/TypeScript/issues/49012)
162162
We extend completion list with extensions from module augmentation (e.g. `.css` files if you have `declare module '*.css'`).
163163
But for unchecked contexts list of extensions can be extended with `tsEssentialPlugins.additionalIncludeExtensions` setting.
164164

165-
### Switch Exclude Covered Cases
166-
167-
(*enabled by default*)
168-
169-
Exclude already covered strings / enums from suggestions ([TS repo issue](https://github.com/microsoft/TypeScript/issues/13711)).
165+
<!-- ## Type-Driven Completions -->
170166

171167
### Mark Code Actions
172168

@@ -226,7 +222,58 @@ Some settings examples:
226222
```
227223

228224
> Note: changeSorting might not preserve sorting of other existing suggestions which not defined by rules, there is WIP
229-
> Also I'm thinking of making it learn and syncing of most-used imports automatically
225+
> Also I'm thinking of making it learn and sync most-used imports automatically
226+
227+
### Namespace Imports
228+
229+
If you always want some modules to be imported automatically as namespace import, you're lucky as there is `autoImport.changeToNamespaceImport` setting for this.
230+
231+
Example:
232+
233+
You're completing following Node.js code in empty file:
234+
235+
```ts
236+
readFileSync
237+
```
238+
239+
Default completion and code fix will change it to:
240+
241+
```ts
242+
import { readFileSync } from 'fs'
243+
244+
readFileSync
245+
```
246+
247+
But if you setup this setting:
248+
249+
```json
250+
"tsEssentialPlugins.autoImport.changeToNamespaceImport": {
251+
"fs": {},
252+
},
253+
```
254+
255+
Completing the same code or accepting import code fix will result:
256+
257+
```ts
258+
import * as fs from 'fs'
259+
260+
fs.readFileSync
261+
```
262+
263+
There is also a way to specify different name for namespace or use default import instead.
264+
265+
However there are cases where you have some modules injected globally in your application (e.g. global `React` variable), then you can specify *auto imports feature* to use them instead of adding an import:
266+
267+
```json
268+
"tsEssentialPlugins.autoImport.changeToNamespaceImport": {
269+
"react": {
270+
"namespace": "React",
271+
"addImport": false
272+
},
273+
},
274+
```
275+
276+
`useState` -> `React.useState`
230277

231278
## Rename Features
232279

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,14 @@
9494
"onLanguage:vue"
9595
],
9696
"scripts": {
97-
"start": "vscode-framework start --skip-launching",
97+
"start": "run-p watch-extension watch-plugin",
98+
"watch-extension": "vscode-framework start --skip-launching",
99+
"watch-plugin": "node buildTsPlugin.mjs --watch",
98100
"build": "tsc && tsc -p typescript --noEmit && vscode-framework build && pnpm build-plugin",
99101
"build-plugin": "node buildTsPlugin.mjs && node buildTsPlugin.mjs --browser",
100-
"watch-plugin": "node buildTsPlugin.mjs --watch",
101102
"lint": "eslint src/**",
102103
"test": "pnpm test-plugin --run && pnpm integration-test",
103-
"test-plugin": "vitest --globals --dir typescript/test/",
104+
"test-plugin": "vitest --globals --dir typescript/test/ --environment ts-plugin",
104105
"integration-test": "node integration/prerun.mjs && tsc -p tsconfig.test.json && node testsOut/runTests.js",
105106
"integration-test:watch": "chokidar \"integration/**\" -c \"pnpm integration-test\" --initial",
106107
"postinstall": "patch-package"
@@ -118,7 +119,9 @@
118119
"type-fest": "^2.13.1",
119120
"typed-jsonfile": "^0.2.1",
120121
"typescript": "^4.9.3",
122+
"vite": "^4.1.1",
121123
"vitest": "^0.26.0",
124+
"vitest-environment-ts-plugin": "./vitest-environment-ts-plugin",
122125
"vscode-manifest": "^0.0.4"
123126
},
124127
"pnpm": {
@@ -139,6 +142,7 @@
139142
"@zardoy/utils": "^0.0.9",
140143
"@zardoy/vscode-utils": "^0.0.47",
141144
"chai": "^4.3.6",
145+
"change-case": "^4.1.2",
142146
"chokidar": "^3.5.3",
143147
"chokidar-cli": "^3.0.0",
144148
"delay": "^5.0.0",
@@ -151,6 +155,7 @@
151155
"lodash.throttle": "^4.1.1",
152156
"mocha": "^10.0.0",
153157
"modify-json-file": "^1.2.2",
158+
"npm-run-all": "^4.1.5",
154159
"path-browserify": "^1.0.1",
155160
"pluralize": "github:plurals/pluralize#36f03cd2d573fa6d23e12e1529fa4627e2af74b4",
156161
"rambda": "^7.2.1",

0 commit comments

Comments
 (0)