Skip to content

Commit 9a796b5

Browse files
committed
remove all traces of move to existing file (unimplemented)
1 parent 09ea4d2 commit 9a796b5

File tree

3 files changed

+8
-88
lines changed

3 files changed

+8
-88
lines changed

src/codeActionProvider.ts

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
import * as vscode from 'vscode'
2-
import { relative, join } from 'path-browserify'
32
import { defaultJsSupersetLangsWithVue } from '@zardoy/vscode-utils/build/langs'
4-
import { partition } from 'lodash'
53
import { registerExtensionCommand, showQuickPick, getExtensionSetting, getExtensionCommandId } from 'vscode-framework'
64
import { compact } from '@zardoy/utils'
75
import { RequestResponseTypes, RequestOptionsTypes } from '../typescript/src/ipcTypes'
86
import { sendCommand } from './sendCommand'
9-
import {
10-
pickFileWithQuickPick,
11-
getTsLikePath,
12-
tsRangeToVscode,
13-
tsTextChangesToVscodeTextEdits,
14-
vscodeRangeToTs,
15-
tsTextChangesToVscodeSnippetTextEdits,
16-
} from './util'
7+
import { tsTextChangesToVscodeTextEdits, vscodeRangeToTs, tsTextChangesToVscodeSnippetTextEdits } from './util'
178

