Skip to content

Commit

Permalink
Browser support, fix definitions, new emmet! (#49)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
zardoy authored Sep 25, 2022
1 parent 72861c3 commit 02481bc
Show file tree
Hide file tree
Showing 31 changed files with 799 additions and 259 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ src/configurationTypeCache.jsonc
coverage
*.lcov
.nyc_output
.vscode-test-web

logs
*.log
Expand Down
31 changes: 25 additions & 6 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Add JSX elements to outline. It also makes sticky scroll works with your tags!

Super recommended for react. Fragments are not rendered.

Also is not supported in the web.

## **Completions Built Different**

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

### Clean Emmet
### Strict Emmet

(*enabled by default*)
(*enabled by default*) when react langs are in `emmet.excludeLanguages`

Emmet that is active **only** inside JSX tags!

You can force enable this by using `Enable Strict Emmet in JSX` command.

*Why?* Issues it fixes: [query](https://github.com/microsoft/vscode/issues?q=sort%3Aupdated-desc+51537+150671+142978+119736).

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

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

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

### Array Method Snippets

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

## Minor Useful Features

### 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!
Web-only feature: `import` path resolution

### Highlight non-function Methods

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

(*enabled by default*)

Appends *space* to almost all keywords e.g. `extends `, like WebStorm does.
Appends *space* to almost all keywords e.g. `const `, like WebStorm does.

### Patch `toString()`

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

### Builtin CodeFix Fixes

## Even Even More

Please look at extension settings, as this extension has much more features than described here!
13 changes: 7 additions & 6 deletions buildTsPlugin.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//@ts-check
import buildTsPlugin from '@zardoy/vscode-utils/build/buildTypescriptPlugin.js'
import { analyzeMetafile } from 'esbuild'

const watch = process.argv[2] === '--watch'
await buildTsPlugin('typescript', undefined, undefined, {
watch,
logLevel: 'info',
sourcemap: watch,
enableBrowser: true,
const result = await buildTsPlugin('typescript', undefined, undefined, {
minify: !process.argv.includes('--watch'),
metafile: true,
banner: {
js: 'let ts',
// js: 'const log = (...args) => console.log(...args.map(a => JSON.stringify(a)))',
},
})

// @ts-ignore
// console.log(await analyzeMetafile(result.metafile))
2 changes: 1 addition & 1 deletion integration/suite/completions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { expect } from 'chai'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error
import { fromFixtures, prepareTsStart } from './utils'

describe('Completions', () => {
describe.skip('Completions', () => {
const editor = () => vscode.window.activeTextEditor!

before(async function () {
Expand Down
2 changes: 1 addition & 1 deletion integration/suite/jsx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { fromFixtures, prepareTsStart, replaceEditorText } from './utils'
//@ts-ignore
import { Configuration } from '../../src/configurationType'

describe('JSX Attributes', () => {
describe.skip('JSX Attributes', () => {
const editor = () => vscode.window.activeTextEditor!

const startPos = new vscode.Position(0, 0)
Expand Down
16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
"license": "MIT",
"preview": true,
"contributes": {
"commands": [
{
"command": "enableStrictEmmetInJsx",
"title": "Enable Strict Emmet in JSX",
"category": "TS Essentials JSX"
}
],
"typescriptServerPlugins": [
{
"name": "typescript-essential-plugins",
Expand Down Expand Up @@ -34,8 +41,8 @@
"scripts": {
"start": "vscode-framework start",
"build": "tsc && tsc -p typescript --noEmit && vscode-framework build && pnpm build-plugin",
"build-plugin": "node buildTsPlugin.mjs",
"watch-plugin": "pnpm build-plugin --watch",
"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/",
Expand Down Expand Up @@ -67,7 +74,7 @@
"@vscode/emmet-helper": "^2.8.4",
"@vscode/test-electron": "^2.1.5",
"@zardoy/utils": "^0.0.9",
"@zardoy/vscode-utils": "^0.0.32",
"@zardoy/vscode-utils": "^0.0.36",
"chai": "^4.3.6",
"chokidar": "^3.5.3",
"chokidar-cli": "^3.0.0",
Expand All @@ -85,7 +92,8 @@
"rambda": "^7.2.1",
"require-from-string": "^2.0.2",
"string-dedent": "^3.0.1",
"vscode-framework": "^0.0.18"
"vscode-framework": "^0.0.18",
"vscode-uri": "^3.0.6"
},
"prettier": {
"semi": false,
Expand Down
33 changes: 14 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 30 additions & 5 deletions src/configurationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export type Configuration = {
'markTsCodeFixes.character': string
// TODO
/**
* Reveal import statement as definition instead of real definition
* Reveal definition in import statement instead of real definition in another file
* @default true
* */
// 'importUpDefinition.enable': boolean
Expand All @@ -119,10 +119,29 @@ export type Configuration = {
* */
'removeCodeFixes.codefixes': ('fixMissingMember' | 'fixMissingProperties' | 'fixMissingAttributes' | 'fixMissingFunctionDeclaration')[]
/**
* Only tag support
* @default fakeEmmet
* */
'jsxEmmet.type': 'realEmmet' | 'fakeEmmet' | 'disabled'
* Use full-blown emmet in jsx/tsx files!
* Requires `jsxPseudoEmmet` be off and `emmet.excludeLanguages` to have `javascriptreact` and `typescriptreact`
* @default true
* */
jsxEmmet: boolean
/**
* Override snippet inserted on `.` literally
* @default false
*/
'jsxEmmet.dotOverride': string | false
/**
* We already change sorting of suggestions, but enabling this option will also make:
* - removing `id` from input suggestions
* - simplify textarea
* Doesn't change preview text for now!
* @default false
*/
'jsxEmmet.modernize': boolean
/**
* Suggests only common tags such as div
* @default false
*/
jsxPseudoEmmet: boolean
/**
* Note: Sorting matters
*/
Expand Down Expand Up @@ -200,6 +219,12 @@ export type Configuration = {
* @default false
*/
supportTsDiagnosticDisableComment: boolean
/**
* Adds special helpers completions in `{}`
* For example when you're trying to complete object props in array
* @default true
*/
// completionHelpers: boolean
/**
* Extend TypeScript outline!
* Extend outline with:
Expand Down
Loading

0 comments on commit 02481bc

Please sign in to comment.