-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(huge-feature): add jsx tags to outline! (#37)
- v0.0.81
- v0.0.80
- v0.0.79
- v0.0.78
- v0.0.77
- v0.0.76
- v0.0.75
- v0.0.74
- v0.0.73
- v0.0.72
- v0.0.71
- v0.0.70
- v0.0.69
- v0.0.68
- v0.0.67
- v0.0.66
- v0.0.65
- v0.0.64
- v0.0.63
- v0.0.62
- v0.0.61
- v0.0.60
- v0.0.59
- v0.0.58
- v0.0.57
- v0.0.56
- v0.0.55
- v0.0.54
- v0.0.53
- v0.0.52
- v0.0.51
- v0.0.50
- v0.0.49
- v0.0.48
- v0.0.47
- v0.0.46
- v0.0.45
- v0.0.44
- v0.0.43
- v0.0.42
- v0.0.41
- v0.0.40
- v0.0.39
- v0.0.38
- v0.0.37
- v0.0.35
- v0.0.34
- v0.0.33
- v0.0.32
- v0.0.31
- v0.0.30
- v0.0.29
- v0.0.28
- v0.0.27
- v0.0.26
- v0.0.25
- v0.0.24
- v0.0.23
- v0.0.22
- v0.0.21
- v0.0.20
- v0.0.19
Showing
10 changed files
with
296 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# TypeScript Essential Plugins | ||
|
||
## Top Features | ||
|
||
### JSX Outline | ||
|
||
(*disabled by default*) Enable with `tsEssentialPlugins.patchOutline` | ||
|
||
Add JSX elements to outline. It also makes sticky scroll works with your tags! | ||
|
||
Super recommended for react. Fragments are not rendered. | ||
|
||
### Method Snippets | ||
|
||
(*enabled by default*) | ||
|
||
Expands arrow callbacks with signature snippet with adding additional undo stack! | ||
|
||
Example: | ||
|
||
```ts | ||
const callback = (arg) => {} | ||
callback -> callback(arg) | ||
``` | ||
|
||
### Clean Emmet | ||
|
||
(*enabled by default*) | ||
|
||
You can turn off emmet integration in JSX and stable emmet suggestion will be *always* within JSX elements. | ||
|
||
*Why?* <https://github.com/microsoft/vscode/issues/51537> | ||
|
||
- supports only tag expansion for now, have 2 modes | ||
|
||
### Remove Definition From References | ||
|
||
(*enabled by default*) | ||
|
||
<https://github.com/microsoft/vscode/issues/160637> | ||
|
||
## Minor Useful Features | ||
|
||
### Highlight non-function Methods | ||
|
||
(*enabled by default*) | ||
|
||
Highlights and lifts non-function methods. Also applies for static class methods. | ||
|
||
### Remove Useless Code Fixes | ||
|
||
(*enabled by default*) | ||
|
||
By default removes `Fix Missing Function Declaration` codefix. Possibly to remove more via setting. | ||
|
||
### Remove Useless Function Props | ||
|
||
(*enabled by default*) | ||
|
||
Removes `Symbol`, `caller`, `prototype` completions on function / classes. | ||
|
||
### Patch `toString()` | ||
|
||
(*enabled by default*) | ||
|
||
Patches `toString()` insert function snippet on number types to remove tabStop. | ||
|
||
### Keywords Insert Text | ||
|
||
(*enabled by default*) | ||
|
||
Almost all keywords would insert space after the name of keyword e.g. `extends` -> `extends ` | ||
|
||
### Correct Sorting | ||
|
||
(*enabled by default*, but doesn't work properly in new versions for now) | ||
|
||
### Mark Code Actions | ||
|
||
(*enabled by default* with two settings) | ||
|
||
Mark all TS code actions with `🔵`, so you can be sure they're coming from TypeScript, and not some other extension. | ||
|
||
### Builtin CodeFix Fixes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
//@ts-check | ||
import buildTsPlugin from '@zardoy/vscode-utils/build/buildTypescriptPlugin.js' | ||
|
||
await buildTsPlugin('typescript') | ||
const watch = process.argv[2] === '--watch' | ||
await buildTsPlugin('typescript', undefined, undefined, { | ||
watch, | ||
logLevel: 'info', | ||
sourcemap: watch, | ||
// banner: { | ||
// js: 'const log = (...args) => console.log(...args.map(a => JSON.stringify(a)))', | ||
// }, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import type tslib from 'typescript/lib/tsserverlibrary' | ||
import requireFromString from 'require-from-string' | ||
|
||
declare const __TS_SEVER_PATH__: string | undefined | ||
|
||
const getPatchedNavModule = (ts: typeof tslib) => { | ||
const tsServerPath = typeof __TS_SEVER_PATH__ !== 'undefined' ? __TS_SEVER_PATH__ : require.main!.filename | ||
const mainScript = require('fs').readFileSync(tsServerPath, 'utf8') as string | ||
const startIdx = mainScript.indexOf('var NavigationBar;') | ||
const ph = '(ts.NavigationBar = {}));' | ||
const lines = mainScript.slice(startIdx, mainScript.indexOf(ph) + ph.length).split(/\r?\n/) | ||
const patchPlaces: { | ||
predicateString: string | ||
linesOffset: number | ||
addString?: string | ||
removeLines?: number | ||
}[] = [ | ||
{ | ||
predicateString: 'function addChildrenRecursively(node)', | ||
linesOffset: 7, | ||
addString: ` | ||
case ts.SyntaxKind.JsxSelfClosingElement: | ||
addLeafNode(node) | ||
break; | ||
case ts.SyntaxKind.JsxElement: | ||
startNode(node) | ||
ts.forEachChild(node, addChildrenRecursively); | ||
endNode() | ||
break`, | ||
}, | ||
{ | ||
predicateString: 'return "<unknown>";', | ||
linesOffset: -2, | ||
addString: ` | ||
case ts.SyntaxKind.JsxSelfClosingElement: | ||
return getNameFromJsxTag(node); | ||
case ts.SyntaxKind.JsxElement: | ||
return getNameFromJsxTag(node.openingElement);`, | ||
}, | ||
] | ||
for (let { addString, linesOffset, predicateString, removeLines = 0 } of patchPlaces) { | ||
const addTypeIndex = lines.findIndex(line => line.includes(predicateString)) | ||
if (addTypeIndex !== -1) { | ||
lines.splice(addTypeIndex + linesOffset, removeLines, ...(addString ? [addString] : [])) | ||
} | ||
} | ||
const getModule = requireFromString('module.exports = (ts, getNameFromJsxTag) => {' + lines.join('\n') + 'return NavigationBar;}') | ||
const getNameFromJsxTag = (node: tslib.JsxSelfClosingElement | tslib.JsxOpeningElement) => { | ||
const { | ||
attributes: { properties }, | ||
} = node | ||
const tagName = node.tagName.getText() | ||
const addDotAttrs = ['class', 'className'] | ||
// TODO refactor to arr | ||
let idAdd = '' | ||
let classNameAdd = '' | ||
properties.forEach(attr => { | ||
if (!ts.isJsxAttribute(attr) || !attr.initializer) return | ||
const attrName = attr.name?.getText() | ||
if (!attrName) return | ||
if (addDotAttrs.includes(attrName)) { | ||
const textAdd = ts.isStringLiteral(attr.initializer) ? attr.initializer.text : '' | ||
for (let char of textAdd.split(' ')) { | ||
if (char) classNameAdd += `.${char}` | ||
} | ||
} else if (attrName === 'id' && ts.isStringLiteral(attr.initializer)) { | ||
idAdd = `#${attr.initializer.text}` | ||
} | ||
}) | ||
return tagName + classNameAdd + idAdd | ||
} | ||
return getModule(ts, getNameFromJsxTag) | ||
} | ||
|
||
let navModule | ||
|
||
export const getNavTreeItems = (ts: typeof tslib, info: tslib.server.PluginCreateInfo, fileName: string) => { | ||
if (!navModule) navModule = getPatchedNavModule(ts) | ||
const program = info.languageService.getProgram() | ||
if (!program) throw new Error('no program') | ||
const sourceFile = program?.getSourceFile(fileName) | ||
if (!sourceFile) throw new Error('no sourceFile') | ||
|
||
const cancellationToken = info.languageServiceHost.getCompilerHost?.()?.getCancellationToken?.() ?? { | ||
isCancellationRequested: () => false, | ||
throwIfCancellationRequested: () => {}, | ||
} | ||
return navModule.getNavigationTree(sourceFile, cancellationToken) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters