Ejemplo n.º 1
0
        public void CompleteCode()
        {
            int offset = TbxCode.TextArea.Caret.Offset;

            string tokenLeftOfCaret = TbxCode.Document.GetIdentifierLeftOf(offset);

            List <ICompletionData> completionData          = new List <ICompletionData>();
            EditorProviderDetails  expectedProviderDetails = GetCompletionProviderDetails();

            AddEnumEntries(expectedProviderDetails, completionData, tokenLeftOfCaret);
            AddDndFunctionsStartingWith(expectedProviderDetails, completionData, tokenLeftOfCaret);
            AddDndPropertiesStartingWith(expectedProviderDetails, completionData, tokenLeftOfCaret);

            if (completionData.Count == 0)
            {
                return;
            }
            completionWindow = new CompletionWindow(TbxCode.TextArea);
            IList <ICompletionData> data = completionWindow.CompletionList.CompletionData;

            foreach (ICompletionData item in completionData)
            {
                data.Add(item);
            }
            ShowCompletionWindow();
        }
Ejemplo n.º 2
0
        void InvokeCodeCompletionIfNecessary(string lastKeyPressed)
        {
            if (lastKeyPressed == null)
            {
                return;
            }
            if (IsIdentifierKey(lastKeyPressed))
            {
                CompleteCode();
            }
            else if (lastKeyPressed.Length > 0)
            {
                EditorProviderDetails expectedProviderDetails = GetCompletionProviderDetails();

                foreach (CompletionProvider completionProvider in completionProviders)
                {
                    if (string.IsNullOrEmpty(expectedProviderDetails.Name) || completionProvider.ProviderName == expectedProviderDetails.Name)
                    {
                        if (completionProvider.ShouldComplete(TbxCode.TextArea, lastKeyPressed[0], expectedProviderDetails.Name))
                        {
                            completionWindow = completionProvider.Complete(TbxCode.TextArea);
                            break;
                        }
                    }
                }
                ShowCompletionWindow();
            }
        }
Ejemplo n.º 3
0
 void AddDndPropertiesStartingWith(EditorProviderDetails expectedProviderDetails, List <ICompletionData> completionData, string tokenLeftOfCaret)
 {
     if (allKnownTokens == null)
     {
         GetAllKnownTokens();
     }
     foreach (PropertyCompletionInfo propertyCompletionInfo in allKnownTokens)
     {
         if (expectedProviderDetails.Type != null)
         {
             if (propertyCompletionInfo.Type.HasFlag(ExpressionType.@enum) && propertyCompletionInfo.EnumTypeName != expectedProviderDetails.Type.Name)
             {
                 continue;
             }
             if (!TypeHelper.Matches(propertyCompletionInfo.Type, expectedProviderDetails.Type))
             {
                 continue;
             }
         }
         if (string.IsNullOrWhiteSpace(tokenLeftOfCaret) || propertyCompletionInfo.Name.ToLower().StartsWith(tokenLeftOfCaret))
         {
             completionData.Add(new IdentifierCompletionData(propertyCompletionInfo.Name, propertyCompletionInfo.Description));
         }
     }
 }
Ejemplo n.º 4
0
        List <string> GetEnumEntries(EditorProviderDetails expectedProviderDetails)
        {
            List <string> enumEntries = new List <string>();

            if (expectedProviderDetails.Type != null && expectedProviderDetails.Type.IsEnum)
            {
                foreach (object enumElement in expectedProviderDetails.Type.GetEnumValues())
                {
                    enumEntries.Add(enumElement.ToString());
                }
            }
            return(enumEntries);
        }
Ejemplo n.º 5
0
        void AddDndFunctionsStartingWith(EditorProviderDetails expectedProviderDetails, List <ICompletionData> completionData, string tokenLeftOfCaret)
        {
            List <DndFunction> dndFunctions = GetDndFunctionsStartingWith(expectedProviderDetails, tokenLeftOfCaret);

            if (dndFunctions == null)
            {
                return;
            }
            foreach (DndFunction dndFunction in dndFunctions)
            {
                if (!string.IsNullOrWhiteSpace(dndFunction.Name))
                {
                    completionData.Add(new FunctionCompletionData(dndFunction));
                }
            }
        }
Ejemplo n.º 6
0
        void AddEnumEntries(EditorProviderDetails expectedProviderDetails, List <ICompletionData> completionData, string tokenLeftOfCaret)
        {
            List <string> enumEntries = GetEnumEntries(expectedProviderDetails);

            if (enumEntries != null)
            {
                foreach (string enumEntry in enumEntries)
                {
                    if (!string.IsNullOrWhiteSpace(enumEntry))
                    {
                        if (string.IsNullOrWhiteSpace(tokenLeftOfCaret) || enumEntry.ToLower().StartsWith(tokenLeftOfCaret))
                        {
                            completionData.Add(new IdentifierCompletionData(enumEntry, $"{expectedProviderDetails.Type.Name}.{enumEntry}"));
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        List <DndFunction> GetDndFunctionsStartingWith(EditorProviderDetails expectedProviderDetails, string tokenLeftOfCaret)
        {
            List <DndFunction> dndFunctions = Expressions.GetFunctionsStartingWith(tokenLeftOfCaret);

            if (expectedProviderDetails.Type == null)
            {
                return(dndFunctions);
            }

            List <DndFunction> filteredFunctions = new List <DndFunction>();

            foreach (DndFunction dndFunction in dndFunctions)
            {
                ReturnTypeAttribute returnType = dndFunction.GetType().GetCustomAttribute <ReturnTypeAttribute>();
                if (returnType != null && returnType.Matches(expectedProviderDetails.Type))
                {
                    filteredFunctions.Add(dndFunction);
                }
            }
            return(filteredFunctions);
        }
Ejemplo n.º 8
0
        EditorProviderDetails GetCompletionProviderDetails()
        {
            EditorProviderDetails result = new EditorProviderDetails();

            DndFunction dndFunction = GetActiveDndFunction(TbxCode.TextArea);

            if (dndFunction != null)
            {
                result.ActiveMethodCall = dndFunction.Name;
                IEnumerable <ParamAttribute> customAttributes = dndFunction.GetType().GetCustomAttributes(typeof(ParamAttribute)).Cast <ParamAttribute>().ToList();
                if (customAttributes != null)
                {
                    int            parameterNumber = TbxCode.Document.GetParameterNumberAtPosition(TbxCode.CaretOffset);
                    ParamAttribute paramAttribute  = customAttributes.FirstOrDefault(x => x.Index == parameterNumber);
                    if (paramAttribute != null)
                    {
                        result.Name = paramAttribute.Editor;
                        result.Type = paramAttribute.Type;
                    }
                }
            }
            return(result);
        }