|
1 |
| -import fs from 'fs' |
2 |
| -import { join } from 'path/posix' |
3 |
| -import tslib, { createProgram, server, SymbolDisplayPartKind, TypeFlags, TypeFormatFlags } from 'typescript/lib/tsserverlibrary' |
4 |
| -import { get } from 'lodash' |
| 1 | +import get from 'lodash.get' |
| 2 | +import type tslib from 'typescript/lib/tsserverlibrary' |
5 | 3 |
|
6 | 4 | //@ts-ignore
|
7 | 5 | import type { Configuration } from '../../src/configurationType'
|
8 | 6 |
|
9 |
| -export = function ({ typescript }: { typescript: typeof tslib }) { |
| 7 | +export = function ({ typescript }: { typescript: typeof import('typescript/lib/tsserverlibrary') }) { |
10 | 8 | let _configuration: Configuration
|
11 | 9 | const c = <T extends keyof Configuration>(key: T): Configuration[T] => get(_configuration, key)
|
12 | 10 |
|
@@ -41,7 +39,7 @@ export = function ({ typescript }: { typescript: typeof tslib }) {
|
41 | 39 | // 'raw prior',
|
42 | 40 | // prior?.entries.map(entry => entry.name),
|
43 | 41 | // )
|
44 |
| - const node = findChildContainingPosition(sourceFile, position) |
| 42 | + const node = findChildContainingPosition(typescript, sourceFile, position) |
45 | 43 | if (node) {
|
46 | 44 | if (c('jsxPseudoEmmet.enable') && (typescript.isJsxElement(node) || (node.parent && typescript.isJsxElement(node.parent)))) {
|
47 | 45 | if (typescript.isJsxOpeningElement(node)) {
|
@@ -216,7 +214,7 @@ export = function ({ typescript }: { typescript: typeof tslib }) {
|
216 | 214 | // sourceFile.update('test', { span: textSpan, newLength: sourceFile.text.length + 2 })
|
217 | 215 | // sourceFile.text = patchText(sourceFile.text, textSpan.start, textSpan.start + textSpan.length, 'test')
|
218 | 216 | // console.log('sourceFile.text', sourceFile.text)
|
219 |
| - const node = findChildContainingPosition(sourceFile, positionOrRange) |
| 217 | + const node = findChildContainingPosition(typescript, sourceFile, positionOrRange) |
220 | 218 | if (!node) {
|
221 | 219 | console.log('no node')
|
222 | 220 | return []
|
@@ -266,10 +264,14 @@ const patchText = (input: string, start: number, end: number, newText: string) =
|
266 | 264 | return input.slice(0, start) + newText + input.slice(end)
|
267 | 265 | }
|
268 | 266 |
|
269 |
| -function findChildContainingPosition(sourceFile: tslib.SourceFile, position: number): tslib.Node | undefined { |
| 267 | +function findChildContainingPosition( |
| 268 | + typescript: typeof import('typescript/lib/tsserverlibrary'), |
| 269 | + sourceFile: tslib.SourceFile, |
| 270 | + position: number, |
| 271 | +): tslib.Node | undefined { |
270 | 272 | function find(node: ts.Node): ts.Node | undefined {
|
271 | 273 | if (position >= node.getStart() && position < node.getEnd()) {
|
272 |
| - return tslib.forEachChild(node, find) || node |
| 274 | + return typescript.forEachChild(node, find) || node |
273 | 275 | }
|
274 | 276 | return
|
275 | 277 | }
|
|
0 commit comments