Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
4485c56f
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,体验更适合开发者的 AI 搜索 >>
提交
4485c56f
编写于
3月 14, 2019
作者:
D
David Barbet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move Go to definition to new fully loaded document API.
上级
e2d6b7d4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
27 addition
and
30 deletion
+27
-30
src/EditorFeatures/Core/GoToDefinition/GoToDefinitionCommandHandler.cs
...tures/Core/GoToDefinition/GoToDefinitionCommandHandler.cs
+27
-30
未找到文件。
src/EditorFeatures/Core/GoToDefinition/GoToDefinitionCommandHandler.cs
浏览文件 @
4485c56f
...
...
@@ -10,6 +10,7 @@
using
Microsoft.VisualStudio.Text
;
using
Microsoft.VisualStudio.Text.Editor.Commanding.Commands
;
using
Microsoft.VisualStudio.Utilities
;
using
Roslyn.Utilities
;
using
VSCommanding
=
Microsoft
.
VisualStudio
.
Commanding
;
namespace
Microsoft.CodeAnalysis.Editor.GoToDefinition
...
...
@@ -30,7 +31,8 @@ internal class GoToDefinitionCommandHandler :
public
VSCommanding
.
CommandState
GetCommandState
(
GoToDefinitionCommandArgs
args
)
{
var
(
document
,
service
)
=
GetDocumentAndService
(
args
.
SubjectBuffer
.
CurrentSnapshot
);
var
document
=
args
.
SubjectBuffer
.
CurrentSnapshot
.
GetOpenDocumentInCurrentContextWithChanges
();
var
service
=
document
?.
GetLanguageService
<
IGoToDefinitionService
>();
return
service
!=
null
?
VSCommanding
.
CommandState
.
Available
:
VSCommanding
.
CommandState
.
Unavailable
;
...
...
@@ -38,18 +40,23 @@ public VSCommanding.CommandState GetCommandState(GoToDefinitionCommandArgs args)
public
bool
ExecuteCommand
(
GoToDefinitionCommandArgs
args
,
CommandExecutionContext
context
)
{
var
subjectBuffer
=
args
.
SubjectBuffer
;
var
(
document
,
service
)
=
GetDocumentAndService
(
subjectBuffer
.
CurrentSnapshot
);
if
(
service
!=
null
)
using
(
context
.
OperationContext
.
AddScope
(
allowCancellation
:
true
,
EditorFeaturesResources
.
Navigating_to_definition
))
{
var
caretPos
=
args
.
TextView
.
GetCaretPoint
(
subjectBuffer
);
if
(
caretPos
.
HasValue
&&
TryExecuteCommand
(
document
,
caretPos
.
Value
,
service
,
context
))
var
subjectBuffer
=
args
.
SubjectBuffer
;
var
document
=
subjectBuffer
.
CurrentSnapshot
.
GetFullyLoadedOpenDocumentInCurrentContextWithChangesAsync
(
context
.
OperationContext
).
WaitAndGetResult
(
context
.
OperationContext
.
UserCancellationToken
);
var
service
=
document
?.
GetLanguageService
<
IGoToDefinitionService
>();
if
(
service
!=
null
)
{
return
true
;
var
caretPos
=
args
.
TextView
.
GetCaretPoint
(
subjectBuffer
);
if
(
caretPos
.
HasValue
&&
TryExecuteCommand
(
document
,
caretPos
.
Value
,
service
,
context
))
{
return
true
;
}
}
}
return
false
;
return
false
;
}
}
// Internal for testing purposes only.
...
...
@@ -61,30 +68,20 @@ internal bool TryExecuteCommand(Document document, int caretPosition, CommandExe
internal
bool
TryExecuteCommand
(
Document
document
,
int
caretPosition
,
IGoToDefinitionService
goToDefinitionService
,
CommandExecutionContext
context
)
{
string
errorMessage
=
null
;
using
(
context
.
OperationContext
.
AddScope
(
allowCancellation
:
true
,
EditorFeaturesResources
.
Navigating_to_definition
))
{
if
(
goToDefinitionService
!=
null
&&
goToDefinitionService
.
TryGoToDefinition
(
document
,
caretPosition
,
context
.
OperationContext
.
UserCancellationToken
))
{
return
true
;
}
errorMessage
=
EditorFeaturesResources
.
Cannot_navigate_to_the_symbol_under_the_caret
;
}
if
(
errorMessage
!=
null
)
if
(
goToDefinitionService
!=
null
&&
goToDefinitionService
.
TryGoToDefinition
(
document
,
caretPosition
,
context
.
OperationContext
.
UserCancellationToken
))
{
// We are about to show a modal UI dialog so we should take over the command execution
// wait context. That means the command system won't attempt to show its own wait dialog
// and also will take it into consideration when measuring command handling duration.
context
.
OperationContext
.
TakeOwnership
();
var
workspace
=
document
.
Project
.
Solution
.
Workspace
;
var
notificationService
=
workspace
.
Services
.
GetService
<
INotificationService
>();
notificationService
.
SendNotification
(
errorMessage
,
title
:
EditorFeaturesResources
.
Go_to_Definition
,
severity
:
NotificationSeverity
.
Information
);
return
true
;
}
var
errorMessage
=
EditorFeaturesResources
.
Cannot_navigate_to_the_symbol_under_the_caret
;
// We are about to show a modal UI dialog so we should take over the command execution
// wait context. That means the command system won't attempt to show its own wait dialog
// and also will take it into consideration when measuring command handling duration.
context
.
OperationContext
.
TakeOwnership
();
var
workspace
=
document
.
Project
.
Solution
.
Workspace
;
var
notificationService
=
workspace
.
Services
.
GetService
<
INotificationService
>();
notificationService
.
SendNotification
(
errorMessage
,
title
:
EditorFeaturesResources
.
Go_to_Definition
,
severity
:
NotificationSeverity
.
Information
);
return
true
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录