本文整理汇总了C#中SyntaxContext类的典型用法代码示例。如果您正苦于以下问题:C# SyntaxContext类的具体用法?C# SyntaxContext怎么用?C# SyntaxContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SyntaxContext类属于命名空间,在下文中一共展示了SyntaxContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetItemsWorkerAsync
protected override Task<IEnumerable<CompletionData>> GetItemsWorkerAsync (CompletionResult completionResult, CompletionEngine engine, CompletionContext completionContext, CompletionTriggerInfo info, SyntaxContext ctx, CancellationToken cancellationToken)
{
var position = completionContext.Position;
var document = completionContext.Document;
var syntaxTree = ctx.SyntaxTree;
if (syntaxTree.IsInNonUserCode(position, cancellationToken) ||
syntaxTree.IsPreProcessorDirectiveContext(position, cancellationToken))
return Task.FromResult (Enumerable.Empty<CompletionData> ());
if (!syntaxTree.IsRightOfDotOrArrowOrColonColon(position, cancellationToken))
return Task.FromResult (Enumerable.Empty<CompletionData> ());
var ma = ctx.LeftToken.Parent as MemberAccessExpressionSyntax;
if (ma == null)
return Task.FromResult (Enumerable.Empty<CompletionData> ());
var model = ctx.CSharpSyntaxContext.SemanticModel;
var symbolInfo = model.GetSymbolInfo (ma.Expression);
if (symbolInfo.Symbol == null || symbolInfo.Symbol.Kind != SymbolKind.Parameter)
return Task.FromResult (Enumerable.Empty<CompletionData> ());
var list = new List<CompletionData> ();
var within = model.GetEnclosingNamedTypeOrAssembly(position, cancellationToken);
var addedSymbols = new HashSet<string> ();
foreach (var ano in ma.AncestorsAndSelf ().OfType<AnonymousMethodExpressionSyntax> ()) {
Analyze (engine, model, ma.Expression, within, list, ano.ParameterList, symbolInfo.Symbol, addedSymbols, cancellationToken);
}
foreach (var ano in ma.AncestorsAndSelf ().OfType<ParenthesizedLambdaExpressionSyntax> ()) {
Analyze (engine, model, ma.Expression, within, list, ano.ParameterList, symbolInfo.Symbol, addedSymbols, cancellationToken);
}
return Task.FromResult ((IEnumerable<CompletionData>)list);
}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:33,代码来源:SenderCompletionContextHandler.cs
示例2: GetItemsWorkerAsync
protected async override Task<IEnumerable<CompletionData>> GetItemsWorkerAsync (CompletionResult completionResult, CompletionEngine engine, CompletionContext completionContext, CompletionTriggerInfo info, SyntaxContext ctx, CancellationToken cancellationToken)
{
var model = ctx.SemanticModel;
var tree = ctx.SyntaxTree;
if (tree.IsInNonUserCode (completionContext.Position, cancellationToken))
return Enumerable.Empty<CompletionData> ();
var token = tree.FindTokenOnLeftOfPosition (completionContext.Position, cancellationToken);
if (token.IsMandatoryNamedParameterPosition ())
return Enumerable.Empty<CompletionData> ();
var result = new List<CompletionData> ();
// check if it's the first parameter and set autoselect == false if a parameterless version exists.
if (token.IsKind (SyntaxKind.OpenParenToken)) {
var parent = token.Parent?.Parent;
if (parent == null)
return Enumerable.Empty<CompletionData> ();
var symbolInfo = model.GetSymbolInfo (parent);
foreach (var symbol in new [] { symbolInfo.Symbol }.Concat (symbolInfo.CandidateSymbols)) {
if (symbol != null && symbol.IsKind (SymbolKind.Method)) {
if (symbol.GetParameters ().Length == 0) {
completionResult.AutoSelect = false;
break;
}
}
}
}
foreach (var _type in ctx.InferredTypes) {
var type = _type;
if (type.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T) {
type = type.GetTypeArguments ().FirstOrDefault ();
if (type == null)
continue;
}
if (type.TypeKind != TypeKind.Enum)
continue;
if (!type.IsEditorBrowsable ())
continue;
// Does type have any aliases?
ISymbol alias = await type.FindApplicableAlias (completionContext.Position, model, cancellationToken).ConfigureAwait (false);
var displayString = RoslynCompletionData.SafeMinimalDisplayString (type, model, completionContext.Position, SymbolDisplayFormat.CSharpErrorMessageFormat);
if (string.IsNullOrEmpty (completionResult.DefaultCompletionString)) {
completionResult.DefaultCompletionString = displayString;
completionResult.AutoCompleteEmptyMatch = true;
}
if (!IsReachable (model, type, token.Parent))
result.Add (engine.Factory.CreateSymbolCompletionData (this, type, displayString));
foreach (IFieldSymbol field in type.GetMembers ().OfType<IFieldSymbol> ()) {
if (field.DeclaredAccessibility == Accessibility.Public && (field.IsConst || field.IsStatic)) {
result.Add (engine.Factory.CreateEnumMemberCompletionData (this, alias, field));
}
}
}
return result;
}
开发者ID:sushihangover,项目名称:monodevelop,代码行数:60,代码来源:EnumMemberContextHandler.cs
示例3: GetItemsWorkerAsync
protected override Task<IEnumerable<CompletionData>> GetItemsWorkerAsync (CompletionResult result, CompletionEngine engine, CompletionContext completionContext, CompletionTriggerInfo info, SyntaxContext ctx, CancellationToken cancellationToken)
{
var document = completionContext.Document;
var position = completionContext.Position;
var tree = ctx.SyntaxTree;
var model = ctx.SemanticModel;
if (tree.IsInNonUserCode (position, cancellationToken))
return Task.FromResult (Enumerable.Empty<CompletionData> ());
if (!ctx.CSharpSyntaxContext.IsAnyExpressionContext)
return Task.FromResult (Enumerable.Empty<CompletionData> ());
var enclosingType = model.GetEnclosingNamedType (position, cancellationToken);
var memberMethods = enclosingType.GetMembers ().OfType<IMethodSymbol> ().Where (m => m.MethodKind == MethodKind.Ordinary).ToArray ();
var list = new List<CompletionData> ();
foreach (var type in ctx.InferredTypes) {
if (type.TypeKind != TypeKind.Delegate)
continue;
AddCompatibleMethods (engine, list, type, memberMethods, cancellationToken);
string delegateName = null;
if (ctx.TargetToken.IsKind (SyntaxKind.PlusEqualsToken)) {
delegateName = GuessEventHandlerBaseName (ctx.LeftToken.Parent, ctx.ContainingTypeDeclaration);
}
AddDelegateHandlers (list, ctx.TargetToken.Parent, model, engine, result, type, position, delegateName, cancellationToken);
}
if (list.Count > 0) {
result.AutoSelect = false;
}
return Task.FromResult ((IEnumerable<CompletionData>)list);
}
开发者ID:zenek-y,项目名称:monodevelop,代码行数:35,代码来源:DelegateCreationContextHandler.cs
示例4: GetItemsWorkerAsync
protected async override Task<IEnumerable<CompletionData>> GetItemsWorkerAsync (CompletionResult completionResult, CompletionEngine engine, CompletionContext completionContext, CompletionTriggerInfo info, SyntaxContext ctx, CancellationToken cancellationToken)
{
var document = completionContext.Document;
var position = completionContext.Position;
var tree = ctx.SyntaxTree;
//DeclarationModifiers modifiers;
SyntaxToken token;
var semanticModel = ctx.SemanticModel;
var enclosingSymbol = semanticModel.GetEnclosingSymbol (position, cancellationToken) as INamedTypeSymbol;
// Only inside classes and structs
if (enclosingSymbol == null || !(enclosingSymbol.TypeKind == TypeKind.Struct || enclosingSymbol.TypeKind == TypeKind.Class)) {
return Enumerable.Empty<CompletionData> ();
}
if (!IsPartialCompletionContext (tree, position, cancellationToken/*, out modifiers*/, out token)) {
if (enclosingSymbol != null && (token.IsKind (SyntaxKind.OpenBraceToken) || token.IsKind (SyntaxKind.CloseBraceToken) || token.IsKind (SyntaxKind.SemicolonToken))) {
return CreateCompletionData (engine, semanticModel, position, enclosingSymbol, token, false, cancellationToken);
}
return Enumerable.Empty<CompletionData> ();
}
return CreateCompletionData (engine, semanticModel, position, enclosingSymbol, token, true, cancellationToken);
}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:26,代码来源:PartialContextHandler.cs
示例5: GetItemsWorkerAsync
protected async override Task<IEnumerable<CompletionData>> GetItemsWorkerAsync (CompletionResult completionResult, CompletionEngine engine, CompletionContext completionContext, CompletionTriggerInfo info, SyntaxContext ctx, CancellationToken cancellationToken)
{
var position = completionContext.Position;
var document = completionContext.Document;
var span = new TextSpan(position, 0);
var semanticModel = await document.GetCSharpSemanticModelForSpanAsync(span, cancellationToken).ConfigureAwait(false);
var syntaxTree = semanticModel.SyntaxTree;
// var ctx = await completionContext.GetSyntaxContextAsync (engine.Workspace, cancellationToken).ConfigureAwait (false);
if (syntaxTree.IsInNonUserCode(position, cancellationToken) ||
syntaxTree.IsPreProcessorDirectiveContext(position, cancellationToken))
{
return Enumerable.Empty<CompletionData> ();
}
if (!syntaxTree.IsRightOfDotOrArrowOrColonColon(position, cancellationToken))
{
return Enumerable.Empty<CompletionData> ();
}
var node = syntaxTree.FindTokenOnLeftOfPosition(position, cancellationToken)
.GetPreviousTokenIfTouchingWord(position)
.Parent;
if (node.Kind() == SyntaxKind.ExplicitInterfaceSpecifier)
{
return await GetCompletionsOffOfExplicitInterfaceAsync(
engine, document, semanticModel, position, ((ExplicitInterfaceSpecifierSyntax)node).Name, cancellationToken).ConfigureAwait(false);
}
return Enumerable.Empty<CompletionData> ();
}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:32,代码来源:ExplicitInterfaceContextHandler.cs
示例6: GetItemsWorkerAsync
protected async override Task<IEnumerable<CompletionData>> GetItemsWorkerAsync (CompletionResult completionResult, CompletionEngine engine, CompletionContext completionContext, CompletionTriggerInfo info, SyntaxContext ctx, CancellationToken cancellationToken)
{
var document = completionContext.Document;
var position = completionContext.Position;
var semanticModel = ctx.SemanticModel;
if (ctx.TargetToken.Parent != null && ctx.TargetToken.Parent.Parent != null &&
ctx.TargetToken.Parent.Parent.IsKind(SyntaxKind.Argument)) {
SourceText text;
if (!completionContext.Document.TryGetText (out text)) {
text = await completionContext.Document.GetTextAsync ();
}
var currentChar = text [completionContext.Position - 1];
if (ctx.TargetToken.Parent == null || !ctx.TargetToken.Parent.IsKind(SyntaxKind.StringLiteralExpression) ||
ctx.TargetToken.Parent.Parent == null || !ctx.TargetToken.Parent.Parent.IsKind(SyntaxKind.Argument) ||
ctx.TargetToken.Parent.Parent.Parent == null || !ctx.TargetToken.Parent.Parent.Parent.IsKind(SyntaxKind.ArgumentList) ||
ctx.TargetToken.Parent.Parent.Parent.Parent == null || !ctx.TargetToken.Parent.Parent.Parent.Parent.IsKind(SyntaxKind.InvocationExpression)) {
return Enumerable.Empty<CompletionData> ();
}
var formatArgument = GetFormatItemNumber(document, position);
var invocationExpression = ctx.TargetToken.Parent.Parent.Parent.Parent as InvocationExpressionSyntax;
return GetFormatCompletionData(engine, semanticModel, invocationExpression, formatArgument, currentChar);
}
return Enumerable.Empty<CompletionData> ();
}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:26,代码来源:FormatItemContextHandler.cs
示例7: GetItemsWorkerAsync
protected async override Task<IEnumerable<CompletionData>> GetItemsWorkerAsync (CompletionResult completionResult, CompletionEngine engine, CompletionContext completionContext, CompletionTriggerInfo info, SyntaxContext ctx, CancellationToken cancellationToken)
{
var document = completionContext.Document;
var position = completionContext.Position;
var tree = ctx.SyntaxTree;
if (tree.IsInNonUserCode(position, cancellationToken))
return Enumerable.Empty<CompletionData> ();
var targetToken = tree.FindTokenOnLeftOfPosition(position, cancellationToken).GetPreviousTokenIfTouchingWord(position);
if (targetToken.IsKind(SyntaxKind.AliasKeyword) && targetToken.Parent.IsKind(SyntaxKind.ExternAliasDirective))
{
var compilation = await document.GetCSharpCompilationAsync(cancellationToken).ConfigureAwait(false);
var aliases = compilation.ExternalReferences.Where(r => r.Properties.Aliases != null).SelectMany(r => r.Properties.Aliases).ToSet();
if (aliases.Any())
{
var root = await tree.GetRootAsync(cancellationToken).ConfigureAwait(false);
var usedAliases = root.ChildNodes().OfType<ExternAliasDirectiveSyntax>().Where(e => !e.Identifier.IsMissing).Select(e => e.Identifier.ValueText);
foreach (var used in usedAliases) {
aliases.Remove (used);
}
aliases.Remove(MetadataReferenceProperties.GlobalAlias);
return aliases.Select (e => engine.Factory.CreateGenericData (this, e, GenericDataType.Undefined));
}
}
return Enumerable.Empty<CompletionData> ();
}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:30,代码来源:ExternAliasContextHandler.cs
示例8: CreateItem
/// <summary>
/// Given a Symbol, creates the completion item for it.
/// </summary>
private CompletionItem CreateItem(
string displayText,
string insertionText,
List<ISymbol> symbols,
SyntaxContext context,
Dictionary<ISymbol, List<ProjectId>> invalidProjectMap,
List<ProjectId> totalProjects,
bool preselect)
{
Contract.ThrowIfNull(symbols);
SupportedPlatformData supportedPlatformData = null;
if (invalidProjectMap != null)
{
List<ProjectId> invalidProjects = null;
foreach (var symbol in symbols)
{
if (invalidProjectMap.TryGetValue(symbol, out invalidProjects))
{
break;
}
}
if (invalidProjects != null)
{
supportedPlatformData = new SupportedPlatformData(invalidProjects, totalProjects, context.Workspace);
}
}
return CreateItem(displayText, insertionText, symbols, context, preselect, supportedPlatformData);
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:34,代码来源:AbstractSymbolCompletionProvider.cs
示例9: LookupCandidateSymbols
protected override IEnumerable<INamedTypeSymbol> LookupCandidateSymbols(SyntaxContext context, INamedTypeSymbol declaredSymbol, CancellationToken cancellationToken)
{
var candidates = base.LookupCandidateSymbols(context, declaredSymbol, cancellationToken);
// The base class applies a broad filter when finding candidates, but since C# requires
// that all parts have the "partial" modifier, the results can be trimmed further here.
return candidates?.Where(symbol => symbol.DeclaringSyntaxReferences.Any(reference => IsPartialTypeDeclaration(reference.GetSyntax(cancellationToken))));
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:8,代码来源:PartialTypeCompletionProvider.cs
示例10: IsExclusiveAsync
public override async Task<bool> IsExclusiveAsync (CompletionContext completionContext, SyntaxContext syntaxContext, CompletionTriggerInfo triggerInfo, CancellationToken cancellationToken)
{
// We're exclusive if this context could only be an object initializer and not also a
// collection initializer. If we're initializing something that could be initialized as
// an object or as a collection, say we're not exclusive. That way the rest of
// intellisense can be used in the collection intitializer.
//
// Consider this case:
// class c : IEnumerable<int>
// {
// public void Add(int addend) { }
// public int foo;
// }
// void foo()
// {
// var b = new c {|
// }
// There we could initialize b using either an object initializer or a collection
// initializer. Since we don't know which the user will use, we'll be non-exclusive, so
// the other providers can help the user write the collection initializer, if they want
// to.
var document = completionContext.Document;
var position = completionContext.Position;
var tree = await document.GetCSharpSyntaxTreeAsync (cancellationToken).ConfigureAwait (false);
if (tree.IsInNonUserCode (position, cancellationToken)) {
return false;
}
var token = tree.FindTokenOnLeftOfPosition (position, cancellationToken);
token = token.GetPreviousTokenIfTouchingWord (position);
if (token.Parent == null) {
return false;
}
var expression = token.Parent.Parent as ExpressionSyntax;
if (expression == null) {
return false;
}
var semanticModel = await document.GetCSharpSemanticModelForNodeAsync (expression, cancellationToken).ConfigureAwait (false);
var initializedType = semanticModel.GetTypeInfo (expression, cancellationToken).Type;
if (initializedType == null) {
return false;
}
// Non-exclusive if initializedType can be initialized as a collection.
if (initializedType.CanSupportCollectionInitializer ()) {
return false;
}
// By default, only our member names will show up.
return true;
}
开发者ID:kdubau,项目名称:monodevelop,代码行数:58,代码来源:ObjectInitializerContextHandler.cs
示例11: override
protected override (string displayText, string insertionText) GetDisplayAndInsertionText(ISymbol symbol, SyntaxContext context)
{
if (symbol is IAliasSymbol)
{
return (symbol.Name, symbol.Name);
}
return base.GetDisplayAndInsertionText(symbol, context);
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:9,代码来源:ObjectCreationCompletionProvider.cs
示例12: GetDisplayAndInsertionText
protected override ValueTuple<string, string> GetDisplayAndInsertionText(ISymbol symbol, SyntaxContext context)
{
if (symbol is IAliasSymbol)
{
return ValueTuple.Create(symbol.Name, symbol.Name);
}
return base.GetDisplayAndInsertionText(symbol, context);
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:9,代码来源:ObjectCreationCompletionProvider.cs
示例13: GetItemsWorkerAsync
protected async override Task<IEnumerable<CompletionData>> GetItemsWorkerAsync (CompletionResult completionResult, CompletionEngine engine, CompletionContext completionContext, CompletionTriggerInfo info, SyntaxContext ctx, CancellationToken cancellationToken)
{
var document = completionContext.Document;
var position = completionContext.Position;
return await document.GetUnionResultsFromDocumentAndLinks(
UnionCompletionItemComparer.Instance,
async (doc, ct) => await GetSpeculativeTCompletions(engine, doc, position, ct).ConfigureAwait(false),
cancellationToken).ConfigureAwait(false);
}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:10,代码来源:SpeculativeTContextHandler.cs
示例14: GetItemsWorkerAsync
protected async override Task<IEnumerable<CompletionData>> GetItemsWorkerAsync (CompletionResult completionResult, CompletionEngine engine, CompletionContext completionContext, CompletionTriggerInfo info, SyntaxContext ctx, CancellationToken cancellationToken)
{
var document = completionContext.Document;
var position = completionContext.Position;
var syntaxTree = await document.GetCSharpSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
if (syntaxTree.IsInNonUserCode(position, cancellationToken) ||
syntaxTree.IsRightOfDotOrArrowOrColonColon(position, cancellationToken) ||
syntaxTree.GetContainingTypeOrEnumDeclaration(position, cancellationToken) is EnumDeclarationSyntax)
{
return Enumerable.Empty<CompletionData>();
}
// var span = new TextSpan(position, 0);
// var semanticModel = await document.GetCSharpSemanticModelForSpanAsync(span, cancellationToken).ConfigureAwait(false);
if (syntaxTree.IsPreProcessorDirectiveContext(position, cancellationToken))
{
var directive = syntaxTree.GetRoot(cancellationToken).FindTokenOnLeftOfPosition(position, includeDirectives: true).GetAncestor<DirectiveTriviaSyntax>();
if (directive.DirectiveNameToken.IsKind(
SyntaxKind.IfKeyword,
SyntaxKind.RegionKeyword,
SyntaxKind.ElseKeyword,
SyntaxKind.ElifKeyword,
SyntaxKind.ErrorKeyword,
SyntaxKind.LineKeyword,
SyntaxKind.PragmaKeyword,
SyntaxKind.EndIfKeyword,
SyntaxKind.UndefKeyword,
SyntaxKind.EndRegionKeyword,
SyntaxKind.WarningKeyword))
{
return Enumerable.Empty<CompletionData>();
}
return await GetSnippetCompletionItemsAsync(cancellationToken).ConfigureAwait(false);
}
var tokenLeftOfPosition = syntaxTree.FindTokenOnLeftOfPosition (position, cancellationToken);
if (syntaxTree.IsGlobalStatementContext(position, cancellationToken) ||
syntaxTree.IsExpressionContext(position, tokenLeftOfPosition, true, cancellationToken) ||
syntaxTree.IsStatementContext(position, tokenLeftOfPosition, cancellationToken) ||
syntaxTree.IsTypeContext(position, cancellationToken) ||
syntaxTree.IsTypeDeclarationContext(position, tokenLeftOfPosition, cancellationToken) ||
syntaxTree.IsNamespaceContext(position, cancellationToken) ||
syntaxTree.IsMemberDeclarationContext(position, tokenLeftOfPosition, cancellationToken) ||
syntaxTree.IsLabelContext(position, cancellationToken))
{
return await GetSnippetCompletionItemsAsync(cancellationToken).ConfigureAwait(false);
}
return Enumerable.Empty<CompletionData>();
}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:53,代码来源:SnippetContextHandler.cs
示例15: GetItemsWorkerAsync
protected async override Task<IEnumerable<CompletionData>> GetItemsWorkerAsync (CompletionResult completionResult, CompletionEngine engine, CompletionContext completionContext, CompletionTriggerInfo info, SyntaxContext ctx, CancellationToken cancellationToken)
{
var model = ctx.SemanticModel;
var result = new List<CompletionData> ();
if (ctx.IsPreProcessorExpressionContext) {
var parseOptions = model.SyntaxTree.Options as CSharpParseOptions;
foreach (var define in parseOptions.PreprocessorSymbolNames) {
result.Add(engine.Factory.CreateGenericData (this, define, GenericDataType.PreprocessorSymbol));
}
}
return result;
}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:13,代码来源:PreProcessorExpressionContextHandler.cs
示例16: CreateCompletionItem
private CompletionItem CreateCompletionItem(
INamedTypeSymbol symbol, SyntaxContext context)
{
var displayAndInsertionText = GetDisplayAndInsertionText(symbol, context);
return SymbolCompletionItem.Create(
displayText: displayAndInsertionText.Item1,
insertionText: displayAndInsertionText.Item2,
symbol: symbol,
contextPosition: context.Position,
properties: GetProperties(symbol, context),
rules: CompletionItemRules.Default);
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:13,代码来源:AbstractPartialTypeCompletionProvider.cs
示例17: GetItemsWorkerAsync
protected async override Task<IEnumerable<CompletionData>> GetItemsWorkerAsync (CompletionResult completionResult, CompletionEngine engine, CompletionContext completionContext, CompletionTriggerInfo info, SyntaxContext ctx, CancellationToken cancellationToken)
{
// var ctx = await completionContext.GetSyntaxContextAsync (engine.Workspace, cancellationToken).ConfigureAwait (false);
var document = completionContext.Document;
var semanticModel = ctx.SemanticModel;
var tree = ctx.SyntaxTree;
if (tree.IsInNonUserCode(completionContext.Position, cancellationToken))
return Enumerable.Empty<CompletionData> ();
var text = await document.GetTextAsync (cancellationToken).ConfigureAwait (false);
var startLineNumber = text.Lines.IndexOf (completionContext.Position);
// modifiers* override modifiers* type? |
Accessibility seenAccessibility;
//DeclarationModifiers modifiers;
var token = tree.FindTokenOnLeftOfPosition(completionContext.Position, cancellationToken);
if (token.Parent == null)
return Enumerable.Empty<CompletionData> ();
var parentMember = token.Parent.AncestorsAndSelf ().OfType<MemberDeclarationSyntax> ().FirstOrDefault (m => !m.IsKind (SyntaxKind.IncompleteMember));
if (!(parentMember is BaseTypeDeclarationSyntax) &&
/* May happen in case:
*
* override $
* public override string Foo () {}
*/
!(token.IsKind (SyntaxKind.OverrideKeyword) && token.Span.Start <= parentMember.Span.Start))
return Enumerable.Empty<CompletionData> ();
var position = completionContext.Position;
var startToken = token.GetPreviousTokenIfTouchingWord(position);
ITypeSymbol returnType;
SyntaxToken tokenBeforeReturnType;
TryDetermineReturnType (startToken, semanticModel, cancellationToken, out returnType, out tokenBeforeReturnType);
if (returnType == null) {
var enclosingType = semanticModel.GetEnclosingSymbol (position, cancellationToken) as INamedTypeSymbol;
if (enclosingType != null && (startToken.IsKind (SyntaxKind.OpenBraceToken) || startToken.IsKind (SyntaxKind.CloseBraceToken) || startToken.IsKind (SyntaxKind.SemicolonToken))) {
return CreateCompletionData (engine, semanticModel, position, returnType, Accessibility.NotApplicable, startToken, tokenBeforeReturnType, false, cancellationToken);
}
}
if (!TryDetermineModifiers(ref tokenBeforeReturnType, text, startLineNumber, out seenAccessibility/*, out modifiers*/) ||
!TryCheckForTrailingTokens (tree, text, startLineNumber, position, cancellationToken)) {
return Enumerable.Empty<CompletionData> ();
}
return CreateCompletionData (engine, semanticModel, position, returnType, seenAccessibility, startToken, tokenBeforeReturnType, true, cancellationToken);
}
开发者ID:zenek-y,项目名称:monodevelop,代码行数:51,代码来源:OverrideContextHandler.cs
示例18: GetInsertionText
public static string GetInsertionText(ISymbol symbol, SyntaxContext context)
{
if (CommonCompletionUtilities.TryRemoveAttributeSuffix(symbol, context, out var name))
{
// Cannot escape Attribute name with the suffix removed. Only use the name with
// the suffix removed if it does not need to be escaped.
if (name.Equals(name.EscapeIdentifier()))
{
return name;
}
}
return symbol.Name.EscapeIdentifier(isQueryContext: context.IsInQuery);
}
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:14,代码来源:SymbolCompletionProvider.cs
示例19: GetPreselectedSymbolsWorker
protected override async Task<ImmutableArray<ISymbol>> GetPreselectedSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
{
var result = await base.GetPreselectedSymbolsWorker(context, position, options, cancellationToken).ConfigureAwait(false);
if (result.Any())
{
var type = (ITypeSymbol)result.Single();
var alias = await type.FindApplicableAlias(position, context.SemanticModel, cancellationToken).ConfigureAwait(false);
if (alias != null)
{
return ImmutableArray.Create(alias);
}
}
return result;
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:15,代码来源:ObjectCreationCompletionProvider.cs
示例20: CreateItems
/// <summary>
/// Given a list of symbols, creates the list of completion items for them.
/// </summary>
protected IEnumerable<CompletionItem> CreateItems(
IEnumerable<ISymbol> symbols,
SyntaxContext context,
Dictionary<ISymbol, List<ProjectId>> invalidProjectMap,
List<ProjectId> totalProjects,
bool preselect)
{
var tree = context.SyntaxTree;
var q = from symbol in symbols
let texts = GetDisplayAndInsertionText(symbol, context)
group symbol by texts into g
select this.CreateItem(g.Key.Item1, g.Key.Item2, g.ToList(), context, invalidProjectMap, totalProjects, preselect);
return q.ToList();
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:19,代码来源:AbstractSymbolCompletionProvider.cs
注:本文中的SyntaxContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论