Пример #1
0
        private static IEnumerable <Run> GetSymbolLocation(DeclarationSymbol symbol)
        {
            if (symbol == null)
            {
                return(new Run[0]);
            }

            var declaration    = symbol.FirstDeclarationOrDefault;
            var sourceSnapshot = declaration?.Source;
            var newLine        = Environment.NewLine;

            if (sourceSnapshot != null &&
                sourceSnapshot != SourceSnapshot.Default &&
                sourceSnapshot.File != null &&
                declaration.Location != null)
            {
                var filename = Path.GetFileName(sourceSnapshot.File.FullName);
                var location = declaration.Location.StartLineColumn;

                return(new [] {
                    new Run(newLine + filename + ":" + location.Line + newLine + newLine)
                    {
                        Foreground = LocationColor
                    },
                    CreateAccentRun("F12"),
                    CreateRun(" go to declaration "),
                    CreateAccentRun("(Ctrl + Click)")
                });
            }

            return(new Run[0]);
        }
Пример #2
0
        private void TrySelectTextForSymbol(DeclarationSymbol symbol, TreeViewItem tvi)
        {
            if (symbol != null)
            {
                var declarations = symbol.GetDeclarationsUntyped().ToList();
                if (declarations.Count == 1)
                {
                    SelectText(declarations[0]);
                }
                else if (declarations.Count > 1)
                {
                    if (!tvi.IsExpanded)
                    {
                        tvi.IsExpanded = true;
                    }
                    foreach (TreeViewItem subItem in tvi.Items)
                    {
                        var decls = subItem.Tag as IEnumerable <Declaration>;
                        if (decls != null)
                        {
                            subItem.IsExpanded = true;
                            subItem.IsSelected = true;

                            foreach (TreeViewItem subSubItem in tvi.Items)
                            {
                                subSubItem.BringIntoView();
                            }

                            break;
                        }
                    }
                }
            }
        }
Пример #3
0
 protected Model([NotNull] DeclarationSymbol symbol, ModelType modelType)
     : this(
         modelType,
         symbol.Id,
         symbol.FirstDeclarationOrDefault.Location,
         symbol.Name,
         symbol.FirstDeclarationOrDefault.Location.Source.File.FullName)
 {
 }
Пример #4
0
 protected SuiteRelatable([NotNull] DeclarationSymbol symbol, ModelType modelType)
     : base(
         modelType,
         symbol.Id,
         symbol.FirstDeclarationOrDefault.Location,
         symbol.Name,
         symbol.FirstDeclarationOrDefault.Location.Source.File.FullName)
 {
 }
Пример #5
0
        public static DeclarationSymbol SpanToSymbol(IList <object> quickInfoContent, NSpan span, IAst ast, out bool foundSomething)
        {
            var cts = new CancellationTokenSource();
            DeclarationSymbol symbol = null;
            var visitor = new CollectSymbolsAndRefsInSpanAstVisitor(cts.Token, span);

            visitor.Visit(ast);

            foreach (var rf in visitor.Refs)
            {
                if (rf.IsAmbiguous)
                {
                    var foundHint = false;
                    foreach (var ambiguity in rf.Ambiguities)
                    {
                        var hint = SymbolToHint(ambiguity);
                        if (hint != null)
                        {
                            quickInfoContent.Add(hint);
                            symbol    = ambiguity;
                            foundHint = true;
                            break;
                        }
                    }

                    if (foundHint)
                    {
                        break;
                    }
                }
                else if (rf.IsSymbolEvaluated)
                {
                    var hint = SymbolToHint(rf.Symbol);
                    if (hint != null)
                    {
                        quickInfoContent.Add(hint);
                        symbol = rf.Symbol;
                        break;
                    }
                }
            }

            foundSomething = visitor.Refs.Count > 0 || visitor.Names.Count > 0;

            return(symbol);
        }
Пример #6
0
 private static Run GetSymbolType(DeclarationSymbol symbol)
 {
     if (symbol is FunctionParameterSymbol)
     {
         return(CreateRun("(parameter) "));
     }
     if (symbol is FunctionSymbol)
     {
         return(CreateRun("(mixin) "));
     }
     if (symbol is TypeSymbol)
     {
         return(CreateRun("(type) "));
     }
     if (symbol is Member.PropertySymbol)
     {
         return(CreateRun("(property) "));
     }
     if (symbol is GlobalDeclaration.VariableSymbol)
     {
         return(CreateRun("(variable) "));
     }
     return(new Run());
 }
Пример #7
0
        private static object SymbolToHint(DeclarationSymbol symbol)
        {
            if (symbol == null)
            {
                return("");
            }

            var textBlock = new TextBlock();
            var inlines   = textBlock.Inlines;

            var functionSymbol = symbol as FunctionSymbol;

            if (functionSymbol != null && functionSymbol.IsParametersEvaluated)
            {
                inlines.Add(GetSymbolType(symbol));
                var parameters    = functionSymbol.Parameters.MakeCompletionList("");
                var parameterRuns = parameters.OfType <FunctionParameterSymbol>()
                                    .SelectMany(GetParameterHintString)
                                    .ToList();

                inlines.Add(CreateAccentRun(functionSymbol.Name));
                inlines.Add(CreateAccentRun("("));

                for (int i = 0; i < parameterRuns.Count; i++)
                {
                    inlines.Add(parameterRuns[i]);
                    if (i < parameterRuns.Count - 1)
                    {
                        inlines.Add(CreateRun(", "));
                    }
                }

                inlines.Add(CreateAccentRun(")"));
                inlines.AddRange(GetSymbolLocation(functionSymbol));
                return(textBlock);
            }

            var variableSymbol = symbol as GlobalDeclaration.VariableSymbol;

            if (variableSymbol != null && variableSymbol.Value.HasValue)
            {
                var declaration = variableSymbol.FirstDeclarationOrDefault;

                if (declaration != null)
                {
                    inlines.Add(GetSymbolType(symbol));
                    inlines.Add(CreateRun(declaration.Location.GetText()));
                    inlines.AddRange(GetSymbolLocation(functionSymbol));
                    return(textBlock);
                }

                return("");
            }

            if (symbol.IsFullNameEvaluated)
            {
                inlines.Add(GetSymbolType(symbol));
                inlines.Add(CreateRun(symbol.FullName));
                inlines.AddRange(GetSymbolLocation(symbol));
                return(textBlock);
            }

            return(null);
        }
