提交 0579f904 编写于 作者: D Dustin Campbell

Merge pull request #5503 from DustinCampbell/issue-5495

Smart indenter should not throw when enter is pressed after invalid query continuation
......@@ -9,7 +9,6 @@
using Microsoft.CodeAnalysis.CSharp.Formatting;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Editor.Implementation.Formatting.Indentation;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Formatting.Rules;
using Microsoft.CodeAnalysis.Options;
......@@ -363,7 +362,10 @@ internal class Indenter : AbstractIndenter
{
// find containing non terminal node
var queryExpressionClause = GetQueryExpressionClause(token);
Contract.ThrowIfNull(queryExpressionClause);
if (queryExpressionClause == null)
{
return GetDefaultIndentationFromTokenLine(token);
}
// find line where first token of the node is
var snapshot = LineToBeIndented.Snapshot;
......
......@@ -2,9 +2,7 @@
using System.Collections.Generic;
using System.Composition;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Extensions;
using Microsoft.CodeAnalysis.CSharp.Syntax;
......@@ -12,7 +10,6 @@
using Microsoft.CodeAnalysis.Editor.Implementation.SmartIndent;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Formatting.Rules;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
......
......@@ -2481,6 +2481,56 @@ static void Main(string[] args)
expectedIndentation: 36);
}
[WorkItem(5495, "https://github.com/dotnet/roslyn/issues/5495")]
[Fact, Trait(Traits.Feature, Traits.Features.SmartIndent)]
public void AfterBadQueryContinuationWithSelectOrGroupClause()
{
var code = @"using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication1
{
class AutomapperConfig
{
public static IEnumerable<string> ConfigureMappings(string name)
{
List<User> anEntireSlewOfItems = new List<User>();
List<UserViewModel> viewModels = new List<UserViewModel>();
var items = (from m in anEntireSlewOfItems into man
join at in viewModels on m.id equals at.id
join c in viewModels on m.name equals c.name
join ct in viewModels on m.phonenumber equals ct.phonenumber
where m.id == 1 &&
m.name == name
select new { M = true, I = at, AT = at }).ToList();
//Mapper.CreateMap<User, UserViewModel>()
// .ForMember(t => t.)
}
}
class User
{
public int id { get; set; }
public string name { get; set; }
public int phonenumber { get; set; }
}
class UserViewModel
{
public int id { get; set; }
public string name { get; set; }
public int phonenumber { get; set; }
}
}";
AssertSmartIndent(
code,
indentationLine: 13,
expectedIndentation: 25);
}
private static void AssertSmartIndentInProjection(string markup, int expectedIndentation, CSharpParseOptions options = null)
{
var optionsSet = options != null
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册