Skip to content

Commit a98aaae

Browse files
authored
Merge pull request #132 from zardoy/develop
2 parents 83cd6d2 + eedfc9c commit a98aaae

File tree

6 files changed

+70
-29
lines changed

6 files changed

+70
-29
lines changed

buildTsPlugin.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
import buildTsPlugin from '@zardoy/vscode-utils/build/buildTypescriptPlugin.js'
33
import { build, analyzeMetafile } from 'esbuild'
44

5-
build({
6-
// bundle: true,
5+
await build({
6+
bundle: true,
7+
external: ['typescript-essential-plugins'],
78
// minify: !watch,
89
entryPoints: ['./typescript/src/volarConfig.ts'],
910
outfile: './out/volarConfig.js',

integration/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const run = async () => {
66
const mocha = new Mocha({
77
color: true,
88
parallel: false,
9-
timeout: process.env.CI ? 4500 : 2000,
9+
timeout: process.env.CI ? 5200 : 2000,
1010
})
1111
const testsRoot = join(__dirname, './suite')
1212
await new Promise<void>(resolve => {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { RequestOptionsTypes } from './ipcTypes'
2+
import { GetConfig } from './types'
3+
import { findChildContainingExactPosition } from './utils'
4+
5+
export const overrideRenameRequest = {
6+
value: undefined as undefined | RequestOptionsTypes['acceptRenameWithParams'],
7+
}
8+
9+
export default (proxy: ts.LanguageService, languageService: ts.LanguageService, c: GetConfig) => {
10+
proxy.findRenameLocations = (
11+
...args: [
12+
fileName: string,
13+
position: number,
14+
findInStrings: boolean,
15+
findInComments: boolean,
16+
providePrefixAndSuffixTextForRename?: boolean | ts.UserPreferences,
17+
]
18+
) => {
19+
if (overrideRenameRequest.value) {
20+
const { comments, strings, alias } = overrideRenameRequest.value
21+
if (comments !== undefined) {
22+
args[3] = comments
23+
}
24+
if (strings !== undefined) {
25+
args[2] = strings
26+
}
27+
if (alias !== undefined) {
28+
if (typeof args[4] === 'object') {
29+
args[4] = {
30+
...args[4],
31+
providePrefixAndSuffixTextForRename: alias,
32+
}
33+
} else {
34+
args[4] = alias
35+
}
36+
}
37+
38+
overrideRenameRequest.value = undefined
39+
}
40+
41+
//@ts-expect-error
42+
const renameLocations = languageService.findRenameLocations(...args)
43+
if (!renameLocations) return renameLocations
44+
// const firstLocation = renameLocations[0]
45+
// if (firstLocation?.fileName === args[0]) {
46+
// const node = findChildContainingExactPosition(languageService.getProgram()!.getSourceFile(args[0])!, firstLocation.textSpan.start)
47+
// if (
48+
// node &&
49+
// ts.isIdentifier(node) &&
50+
// ts.isArrayBindingPattern(node.parent) &&
51+
// node.parent.elements.length === 2 &&
52+
// ts.isVariableDeclaration(node.parent.parent)
53+
// ) {
54+
// // firstLocation.
55+
// }
56+
// }
57+
return renameLocations
58+
}
59+
}

typescript/src/decorateProxy.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import decorateFormatFeatures from './decorateFormatFeatures'
1818
import libDomPatching from './libDomPatching'
1919
import decorateSignatureHelp from './decorateSignatureHelp'
2020
import { approveCast, findChildContainingExactPosition } from './utils'
21+
import decorateFindRenameLocations from './decorateFindRenameLocations'
2122

2223
/** @internal */
2324
export const thisPluginMarker = '__essentialPluginsMarker__'
@@ -31,10 +32,6 @@ export const getInitialProxy = (languageService: ts.LanguageService, proxy = Obj
3132
return proxy
3233
}
3334

34-
export const overrideRequestPreferences = {
35-
rename: undefined as undefined | RequestOptionsTypes['acceptRenameWithParams'],
36-
}
37-
3835
export const decorateLanguageService = (
3936
{ languageService, languageServiceHost }: ts.server.PluginCreateInfo,
4037
existingProxy: ts.LanguageService | undefined,
@@ -145,23 +142,7 @@ export const decorateLanguageService = (
145142
decorateWorkspaceSymbolSearch(proxy, languageService, c, languageServiceHost)
146143
decorateFormatFeatures(proxy, languageService, languageServiceHost, c)
147144
decorateSignatureHelp(proxy, languageService, languageServiceHost, c)
148-
proxy.findRenameLocations = (fileName, position, findInStrings, findInComments, providePrefixAndSuffixTextForRename) => {
149-
if (overrideRequestPreferences.rename) {
150-
try {
151-
const { comments, strings, alias } = overrideRequestPreferences.rename
152-
return languageService.findRenameLocations(
153-
fileName,
154-
position,
155-
strings ?? findInStrings,
156-
comments ?? findInComments,
157-
alias ?? providePrefixAndSuffixTextForRename,
158-
)
159-
} finally {
160-
overrideRequestPreferences.rename = undefined
161-
}
162-
}
163-
return languageService.findRenameLocations(fileName, position, findInStrings, findInComments, providePrefixAndSuffixTextForRename)
164-
}
145+
decorateFindRenameLocations(proxy, languageService, c)
165146

166147
libDomPatching(languageServiceHost, c)
167148

typescript/src/specialCommands/handle.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { compact } from '@zardoy/utils'
22
import { getExtendedCodeActions } from '../codeActions/getCodeActions'
3-
import constructMethodSnippet from '../constructMethodSnippet'
4-
import { overrideRequestPreferences } from '../decorateProxy'
53
import { NodeAtPositionResponse, RequestOptionsTypes, RequestResponseTypes, TriggerCharacterCommand, triggerCharacterCommands } from '../ipcTypes'
64
import { GetConfig } from '../types'
75
import { findChildContainingExactPosition, findChildContainingPosition, getNodePath } from '../utils'
86
import { lastResolvedCompletion } from '../completionEntryDetails'
7+
import { overrideRenameRequest } from '../decorateFindRenameLocations'
98
import getEmmetCompletions from './emmet'
109
import objectIntoArrayConverters from './objectIntoArrayConverters'
1110

@@ -200,7 +199,7 @@ export default (
200199
}
201200
if (specialCommand === 'acceptRenameWithParams') {
202201
changeType<RequestOptionsTypes['acceptRenameWithParams']>(specialCommandArg)
203-
overrideRequestPreferences.rename = specialCommandArg
202+
overrideRenameRequest.value = specialCommandArg
204203
return undefined
205204
}
206205
if (specialCommand === 'pickAndInsertFunctionArguments') {

typescript/src/volarConfig.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* eslint-disable @typescript-eslint/no-require-imports */
22

3-
import { compact } from '@zardoy/utils'
4-
import { get } from 'lodash'
3+
import get from 'lodash/get'
54
import type { Configuration } from './types'
65

76
// will be required from ./node_modules/typescript-essential-plugins/index.js
87
const originalPluginFactory = require('typescript-essential-plugins')
98

9+
const compact = <T>(arr: Array<T | undefined>): T[] => arr.filter(Boolean) as T[]
10+
1011
const plugin = ((context, { typescript: tsModule } = {}) => {
1112
if (!context) throw new Error('Not recieve context')
1213
const { typescript } = context

0 commit comments

Comments
 (0)