Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
7c96862d
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,发现更多精彩内容 >>
提交
7c96862d
编写于
6月 19, 2018
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use workspace edit to create new file on refactor
#10659
上级
fae2d736
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
35 addition
and
29 deletion
+35
-29
extensions/typescript-language-features/src/features/organizeImports.ts
...escript-language-features/src/features/organizeImports.ts
+1
-1
extensions/typescript-language-features/src/features/quickFix.ts
...ons/typescript-language-features/src/features/quickFix.ts
+1
-1
extensions/typescript-language-features/src/features/refactor.ts
...ons/typescript-language-features/src/features/refactor.ts
+22
-23
extensions/typescript-language-features/src/features/updatePathsOnRename.ts
...ipt-language-features/src/features/updatePathsOnRename.ts
+1
-1
extensions/typescript-language-features/src/utils/codeAction.ts
...ions/typescript-language-features/src/utils/codeAction.ts
+1
-1
extensions/typescript-language-features/src/utils/typeConverters.ts
.../typescript-language-features/src/utils/typeConverters.ts
+9
-2
未找到文件。
extensions/typescript-language-features/src/features/organizeImports.ts
浏览文件 @
7c96862d
...
...
@@ -39,7 +39,7 @@ class OrganizeImportsCommand implements Command {
return
false
;
}
const
edits
=
typeconverts
.
WorkspaceEdit
.
fromF
romF
ileCodeEdits
(
this
.
client
,
response
.
body
);
const
edits
=
typeconverts
.
WorkspaceEdit
.
fromFileCodeEdits
(
this
.
client
,
response
.
body
);
return
await
vscode
.
workspace
.
applyEdit
(
edits
);
}
}
...
...
extensions/typescript-language-features/src/features/quickFix.ts
浏览文件 @
7c96862d
...
...
@@ -92,7 +92,7 @@ class ApplyFixAllCodeAction implements Command {
return
;
}
const
edit
=
typeConverters
.
WorkspaceEdit
.
fromF
romF
ileCodeEdits
(
this
.
client
,
combinedCodeFixesResponse
.
body
.
changes
);
const
edit
=
typeConverters
.
WorkspaceEdit
.
fromFileCodeEdits
(
this
.
client
,
combinedCodeFixesResponse
.
body
.
changes
);
await
vscode
.
workspace
.
applyEdit
(
edit
);
if
(
combinedCodeFixesResponse
.
command
)
{
...
...
extensions/typescript-language-features/src/features/refactor.ts
浏览文件 @
7c96862d
...
...
@@ -4,15 +4,14 @@
*--------------------------------------------------------------------------------------------*/
import
*
as
vscode
from
'
vscode
'
;
import
*
as
fs
from
'
fs
'
;
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
import
API
from
'
../utils/api
'
;
import
{
Command
,
CommandManager
}
from
'
../utils/commandManager
'
;
import
{
VersionDependentRegistration
}
from
'
../utils/dependentRegistration
'
;
import
*
as
typeConverters
from
'
../utils/typeConverters
'
;
import
FormattingOptionsManager
from
'
./fileConfigurationManager
'
;
import
{
CommandManager
,
Command
}
from
'
../utils/commandManager
'
;
import
{
VersionDependentRegistration
}
from
'
../utils/dependentRegistration
'
;
import
API
from
'
../utils/api
'
;
class
ApplyRefactoringCommand
implements
Command
{
public
static
readonly
ID
=
'
_typescript.applyRefactoring
'
;
...
...
@@ -35,30 +34,17 @@ class ApplyRefactoringCommand implements Command {
action
};
const
response
=
await
this
.
client
.
execute
(
'
getEditsForRefactor
'
,
args
);
if
(
!
response
||
!
response
.
body
||
!
response
.
body
.
edits
.
length
)
{
const
body
=
response
&&
response
.
body
;
if
(
!
body
||
!
body
.
edits
.
length
)
{
return
false
;
}
for
(
const
edit
of
response
.
body
.
edits
)
{
try
{
await
vscode
.
workspace
.
openTextDocument
(
edit
.
fileName
);
}
catch
{
try
{
if
(
!
fs
.
existsSync
(
edit
.
fileName
))
{
fs
.
writeFileSync
(
edit
.
fileName
,
''
);
}
}
catch
{
// noop
}
}
}
const
edit
=
typeConverters
.
WorkspaceEdit
.
fromFromFileCodeEdits
(
this
.
client
,
response
.
body
.
edits
);
if
(
!
(
await
vscode
.
workspace
.
applyEdit
(
edit
)))
{
const
workspaceEdit
=
await
this
.
toWorkspaceEdit
(
body
);
if
(
!
(
await
vscode
.
workspace
.
applyEdit
(
workspaceEdit
)))
{
return
false
;
}
const
renameLocation
=
response
.
body
.
renameLocation
;
const
renameLocation
=
body
.
renameLocation
;
if
(
renameLocation
)
{
await
vscode
.
commands
.
executeCommand
(
'
editor.action.rename
'
,
[
document
.
uri
,
...
...
@@ -67,6 +53,19 @@ class ApplyRefactoringCommand implements Command {
}
return
true
;
}
private
async
toWorkspaceEdit
(
body
:
Proto
.
RefactorEditInfo
)
{
const
workspaceEdit
=
new
vscode
.
WorkspaceEdit
();
for
(
const
edit
of
body
.
edits
)
{
try
{
await
vscode
.
workspace
.
openTextDocument
(
edit
.
fileName
);
}
catch
{
workspaceEdit
.
createFile
(
this
.
client
.
toResource
(
edit
.
fileName
));
}
}
typeConverters
.
WorkspaceEdit
.
withFileCodeEdits
(
workspaceEdit
,
this
.
client
,
body
.
edits
);
return
workspaceEdit
;
}
}
class
SelectRefactorCommand
implements
Command
{
...
...
extensions/typescript-language-features/src/features/updatePathsOnRename.ts
浏览文件 @
7c96862d
...
...
@@ -227,7 +227,7 @@ export class UpdateImportsOnFileRenameHandler {
for
(
const
edit
of
response
.
body
)
{
edits
.
push
(
await
this
.
fixEdit
(
edit
,
isDirectoryRename
,
oldFile
,
newFile
));
}
return
typeConverters
.
WorkspaceEdit
.
fromF
romF
ileCodeEdits
(
this
.
client
,
edits
);
return
typeConverters
.
WorkspaceEdit
.
fromFileCodeEdits
(
this
.
client
,
edits
);
}
private
async
fixEdit
(
...
...
extensions/typescript-language-features/src/utils/codeAction.ts
浏览文件 @
7c96862d
...
...
@@ -13,7 +13,7 @@ export function getEditForCodeAction(
action
:
Proto
.
CodeAction
):
WorkspaceEdit
|
undefined
{
return
action
.
changes
&&
action
.
changes
.
length
?
typeConverters
.
WorkspaceEdit
.
fromF
romF
ileCodeEdits
(
client
,
action
.
changes
)
?
typeConverters
.
WorkspaceEdit
.
fromFileCodeEdits
(
client
,
action
.
changes
)
:
undefined
;
}
...
...
extensions/typescript-language-features/src/utils/typeConverters.ts
浏览文件 @
7c96862d
...
...
@@ -50,11 +50,18 @@ export namespace TextEdit {
}
export
namespace
WorkspaceEdit
{
export
function
fromFromFileCodeEdits
(
export
function
fromFileCodeEdits
(
client
:
ITypeScriptServiceClient
,
edits
:
Iterable
<
Proto
.
FileCodeEdits
>
):
vscode
.
WorkspaceEdit
{
return
withFileCodeEdits
(
new
vscode
.
WorkspaceEdit
(),
client
,
edits
);
}
export
function
withFileCodeEdits
(
workspaceEdit
:
vscode
.
WorkspaceEdit
,
client
:
ITypeScriptServiceClient
,
edits
:
Iterable
<
Proto
.
FileCodeEdits
>
):
vscode
.
WorkspaceEdit
{
const
workspaceEdit
=
new
vscode
.
WorkspaceEdit
();
for
(
const
edit
of
edits
)
{
for
(
const
textChange
of
edit
.
textChanges
)
{
workspaceEdit
.
replace
(
client
.
toResource
(
edit
.
fileName
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录