Example #1
0
        public static IEnumerable <CompletionItem> GetCompletionForOfParent(Node node, Token variableNameToken,
                                                                            string userFilterText)
        {
            var completionItems = new List <CompletionItem>();

            if (node == null)
            {
                return(completionItems);
            }

            var currentVariable = node.SymbolTable.GetVariables(
                v => v != null && v.Name.Equals(variableNameToken.Text, StringComparison.InvariantCultureIgnoreCase), SymbolTable.Scope.Global)
                                  .FirstOrDefault();

            if (currentVariable == null)
            {
                return(completionItems);
            }

            var currentParent = currentVariable.Parent as DataDefinition;

            if (currentParent != null)
            {
                completionItems.Add(CompletionFactoryHelpers.CreateCompletionItemForVariable(currentParent));
            }
            return(completionItems);
        }
Example #2
0
        private static void SearchVariableInTypesAndLevels(Node node, DataDefinition variable, ref List <CompletionItem> completionItems)
        {
            var symbolTable = node.SymbolTable;

            if (!variable.IsPartOfATypeDef)                                         //Variable is not comming from a type.
            {
                if (symbolTable.GetVariablesExplicit(new URI(variable.Name)).Any()) //Check if this variable is present locally.
                {
                    completionItems.Add(CompletionFactoryHelpers.CreateCompletionItemForVariable(variable));
                }
            }
            else
            {
                if (symbolTable.TypesReferences != null) //We are in a typedef, get references of this type
                {
                    var type = variable.ParentTypeDefinition;
                    IEnumerable <DataDefinition> references = null;
                    references = symbolTable.TypesReferences.Where(t => t.Key == type).SelectMany(r => r.Value);

                    foreach (var reference in references)
                    {
                        if (symbolTable.GetVariablesExplicit(new URI(reference.Name)).Any())                                                                                             //Check if this variable is present locally. If not just ignore it
                        {
                            if (reference.ParentTypeDefinition == null)                                                                                                                  //Check if the variable is inside a typedef or not, if not it's a final varaible
                            {
                                var referenceArrangedQualifiedName = string.Join("::", reference.VisualQualifiedName.ToString().Split(reference.VisualQualifiedName.Separator).Skip(1)); //Skip Program Name
                                var finalQualifiedName             = string.Format("{0}::{1}", referenceArrangedQualifiedName, variable.VisualQualifiedName.Head);
                                var variableDisplay = string.Format("{0} ({1}) ({2})", variable.Name, variable.DataType.Name, finalQualifiedName);
                                completionItems.Add(new CompletionItem(variableDisplay)
                                {
                                    insertText = finalQualifiedName, kind = CompletionItemKind.Variable
                                });
                            }
                            else //If the reference is always in a typedef, let's loop and ride up until we are in a final variable
                            {
                                var tempCompletionItems = new List <CompletionItem>();
                                SearchVariableInTypesAndLevels(node, reference, ref tempCompletionItems);

                                if (tempCompletionItems.Count > 0)
                                {
                                    foreach (var tempComp in tempCompletionItems)
                                    {
                                        tempComp.insertText += "::" + variable.VisualQualifiedName.Head;
                                        tempComp.label       = string.Format("{0} ({1}) ({2})", variable.Name, variable.DataType.Name, tempComp.insertText);
                                        completionItems.Add(tempComp);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }