public CompletionModel(SemanticModel semanticModel, TextSpan applicableSpan, ITextSnapshot textSnapshot, IEnumerable<CompletionItem> items) { SemanticModel = semanticModel; ApplicableSpan = applicableSpan; TextSnapshot = textSnapshot; Items = items.ToImmutableArray(); }
public IEnumerable<CompletionItem> GetItems(SemanticModel semanticModel, SourceLocation position) { var syntaxTree = semanticModel.Compilation.SyntaxTree; return GetAvailableKeywords(syntaxTree, position) .Select(k => k.GetText()) .Select(t => new CompletionItem(t, t, t + " Keyword", Glyph.Keyword)); }
private QuickInfoModel(SemanticModel semanticModel, TextSpan span, Glyph glyph, SymbolMarkup markup, string documentation) { SemanticModel = semanticModel; Span = span; Glyph = glyph; Markup = markup; Documentation = documentation; }
private static IEnumerable<CompletionItem> GetMemberCompletions(SemanticModel semanticModel, FieldAccessExpressionSyntax propertyAccessExpression) { var targetType = semanticModel.GetExpressionType(propertyAccessExpression.Expression); if (targetType != null && !targetType.IsUnknown() && !targetType.IsError()) return GetTypeCompletions(targetType); return Enumerable.Empty<CompletionItem>(); }
public SemanticTaggerVisitor(SemanticModel semanticModel, HlslClassificationService classificationService, ITextSnapshot snapshot, List<ITagSpan<IClassificationTag>> results, CancellationToken cancellationToken) { _semanticModel = semanticModel; _classificationService = classificationService; _snapshot = snapshot; _results = results; _cancellationToken = cancellationToken; }
public IEnumerable<HighlightSpan> GetHighlights(SemanticModel semanticModel, SourceLocation position) { var symbolAtPosition = semanticModel.FindSymbol(position); if (symbolAtPosition == null) return Enumerable.Empty<HighlightSpan>(); return semanticModel.FindUsages(symbolAtPosition.Value.Symbol) .Select(s => new HighlightSpan(s.Span, s.Kind == SymbolSpanKind.Definition)); }
private static IEnumerable<CompletionItem> GetGlobalCompletions(SemanticModel semanticModel, SourceLocation position) { var symbols = semanticModel.LookupSymbols(position) .Where(x => !(x is SemanticSymbol)) .Where(x => !(x is AttributeSymbol)); if (!semanticModel.SyntaxTree.PossiblyInTypeName(position)) symbols = symbols.Where(x => !(x is TypeSymbol)); return CreateSymbolCompletions(symbols); }
public static bool TryGetSemanticModel(this ITextSnapshot snapshot, CancellationToken cancellationToken, out SemanticModel semanticModel) { if (HlslPackage.Instance != null && !HlslPackage.Instance.Options.AdvancedOptions.EnableIntelliSense) { semanticModel = null; return false; } try { semanticModel = CachedSemanticModels.GetValue(snapshot, key => { try { var syntaxTree = key.GetSyntaxTree(cancellationToken); var compilation = new Compilation(syntaxTree); return compilation.GetSemanticModel(cancellationToken); } catch (OperationCanceledException) { throw; } catch (Exception ex) { Logger.Log($"Failed to create semantic model: {ex}"); return null; } }); } catch (OperationCanceledException) { semanticModel = null; } return semanticModel != null; }
public IEnumerable<CompletionItem> GetItems(SemanticModel semanticModel, SourceLocation position) { var root = semanticModel.SyntaxTree.Root; // We don't want to show a completions for these cases. if (semanticModel.SyntaxTree.PossiblyInUserGivenName(position)) return Enumerable.Empty<CompletionItem>(); if (semanticModel.SyntaxTree.DefinitelyInMacro(position)) return Enumerable.Empty<CompletionItem>(); if (semanticModel.SyntaxTree.DefinitelyInVariableDeclaratorQualifier(position)) return Enumerable.Empty<CompletionItem>(); // Comments and literals don't get completion information if (root.InComment(position) || root.InLiteral(position)) return Enumerable.Empty<CompletionItem>(); if (semanticModel.SyntaxTree.DefinitelyInTypeName(position)) return GetTypeCompletions(semanticModel, position); var propertyAccessExpression = GetPropertyAccessExpression(root, position); return propertyAccessExpression == null ? GetGlobalCompletions(semanticModel, position) : GetMemberCompletions(semanticModel, propertyAccessExpression); }
private static QuickInfoModel GetQuickInfoModel(SemanticModel semanticModel, int position, IEnumerable<IQuickInfoModelProvider> providers) { return providers .Select(p => p.GetModel(semanticModel, semanticModel.Compilation.SyntaxTree.MapRootFilePosition(position))) .FirstOrDefault(t => t != null); }
public static QuickInfoModel ForMacroReference(SemanticModel semanticModel, TextSpan span, MacroReference macroReference) { var glyph = Glyph.Macro; var symbolMarkup = new SymbolMarkup(new[] { new SymbolMarkupToken(SymbolMarkupKind.PlainText, $"(macro reference) {macroReference.DefineDirective.ToString(true)}") }); return new QuickInfoModel(semanticModel, span, glyph, symbolMarkup, string.Empty); }
public static QuickInfoModel ForMacroDefinition(SemanticModel semanticModel, TextSpan span, DefineDirectiveTriviaSyntax macroDefinition) { var glyph = Glyph.Macro; var symbolMarkup = new SymbolMarkup(new[] { new SymbolMarkupToken(SymbolMarkupKind.PlainText, $"(macro definition) {macroDefinition}") }); return new QuickInfoModel(semanticModel, span, glyph, symbolMarkup, string.Empty); }
public static QuickInfoModel ForSymbol(SemanticModel semanticModel, TextSpan span, Symbol symbol) { var glyph = symbol.GetGlyph(); var symbolMarkup = SymbolMarkup.ForSymbol(symbol); return new QuickInfoModel(semanticModel, span, glyph, symbolMarkup, symbol.Documentation); }
private static IEnumerable<SymbolSpan> GetSymbolSpans(SemanticModel semanticModel, SyntaxNode node) { switch (node.Kind) { case SyntaxKind.VariableDeclarator: { var expression = (VariableDeclaratorSyntax) node; var symbol = semanticModel.GetDeclaredSymbol(expression); if (symbol != null) yield return SymbolSpan.CreateDefinition(symbol, expression.Identifier.SourceRange, expression.Identifier.Span); break; } case SyntaxKind.ClassType: { var expression = (ClassTypeSyntax) node; var symbol = semanticModel.GetDeclaredSymbol(expression); if (symbol != null) yield return SymbolSpan.CreateDefinition(symbol, expression.Name.SourceRange, expression.Name.Span); break; } case SyntaxKind.StructType: { var expression = (StructTypeSyntax) node; var symbol = semanticModel.GetDeclaredSymbol(expression); if (symbol != null && expression.Name != null) yield return SymbolSpan.CreateDefinition(symbol, expression.Name.SourceRange, expression.Name.Span); break; } case SyntaxKind.InterfaceType: { var expression = (InterfaceTypeSyntax) node; var symbol = semanticModel.GetDeclaredSymbol(expression); if (symbol != null) yield return SymbolSpan.CreateDefinition(symbol, expression.Name.SourceRange, expression.Name.Span); break; } case SyntaxKind.IdentifierName: { var expression = (IdentifierNameSyntax) node; var symbol = semanticModel.GetSymbol(expression); if (symbol != null) yield return SymbolSpan.CreateReference(symbol, expression.Name.SourceRange, expression.Name.Span); break; } case SyntaxKind.IdentifierDeclarationName: { var expression = (IdentifierDeclarationNameSyntax) node; var symbol = semanticModel.GetSymbol(expression); if (symbol != null) yield return SymbolSpan.CreateDefinition(symbol, expression.Name.SourceRange, expression.Name.Span); break; } case SyntaxKind.FieldAccessExpression: { var expression = (FieldAccessExpressionSyntax) node; var symbol = semanticModel.GetSymbol(expression); if (symbol != null) yield return SymbolSpan.CreateReference(symbol, expression.Name.SourceRange, expression.Name.Span); break; } case SyntaxKind.MethodInvocationExpression: { var expression = (MethodInvocationExpressionSyntax) node; var symbol = semanticModel.GetSymbol(expression); if (symbol != null) yield return SymbolSpan.CreateReference(symbol, expression.Name.SourceRange, expression.Name.Span); break; } case SyntaxKind.FunctionInvocationExpression: { var expression = (FunctionInvocationExpressionSyntax) node; var symbol = semanticModel.GetSymbol(expression); if (symbol != null) yield return SymbolSpan.CreateReference(symbol, expression.Name.GetUnqualifiedName().Name.SourceRange, expression.Name.GetUnqualifiedName().Name.Span); break; } case SyntaxKind.FunctionDefinition: { var expression = (FunctionDefinitionSyntax) node; var symbol = semanticModel.GetDeclaredSymbol(expression); if (symbol != null) yield return SymbolSpan.CreateDefinition(symbol, expression.Name.GetUnqualifiedName().Name.SourceRange, expression.Name.GetUnqualifiedName().Name.Span); break; } case SyntaxKind.FunctionDeclaration: { var expression = (FunctionDeclarationSyntax) node; var symbol = semanticModel.GetDeclaredSymbol(expression); if (symbol != null) yield return SymbolSpan.CreateDefinition(symbol, expression.Name.GetUnqualifiedName().Name.SourceRange, expression.Name.GetUnqualifiedName().Name.Span); break; } } }
private static IEnumerable<CompletionItem> GetTypeCompletions(SemanticModel semanticModel, SourceLocation position) { var symbols = semanticModel.LookupSymbols(position).OfType<TypeSymbol>(); return CreateSymbolCompletions(symbols); }