189
// extended and interactive code actions
1910
export default () => {
@@ -53,7 +44,7 @@ export default () => {
5344
if (context.triggerKind !== vscode.CodeActionTriggerKind.Invoke) return
5445
const result = await getPossibleTwoStepRefactorings(range)
5546
if (!result) return
56-
const { turnArrayIntoObject, moveToExistingFile, extendedCodeActions } = result
47+
const { turnArrayIntoObject, extendedCodeActions } = result
5748
const codeActions: vscode.CodeAction[] = []
5849
const getCommand = (arg): vscode.Command | undefined => ({
5950
title: '',
@@ -69,14 +60,6 @@ export default () => {
6960
})
7061
}
7162

72-
if (moveToExistingFile) {
73-
// codeActions.push({
74-
// title: `Move to existing file`,
75-
// command: getCommand({ moveToExistingFile }),
76-
// kind: vscode.CodeActionKind.Refactor.append('move'),
77-
// })
78-
}
79-
8063
codeActions.push(
8164
...compact(
8265
extendedCodeActions.map(({ title, kind, codes }): ExtendedCodeAction | undefined => {
@@ -131,7 +114,7 @@ export default () => {
131114
registerExtensionCommand('applyRefactor' as any, async (_, arg?: RequestResponseTypes['getTwoStepCodeActions']) => {
132115
if (!arg) return
133116
let sendNextData: RequestOptionsTypes['twoStepCodeActionSecondStep']['data'] | undefined
134-
const { turnArrayIntoObject, moveToExistingFile } = arg
117+
const { turnArrayIntoObject } = arg
135118
if (turnArrayIntoObject) {
136119
const { keysCount, totalCount, totalObjectCount } = turnArrayIntoObject
137120
const selectedKey = await showQuickPick(
@@ -155,54 +138,12 @@ export default () => {
155138
}
156139
}
157140

158-
if (moveToExistingFile) {
159-
sendNextData = {
160-
name: 'moveToExistingFile',
161-
}
162-
}
163-
164141
if (!sendNextData) return
165142
const editor = vscode.window.activeTextEditor!
166143
const nextResponse = await getSecondStepRefactoringData(editor.selection, sendNextData)
167144
if (!nextResponse) throw new Error('No code action data. Try debug.')
168145
const edit = new vscode.WorkspaceEdit()
169-
let mainChanges = 'edits' in nextResponse && nextResponse.edits
170-
if (moveToExistingFile && 'fileNames' in nextResponse) {
171-
const { fileNames, fileEdits } = nextResponse
172-
const selectedFilePath = await pickFileWithQuickPick(fileNames)
173-
if (!selectedFilePath) return
174-
const document = await vscode.workspace.openTextDocument(vscode.Uri.file(selectedFilePath))
175-
// const outline = await vscode.commands.executeCommand('vscode.executeDocumentSymbolProvider', document.uri)
176-
177-
const currentEditorPath = getTsLikePath(vscode.window.activeTextEditor!.document.uri)
178-
const currentFileEdits = [...fileEdits.find(fileEdit => fileEdit.fileName === currentEditorPath)!.textChanges]
179-
const textChangeIndexToPatch = currentFileEdits.findIndex(currentFileEdit => currentFileEdit.newText.trim())
180-
const { newText: updateImportText } = currentFileEdits[textChangeIndexToPatch]!
181-
// TODO-mid use native path resolver (ext, index, alias)
182-
let newRelativePath = relative(join(currentEditorPath, '..'), selectedFilePath)
183-
if (!newRelativePath.startsWith('./') && !newRelativePath.startsWith('../')) newRelativePath = `./${newRelativePath}`
184-
currentFileEdits[textChangeIndexToPatch]!.newText = updateImportText.replace(/(['"]).+(['"])/, (_m, g1) => `${g1}${newRelativePath}${g1}`)
185-
mainChanges = currentFileEdits
186-
const newFileText = fileEdits.find(fileEdit => fileEdit.isNewFile)!.textChanges[0]!.newText
187-
const [importLines, otherLines] = partition(newFileText.split('\n'), line => line.startsWith('import '))
188-
const startPos = new vscode.Position(0, 0)
189-
const newFileNodes = await sendCommand<RequestResponseTypes['filterBySyntaxKind']>('filterBySyntaxKind', {
190-
position: startPos,
191-
document,
192-
})
193-
const lastImportDeclaration = newFileNodes?.nodesByKind.ImportDeclaration?.at(-1)
194-
const lastImportEnd = lastImportDeclaration ? tsRangeToVscode(document, lastImportDeclaration.range).end : startPos
195-
edit.set(vscode.Uri.file(selectedFilePath), [
196-
{
197-
range: new vscode.Range(startPos, startPos),
198-
newText: [...importLines, '\n'].join('\n'),
199-
},
200-
{
201-
range: new vscode.Range(lastImportEnd, lastImportEnd),
202-
newText: ['\n', ...otherLines].join('\n'),
203-
},
204-
])
205-
}
146+
const mainChanges = 'edits' in nextResponse && nextResponse.edits
206147

207148
if (!mainChanges) return
208149
edit.set(editor.document.uri, tsTextChangesToVscodeTextEdits(editor.document, mainChanges))

typescript/src/ipcTypes.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export type RequestResponseTypes = {
6464
totalCount: number
6565
totalObjectCount: number
6666
}
67-
moveToExistingFile?: Record<string, unknown>
6867
extendedCodeActions: IpcExtendedCodeAction[]
6968
}
7069
twoStepCodeActionSecondStep:
@@ -97,14 +96,10 @@ export type RequestOptionsTypes = {
9796
}
9897
twoStepCodeActionSecondStep: {
9998
range: [number, number]
100-
data:
101-
| {
102-
name: 'turnArrayIntoObject'
103-
selectedKeyName?: string
104-
}
105-
| {
106-
name: 'moveToExistingFile'
107-
}
99+
data: {
100+
name: 'turnArrayIntoObject'
101+
selectedKeyName?: string
102+
}
108103
}
109104

110105
acceptRenameWithParams: {

typescript/src/specialCommands/handle.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ export default (
3838
changeType<RequestOptionsTypes['getTwoStepCodeActions']>(specialCommandArg)
3939
const node = findChildContainingPosition(ts, sourceFile, position)
4040
const posEnd = { pos: specialCommandArg.range[0], end: specialCommandArg.range[1] }
41-
const moveToExistingFile = previousGetCodeActionsResult.value?.some(x => x.name === 'Move to a new file')
4241

4342
const extendedCodeActions = getExtendedCodeActions(sourceFile, posEnd, languageService, undefined, undefined)
4443
return {
4544
turnArrayIntoObject: objectIntoArrayConverters(posEnd, node, undefined),
46-
moveToExistingFile: moveToExistingFile ? {} : undefined,
4745
extendedCodeActions,
4846
}
4947
}
@@ -71,20 +69,6 @@ export default (
7169
}
7270
break
7371
}
74-
case 'moveToExistingFile': {
75-
const { edits } =
76-
languageService.getEditsForRefactor(fileName, formatOptions ?? {}, posEnd, 'Move to a new file', 'Move to a new file', preferences) ?? {}
77-
if (!edits) return
78-
data = {
79-
fileEdits: edits,
80-
fileNames: languageService
81-
.getProgram()!
82-
.getSourceFiles()
83-
.map(f => f.fileName)
84-
.filter(name => !name.includes('/node_modules/')),
85-
}
86-
break
87-
}
8872
}
8973
return data
9074
}

0 commit comments

Comments
 (0)