Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
4e2cb832
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,发现更多精彩内容 >>
未验证
提交
4e2cb832
编写于
9月 19, 2020
作者:
M
msftbot[bot]
提交者:
GitHub
9月 19, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #47846 from jasonmalinowski/fix-issues-with-opening-source-generated-files
Fix issues with opening source generated files
上级
4f600e6a
2ea0d2c0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
30 addition
and
39 deletion
+30
-39
src/VisualStudio/Core/Def/Implementation/Workspace/SourceGeneratedFileManager.cs
...ef/Implementation/Workspace/SourceGeneratedFileManager.cs
+22
-1
src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioDocumentNavigationService.cs
...tation/Workspace/VisualStudioDocumentNavigationService.cs
+7
-2
src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioDocumentNavigationServiceFactory.cs
...Workspace/VisualStudioDocumentNavigationServiceFactory.cs
+0
-34
src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpSourceGenerators.cs
...ionTest/IntegrationTests/CSharp/CSharpSourceGenerators.cs
+1
-2
未找到文件。
src/VisualStudio/Core/Def/Implementation/Workspace/SourceGeneratedFileManager.cs
浏览文件 @
4e2cb832
...
...
@@ -20,6 +20,7 @@
using
Microsoft.VisualStudio.Editor
;
using
Microsoft.VisualStudio.Imaging
;
using
Microsoft.VisualStudio.Imaging.Interop
;
using
Microsoft.VisualStudio.LanguageServices.Implementation.Extensions
;
using
Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem
;
using
Microsoft.VisualStudio.Shell
;
using
Microsoft.VisualStudio.Shell.Interop
;
...
...
@@ -41,6 +42,7 @@ internal sealed class SourceGeneratedFileManager : IRunningDocumentTableEventLis
private
readonly
IAsynchronousOperationListener
_listener
;
private
readonly
IVsRunningDocumentTable
_runningDocumentTable
;
private
readonly
ITextDocumentFactoryService
_textDocumentFactoryService
;
private
readonly
VisualStudioDocumentNavigationService
_visualStudioDocumentNavigationService
;
private
readonly
RunningDocumentTableEventTracker
_runningDocumentTableEventTracker
;
...
...
@@ -63,6 +65,7 @@ internal sealed class SourceGeneratedFileManager : IRunningDocumentTableEventLis
IVsEditorAdaptersFactoryService
editorAdaptersFactoryService
,
ITextDocumentFactoryService
textDocumentFactoryService
,
VisualStudioWorkspace
visualStudioWorkspace
,
VisualStudioDocumentNavigationService
visualStudioDocumentNavigationService
,
IAsynchronousOperationListenerProvider
listenerProvider
)
{
_serviceProvider
=
serviceProvider
;
...
...
@@ -70,6 +73,7 @@ internal sealed class SourceGeneratedFileManager : IRunningDocumentTableEventLis
_textDocumentFactoryService
=
textDocumentFactoryService
;
_temporaryDirectory
=
Path
.
Combine
(
Path
.
GetTempPath
(),
"VisualStudioSourceGeneratedDocuments"
);
_visualStudioWorkspace
=
visualStudioWorkspace
;
_visualStudioDocumentNavigationService
=
visualStudioDocumentNavigationService
;
Directory
.
CreateDirectory
(
_temporaryDirectory
);
...
...
@@ -99,7 +103,12 @@ public void NavigateToSourceGeneratedFile(Project project, ISourceGenerator gene
// The file name we generate here is chosen to match the compiler's choice, so the debugger can recognize the files should match.
// This can only be changed if the compiler changes the algorithm as well.
var
temporaryFilePath
=
Path
.
Combine
(
projectDirectory
,
$"
{
generatorType
.
Module
.
ModuleVersionId
}
_
{
generatorType
.
FullName
}
_
{
generatedSourceHintName
}
"
);
File
.
WriteAllText
(
temporaryFilePath
,
""
);
// Don't write to the file if it's already there, as that potentially triggers a file reload
if
(!
File
.
Exists
(
temporaryFilePath
))
{
File
.
WriteAllText
(
temporaryFilePath
,
""
);
}
var
openDocumentService
=
_serviceProvider
.
GetService
<
SVsUIShellOpenDocument
,
IVsUIShellOpenDocument
>();
var
hr
=
openDocumentService
.
OpenDocumentViaProject
(
...
...
@@ -114,6 +123,12 @@ public void NavigateToSourceGeneratedFile(Project project, ISourceGenerator gene
{
windowFrame
.
Show
();
}
// We should have the file now, so navigate to the right span
if
(
_openFiles
.
TryGetValue
(
temporaryFilePath
,
out
var
openFile
))
{
openFile
.
NavigateToSpan
(
sourceSpan
);
}
}
public
bool
TryParseGeneratedFilePath
(
...
...
@@ -425,6 +440,12 @@ private void EnsureWindowFrameInfoBarUpdated()
_currentWindowFrameImageMoniker
=
_windowFrameImageMonikerToShow
;
_currentWindowFrameInfoBarElement
=
infoBarUI
;
}
public
void
NavigateToSpan
(
TextSpan
sourceSpan
)
{
var
sourceText
=
_textBuffer
.
CurrentSnapshot
.
AsText
();
_fileManager
.
_visualStudioDocumentNavigationService
.
NavigateTo
(
_textBuffer
,
sourceText
.
GetVsTextSpanForSpan
(
sourceSpan
));
}
}
}
}
src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioDocumentNavigationService.cs
浏览文件 @
4e2cb832
...
...
@@ -4,6 +4,7 @@
using
System
;
using
System.Collections.Immutable
;
using
System.Composition
;
using
System.Diagnostics
;
using
System.Linq
;
using
System.Threading
;
...
...
@@ -11,6 +12,7 @@
using
Microsoft.CodeAnalysis.Editor.Shared.Utilities
;
using
Microsoft.CodeAnalysis.ErrorReporting
;
using
Microsoft.CodeAnalysis.Host
;
using
Microsoft.CodeAnalysis.Host.Mef
;
using
Microsoft.CodeAnalysis.Internal.Log
;
using
Microsoft.CodeAnalysis.Navigation
;
using
Microsoft.CodeAnalysis.Options
;
...
...
@@ -19,7 +21,6 @@
using
Microsoft.VisualStudio.Editor
;
using
Microsoft.VisualStudio.LanguageServices.Implementation.Extensions
;
using
Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem
;
using
Microsoft.VisualStudio.LanguageServices.Implementation.Venus
;
using
Microsoft.VisualStudio.Shell
;
using
Microsoft.VisualStudio.Shell.Interop
;
using
Microsoft.VisualStudio.Text
;
...
...
@@ -32,12 +33,16 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation
{
using
Workspace
=
Microsoft
.
CodeAnalysis
.
Workspace
;
[
ExportWorkspaceService
(
typeof
(
IDocumentNavigationService
),
ServiceLayer
.
Host
),
Shared
]
[
Export
(
typeof
(
VisualStudioDocumentNavigationService
))]
internal
sealed
class
VisualStudioDocumentNavigationService
:
ForegroundThreadAffinitizedObject
,
IDocumentNavigationService
{
private
readonly
IServiceProvider
_serviceProvider
;
private
readonly
IVsEditorAdaptersFactoryService
_editorAdaptersFactoryService
;
private
readonly
IVsRunningDocumentTable4
_runningDocumentTable
;
[
ImportingConstructor
]
[
Obsolete
(
MefConstruction
.
ImportingConstructorMessage
,
error
:
true
)]
public
VisualStudioDocumentNavigationService
(
IThreadingContext
threadingContext
,
SVsServiceProvider
serviceProvider
,
...
...
@@ -357,7 +362,7 @@ private static Document OpenDocument(Workspace workspace, DocumentId documentId)
return
workspace
.
CurrentSolution
.
GetDocument
(
documentId
);
}
p
rivate
bool
NavigateTo
(
ITextBuffer
textBuffer
,
VsTextSpan
vsTextSpan
)
p
ublic
bool
NavigateTo
(
ITextBuffer
textBuffer
,
VsTextSpan
vsTextSpan
)
{
using
(
Logger
.
LogBlock
(
FunctionId
.
NavigationService_VSDocumentNavigationService_NavigateTo
,
CancellationToken
.
None
))
{
...
...
src/VisualStudio/Core/Def/Implementation/Workspace/VisualStudioDocumentNavigationServiceFactory.cs
已删除
100644 → 0
浏览文件 @
4f600e6a
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
System
;
using
System.Composition
;
using
Microsoft.CodeAnalysis.Editor.Shared.Utilities
;
using
Microsoft.CodeAnalysis.Host
;
using
Microsoft.CodeAnalysis.Host.Mef
;
using
Microsoft.CodeAnalysis.Navigation
;
using
Microsoft.VisualStudio.Editor
;
using
Microsoft.VisualStudio.Shell
;
namespace
Microsoft.VisualStudio.LanguageServices.Implementation
{
[
ExportWorkspaceServiceFactory
(
typeof
(
IDocumentNavigationService
),
ServiceLayer
.
Host
),
Shared
]
internal
sealed
class
VisualStudioDocumentNavigationServiceFactory
:
IWorkspaceServiceFactory
{
private
readonly
IDocumentNavigationService
_singleton
;
[
ImportingConstructor
]
[
Obsolete
(
MefConstruction
.
ImportingConstructorMessage
,
error
:
true
)]
public
VisualStudioDocumentNavigationServiceFactory
(
IThreadingContext
threadingContext
,
SVsServiceProvider
serviceProvider
,
IVsEditorAdaptersFactoryService
editorAdaptersFactoryService
)
{
_singleton
=
new
VisualStudioDocumentNavigationService
(
threadingContext
,
serviceProvider
,
editorAdaptersFactoryService
);
}
public
IWorkspaceService
CreateService
(
HostWorkspaceServices
workspaceServices
)
=>
_singleton
;
}
}
src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpSourceGenerators.cs
浏览文件 @
4e2cb832
...
...
@@ -27,8 +27,6 @@ public override async Task InitializeAsync()
{
await
base
.
InitializeAsync
();
// Right now source generators are still restricted to /langver:preview
VisualStudio
.
SolutionExplorer
.
SetLanguageVersion
(
new
ProjectUtils
.
Project
(
ProjectName
),
"preview"
);
VisualStudio
.
SolutionExplorer
.
AddAnalyzerReference
(
typeof
(
IntegrationTestSourceGenerator
).
Assembly
.
Location
,
new
ProjectUtils
.
Project
(
ProjectName
));
}
...
...
@@ -47,6 +45,7 @@ public static void Main()
VisualStudio
.
Editor
.
PlaceCaret
(
IntegrationTestSourceGenerator
.
GeneratedClassName
);
VisualStudio
.
Editor
.
GoToDefinition
();
Assert
.
Equal
(
$"
{
IntegrationTestSourceGenerator
.
GeneratedClassName
}
.cs
{
ServicesVSResources
.
generated_suffix
}
"
,
VisualStudio
.
Shell
.
GetActiveWindowCaption
());
Assert
.
Equal
(
IntegrationTestSourceGenerator
.
GeneratedClassName
,
VisualStudio
.
Editor
.
GetSelectedText
());
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录