提交 4233717e 编写于 作者: C Charles Stoner 提交者: GitHub

Merge pull request #16463 from vslsnap/merge-dev15-rc3-into-master-20170112-160132

Merge dev15-rc3 into master
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO;
using System.Collections.Generic;
using System.IO;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
......@@ -25,6 +26,10 @@ private CoreClrBuildClient(RequestLanguage language, CompileFunc compileFunc)
internal static int Run(IEnumerable<string> arguments, RequestLanguage language, CompileFunc compileFunc)
{
// Register encodings for console
// https://github.com/dotnet/roslyn/issues/10785
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
// Should be using BuildClient.GetCommandLineArgs(arguments) here. But the native invoke
// ends up giving us both CoreRun and the exe file. Need to find a good way to remove the host
// as well as the EXE argument.
......
......@@ -184,8 +184,13 @@ public IEnumerable<DiagnosticData> ConvertToLocalDiagnostics(Document targetDocu
if (TryReduceAnalyzersToRun(analyzerDriverOpt, version, existing, out var analyzersToRun))
{
// it looks like we can reduce the set. create new CompilationWithAnalyzer.
var analyzerDriverWithReducedSet = await _owner._compilationManager.CreateAnalyzerDriverAsync(
project, analyzersToRun, analyzerDriverOpt.AnalysisOptions.ReportSuppressedDiagnostics, cancellationToken).ConfigureAwait(false);
// if we reduced to 0, we just pass in null for analyzer drvier. it could be reduced to 0
// since we might have up to date results for analyzers from compiler but not for
// workspace analyzers.
var analyzerDriverWithReducedSet =
analyzersToRun.Length == 0 ?
null : await _owner._compilationManager.CreateAnalyzerDriverAsync(
project, analyzersToRun, analyzerDriverOpt.AnalysisOptions.ReportSuppressedDiagnostics, cancellationToken).ConfigureAwait(false);
var result = await ComputeDiagnosticsAsync(analyzerDriverWithReducedSet, project, stateSets, cancellationToken).ConfigureAwait(false);
return MergeExistingDiagnostics(version, existing, result);
......@@ -250,9 +255,6 @@ public IEnumerable<DiagnosticData> ConvertToLocalDiagnostics(Document targetDocu
builder.Add(analyzer);
}
// if this condition is true, it shouldn't be called.
Contract.ThrowIfTrue(builder.Count == 0);
// all of analyzers are out of date.
if (builder.Count == existingAnalyzers.Length)
{
......
......@@ -48,7 +48,7 @@ private class SearchResult : INavigateToSearchResult
var declaredNavigableItem = navigableItem as NavigableItemFactory.DeclaredSymbolNavigableItem;
Debug.Assert(declaredNavigableItem != null);
_lazySummary = new Lazy<string>(() => declaredNavigableItem.Symbol?.GetDocumentationComment()?.SummaryText);
_lazySummary = new Lazy<string>(() => declaredNavigableItem.SymbolOpt?.GetDocumentationComment()?.SummaryText);
_lazyAdditionalInfo = new Lazy<string>(() =>
{
switch (declaredSymbolInfo.Kind)
......
......@@ -18,16 +18,16 @@ internal class DeclaredSymbolNavigableItem : INavigableItem
public ImmutableArray<TaggedText> DisplayTaggedParts => _lazyDisplayTaggedParts.Value;
public Document Document { get; }
public Glyph Glyph => Symbol?.GetGlyph() ?? Glyph.Error;
public Glyph Glyph => this.SymbolOpt?.GetGlyph() ?? Glyph.Error;
public TextSpan SourceSpan => _declaredSymbolInfo.Span;
public ISymbol Symbol => _lazySymbol.Value;
public ISymbol SymbolOpt => _lazySymbolOpt.Value;
public ImmutableArray<INavigableItem> ChildItems => ImmutableArray<INavigableItem>.Empty;
public bool DisplayFileLocation => false;
private readonly DeclaredSymbolInfo _declaredSymbolInfo;
private readonly Lazy<ImmutableArray<TaggedText>> _lazyDisplayTaggedParts;
private readonly Lazy<ISymbol> _lazySymbol;
private readonly Lazy<ISymbol> _lazySymbolOpt;
/// <summary>
/// DeclaredSymbolInfos always come from some actual declaration in source. So they're
......@@ -40,18 +40,18 @@ public DeclaredSymbolNavigableItem(Document document, DeclaredSymbolInfo declare
Document = document;
_declaredSymbolInfo = declaredSymbolInfo;
_lazySymbol = new Lazy<ISymbol>(FindSymbol);
_lazySymbolOpt = new Lazy<ISymbol>(TryFindSymbol);
_lazyDisplayTaggedParts = new Lazy<ImmutableArray<TaggedText>>(() =>
{
try
{
if (Symbol == null)
if (this.SymbolOpt == null)
{
return default(ImmutableArray<TaggedText>);
}
return GetSymbolDisplayTaggedParts(Document.Project, Symbol);
return GetSymbolDisplayTaggedParts(Document.Project, this.SymbolOpt);
}
catch (Exception e) when (FatalError.Report(e))
{
......@@ -60,7 +60,7 @@ public DeclaredSymbolNavigableItem(Document document, DeclaredSymbolInfo declare
});
}
private ISymbol FindSymbol()
private ISymbol TryFindSymbol()
{
// Here, we will use partial semantics. We are going to use this symbol to get a glyph, display string,
// and potentially documentation comments. The first two should work fine even if we don't have full
......@@ -71,7 +71,7 @@ private ISymbol FindSymbol()
// CancellationToken.None.
var semanticModel = Document.GetPartialSemanticModelAsync(CancellationToken.None).GetAwaiter().GetResult();
return _declaredSymbolInfo.Resolve(semanticModel, CancellationToken.None);
return _declaredSymbolInfo.TryResolve(semanticModel, CancellationToken.None);
}
}
}
......
......@@ -40,7 +40,7 @@ try
switch ($branchName)
{
"dev15-rc2" { }
"dev15-rc3" { }
"master" { }
default
{
......
......@@ -518,13 +518,13 @@ public int Space_WithinSquares
set { SetBooleanOption(CSharpFormattingOptions.SpaceWithinSquareBrackets, value); }
}
public string Style_PreferIntrinsicPredefinedTypeKeywordInDeclaration
public string Style_PreferIntrinsicPredefinedTypeKeywordInDeclaration_CodeStyle
{
get { return GetXmlOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration); }
set { SetXmlOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration, value); }
}
public string Style_PreferIntrinsicPredefinedTypeKeywordInMemberAccess
public string Style_PreferIntrinsicPredefinedTypeKeywordInMemberAccess_CodeStyle
{
get { return GetXmlOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess); }
set { SetXmlOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess, value); }
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.ErrorLogger;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Options;
......@@ -48,6 +51,21 @@ public bool CanNavigateToSpan(Workspace workspace, DocumentId documentId, TextSp
var document = workspace.CurrentSolution.GetDocument(documentId);
var text = document.GetTextAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None);
var boundedTextSpan = GetSpanWithinDocumentBounds(textSpan, text.Length);
if (boundedTextSpan != textSpan)
{
try
{
throw new ArgumentOutOfRangeException();
}
catch (ArgumentOutOfRangeException e) when (FatalError.ReportWithoutCrash(e))
{
}
return false;
}
var vsTextSpan = text.GetVsTextSpanForSpan(textSpan);
return CanMapFromSecondaryBufferToPrimaryBuffer(workspace, documentId, vsTextSpan);
......@@ -82,6 +100,21 @@ public bool CanNavigateToPosition(Workspace workspace, DocumentId documentId, in
var document = workspace.CurrentSolution.GetDocument(documentId);
var text = document.GetTextAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None);
var boundedPosition = GetPositionWithinDocumentBounds(position, text.Length);
if (boundedPosition != position)
{
try
{
throw new ArgumentOutOfRangeException();
}
catch (ArgumentOutOfRangeException e) when (FatalError.ReportWithoutCrash(e))
{
}
return false;
}
var vsTextSpan = text.GetVsTextSpanForPosition(position, virtualSpace);
return CanMapFromSecondaryBufferToPrimaryBuffer(workspace, documentId, vsTextSpan);
......@@ -106,7 +139,20 @@ public bool TryNavigateToSpan(Workspace workspace, DocumentId documentId, TextSp
var text = document.GetTextAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None);
var textBuffer = text.Container.GetTextBuffer();
var vsTextSpan = text.GetVsTextSpanForSpan(textSpan);
var boundedTextSpan = GetSpanWithinDocumentBounds(textSpan, text.Length);
if (boundedTextSpan != textSpan)
{
try
{
throw new ArgumentOutOfRangeException();
}
catch (ArgumentOutOfRangeException e) when (FatalError.ReportWithoutCrash(e))
{
}
}
var vsTextSpan = text.GetVsTextSpanForSpan(boundedTextSpan);
if (IsSecondaryBuffer(workspace, documentId) &&
!vsTextSpan.TryMapSpanFromSecondaryBufferToPrimaryBuffer(workspace, documentId, out vsTextSpan))
{
......@@ -165,7 +211,19 @@ public bool TryNavigateToPosition(Workspace workspace, DocumentId documentId, in
var text = document.GetTextAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None);
var textBuffer = text.Container.GetTextBuffer();
var vsTextSpan = text.GetVsTextSpanForPosition(position, virtualSpace);
var boundedPosition = GetPositionWithinDocumentBounds(position, text.Length);
if (boundedPosition != position)
{
try
{
throw new ArgumentOutOfRangeException();
}
catch (ArgumentOutOfRangeException e) when (FatalError.ReportWithoutCrash(e))
{
}
}
var vsTextSpan = text.GetVsTextSpanForPosition(boundedPosition, virtualSpace);
if (IsSecondaryBuffer(workspace, documentId) &&
!vsTextSpan.TryMapSpanFromSecondaryBufferToPrimaryBuffer(workspace, documentId, out vsTextSpan))
......@@ -176,6 +234,36 @@ public bool TryNavigateToPosition(Workspace workspace, DocumentId documentId, in
return NavigateTo(textBuffer, vsTextSpan);
}
/// <summary>
/// It is unclear why, but we are sometimes asked to navigate to a position that is not
/// inside the bounds of the associated <see cref="Document"/>. This method returns a
/// position that is guaranteed to be inside the <see cref="Document"/> bounds. If the
/// returned position is different from the given position, then the worst observable
/// behavior is either no navigation or navigation to the end of the document. See the
/// following bugs for more details:
/// https://devdiv.visualstudio.com/DevDiv/_workitems?id=112211
/// https://devdiv.visualstudio.com/DevDiv/_workitems?id=136895
/// https://devdiv.visualstudio.com/DevDiv/_workitems?id=224318
/// https://devdiv.visualstudio.com/DevDiv/_workitems?id=235409
/// </summary>
private static int GetPositionWithinDocumentBounds(int position, int documentLength)
{
return Math.Min(documentLength, Math.Max(position, 0));
}
/// <summary>
/// It is unclear why, but we are sometimes asked to navigate to a <see cref="TextSpan"/>
/// that is not inside the bounds of the associated <see cref="Document"/>. This method
/// returns a span that is guaranteed to be inside the <see cref="Document"/> bounds. If
/// the returned span is different from the given span, then the worst observable behavior
/// is either no navigation or navigation to the end of the document.
/// See https://github.com/dotnet/roslyn/issues/7660 for more details.
/// </summary>
private static TextSpan GetSpanWithinDocumentBounds(TextSpan span, int documentLength)
{
return TextSpan.FromBounds(GetPositionWithinDocumentBounds(span.Start, documentLength), GetPositionWithinDocumentBounds(span.End, documentLength));
}
private static Document OpenDocument(Workspace workspace, DocumentId documentId, OptionSet options)
{
options = options ?? workspace.Options;
......
......@@ -1186,6 +1186,24 @@ internal class ServicesVSResources {
}
}
/// <summary>
/// Looks up a localized string similar to Move down.
/// </summary>
internal static string Move_down {
get {
return ResourceManager.GetString("Move_down", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Move up.
/// </summary>
internal static string Move_up {
get {
return ResourceManager.GetString("Move_up", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Name:.
/// </summary>
......@@ -1679,6 +1697,15 @@ internal class ServicesVSResources {
}
}
/// <summary>
/// Looks up a localized string similar to Remove.
/// </summary>
internal static string Remove {
get {
return ResourceManager.GetString("Remove", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Remove {0}.
/// </summary>
......
......@@ -858,4 +858,13 @@ Additional information: {1}</value>
<data name="Get_help_for_0_from_Bing" xml:space="preserve">
<value>Get help for '{0}' from Bing</value>
</data>
<data name="Move_down" xml:space="preserve">
<value>Move down</value>
</data>
<data name="Move_up" xml:space="preserve">
<value>Move up</value>
</data>
<data name="Remove" xml:space="preserve">
<value>Remove</value>
</data>
</root>
\ No newline at end of file
using System;
using System.ComponentModel.Composition;
using System.Diagnostics;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Options;
using Microsoft.Internal.VisualStudio.Shell;
using Microsoft.Internal.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.LanguageServices;
using Microsoft.VisualStudio.LanguageServices.Setup;
namespace Microsoft.VisualStudio.LanguageServices.Telemetry
{
......@@ -18,6 +15,13 @@ public static void Initialize(IServiceProvider serviceProvider)
var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
var optionService = componentModel.GetService<IGlobalOptionService>();
// Fetch the session synchronously on the UI thread; if this doesn't happen before we try using this on
// the background thread then we will experience hangs like we see in this bug:
// https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?_a=edit&id=190808 or
// https://devdiv.visualstudio.com/DevDiv/_workitems?id=296981&_a=edit
var unused1 = TelemetryHelper.TelemetryService;
var unused2 = TelemetryHelper.DefaultTelemetrySession;
var telemetryService = serviceProvider.GetService(typeof(SVsTelemetryService)) as IVsTelemetryService;
Logger.SetLogger(
AggregateLogger.Create(
......
......@@ -30,11 +30,6 @@ public VSTelemetryActivityLogger(IVsTelemetryService service) : base(assertIsFor
{
_service = service;
_pendingActivities = new ConcurrentDictionary<int, TelemetryActivity>(concurrencyLevel: 2, capacity: 10);
// Fetch the session synchronously on the UI thread; if this doesn't happen before we try using this on
// the background thread then we will experience hangs like we see in this bug:
// https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?_a=edit&id=190808
var unused = TelemetryHelper.DefaultTelemetrySession;
}
public bool IsEnabled(FunctionId functionId)
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Globalization;
using System.Windows.Controls;
using Microsoft.VisualStudio.PlatformUI;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options
{
/// <summary>
/// DataGridTemplateColumns have custom controls that should be focused instead of the cell.
/// </summary>
internal class ColumnToTabStopConverter : ValueConverter<DataGridColumn, bool>
{
protected override bool Convert(DataGridColumn value, object parameter, CultureInfo culture)
{
// We use DataGridTemplateColumns in our options grids to contain controls (as opposed
// to plain text in DataGridTextColumns). We want the tab stop to be on the contained
// control and not the cell itself, so don't have DataGridTemplateColumns be tab stops.
return !(value is DataGridTemplateColumn);
}
}
}
......@@ -15,11 +15,17 @@
<Grid>
<Grid.Resources>
<options:ColumnToTabStopConverter x:Key="ColumnToTabStopConverter" />
<Style x:Key="DataGridStyle" TargetType="DataGrid">
<Setter Property="CellStyle">
<Setter.Value>
<Style TargetType="DataGridCell">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="IsTabStop"
Value="{Binding
Path=Column,
Converter={StaticResource ColumnToTabStopConverter},
RelativeSource={RelativeSource Self}}"/>
</Style>
</Setter.Value>
</Setter>
......@@ -93,6 +99,7 @@
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="AutomationProperties.Name" Value="{Binding GroupName}" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
......@@ -107,7 +114,13 @@
DisplayMemberPath="Name"
SelectedItem="{Binding SelectedPreference, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Left"/>
HorizontalContentAlignment="Left">
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Setter Property="AutomationProperties.Name" Value="{Binding Name}" />
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
......@@ -142,6 +155,11 @@
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Setter Property="AutomationProperties.Name" Value="{Binding Name}" />
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
......
......@@ -23,6 +23,7 @@
<Setter.Value>
<Style TargetType="DataGridCell">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="IsTabStop" Value="False" />
</Style>
</Setter.Value>
</Setter>
......@@ -158,7 +159,13 @@
SelectedItem="{Binding SelectedSpecification, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Left"
ToolTip="{Binding Path=SelectedItem.Name, RelativeSource={RelativeSource Self}}"/>
ToolTip="{Binding Path=SelectedItem.Name, RelativeSource={RelativeSource Self}}">
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Setter Property="AutomationProperties.Name" Value="{Binding Name}" />
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
......@@ -176,6 +183,11 @@
VerticalContentAlignment="Center"
HorizontalContentAlignment="Left"
ToolTip="{Binding Path=SelectedItem.Name, RelativeSource={RelativeSource Self}}">
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Setter Property="AutomationProperties.Name" Value="{Binding Name}" />
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
......@@ -211,6 +223,11 @@
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Setter Property="AutomationProperties.Name" Value="{Binding Name}" />
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
......@@ -219,14 +236,15 @@
Width="30">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Click="RemoveButton_Click"
<Button Click="RemoveButton_Click"
Height="16"
Width="16"
Margin="5, 0, 0, 0"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Center"
HorizontalAlignment="Center"
VerticalAlignment="Center">
VerticalAlignment="Center"
AutomationProperties.Name="{Binding RemoveAutomationText}">
<imaging:CrispImage Moniker="{x:Static imagecatalog:KnownMonikers.DeleteListItem}" />
</Button>
</DataTemplate>
......
......@@ -275,6 +275,11 @@ public bool CanMoveDown
}
}
public string MoveUpAutomationText => ServicesVSResources.Move_up;
public string MoveDownAutomationText => ServicesVSResources.Move_down;
public string RemoveAutomationText => ServicesVSResources.Remove;
public bool IsComplete()
{
return SelectedSpecification != null && SelectedStyle != null && SelectedNotificationPreference != null;
......
......@@ -210,6 +210,7 @@
<Compile Include="Options\AbstractCodeStyleOptionViewModel.cs" />
<Compile Include="Options\BooleanCodeStyleOptionViewModel.cs" />
<Compile Include="Options\CodeStylePreference.cs" />
<Compile Include="Options\ColumnToTabStopConverter.cs" />
<Compile Include="Options\Converters\MarginConverter.cs" />
<Compile Include="Options\SimpleCodeStyleOptionViewModel.cs" />
<Compile Include="Options\AbstractCheckBoxViewModel.cs" />
......@@ -287,4 +288,4 @@
</ItemGroup>
<ItemGroup />
<Import Project="..\..\..\..\build\Targets\Imports.targets" />
</Project>
</Project>
\ No newline at end of file
......@@ -31,10 +31,13 @@ private class WorkspaceHost : ForegroundThreadAffinitizedObject, IVisualStudioWo
_workspace = workspace;
_client = client;
_currentSolutionId = workspace.CurrentSolution.Id;
}
public Task InitializeAsync()
{
// Ensure that we populate the remote service with the initial state of
// the workspace's solution.
RegisterPrimarySolutionAsync().Wait();
return RegisterPrimarySolutionAsync();
}
public void OnAfterWorkingFolderChange()
......
......@@ -54,20 +54,24 @@ internal partial class ServiceHubRemoteHostClient : RemoteHostClient
}
}
private static Task RegisterWorkspaceHostAsync(Workspace workspace, RemoteHostClient client)
private static async Task RegisterWorkspaceHostAsync(Workspace workspace, RemoteHostClient client)
{
var vsWorkspace = workspace as VisualStudioWorkspaceImpl;
if (vsWorkspace == null)
{
return Task.CompletedTask;
return;
}
// don't block UI thread while initialize workspace host
var host = new WorkspaceHost(vsWorkspace, client);
await host.InitializeAsync().ConfigureAwait(false);
// RegisterWorkspaceHost is required to be called from UI thread so push the code
// to UI thread to run.
return Task.Factory.SafeStartNew(() =>
await Task.Factory.SafeStartNew(() =>
{
vsWorkspace.ProjectTracker.RegisterWorkspaceHost(new WorkspaceHost(vsWorkspace, client));
}, CancellationToken.None, ForegroundThreadAffinitizedObject.CurrentForegroundThreadData.TaskScheduler);
vsWorkspace.ProjectTracker.RegisterWorkspaceHost(host);
}, CancellationToken.None, ForegroundThreadAffinitizedObject.CurrentForegroundThreadData.TaskScheduler).ConfigureAwait(false);
}
private ServiceHubRemoteHostClient(
......
......@@ -143,7 +143,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options
End Set
End Property
Public Property Style_PreferIntrinsicPredefinedTypeKeywordInDeclaration As String
Public Property Style_PreferIntrinsicPredefinedTypeKeywordInDeclaration_CodeStyle As String
Get
Return GetXmlOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInDeclaration)
End Get
......@@ -152,7 +152,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options
End Set
End Property
Public Property Style_PreferIntrinsicPredefinedTypeKeywordInMemberAccess As String
Public Property Style_PreferIntrinsicPredefinedTypeKeywordInMemberAccess_CodeStyle As String
Get
Return GetXmlOption(CodeStyleOptions.PreferIntrinsicPredefinedTypeKeywordInMemberAccess)
End Get
......
......@@ -55,7 +55,7 @@ public class CodeStyleOptions
public static readonly PerLanguageOption<CodeStyleOption<bool>> PreferIntrinsicPredefinedTypeKeywordInDeclaration = new PerLanguageOption<CodeStyleOption<bool>>(nameof(CodeStyleOptions), nameof(PreferIntrinsicPredefinedTypeKeywordInDeclaration), defaultValue: TrueWithNoneEnforcement,
storageLocations: new OptionStorageLocation[]{
new EditorConfigStorageLocation("dotnet_style_predefined_type_for_locals_parameters_members"),
new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.PreferIntrinsicPredefinedTypeKeywordInDeclaration")});
new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.PreferIntrinsicPredefinedTypeKeywordInDeclaration.CodeStyle")});
/// <summary>
/// This option says if we should prefer keyword for Intrinsic Predefined Types in Member Access Expression
......@@ -63,7 +63,7 @@ public class CodeStyleOptions
public static readonly PerLanguageOption<CodeStyleOption<bool>> PreferIntrinsicPredefinedTypeKeywordInMemberAccess = new PerLanguageOption<CodeStyleOption<bool>>(nameof(CodeStyleOptions), nameof(PreferIntrinsicPredefinedTypeKeywordInMemberAccess), defaultValue: TrueWithNoneEnforcement,
storageLocations: new OptionStorageLocation[]{
new EditorConfigStorageLocation("dotnet_style_predefined_type_for_member_access"),
new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.PreferIntrinsicPredefinedTypeKeywordInMemberAccess")});
new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.PreferIntrinsicPredefinedTypeKeywordInMemberAccess.CodeStyle")});
internal static readonly PerLanguageOption<CodeStyleOption<bool>> PreferThrowExpression = new PerLanguageOption<CodeStyleOption<bool>>(
nameof(CodeStyleOptions),
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
......@@ -79,48 +81,52 @@ internal void WriteTo(ObjectWriter writer)
}
}
internal static DeclaredSymbolInfo ReadFrom(ObjectReader reader)
internal static DeclaredSymbolInfo ReadFrom_ThrowsOnFailure(ObjectReader reader)
{
try
{
var name = reader.ReadString();
var immediateContainer = reader.ReadString();
var entireContainer = reader.ReadString();
var kind = (DeclaredSymbolInfoKind)reader.ReadByte();
var spanStart = reader.ReadInt32();
var spanLength = reader.ReadInt32();
var parameterCount = reader.ReadUInt16();
var typeParameterCount = reader.ReadUInt16();
var inheritanceNamesLength = reader.ReadInt32();
var builder = ImmutableArray.CreateBuilder<string>(inheritanceNamesLength);
for (var i = 0; i < inheritanceNamesLength; i++)
{
builder.Add(reader.ReadString());
}
var name = reader.ReadString();
var immediateContainer = reader.ReadString();
var entireContainer = reader.ReadString();
var kind = (DeclaredSymbolInfoKind)reader.ReadByte();
var spanStart = reader.ReadInt32();
var spanLength = reader.ReadInt32();
var parameterCount = reader.ReadUInt16();
var typeParameterCount = reader.ReadUInt16();
return new DeclaredSymbolInfo(
name, immediateContainer, entireContainer, kind, new TextSpan(spanStart, spanLength),
builder.MoveToImmutable(),
parameterCount, typeParameterCount);
}
catch
var inheritanceNamesLength = reader.ReadInt32();
var builder = ImmutableArray.CreateBuilder<string>(inheritanceNamesLength);
for (var i = 0; i < inheritanceNamesLength; i++)
{
return default(DeclaredSymbolInfo);
builder.Add(reader.ReadString());
}
return new DeclaredSymbolInfo(
name, immediateContainer, entireContainer, kind, new TextSpan(spanStart, spanLength),
builder.MoveToImmutable(), parameterCount, typeParameterCount);
}
public async Task<ISymbol> ResolveAsync(Document document, CancellationToken cancellationToken)
public async Task<ISymbol> TryResolveAsync(Document document, CancellationToken cancellationToken)
{
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
return Resolve(semanticModel, cancellationToken);
return TryResolve(semanticModel, cancellationToken);
}
public ISymbol Resolve(SemanticModel semanticModel, CancellationToken cancellationToken)
public ISymbol TryResolve(SemanticModel semanticModel, CancellationToken cancellationToken)
{
var root = semanticModel.SyntaxTree.GetRoot(cancellationToken);
var node = root.FindNode(this.Span);
return semanticModel.GetDeclaredSymbol(node, cancellationToken);
if (root.FullSpan.Contains(this.Span))
{
var node = root.FindNode(this.Span);
return semanticModel.GetDeclaredSymbol(node, cancellationToken);
}
else
{
var message =
$@"Invalid span in {nameof(DeclaredSymbolInfo)}.
{nameof(this.Span)} = {this.Span}
{nameof(root.FullSpan)} = {root.FullSpan}";
FatalError.ReportWithoutCrash(new InvalidOperationException(message));
return null;
}
}
}
}
}
\ No newline at end of file
......@@ -658,7 +658,7 @@ internal static class DependentTypeFinder
(inheritanceQuery.DerivesFromSystemValueType && info.Kind == DeclaredSymbolInfoKind.Struct) ||
(inheritanceQuery.DerivesFromSystemMulticastDelegate && info.Kind == DeclaredSymbolInfoKind.Delegate))
{
var symbol = await ResolveAsync(document, info, cachedModels, cancellationToken).ConfigureAwait(false) as INamedTypeSymbol;
var symbol = await TryResolveAsync(document, info, cachedModels, cancellationToken).ConfigureAwait(false) as INamedTypeSymbol;
if (symbol != null)
{
result.Add(SymbolAndProjectId.Create(symbol, projectId));
......@@ -671,7 +671,7 @@ internal static class DependentTypeFinder
// Also, we can't just look for an empty inheritance list. We may have
// something like: "class C : IFoo". This type derives from object, despite
// having a non-empty list.
var symbol = await ResolveAsync(document, info, cachedModels, cancellationToken).ConfigureAwait(false) as INamedTypeSymbol;
var symbol = await TryResolveAsync(document, info, cachedModels, cancellationToken).ConfigureAwait(false) as INamedTypeSymbol;
if (symbol?.BaseType?.SpecialType == SpecialType.System_Object)
{
result.Add(SymbolAndProjectId.Create(symbol, projectId));
......@@ -680,7 +680,7 @@ internal static class DependentTypeFinder
else if (AnyInheritanceNamesMatch(info, inheritanceQuery.TypeNames))
{
// Looks like we have a potential match. Actually check if the symbol is viable.
var symbol = await ResolveAsync(document, info, cachedModels, cancellationToken).ConfigureAwait(false) as INamedTypeSymbol;
var symbol = await TryResolveAsync(document, info, cachedModels, cancellationToken).ConfigureAwait(false) as INamedTypeSymbol;
if (symbol != null)
{
if (typeImmediatelyMatches(typesToSearchFor, symbol))
......@@ -705,13 +705,13 @@ internal static class DependentTypeFinder
return false;
}
private static async Task<ISymbol> ResolveAsync(
private static async Task<ISymbol> TryResolveAsync(
Document document, DeclaredSymbolInfo info, ConcurrentSet<SemanticModel> cachedModels,
CancellationToken cancellationToken)
{
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
cachedModels.Add(semanticModel);
return info.Resolve(semanticModel, cancellationToken);
return info.TryResolve(semanticModel, cancellationToken);
}
private class InheritanceQuery
......
......@@ -106,7 +106,7 @@ public void WriteTo(ObjectWriter writer)
writer.WriteInt32((int)_containingNodes);
}
public static ContextInfo? ReadFrom(ObjectReader reader)
public static ContextInfo? TryReadFrom(ObjectReader reader)
{
try
{
......
......@@ -26,7 +26,7 @@ public void WriteTo(ObjectWriter writer)
}
}
public static DeclarationInfo? ReadFrom(ObjectReader reader)
public static DeclarationInfo? TryReadFrom(ObjectReader reader)
{
try
{
......@@ -34,7 +34,7 @@ public void WriteTo(ObjectWriter writer)
var builder = ImmutableArray.CreateBuilder<DeclaredSymbolInfo>(declaredSymbolCount);
for (int i = 0; i < declaredSymbolCount; i++)
{
builder.Add(DeclaredSymbolInfo.ReadFrom(reader));
builder.Add(DeclaredSymbolInfo.ReadFrom_ThrowsOnFailure(reader));
}
return new DeclarationInfo(builder.MoveToImmutable());
......
......@@ -47,7 +47,7 @@ public void WriteTo(ObjectWriter writer)
_escapedIdentifierFilter.WriteTo(writer);
}
public static IdentifierInfo? ReadFrom(ObjectReader reader)
public static IdentifierInfo? TryReadFrom(ObjectReader reader)
{
try
{
......
......@@ -143,9 +143,9 @@ public void WriteTo(ObjectWriter writer)
private static SyntaxTreeIndex ReadFrom(ObjectReader reader, VersionStamp version)
{
var identifierInfo = IdentifierInfo.ReadFrom(reader);
var contextInfo = ContextInfo.ReadFrom(reader);
var declarationInfo = DeclarationInfo.ReadFrom(reader);
var identifierInfo = IdentifierInfo.TryReadFrom(reader);
var contextInfo = ContextInfo.TryReadFrom(reader);
var declarationInfo = DeclarationInfo.TryReadFrom(reader);
if (identifierInfo == null || contextInfo == null || declarationInfo == null)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册