Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
639ccb01
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
639ccb01
编写于
10月 23, 2019
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Batch renames for js/ts
Fixes #76268
上级
e4478d36
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
76 addition
and
23 deletion
+76
-23
extensions/typescript-language-features/src/features/updatePathsOnRename.ts
...ipt-language-features/src/features/updatePathsOnRename.ts
+76
-23
未找到文件。
extensions/typescript-language-features/src/features/updatePathsOnRename.ts
浏览文件 @
639ccb01
...
...
@@ -98,26 +98,36 @@ class UpdateImportsOnFileRenameHandler extends Disposable {
private
async
flushRenames
():
Promise
<
void
>
{
const
renames
=
Array
.
from
(
this
.
_pendingRenames
);
this
.
_pendingRenames
.
clear
();
for
(
const
{
oldUri
,
newUri
,
newFilePath
,
oldFilePath
,
jsTsFileThatIsBeingMoved
}
of
renames
)
{
const
document
=
await
vscode
.
workspace
.
openTextDocument
(
jsTsFileThatIsBeingMoved
);
for
(
const
group
of
this
.
groupRenames
(
renames
))
{
const
edits
=
new
vscode
.
WorkspaceEdit
();
const
resourcesBeingRenamed
:
vscode
.
Uri
[]
=
[];
// Make sure TS knows about file
this
.
client
.
bufferSyncSupport
.
closeResource
(
oldUri
);
this
.
client
.
bufferSyncSupport
.
openTextDocument
(
document
);
for
(
const
{
oldUri
,
newUri
,
newFilePath
,
oldFilePath
,
jsTsFileThatIsBeingMoved
}
of
group
)
{
const
document
=
await
vscode
.
workspace
.
openTextDocument
(
jsTsFileThatIsBeingMoved
);
const
edits
=
await
this
.
getEditsForFileRename
(
document
,
oldFilePath
,
newFilePath
);
if
(
!
edits
||
!
edits
.
size
)
{
return
;
// Make sure TS knows about file
this
.
client
.
bufferSyncSupport
.
closeResource
(
oldUri
);
this
.
client
.
bufferSyncSupport
.
openTextDocument
(
document
);
if
(
await
this
.
withEditsForFileRename
(
edits
,
document
,
oldFilePath
,
newFilePath
))
{
resourcesBeingRenamed
.
push
(
newUri
);
}
}
if
(
await
this
.
confirmActionWithUser
(
newUri
))
{
await
vscode
.
workspace
.
applyEdit
(
edits
);
if
(
edits
.
size
)
{
if
(
await
this
.
confirmActionWithUser
(
resourcesBeingRenamed
))
{
await
vscode
.
workspace
.
applyEdit
(
edits
);
}
}
}
}
private
async
confirmActionWithUser
(
newResource
:
vscode
.
Uri
):
Promise
<
boolean
>
{
const
config
=
this
.
getConfiguration
(
newResource
);
private
async
confirmActionWithUser
(
newResources
:
readonly
vscode
.
Uri
[]):
Promise
<
boolean
>
{
if
(
!
newResources
.
length
)
{
return
false
;
}
const
config
=
this
.
getConfiguration
(
newResources
[
0
]);
const
setting
=
config
.
get
<
UpdateImportsOnFileMoveSetting
>
(
updateImportsOnFileMoveName
);
switch
(
setting
)
{
case
UpdateImportsOnFileMoveSetting
.
Always
:
...
...
@@ -126,7 +136,7 @@ class UpdateImportsOnFileRenameHandler extends Disposable {
return
false
;
case
UpdateImportsOnFileMoveSetting
.
Prompt
:
default
:
return
this
.
promptUser
(
newResource
);
return
this
.
promptUser
(
newResource
s
);
}
}
...
...
@@ -134,7 +144,11 @@ class UpdateImportsOnFileRenameHandler extends Disposable {
return
vscode
.
workspace
.
getConfiguration
(
doesResourceLookLikeATypeScriptFile
(
resource
)
?
'
typescript
'
:
'
javascript
'
,
resource
);
}
private
async
promptUser
(
newResource
:
vscode
.
Uri
):
Promise
<
boolean
>
{
private
async
promptUser
(
newResources
:
readonly
vscode
.
Uri
[]):
Promise
<
boolean
>
{
if
(
!
newResources
.
length
)
{
return
false
;
}
const
enum
Choice
{
None
=
0
,
Accept
=
1
,
...
...
@@ -144,11 +158,14 @@ class UpdateImportsOnFileRenameHandler extends Disposable {
}
interface
Item
extends
vscode
.
MessageItem
{
choice
:
Choice
;
readonly
choice
:
Choice
;
}
const
response
=
await
vscode
.
window
.
showInformationMessage
<
Item
>
(
localize
(
'
prompt
'
,
"
Update imports for moved file: '{0}'?
"
,
path
.
basename
(
newResource
.
fsPath
)),
{
this
.
getConfirmMessage
(
newResources
.
length
===
1
?
localize
(
'
prompt
'
,
"
Update imports for moved file:
"
)
:
localize
(
'
promptMoreThanOne
'
,
"
Update imports for moved files:
"
),
newResources
),
{
modal
:
true
,
},
{
title
:
localize
(
'
reject.title
'
,
"
No
"
),
...
...
@@ -180,7 +197,7 @@ class UpdateImportsOnFileRenameHandler extends Disposable {
}
case
Choice
.
Always
:
{
const
config
=
this
.
getConfiguration
(
newResource
);
const
config
=
this
.
getConfiguration
(
newResource
s
[
0
]
);
config
.
update
(
updateImportsOnFileMoveName
,
UpdateImportsOnFileMoveSetting
.
Always
,
...
...
@@ -189,7 +206,7 @@ class UpdateImportsOnFileRenameHandler extends Disposable {
}
case
Choice
.
Never
:
{
const
config
=
this
.
getConfiguration
(
newResource
);
const
config
=
this
.
getConfiguration
(
newResource
s
[
0
]
);
config
.
update
(
updateImportsOnFileMoveName
,
UpdateImportsOnFileMoveSetting
.
Never
,
...
...
@@ -217,11 +234,12 @@ class UpdateImportsOnFileRenameHandler extends Disposable {
return
(
await
this
.
_handles
(
resource
))
?
resource
:
undefined
;
}
private
async
getEditsForFileRename
(
private
async
withEditsForFileRename
(
edits
:
vscode
.
WorkspaceEdit
,
document
:
vscode
.
TextDocument
,
oldFilePath
:
string
,
newFilePath
:
string
,
):
Promise
<
vscode
.
WorkspaceEdit
|
undefined
>
{
):
Promise
<
boolean
>
{
const
response
=
await
this
.
client
.
interruptGetErr
(()
=>
{
this
.
fileConfigurationManager
.
setGlobalConfigurationFromDocument
(
document
,
nulToken
);
const
args
:
Proto
.
GetEditsForFileRenameRequestArgs
=
{
...
...
@@ -230,11 +248,46 @@ class UpdateImportsOnFileRenameHandler extends Disposable {
};
return
this
.
client
.
execute
(
'
getEditsForFileRename
'
,
args
,
nulToken
);
});
if
(
response
.
type
!==
'
response
'
)
{
return
;
if
(
response
.
type
!==
'
response
'
||
!
response
.
body
.
length
)
{
return
false
;
}
typeConverters
.
WorkspaceEdit
.
withFileCodeEdits
(
edits
,
this
.
client
,
response
.
body
);
return
true
;
}
private
groupRenames
(
renames
:
Iterable
<
RenameAction
>
):
Iterable
<
Iterable
<
RenameAction
>>
{
const
groups
=
new
Map
<
string
,
Set
<
RenameAction
>>
();
for
(
const
rename
of
renames
)
{
// Group renames by type (js/ts) and by workspace.
const
key
=
`
${
this
.
client
.
getWorkspaceRootForResource
(
rename
.
jsTsFileThatIsBeingMoved
)}
@@@
${
doesResourceLookLikeATypeScriptFile
(
rename
.
jsTsFileThatIsBeingMoved
)}
`
;
if
(
!
groups
.
has
(
key
))
{
groups
.
set
(
key
,
new
Set
());
}
groups
.
get
(
key
)
!
.
add
(
rename
);
}
return
groups
.
values
();
}
private
getConfirmMessage
(
start
:
string
,
resourcesToConfirm
:
readonly
vscode
.
Uri
[]):
string
{
const
MAX_CONFIRM_FILES
=
10
;
const
paths
=
[
start
];
paths
.
push
(
''
);
paths
.
push
(...
resourcesToConfirm
.
slice
(
0
,
MAX_CONFIRM_FILES
).
map
(
r
=>
path
.
basename
(
r
.
fsPath
)));
if
(
resourcesToConfirm
.
length
>
MAX_CONFIRM_FILES
)
{
if
(
resourcesToConfirm
.
length
-
MAX_CONFIRM_FILES
===
1
)
{
paths
.
push
(
localize
(
'
moreFile
'
,
"
...1 additional file not shown
"
));
}
else
{
paths
.
push
(
localize
(
'
moreFiles
'
,
"
...{0} additional files not shown
"
,
resourcesToConfirm
.
length
-
MAX_CONFIRM_FILES
));
}
}
return
typeConverters
.
WorkspaceEdit
.
fromFileCodeEdits
(
this
.
client
,
response
.
body
);
paths
.
push
(
''
);
return
paths
.
join
(
'
\n
'
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录