Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
50cab999
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
50cab999
编写于
7月 05, 2020
作者:
A
Allison Chou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove unnecessary local function
上级
fe24b8a7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
42 addition
and
57 deletion
+42
-57
src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionResolveHandler.cs
.../Protocol/Handler/CodeActions/CodeActionResolveHandler.cs
+42
-57
未找到文件。
src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionResolveHandler.cs
浏览文件 @
50cab999
...
...
@@ -89,43 +89,11 @@ internal class CodeActionResolveHandler : AbstractRequestHandler<LSP.VSCodeActio
// Add workspace edits
var
applyChangesOperations
=
operations
.
OfType
<
ApplyChangesOperation
>();
if
(
applyChangesOperations
.
Any
())
{
var
workspaceEdits
=
await
ComputeWorkspaceEdits
(
applyChangesOperations
,
document
!,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
workspaceEdits
!=
null
)
{
codeAction
.
Edit
=
new
LSP
.
WorkspaceEdit
{
DocumentChanges
=
workspaceEdits
};
}
else
{
// The workspace edit is something we don't currently support, like adding a new document.
runAsCommand
=
true
;
}
}
// Set up to run as command on the server instead of using WorkspaceEdits.
var
commandOperations
=
operations
.
All
(
operation
=>
!(
operation
is
ApplyChangesOperation
));
if
(
commandOperations
||
runAsCommand
)
{
codeAction
.
Command
=
new
LSP
.
Command
{
CommandIdentifier
=
CodeActionsHandler
.
RunCodeActionCommandName
,
Title
=
codeAction
.
Title
,
Arguments
=
new
object
[]
{
data
}
};
}
return
codeAction
;
// Local functions
static
async
Task
<
TextDocumentEdit
[]?>
ComputeWorkspaceEdits
(
IEnumerable
<
ApplyChangesOperation
>
applyChangesOperations
,
Document
document
,
CancellationToken
cancellationToken
)
{
using
var
_
=
ArrayBuilder
<
TextDocumentEdit
>.
GetInstance
(
out
var
textDocumentEdits
);
foreach
(
var
applyChangesOperation
in
applyChangesOperations
)
{
var
solution
=
document
.
Project
.
Solution
;
var
solution
=
document
!
.
Project
.
Solution
;
var
changes
=
applyChangesOperation
.
ChangedSolution
.
GetChanges
(
solution
);
var
projectChanges
=
changes
.
GetProjectChanges
();
...
...
@@ -136,7 +104,8 @@ internal class CodeActionResolveHandler : AbstractRequestHandler<LSP.VSCodeActio
pc
=>
pc
.
GetAddedDocuments
().
Concat
(
pc
.
GetAddedAdditionalDocuments
().
Concat
(
pc
.
GetAddedAnalyzerConfigDocuments
())));
if
(
addedDocuments
.
Any
())
{
return
null
;
runAsCommand
=
true
;
break
;
}
var
changedDocuments
=
projectChanges
.
SelectMany
(
pc
=>
pc
.
GetChangedDocuments
());
...
...
@@ -151,7 +120,8 @@ internal class CodeActionResolveHandler : AbstractRequestHandler<LSP.VSCodeActio
changedAnalyzerConfigDocuments
.
Any
()
||
changedAdditionalDocuments
.
Any
())
{
return
null
;
runAsCommand
=
true
;
break
;
}
// Changed documents
...
...
@@ -177,32 +147,47 @@ internal class CodeActionResolveHandler : AbstractRequestHandler<LSP.VSCodeActio
cancellationToken
).
ConfigureAwait
(
false
);
}
return
textDocumentEdits
.
ToArray
();
static
async
Task
AddTextDocumentEdits
<
T
>(
ArrayBuilder
<
TextDocumentEdit
>
textDocumentEdits
,
ApplyChangesOperation
applyChangesOperation
,
Solution
solution
,
IEnumerable
<
DocumentId
>
changedDocuments
,
Func
<
DocumentId
,
T
?>
getNewDocumentFunc
,
Func
<
DocumentId
,
T
?>
getOldDocumentFunc
,
CancellationToken
cancellationToken
)
where
T
:
TextDocument
codeAction
.
Edit
=
new
LSP
.
WorkspaceEdit
{
DocumentChanges
=
textDocumentEdits
.
ToArray
()
};
}
// Set up to run as command on the server instead of using WorkspaceEdits.
var
commandOperations
=
operations
.
All
(
operation
=>
!(
operation
is
ApplyChangesOperation
));
if
(
commandOperations
||
runAsCommand
)
{
codeAction
.
Command
=
new
LSP
.
Command
{
foreach
(
var
docId
in
changedDocuments
)
{
var
newDoc
=
getNewDocumentFunc
(
docId
);
var
oldDoc
=
getOldDocumentFunc
(
docId
);
CommandIdentifier
=
CodeActionsHandler
.
RunCodeActionCommandName
,
Title
=
codeAction
.
Title
,
Arguments
=
new
object
[]
{
data
}
};
}
var
oldText
=
await
oldDoc
!.
GetTextAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
newText
=
await
newDoc
!.
GetTextAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
return
codeAction
;
var
textChanges
=
newText
.
GetTextChanges
(
oldText
).
ToList
();
// Local functions
static
async
Task
AddTextDocumentEdits
<
T
>(
ArrayBuilder
<
TextDocumentEdit
>
textDocumentEdits
,
ApplyChangesOperation
applyChangesOperation
,
Solution
solution
,
IEnumerable
<
DocumentId
>
changedDocuments
,
Func
<
DocumentId
,
T
?>
getNewDocumentFunc
,
Func
<
DocumentId
,
T
?>
getOldDocumentFunc
,
CancellationToken
cancellationToken
)
where
T
:
TextDocument
{
foreach
(
var
docId
in
changedDocuments
)
{
var
newDoc
=
getNewDocumentFunc
(
docId
);
var
oldDoc
=
getOldDocumentFunc
(
docId
);
var
edits
=
textChanges
.
Select
(
tc
=>
ProtocolConversions
.
TextChangeToTextEdit
(
tc
,
oldText
)).
ToArray
();
var
documentIdentifier
=
new
VersionedTextDocumentIdentifier
{
Uri
=
newDoc
.
GetURI
()
};
textDocumentEdits
.
Add
(
new
TextDocumentEdit
{
TextDocument
=
documentIdentifier
,
Edits
=
edits
.
ToArray
()
});
}
var
oldText
=
await
oldDoc
!.
GetTextAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
newText
=
await
newDoc
!.
GetTextAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
textChanges
=
newText
.
GetTextChanges
(
oldText
).
ToList
();
var
edits
=
textChanges
.
Select
(
tc
=>
ProtocolConversions
.
TextChangeToTextEdit
(
tc
,
oldText
)).
ToArray
();
var
documentIdentifier
=
new
VersionedTextDocumentIdentifier
{
Uri
=
newDoc
.
GetURI
()
};
textDocumentEdits
.
Add
(
new
TextDocumentEdit
{
TextDocument
=
documentIdentifier
,
Edits
=
edits
.
ToArray
()
});
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录