Skip to content

Commit 43fae3d

Browse files
committed
try to use fully exposed TS api in fullTs var
1 parent 417568c commit 43fae3d

File tree

13 files changed

+1505
-27
lines changed

13 files changed

+1505
-27
lines changed

buildTsPlugin.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const result = await buildTsPlugin('typescript', undefined, undefined, {
66
minify: !process.argv.includes('--watch'),
77
metafile: true,
88
banner: {
9-
js: 'let ts',
9+
js: 'let ts, tsFull;',
1010
// js: 'const log = (...args) => console.log(...args.map(a => JSON.stringify(a)))',
1111
},
1212
})

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
"type-fest": "^2.13.1",
6363
"typed-jsonfile": "^0.2.1",
6464
"typescript": "^4.8.3",
65-
"typescript-old": "npm:[email protected]",
6665
"vitest": "^0.15.1",
6766
"vscode-manifest": "^0.0.4"
6867
},
@@ -93,6 +92,8 @@
9392
"rambda": "^7.2.1",
9493
"require-from-string": "^2.0.2",
9594
"string-dedent": "^3.0.1",
95+
"ts-expose-internals": "^4.8.4",
96+
"unleashed-typescript": "^1.3.0",
9697
"vscode-framework": "^0.0.18",
9798
"vscode-uri": "^3.0.6"
9899
},

patches/ts-expose-internals+^4.8.4.patch

Lines changed: 1452 additions & 0 deletions
Large diffs are not rendered by default.

pnpm-lock.yaml

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

typescript/src/codeActions/toggleBraces.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const tryToApply: ApplyCodeAction = (ts, sourceFile, pos, range) => {
66
const currentNode = findChildContainingPosition(ts, sourceFile, pos)
77
if (!currentNode) return
88
const closestBlock = findClosestParent(
9-
ts,
109
currentNode,
1110
[
1211
ts.SyntaxKind.IfStatement,

typescript/src/completions/postfixesAtPosition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default (position: number, fileName: string, scriptSnapshot: ts.IScriptSn
1818
let foundNode: ts.Node | undefined
1919
if (
2020
ts.isIdentifier(node) &&
21-
(foundNode = findClosestParent(ts, node, [ts.SyntaxKind.BinaryExpression, ts.SyntaxKind.IfStatement], [])) &&
21+
(foundNode = findClosestParent(node, [ts.SyntaxKind.BinaryExpression, ts.SyntaxKind.IfStatement], [])) &&
2222
(!ts.isBinaryExpression(foundNode!) || !isComparingToken(foundNode.operatorToken))
2323
) {
2424
if (ts.isIdentifier(node)) {

typescript/src/getPatchedNavTree.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import type tslib from 'typescript/lib/tsserverlibrary'
21
import { nodeModules } from './utils'
32

43
// uses at testing only
54
declare const __TS_SEVER_PATH__: string | undefined
65

7-
const getPatchedNavModule = (ts: typeof tslib) => {
6+
const getPatchedNavModule = () => {
87
const tsServerPath = typeof __TS_SEVER_PATH__ !== 'undefined' ? __TS_SEVER_PATH__ : require.main!.filename
98
const mainScript = nodeModules!.fs.readFileSync(tsServerPath, 'utf8') as string
109
const startIdx = mainScript.indexOf('var NavigationBar;')
@@ -75,8 +74,8 @@ const getPatchedNavModule = (ts: typeof tslib) => {
7574

7675
let navModule
7776

78-
export const getNavTreeItems = (ts: typeof tslib, info: ts.server.PluginCreateInfo, fileName: string) => {
79-
if (!navModule) navModule = getPatchedNavModule(ts)
77+
export const getNavTreeItems = (info: ts.server.PluginCreateInfo, fileName: string) => {
78+
if (!navModule) navModule = getPatchedNavModule()
8079
const program = info.languageService.getProgram()
8180
if (!program) throw new Error('no program')
8281
const sourceFile = program?.getSourceFile(fileName)

typescript/src/globals.d.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
// prvided by esbuild in buildTsPlugin.mjs
2-
declare let ts: typeof import('typescript/lib/tsserverlibrary')
1+
import('ts-expose-internals')
2+
// prvided by esbuild at top-level of bundle in buildTsPlugin.mjs
3+
declare let ts: typeof import('typescript')
4+
declare let tsFull: typeof import('typescript-full')
5+
6+
// declare type ts = import('typescript')
7+
// export {}
8+
// export * from 'typescript'
9+
// // export * from 'typescript/lib/tsserverlibrary'
10+
11+
// export as namespace ts
12+
// declare global {
13+
// export as namespace ts
14+
// declare let ts: typeof import('typescript')
15+
// }
316

417
declare let __WEB__: boolean

typescript/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const decorateLanguageService = (info: ts.server.PluginCreateInfo, existingProxy
9898
// so we forced to communicate via fs
9999
const config = JSON.parse(ts.sys.readFile(require('path').join(__dirname, '../../plugin-config.json'), 'utf8') ?? '{}')
100100
proxy.getNavigationTree = fileName => {
101-
if (c('patchOutline') || config.patchOutline) return getNavTreeItems(ts, info, fileName)
101+
if (c('patchOutline') || config.patchOutline) return getNavTreeItems(info, fileName)
102102
return info.languageService.getNavigationTree(fileName)
103103
}
104104
}
@@ -110,7 +110,7 @@ const decorateLanguageService = (info: ts.server.PluginCreateInfo, existingProxy
110110
const updateConfigListeners: Array<() => void> = []
111111

112112
const plugin: ts.server.PluginModuleFactory = ({ typescript }) => {
113-
ts = typescript
113+
ts = tsFull = typescript as any
114114
return {
115115
create(info) {
116116
// receive fresh config

typescript/src/specialCommands/prepareTextForEmmet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default (
2222
): false | string => {
2323
const text = getTextInner(position, leftNode)
2424
if (text === false) return false
25-
const closestElem = findClosestParent(ts, leftNode, [ts.SyntaxKind.JsxElement], [ts.SyntaxKind.JsxFragment]) as ts.JsxElement | undefined
25+
const closestElem = findClosestParent(leftNode, [ts.SyntaxKind.JsxElement], [ts.SyntaxKind.JsxFragment]) as ts.JsxElement | undefined
2626
const bannedTags = ['style']
2727
const tagName = closestElem?.openingElement.tagName.getText()
2828
if (tagName && bannedTags.includes(tagName)) return false

0 commit comments

Comments
 (0)