Skip to content

Commit 02481bc

Browse files
authored
Browser support, fix definitions, new emmet! (#49)
- fix: fix `findNodeAtPosition` that it was always looking for a node one char behind. To restore old behavior, use `offset: offset - 1` in first arg. Also fix that it now receives data in the first arg. - Meet new strict emmet! `jsxEmmet.type` setting was removed in favor of two new settings: `jsxEmmet` and `jsxPseudoEmmet` (which is disabled by default now) - Meet web support! New web-only feature: now it is possible to click on `import` paths! - fix array method snippets in some cases - add experimental declare missing property *codefix*. It will be most probably removed from here :D
1 parent 72861c3 commit 02481bc

31 files changed

+799
-259
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ src/configurationTypeCache.jsonc
1818
coverage
1919
*.lcov
2020
.nyc_output
21+
.vscode-test-web
2122

2223
logs
2324
*.log

README.MD

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Add JSX elements to outline. It also makes sticky scroll works with your tags!
1010

1111
Super recommended for react. Fragments are not rendered.
1212

13+
Also is not supported in the web.
14+
1315
## **Completions Built Different**
1416

1517
90% work done in this extension highly improves completions experience!
@@ -27,15 +29,22 @@ const callback = (arg) => {}
2729
callback -> callback(arg)
2830
```
2931

30-
### Clean Emmet
32+
### Strict Emmet
3133

32-
(*enabled by default*)
34+
(*enabled by default*) when react langs are in `emmet.excludeLanguages`
35+
36+
Emmet that is active **only** inside JSX tags!
37+
38+
You can force enable this by using `Enable Strict Emmet in JSX` command.
39+
40+
*Why?* Issues it fixes: [query](https://github.com/microsoft/vscode/issues?q=sort%3Aupdated-desc+51537+150671+142978+119736).
3341

34-
You can turn off emmet integration in JSX and stable emmet suggestion will be *always* within JSX elements.
42+
#### Optional Emmet Features
3543

36-
*Why?* <https://github.com/microsoft/vscode/issues/51537>
44+
- cleanup input & textarea suggestions
45+
- override `.` snippet
3746

38-
- supports only tag expansion for now, have 2 modes
47+
Is not supported in the web for now.
3948

4049
### Array Method Snippets
4150

@@ -57,6 +66,12 @@ usersList.map // -> usersList.map((user) => )
5766

5867
## Minor Useful Features
5968

69+
### Web Support
70+
71+
> Note: when you open TS/JS file in the web for the first time you currently need to switch editors to make everything work!
72+
73+
Web-only feature: `import` path resolution
74+
6075
### Highlight non-function Methods
6176

6277
(*enabled by default*)
@@ -90,7 +105,7 @@ Removes `Symbol`, `caller`, `prototype` completions on function / classes.
90105

91106
(*enabled by default*)
92107

93-
Appends *space* to almost all keywords e.g. `extends `, like WebStorm does.
108+
Appends *space* to almost all keywords e.g. `const `, like WebStorm does.
94109

95110
### Patch `toString()`
96111

@@ -109,3 +124,7 @@ Patches `toString()` insert function snippet on number types to remove tabStop.
109124
Mark all TS code actions with `🔵`, so you can be sure they're coming from TypeScript, and not some other extension.
110125

111126
### Builtin CodeFix Fixes
127+
128+
## Even Even More
129+
130+
Please look at extension settings, as this extension has much more features than described here!

buildTsPlugin.mjs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
//@ts-check
22
import buildTsPlugin from '@zardoy/vscode-utils/build/buildTypescriptPlugin.js'
3+
import { analyzeMetafile } from 'esbuild'
34

4-
const watch = process.argv[2] === '--watch'
5-
await buildTsPlugin('typescript', undefined, undefined, {
6-
watch,
7-
logLevel: 'info',
8-
sourcemap: watch,
9-
enableBrowser: true,
5+
const result = await buildTsPlugin('typescript', undefined, undefined, {
6+
minify: !process.argv.includes('--watch'),
7+
metafile: true,
108
banner: {
119
js: 'let ts',
1210
// js: 'const log = (...args) => console.log(...args.map(a => JSON.stringify(a)))',
1311
},
1412
})
13+
14+
// @ts-ignore
15+
// console.log(await analyzeMetafile(result.metafile))

integration/suite/completions.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { expect } from 'chai'
55
// eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error
66
import { fromFixtures, prepareTsStart } from './utils'
77

8-
describe('Completions', () => {
8+
describe.skip('Completions', () => {
99
const editor = () => vscode.window.activeTextEditor!
1010

1111
before(async function () {

integration/suite/jsx.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { fromFixtures, prepareTsStart, replaceEditorText } from './utils'
77
//@ts-ignore
88
import { Configuration } from '../../src/configurationType'
99

10-
describe('JSX Attributes', () => {
10+
describe.skip('JSX Attributes', () => {
1111
const editor = () => vscode.window.activeTextEditor!
1212

1313
const startPos = new vscode.Position(0, 0)

package.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
"license": "MIT",
66
"preview": true,
77
"contributes": {
8+
"commands": [
9+
{
10+
"command": "enableStrictEmmetInJsx",
11+
"title": "Enable Strict Emmet in JSX",
12+
"category": "TS Essentials JSX"
13+
}
14+
],
815
"typescriptServerPlugins": [
916
{
1017
"name": "typescript-essential-plugins",
@@ -34,8 +41,8 @@
3441
"scripts": {
3542
"start": "vscode-framework start",
3643
"build": "tsc && tsc -p typescript --noEmit && vscode-framework build && pnpm build-plugin",
37-
"build-plugin": "node buildTsPlugin.mjs",
38-
"watch-plugin": "pnpm build-plugin --watch",
44+
"build-plugin": "node buildTsPlugin.mjs && node buildTsPlugin.mjs --browser",
45+
"watch-plugin": "node buildTsPlugin.mjs --watch",
3946
"lint": "eslint src/**",
4047
"test": "pnpm test-plugin --run && pnpm integration-test",
4148
"test-plugin": "vitest --globals --dir typescript/test/",
@@ -67,7 +74,7 @@
6774
"@vscode/emmet-helper": "^2.8.4",
6875
"@vscode/test-electron": "^2.1.5",
6976
"@zardoy/utils": "^0.0.9",
70-
"@zardoy/vscode-utils": "^0.0.32",
77+
"@zardoy/vscode-utils": "^0.0.36",
7178
"chai": "^4.3.6",
7279
"chokidar": "^3.5.3",
7380
"chokidar-cli": "^3.0.0",
@@ -85,7 +92,8 @@
8592
"rambda": "^7.2.1",
8693
"require-from-string": "^2.0.2",
8794
"string-dedent": "^3.0.1",
88-
"vscode-framework": "^0.0.18"
95+
"vscode-framework": "^0.0.18",
96+
"vscode-uri": "^3.0.6"
8997
},
9098
"prettier": {
9199
"semi": false,

pnpm-lock.yaml

Lines changed: 14 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/configurationType.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export type Configuration = {
105105
'markTsCodeFixes.character': string
106106
// TODO
107107
/**
108-
* Reveal import statement as definition instead of real definition
108+
* Reveal definition in import statement instead of real definition in another file
109109
* @default true
110110
* */
111111
// 'importUpDefinition.enable': boolean
@@ -119,10 +119,29 @@ export type Configuration = {
119119
* */
120120
'removeCodeFixes.codefixes': ('fixMissingMember' | 'fixMissingProperties' | 'fixMissingAttributes' | 'fixMissingFunctionDeclaration')[]
121121
/**
122-
* Only tag support
123-
* @default fakeEmmet
124-
* */
125-
'jsxEmmet.type': 'realEmmet' | 'fakeEmmet' | 'disabled'
122+
* Use full-blown emmet in jsx/tsx files!
123+
* Requires `jsxPseudoEmmet` be off and `emmet.excludeLanguages` to have `javascriptreact` and `typescriptreact`
124+
* @default true
125+
* */
126+
jsxEmmet: boolean
127+
/**
128+
* Override snippet inserted on `.` literally
129+
* @default false
130+
*/
131+
'jsxEmmet.dotOverride': string | false
132+
/**
133+
* We already change sorting of suggestions, but enabling this option will also make:
134+
* - removing `id` from input suggestions
135+
* - simplify textarea
136+
* Doesn't change preview text for now!
137+
* @default false
138+
*/
139+
'jsxEmmet.modernize': boolean
140+
/**
141+
* Suggests only common tags such as div
142+
* @default false
143+
*/
144+
jsxPseudoEmmet: boolean
126145
/**
127146
* Note: Sorting matters
128147
*/
@@ -200,6 +219,12 @@ export type Configuration = {
200219
* @default false
201220
*/
202221
supportTsDiagnosticDisableComment: boolean
222+
/**
223+
* Adds special helpers completions in `{}`
224+
* For example when you're trying to complete object props in array
225+
* @default true
226+
*/
227+
// completionHelpers: boolean
203228
/**
204229
* Extend TypeScript outline!
205230
* Extend outline with:

0 commit comments

Comments
 (0)