1
1
import lodashGet from 'lodash.get'
2
- import { camelCase } from 'change-case'
3
- import _ from 'lodash'
4
2
import { getCompletionsAtPosition , PrevCompletionMap , PrevCompletionsAdditionalData } from './completionsAtPosition'
5
3
import { RequestOptionsTypes , TriggerCharacterCommand } from './ipcTypes'
6
4
import { getNavTreeItems } from './getPatchedNavTree'
@@ -17,9 +15,9 @@ import decorateWorkspaceSymbolSearch from './workspaceSymbolSearch'
17
15
import decorateFormatFeatures from './decorateFormatFeatures'
18
16
import libDomPatching from './libDomPatching'
19
17
import decorateSignatureHelp from './decorateSignatureHelp'
20
- import { approveCast , findChildContainingExactPosition } from './utils'
21
18
import decorateFindRenameLocations from './decorateFindRenameLocations'
22
19
import decorateQuickInfoAtPosition from './decorateQuickInfoAtPosition'
20
+ import decorateEditsForFileRename from './decorateEditsForFileRename'
23
21
24
22
/** @internal */
25
23
export const thisPluginMarker = '__essentialPluginsMarker__'
@@ -47,49 +45,6 @@ export const decorateLanguageService = (
47
45
let prevCompletionsMap : PrevCompletionMap
48
46
let prevCompletionsAdditionalData : PrevCompletionsAdditionalData
49
47
50
- proxy . getEditsForFileRename = ( oldFilePath , newFilePath , formatOptions , preferences ) => {
51
- let edits = languageService . getEditsForFileRename ( oldFilePath , newFilePath , formatOptions , preferences )
52
- if ( c ( 'renameImportNameOfFileRename' ) ) {
53
- const predictedNameFromPath = ( p : string ) => camelCase ( p . split ( / [ / \\ ] / g) . pop ( ) ! . replace ( / \. .+ / , '' ) )
54
- const oldPredictedName = predictedNameFromPath ( oldFilePath )
55
- const newPredictedName = predictedNameFromPath ( newFilePath )
56
- for ( const edit of edits ) {
57
- const possiblyAddRename = ( identifier : ts . Identifier | undefined ) => {
58
- if ( identifier ?. text !== oldPredictedName ) return
59
- const sourceFile = languageService . getProgram ( ) ! . getSourceFile ( edit . fileName ) !
60
- const newRenameEdits = proxy . findRenameLocations ( edit . fileName , identifier . pos , false , false , preferences ?? { } ) ?? [ ]
61
- if ( ! newRenameEdits ) return
62
- // maybe cancel symbol rename on collision instead?
63
- const newInsertName = tsFull . getUniqueName ( newPredictedName , sourceFile as any )
64
- const addEdits = Object . entries ( _ . groupBy ( newRenameEdits , ( { fileName } ) => fileName ) ) . map (
65
- ( [ fileName , changes ] ) : ts . FileTextChanges => ( {
66
- fileName,
67
- textChanges : changes . map (
68
- ( { prefixText = '' , suffixText = '' , textSpan } ) : ts . TextChange => ( {
69
- newText : prefixText + newInsertName + suffixText ,
70
- span : textSpan ,
71
- } ) ,
72
- ) ,
73
- } ) ,
74
- )
75
- edits = [ ...edits , ...addEdits ]
76
- }
77
- for ( const textChange of edit . textChanges ) {
78
- const node = findChildContainingExactPosition ( languageService . getProgram ( ) ! . getSourceFile ( edit . fileName ) ! , textChange . span . start )
79
- if ( ! node ) continue
80
- if ( node && ts . isStringLiteral ( node ) && ts . isImportDeclaration ( node . parent ) && node . parent . importClause ) {
81
- const { importClause } = node . parent
82
- possiblyAddRename ( importClause ?. name )
83
- if ( approveCast ( importClause . namedBindings , ts . isNamespaceImport ) ) {
84
- possiblyAddRename ( importClause . namedBindings . name )
85
- }
86
- }
87
- }
88
- }
89
- }
90
- return edits
91
- }
92
-
93
48
proxy . getCompletionsAtPosition = ( fileName , position , options , formatOptions ) => {
94
49
if ( options ?. triggerCharacter && typeof options . triggerCharacter !== 'string' ) {
95
50
return languageService . getCompletionsAtPosition ( fileName , position , options )
@@ -134,6 +89,7 @@ export const decorateLanguageService = (
134
89
135
90
proxy . getCompletionEntryDetails = ( ...inputArgs ) => completionEntryDetails ( inputArgs , languageService , prevCompletionsMap , c , prevCompletionsAdditionalData )
136
91
92
+ decorateEditsForFileRename ( proxy , languageService , c )
137
93
decorateCodeActions ( proxy , languageService , languageServiceHost , c )
138
94
decorateCodeFixes ( proxy , languageService , languageServiceHost , c )
139
95
decorateSemanticDiagnostics ( proxy , languageService , languageServiceHost , c )
0 commit comments