Skip to content

Commit

Permalink
Merge pull request #98 from zardoy/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy authored Feb 15, 2023
2 parents e2a60c7 + da7bb72 commit 3a25f12
Show file tree
Hide file tree
Showing 38 changed files with 1,434 additions and 361 deletions.
41 changes: 41 additions & 0 deletions CONTRIBUTING.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!-- https://github.com/vitest-dev/vitest/blob/main/CONTRIBUTING.md -->
# TypeScript Essential Plugins Contributing Guide

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!
Let us give you some high-level overview for you.

## Repo Setup

> Quick Tip: You can use [ni](https://github.com/antfu/ni) to help switching between repos using different package managers.
> `ni` is equivalent to `pnpm install` and `nr script` is equivalent to `pnpm script`
### Start in Development

To start the VS Code plugin extension locally for developing:

0. Ensure you have pnpm installed (minimum v6): `npm i -g pnpm`

1. Run `pnpm install` in root folder

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*).

- 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.

### Files Structure Overview

- `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`.)
- `src/configurationType.ts` - Extension configuration live here. Add / change settings here. It is used to generate `out/package.json`'s `contributes.configuration`.
- `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.

### Running Tests

#### Unit Tests

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.

To launch them run `pnpm test-plugin`.

#### Integration Tests

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.
> 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.
67 changes: 57 additions & 10 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ This also makes plugin work in Volar's takeover mode!

### Web Support

> Note: when you open TS/JS file in the web for the first time you currently need to switch editors to make everything work!
> 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.
Web-only feature: `import` path resolution
There is web-only feature: fix clicking on relative `import` paths.

### `in` Keyword Suggestions

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

(*enabled by default*)

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

### Enforce Properties Sorting
### Restore Properties Sorting

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

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

### Switch Exclude Covered Cases

(*enabled by default*)

Exclude already covered strings / enums from suggestions ([TS repo issue](https://github.com/microsoft/TypeScript/issues/13711)).
<!-- ## Type-Driven Completions -->

### Mark Code Actions

Expand Down Expand Up @@ -226,7 +222,58 @@ Some settings examples:
```

> Note: changeSorting might not preserve sorting of other existing suggestions which not defined by rules, there is WIP
> Also I'm thinking of making it learn and syncing of most-used imports automatically
> Also I'm thinking of making it learn and sync most-used imports automatically
### Namespace Imports

If you always want some modules to be imported automatically as namespace import, you're lucky as there is `autoImport.changeToNamespaceImport` setting for this.

Example:

You're completing following Node.js code in empty file:

```ts
readFileSync
```

Default completion and code fix will change it to:

```ts
import { readFileSync } from 'fs'

readFileSync
```

But if you setup this setting:

```json
"tsEssentialPlugins.autoImport.changeToNamespaceImport": {
"fs": {},
},
```

Completing the same code or accepting import code fix will result:

```ts
import * as fs from 'fs'

fs.readFileSync
```

There is also a way to specify different name for namespace or use default import instead.

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:

```json
"tsEssentialPlugins.autoImport.changeToNamespaceImport": {
"react": {
"namespace": "React",
"addImport": false
},
},
```

`useState` -> `React.useState`

## Rename Features

Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,14 @@
"onLanguage:vue"
],
"scripts": {
"start": "vscode-framework start --skip-launching",
"start": "run-p watch-extension watch-plugin",
"watch-extension": "vscode-framework start --skip-launching",
"watch-plugin": "node buildTsPlugin.mjs --watch",
"build": "tsc && tsc -p typescript --noEmit && vscode-framework build && pnpm build-plugin",
"build-plugin": "node buildTsPlugin.mjs && node buildTsPlugin.mjs --browser",
"watch-plugin": "node buildTsPlugin.mjs --watch",
"lint": "eslint src/**",
"test": "pnpm test-plugin --run && pnpm integration-test",
"test-plugin": "vitest --globals --dir typescript/test/",
"test-plugin": "vitest --globals --dir typescript/test/ --environment ts-plugin",
"integration-test": "node integration/prerun.mjs && tsc -p tsconfig.test.json && node testsOut/runTests.js",
"integration-test:watch": "chokidar \"integration/**\" -c \"pnpm integration-test\" --initial",
"postinstall": "patch-package"
Expand All @@ -118,7 +119,9 @@
"type-fest": "^2.13.1",
"typed-jsonfile": "^0.2.1",
"typescript": "^4.9.3",
"vite": "^4.1.1",
"vitest": "^0.26.0",
"vitest-environment-ts-plugin": "./vitest-environment-ts-plugin",
"vscode-manifest": "^0.0.4"
},
"pnpm": {
Expand All @@ -139,6 +142,7 @@
"@zardoy/utils": "^0.0.9",
"@zardoy/vscode-utils": "^0.0.47",
"chai": "^4.3.6",
"change-case": "^4.1.2",
"chokidar": "^3.5.3",
"chokidar-cli": "^3.0.0",
"delay": "^5.0.0",
Expand All @@ -151,6 +155,7 @@
"lodash.throttle": "^4.1.1",
"mocha": "^10.0.0",
"modify-json-file": "^1.2.2",
"npm-run-all": "^4.1.5",
"path-browserify": "^1.0.1",
"pluralize": "github:plurals/pluralize#36f03cd2d573fa6d23e12e1529fa4627e2af74b4",
"rambda": "^7.2.1",
Expand Down
Loading

0 comments on commit 3a25f12

Please sign in to comment.