Пример #8
0
 protected ScenarioBaseModel([NotNull] DeclarationSymbol symbol, ModelType modelType)
     : base(symbol, modelType)
 {
 }
Пример #9
0
 protected PlatformBase([NotNull] DeclarationSymbol symbol, ModelType modelType)
     : base(symbol, modelType)
 {
 }
Пример #10
0
        public static MyCompletion FromSymbol(DeclarationSymbol symbol, IAst[] stack)
        {
            var completionType = CompletionType.Normal;
            var imageSource    = ClassImage;
            var name           = symbol.Name;

            if (name.Contains('.'))
            {
                name = name.Split('.').Last();
            }

            if (symbol is TypeSymbol)
            {
                completionType = CompletionType.Node;
                imageSource    = ClassImage;
            }
            else if (symbol is GlobalDeclaration.ContentFunctionSymbol)
            {
                var fun = (GlobalDeclaration.ContentFunctionSymbol)symbol;
                completionType = fun.Parameters.MakeCompletionList("").Any()
                    ? CompletionType.ContentFunctionRefWithParams
                    : CompletionType.ContentFunctionRef;
                imageSource = ComponentImage;
            }
            else if (symbol is GlobalDeclaration.TypeFunctionSymbol)
            {
                var fun = (GlobalDeclaration.TypeFunctionSymbol)symbol;
                completionType = fun.Parameters.MakeCompletionList("").Any()
                    ? CompletionType.TypeFunctionRefWithParams
                    : CompletionType.TypeFunctionRef;
                imageSource = ComponentImage;
            }
            else if (symbol is Member.PropertySymbol)
            {
                var fullName = symbol.FullName;
                if (fullName.StartsWith("System.Windows.Media.Brushes") || fullName.StartsWith("Windows.UI.Colors"))
                {
                    imageSource = ColorWheelImage;
                }
                else
                {
                    imageSource = PropertyImage;
                }

                completionType = CompletionType.Property;
            }
            else if (symbol is VariableRefSymbol)
            {
                name        = "$" + name;
                imageSource = ReferenceImage;
            }
            else if (symbol is Member.MethodSymbol)
            {
                imageSource = MethodImage;
            }
            else if (symbol is Member.EventSymbol)
            {
                imageSource = EventImage;
            }
            else if (symbol is Member.FieldSymbol)
            {
                imageSource = FieldImage;
            }
            else if (symbol is EnumMemberSymbol)
            {
                imageSource = EnumItemImage;
            }

            if (symbol is GlobalDeclaration.TypeFunctionSymbol)
            {
                name = "@" + name;
            }
            else if (symbol is GlobalDeclaration.ContentFunctionSymbol)
            {
                name = "#" + name;
            }

            return(new MyCompletion(name, name, symbol.FullName, imageSource, "", completionType, symbol, stack));
        }
    private void TrySelectTextForSymbol(DeclarationSymbol symbol, TreeViewItem tvi)
    {
      if (symbol != null)
      {
        var declarations = symbol.GetDeclarationsUntyped().ToList();
        if (declarations.Count == 1)
          SelectText(declarations[0]);
        else if (declarations.Count > 1)
        {
          if (!tvi.IsExpanded)
            tvi.IsExpanded = true;
          foreach (TreeViewItem subItem in tvi.Items)
          {
            var decls = subItem.Tag as IEnumerable<Declaration>;
            if (decls != null)
            {
              subItem.IsExpanded = true;
              subItem.IsSelected = true;

              foreach (TreeViewItem subSubItem in tvi.Items)
                subSubItem.BringIntoView();

              break;
            }
          }
        }
      }
    }
Пример #12
0
 protected DeploymentBaseModel([NotNull] DeclarationSymbol symbol, ModelType modelType)
     : base(symbol, modelType)
 {
 }
Пример #13
0
 public ValueModel(DeclarationSymbol symbol, ParsedValue <string> value) : this(symbol.GetSource(), value)
 {
 }
 protected CurryingApplicableDeployment([NotNull] DeclarationSymbol symbol, ModelType modelType)
     : base(symbol, modelType)
 {
 }
Пример #15
0
 private bool IsSpecialSymbol(DeclarationSymbol symbol)
 {
     return(symbol.Name.StartsWith("$"));
 }
Пример #16
0
 public static SourceSnapshot GetSource(this DeclarationSymbol symbol)
 {
     return(symbol.FirstDeclarationOrDefault.Location.Source);
 }
Пример #17
0
 protected ProductBaseModel([NotNull] DeclarationSymbol symbol, ModelType modelType)
     : base(symbol, modelType)
 {
 }
Пример #18
0
 public MyCompletion(string displayText, string insertionText, string description, ImageSource iconSource, string iconAutomationText, CompletionType completionType, DeclarationSymbol symbol, IAst[] stack) : base(displayText, insertionText, description, iconSource, iconAutomationText)
 {
     _stack         = stack;
     CompletionType = completionType;
     Symbol         = symbol;
 }