提交 a1e70603 编写于 作者: T Tomas Matousek

Add more filters

上级 cf24e4d5
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // 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.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
...@@ -8,6 +9,7 @@ ...@@ -8,6 +9,7 @@
using Microsoft.CodeAnalysis.Completion.Providers; using Microsoft.CodeAnalysis.Completion.Providers;
using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Extensions;
using Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery; using Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.LanguageServices; using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.Extensions;
...@@ -37,6 +39,8 @@ public override bool IsTriggerCharacter(SourceText text, int characterPosition, ...@@ -37,6 +39,8 @@ public override bool IsTriggerCharacter(SourceText text, int characterPosition,
protected override async Task<IEnumerable<CompletionItem>> GetItemsWorkerAsync( protected override async Task<IEnumerable<CompletionItem>> GetItemsWorkerAsync(
Document document, int position, CompletionTriggerInfo triggerInfo, Document document, int position, CompletionTriggerInfo triggerInfo,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{
try
{ {
var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
if (tree.IsInNonUserCode(position, cancellationToken)) if (tree.IsInNonUserCode(position, cancellationToken))
...@@ -106,6 +110,11 @@ public override bool IsTriggerCharacter(SourceText text, int characterPosition, ...@@ -106,6 +110,11 @@ public override bool IsTriggerCharacter(SourceText text, int characterPosition,
return SpecializedCollections.SingletonEnumerable(item); return SpecializedCollections.SingletonEnumerable(item);
} }
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
private INamedTypeSymbol GetCompletionListType(ITypeSymbol type, INamedTypeSymbol within, Compilation compilation) private INamedTypeSymbol GetCompletionListType(ITypeSymbol type, INamedTypeSymbol within, Compilation compilation)
{ {
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // 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.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
...@@ -8,6 +9,7 @@ ...@@ -8,6 +9,7 @@
using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Simplification; using Microsoft.CodeAnalysis.Simplification;
using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.Text;
...@@ -49,6 +51,7 @@ public static bool ContainingTypesOrSelfHasUnsafeKeyword(this ITypeSymbol contai ...@@ -49,6 +51,7 @@ public static bool ContainingTypesOrSelfHasUnsafeKeyword(this ITypeSymbol contai
public static async Task<ISymbol> FindApplicableAlias(this ITypeSymbol type, int position, SemanticModel semanticModel, CancellationToken cancellationToken) public static async Task<ISymbol> FindApplicableAlias(this ITypeSymbol type, int position, SemanticModel semanticModel, CancellationToken cancellationToken)
{ {
try {
if (semanticModel.IsSpeculativeSemanticModel) if (semanticModel.IsSpeculativeSemanticModel)
{ {
position = semanticModel.OriginalPositionForSpeculation; position = semanticModel.OriginalPositionForSpeculation;
...@@ -69,6 +72,11 @@ public static async Task<ISymbol> FindApplicableAlias(this ITypeSymbol type, int ...@@ -69,6 +72,11 @@ public static async Task<ISymbol> FindApplicableAlias(this ITypeSymbol type, int
return null; return null;
} }
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
private static IEnumerable<UsingDirectiveSyntax> GetApplicableUsings(int position, SyntaxNode root) private static IEnumerable<UsingDirectiveSyntax> GetApplicableUsings(int position, SyntaxNode root)
{ {
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // 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.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.FindSymbols; using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.LanguageServices; using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.SemanticModelWorkspaceService; using Microsoft.CodeAnalysis.SemanticModelWorkspaceService;
using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Shared.Extensions namespace Microsoft.CodeAnalysis.Shared.Extensions
{ {
...@@ -38,6 +41,8 @@ public static bool IsOpen(this Document document) ...@@ -38,6 +41,8 @@ public static bool IsOpen(this Document document)
/// if exact location (not relative location) is needed from symbol, regular GetSemanticModel should be used. /// if exact location (not relative location) is needed from symbol, regular GetSemanticModel should be used.
/// </summary> /// </summary>
public static async Task<SemanticModel> GetSemanticModelForSpanAsync(this Document document, TextSpan span, CancellationToken cancellationToken) public static async Task<SemanticModel> GetSemanticModelForSpanAsync(this Document document, TextSpan span, CancellationToken cancellationToken)
{
try
{ {
var syntaxFactService = document.Project.LanguageServices.GetService<ISyntaxFactsService>(); var syntaxFactService = document.Project.LanguageServices.GetService<ISyntaxFactsService>();
var semanticModelService = document.Project.Solution.Workspace.Services.GetService<ISemanticModelService>(); var semanticModelService = document.Project.Solution.Workspace.Services.GetService<ISemanticModelService>();
...@@ -56,6 +61,11 @@ public static async Task<SemanticModel> GetSemanticModelForSpanAsync(this Docume ...@@ -56,6 +61,11 @@ public static async Task<SemanticModel> GetSemanticModelForSpanAsync(this Docume
var node = token.Parent.AncestorsAndSelf().FirstOrDefault(a => a.FullSpan.Contains(span)); var node = token.Parent.AncestorsAndSelf().FirstOrDefault(a => a.FullSpan.Contains(span));
return await GetSemanticModelForNodeAsync(semanticModelService, syntaxFactService, document, node, span, cancellationToken).ConfigureAwait(false); return await GetSemanticModelForNodeAsync(semanticModelService, syntaxFactService, document, node, span, cancellationToken).ConfigureAwait(false);
} }
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
/// <summary> /// <summary>
/// this will return either regular semantic model or speculative semantic based on context. /// this will return either regular semantic model or speculative semantic based on context.
...@@ -123,6 +133,8 @@ public static bool IsFromPrimaryBranch(this Document document) ...@@ -123,6 +133,8 @@ public static bool IsFromPrimaryBranch(this Document document)
} }
public static async Task<bool> IsForkedDocumentWithSyntaxChangesAsync(this Document document, CancellationToken cancellationToken) public static async Task<bool> IsForkedDocumentWithSyntaxChangesAsync(this Document document, CancellationToken cancellationToken)
{
try
{ {
if (document.IsFromPrimaryBranch()) if (document.IsFromPrimaryBranch())
{ {
...@@ -140,6 +152,11 @@ public static async Task<bool> IsForkedDocumentWithSyntaxChangesAsync(this Docum ...@@ -140,6 +152,11 @@ public static async Task<bool> IsForkedDocumentWithSyntaxChangesAsync(this Docum
var currentDocumentVersion = await currentDocument.GetSyntaxVersionAsync(cancellationToken).ConfigureAwait(false); var currentDocumentVersion = await currentDocument.GetSyntaxVersionAsync(cancellationToken).ConfigureAwait(false);
return !documentVersion.Equals(currentDocumentVersion); return !documentVersion.Equals(currentDocumentVersion);
} }
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
public static async Task<IEnumerable<DeclaredSymbolInfo>> GetDeclaredSymbolInfosAsync(this Document document, CancellationToken cancellationToken) public static async Task<IEnumerable<DeclaredSymbolInfo>> GetDeclaredSymbolInfosAsync(this Document document, CancellationToken cancellationToken)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册