Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
c8319ad2
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 搜索 >>
提交
c8319ad2
编写于
2月 20, 2020
作者:
D
David Barbet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Listen for workspace registration changes to ensure we add/remove the navbar on extension changes.
上级
fea95d79
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
45 addition
and
15 deletion
+45
-15
src/EditorFeatures/Core/Extensibility/NavigationBar/INavigationBarController.cs
...e/Extensibility/NavigationBar/INavigationBarController.cs
+2
-0
src/EditorFeatures/Core/Implementation/NavigationBar/NavigationBarController.cs
...e/Implementation/NavigationBar/NavigationBarController.cs
+1
-12
src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractLanguageService`2.VsCodeWindowManager.cs
...eService/AbstractLanguageService`2.VsCodeWindowManager.cs
+42
-3
未找到文件。
src/EditorFeatures/Core/Extensibility/NavigationBar/INavigationBarController.cs
浏览文件 @
c8319ad2
...
...
@@ -7,5 +7,7 @@ namespace Microsoft.CodeAnalysis.Editor
internal
interface
INavigationBarController
{
void
Disconnect
();
void
SetWorkspace
(
Workspace
newWorkspace
);
}
}
src/EditorFeatures/Core/Implementation/NavigationBar/NavigationBarController.cs
浏览文件 @
c8319ad2
...
...
@@ -33,7 +33,6 @@ internal partial class NavigationBarController : ForegroundThreadAffinitizedObje
private
readonly
ITextBuffer
_subjectBuffer
;
private
readonly
IWaitIndicator
_waitIndicator
;
private
readonly
IAsynchronousOperationListener
_asyncListener
;
private
readonly
WorkspaceRegistration
_workspaceRegistration
;
/// <summary>
/// If we have pushed a full list to the presenter in response to a focus event, this
...
...
@@ -57,8 +56,6 @@ internal partial class NavigationBarController : ForegroundThreadAffinitizedObje
_subjectBuffer
=
subjectBuffer
;
_waitIndicator
=
waitIndicator
;
_asyncListener
=
asyncListener
;
_workspaceRegistration
=
Workspace
.
GetWorkspaceRegistration
(
subjectBuffer
.
AsTextContainer
());
_workspaceRegistration
.
WorkspaceChanged
+=
OnWorkspaceRegistrationChanged
;
presenter
.
CaretMoved
+=
OnCaretMoved
;
presenter
.
ViewFocused
+=
OnViewFocused
;
...
...
@@ -76,18 +73,12 @@ internal partial class NavigationBarController : ForegroundThreadAffinitizedObje
null
));
_selectedItemInfoTask
=
Task
.
FromResult
(
new
NavigationBarSelectedTypeAndMember
(
null
,
null
));
if
(
_workspaceRegistration
.
Workspace
!=
null
)
{
ConnectToWorkspace
(
_workspaceRegistration
.
Workspace
);
}
}
p
rivate
void
OnWorkspaceRegistrationChanged
(
object
sender
,
EventArgs
e
)
p
ublic
void
SetWorkspace
(
Workspace
newWorkspac
e
)
{
DisconnectFromWorkspace
();
var
newWorkspace
=
_workspaceRegistration
.
Workspace
;
if
(
newWorkspace
!=
null
)
{
ConnectToWorkspace
(
newWorkspace
);
...
...
@@ -151,8 +142,6 @@ public void Disconnect()
_presenter
.
Disconnect
();
_workspaceRegistration
.
WorkspaceChanged
-=
OnWorkspaceRegistrationChanged
;
_disconnected
=
true
;
// Cancel off any remaining background work
...
...
src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractLanguageService`2.VsCodeWindowManager.cs
浏览文件 @
c8319ad2
...
...
@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#
nullable
enable
using
System.Diagnostics
;
using
System.Linq
;
using
Microsoft.CodeAnalysis.Editor
;
...
...
@@ -9,9 +11,12 @@
using
Microsoft.CodeAnalysis.Options
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Text
;
using
Microsoft.CodeAnalysis
;
using
Microsoft.VisualStudio.LanguageServices.Implementation.NavigationBar
;
using
Microsoft.VisualStudio.TextManager.Interop
;
using
Roslyn.Utilities
;
using
Microsoft.CodeAnalysis.Editor.Shared.Utilities
;
using
System.Runtime.InteropServices
;
namespace
Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService
{
...
...
@@ -23,9 +28,11 @@ internal class VsCodeWindowManager : IVsCodeWindowManager, IVsCodeWindowEvents
private
readonly
IVsCodeWindow
_codeWindow
;
private
readonly
ComEventSink
_sink
;
private
readonly
IOptionService
_optionService
;
private
readonly
IThreadingContext
_threadingContext
;
private
INavigationBarController
_navigationBarController
;
private
IVsDropdownBarClient
_dropdownBarClient
;
private
INavigationBarController
?
_navigationBarController
;
private
IVsDropdownBarClient
?
_dropdownBarClient
;
private
WorkspaceRegistration
_workspaceRegistration
;
public
VsCodeWindowManager
(
TLanguageService
languageService
,
IVsCodeWindow
codeWindow
)
{
...
...
@@ -33,10 +40,31 @@ public VsCodeWindowManager(TLanguageService languageService, IVsCodeWindow codeW
_codeWindow
=
codeWindow
;
var
workspace
=
languageService
.
Package
.
ComponentModel
.
GetService
<
VisualStudioWorkspace
>();
_optionService
=
workspace
.
Services
.
GetService
<
IOptionService
>();
_optionService
=
workspace
.
Services
.
GetRequiredService
<
IOptionService
>();
_threadingContext
=
languageService
.
Package
.
ComponentModel
.
GetService
<
IThreadingContext
>();
_sink
=
ComEventSink
.
Advise
<
IVsCodeWindowEvents
>(
codeWindow
,
this
);
_optionService
.
OptionChanged
+=
OnOptionChanged
;
_workspaceRegistration
=
GetWorkspaceRegistration
();
_workspaceRegistration
.
WorkspaceChanged
+=
OnWorkspaceRegistrationChanged
;
}
private
void
OnWorkspaceRegistrationChanged
(
object
sender
,
System
.
EventArgs
e
)
{
_threadingContext
.
JoinableTaskFactory
.
Run
(
async
()
=>
{
// This event may not be triggered on the main thread, but adding and removing the navbar
// must be done from the main thread.
await
_threadingContext
.
JoinableTaskFactory
.
SwitchToMainThreadAsync
();
_navigationBarController
?.
SetWorkspace
(
_workspaceRegistration
.
Workspace
);
// Trigger a check to see if the dropdown should be added / removed now that the buffer is in a different workspace.
var
enabled
=
_optionService
.
GetOption
(
NavigationBarOptions
.
ShowNavigationBar
,
_languageService
.
RoslynLanguageName
);
AddOrRemoveDropdown
(
enabled
);
});
}
private
void
SetupView
(
IVsTextView
view
)
...
...
@@ -60,6 +88,14 @@ private void OnOptionChanged(object sender, OptionChangedEventArgs e)
AddOrRemoveDropdown
(
enabled
);
}
private
WorkspaceRegistration
GetWorkspaceRegistration
()
{
ErrorHandler
.
ThrowOnFailure
(
_codeWindow
.
GetBuffer
(
out
var
buffer
));
var
textContainer
=
_languageService
.
EditorAdaptersFactoryService
.
GetDataBuffer
(
buffer
).
AsTextContainer
();
return
CodeAnalysis
.
Workspace
.
GetWorkspaceRegistration
(
textContainer
);
}
private
void
AddOrRemoveDropdown
(
bool
enabled
)
{
if
(!(
_codeWindow
is
IVsDropdownBarManager
dropdownManager
))
...
...
@@ -77,6 +113,7 @@ private void AddOrRemoveDropdown(bool enabled)
var
document
=
_languageService
.
EditorAdaptersFactoryService
.
GetDataBuffer
(
buffer
).
AsTextContainer
().
GetRelatedDocuments
().
FirstOrDefault
();
if
(
document
.
GetLanguageService
<
INavigationBarItemService
>()
==
null
)
{
RemoveDropdownBar
(
dropdownManager
);
return
;
}
...
...
@@ -132,6 +169,7 @@ private void AdddropdownBar(IVsDropdownBarManager dropdownManager)
var
textBuffer
=
_languageService
.
EditorAdaptersFactoryService
.
GetDataBuffer
(
buffer
);
var
controllerFactoryService
=
_languageService
.
Package
.
ComponentModel
.
GetService
<
INavigationBarControllerFactoryService
>();
var
newController
=
controllerFactoryService
.
CreateController
(
navigationBarClient
,
textBuffer
);
newController
.
SetWorkspace
(
_workspaceRegistration
.
Workspace
);
var
hr
=
dropdownManager
.
AddDropdownBar
(
cCombos
:
3
,
pClient
:
navigationBarClient
);
if
(
ErrorHandler
.
Failed
(
hr
))
...
...
@@ -198,6 +236,7 @@ public int RemoveAdornments()
{
_sink
.
Unadvise
();
_optionService
.
OptionChanged
-=
OnOptionChanged
;
_workspaceRegistration
.
WorkspaceChanged
-=
OnWorkspaceRegistrationChanged
;
AddOrRemoveDropdown
(
enabled
:
false
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录