public CSharpOverloadProvider(CSharpCompletionContext context, int startOffset, IEnumerable<CSharpInsightItem> items)
        {
            Debug.Assert(items != null);
            this.context = context;
            this.startOffset = startOffset;
            this.selectedIndex = 0;
            this.items = items.ToList();

            Update(context);
        }
Example #2
0
        public CSharpOverloadProvider(CSharpCompletionContext context, int startOffset, IEnumerable <CSharpInsightItem> items)
        {
            Debug.Assert(items != null);
            this.context       = context;
            this.startOffset   = startOffset;
            this.selectedIndex = 0;
            this.items         = items.ToList();

            Update(context);
        }
Example #3
0
        public void Update(CSharpCompletionContext completionContext)
        {
            var completionFactory = new CSharpCompletionDataFactory(completionContext.TypeResolveContextAtCaret, completionContext);
            var pce = new CSharpParameterCompletionEngine(
                completionContext.Document,
                completionContext.CompletionContextProvider,
                completionFactory,
                completionContext.ProjectContent,
                completionContext.TypeResolveContextAtCaret
                );

            var completionChar = completionContext.Document.GetCharAt(completionContext.Offset - 1);
            var docText        = completionContext.Document.Text;

            Debug.Print("Update Completion char: '{0}'", completionChar);
            int parameterIndex = pce.GetCurrentParameterIndex(startOffset, completionContext.Offset);

            if (parameterIndex < 0)
            {
                RequestClose = true;
                return;
            }
            else
            {
                if (parameterIndex > items[selectedIndex].Method.Parameters.Count)
                {
                    var newItem = items.FirstOrDefault(i => parameterIndex <= i.Method.Parameters.Count);
                    SelectedIndex = items.IndexOf(newItem);
                }
                if (parameterIndex > 0)
                {
                    parameterIndex--; // NR returns 1-based parameter index
                }
                foreach (var item in items)
                {
                    item.HighlightParameter(parameterIndex);
                }
            }
        }
Example #4
0
        public CodeCompletionResult GetCompletions(IDocument document, int offset, bool controlSpace, string usings, string variables = null)
        {
            var result = new CodeCompletionResult();

            if (String.IsNullOrEmpty(document.FileName))
            {
                return(result);
            }

            var completionContext = new CSharpCompletionContext(document, offset, projectContent, usings, variables);

            var completionFactory = new CSharpCompletionDataFactory(completionContext.TypeResolveContextAtCaret, completionContext);
            var cce = new CSharpCompletionEngine(
                completionContext.Document,
                completionContext.CompletionContextProvider,
                completionFactory,
                completionContext.ProjectContent,
                completionContext.TypeResolveContextAtCaret
                );

            cce.EolMarker        = Environment.NewLine;
            cce.FormattingPolicy = FormattingOptionsFactory.CreateSharpDevelop();


            var completionChar = completionContext.Document.GetCharAt(completionContext.Offset - 1);
            int startPos, triggerWordLength;
            IEnumerable <ICSharpCode.NRefactory.Completion.ICompletionData> completionData;

            if (controlSpace)
            {
                if (!cce.TryGetCompletionWord(completionContext.Offset, out startPos, out triggerWordLength))
                {
                    startPos          = completionContext.Offset;
                    triggerWordLength = 0;
                }
                completionData = cce.GetCompletionData(startPos, true);
                //this outputs tons of available entities
                //if (triggerWordLength == 0)
                //    completionData = completionData.Concat(cce.GetImportCompletionData(startPos));
            }
            else
            {
                startPos = completionContext.Offset;

                if (char.IsLetterOrDigit(completionChar) || completionChar == '_')
                {
                    if (startPos > 1 && char.IsLetterOrDigit(completionContext.Document.GetCharAt(startPos - 2)))
                    {
                        return(result);
                    }
                    completionData = cce.GetCompletionData(startPos, false);
                    startPos--;
                    triggerWordLength = 1;
                }
                else
                {
                    completionData    = cce.GetCompletionData(startPos, false);
                    triggerWordLength = 0;
                }
            }

            result.TriggerWordLength = triggerWordLength;
            result.TriggerWord       = completionContext.Document.GetText(completionContext.Offset - triggerWordLength, triggerWordLength);
            Debug.Print("Trigger word: '{0}'", result.TriggerWord);

            //cast to AvalonEdit completion data and add to results
            foreach (var completion in completionData)
            {
                var cshellCompletionData = completion as ICSharpCode.CodeCompletion.DataItems.CompletionData;
                if (cshellCompletionData != null)
                {
                    cshellCompletionData.TriggerWord       = result.TriggerWord;
                    cshellCompletionData.TriggerWordLength = result.TriggerWordLength;

                    if (completion is ICSharpCode.CodeCompletion.DataItems.EntityCompletionData)
                    {
                        string typename = String.Empty;

                        var entity = cshellCompletionData as ICSharpCode.CodeCompletion.DataItems.EntityCompletionData;

                        if (entity.Entity is ICSharpCode.NRefactory.TypeSystem.Implementation.DefaultResolvedTypeDefinition)
                        {
                            var def = entity.Entity as ICSharpCode.NRefactory.TypeSystem.Implementation.DefaultResolvedTypeDefinition;

                            typename = def.FullTypeName.ReflectionName;
                        }
                        else
                        {
                            typename = entity.Entity.DeclaringType.FullName;
                        }

                        Type type = Type.GetType(typename);

                        if (!AllowedType(type))
                        {
                            continue;
                        }
                    }

                    result.CompletionData.Add(cshellCompletionData);

                    // piggyback 'region' preprocessor to add our own
                    if (cshellCompletionData.DisplayText == "region")
                    {
                        DataItems.CompletionData import = new DataItems.CompletionData("import");
                        import.CompletionCategory = cshellCompletionData.CompletionCategory;
                        import.Image = cshellCompletionData.Image;
                        result.CompletionData.Add(import);
                    }
                }
            }

            //method completions
            if (!controlSpace)
            {
                // Method Insight
                var pce = new CSharpParameterCompletionEngine(
                    completionContext.Document,
                    completionContext.CompletionContextProvider,
                    completionFactory,
                    completionContext.ProjectContent,
                    completionContext.TypeResolveContextAtCaret
                    );

                var parameterDataProvider = pce.GetParameterDataProvider(completionContext.Offset, completionChar);
                result.OverloadProvider = parameterDataProvider as IOverloadProvider;
            }

            return(result);
        }
        public CodeCompletionResult GetCompletions(IDocument document, int offset, bool controlSpace, string usings, string variables)
        {
            var result = new CodeCompletionResult();

            if (String.IsNullOrEmpty(document.FileName))
                return result;

            var completionContext = new CSharpCompletionContext(document, offset, projectContent, usings, variables);

            var completionFactory = new CSharpCompletionDataFactory(completionContext.TypeResolveContextAtCaret, completionContext);
            var cce = new CSharpCompletionEngine(
                completionContext.Document,
                completionContext.CompletionContextProvider,
                completionFactory,
                completionContext.ProjectContent,
                completionContext.TypeResolveContextAtCaret
                );

            cce.EolMarker = Environment.NewLine;
            cce.FormattingPolicy = FormattingOptionsFactory.CreateSharpDevelop();


            var completionChar = completionContext.Document.GetCharAt(completionContext.Offset - 1);
            int startPos, triggerWordLength;
            IEnumerable<ICSharpCode.NRefactory.Completion.ICompletionData> completionData;
            if (controlSpace)
            {
                if (!cce.TryGetCompletionWord(completionContext.Offset, out startPos, out triggerWordLength))
                {
                    startPos = completionContext.Offset;
                    triggerWordLength = 0;
                }
                completionData = cce.GetCompletionData(startPos, true);
                //this outputs tons of available entities
                //if (triggerWordLength == 0)
                //    completionData = completionData.Concat(cce.GetImportCompletionData(startPos));
            }
            else
            {
                startPos = completionContext.Offset;

                if (char.IsLetterOrDigit(completionChar) || completionChar == '_')
                {
                    if (startPos > 1 && char.IsLetterOrDigit(completionContext.Document.GetCharAt(startPos - 2)))
                        return result;
                    completionData = cce.GetCompletionData(startPos, false);
                    startPos--;
                    triggerWordLength = 1;
                }
                else
                {
                    completionData = cce.GetCompletionData(startPos, false);
                    triggerWordLength = 0;
                }
            }

            result.TriggerWordLength = triggerWordLength;
            result.TriggerWord = completionContext.Document.GetText(completionContext.Offset - triggerWordLength, triggerWordLength);
            Debug.Print("Trigger word: '{0}'", result.TriggerWord);

            //cast to AvalonEdit completion data and add to results
            foreach (var completion in completionData)
            {
                var cshellCompletionData = completion as ICSharpCode.CodeCompletion.DataItems.CompletionData;
                if (cshellCompletionData != null)
                {
                    cshellCompletionData.TriggerWord = result.TriggerWord;
                    cshellCompletionData.TriggerWordLength = result.TriggerWordLength;
                    result.CompletionData.Add(cshellCompletionData);
                }
            }

            //method completions
            if (!controlSpace)
            {
                // Method Insight
                var pce = new CSharpParameterCompletionEngine(
                    completionContext.Document,
                    completionContext.CompletionContextProvider,
                    completionFactory,
                    completionContext.ProjectContent,
                    completionContext.TypeResolveContextAtCaret
                );

                var parameterDataProvider = pce.GetParameterDataProvider(completionContext.Offset, completionChar);
                result.OverloadProvider = parameterDataProvider as IOverloadProvider;
            }

            return result;
        }
 public CSharpCompletionDataFactory(CSharpTypeResolveContext contextAtCaret, CSharpCompletionContext context)
 {
     Debug.Assert(contextAtCaret != null);
     this.contextAtCaret = contextAtCaret;
     this.context = context;
 }
        public CodeCompletionResult GetCompletions(IDocument document, int offset, bool controlSpace, string usings, string variables)
        {
            var result = new CodeCompletionResult();

            if (String.IsNullOrEmpty(document.FileName))
            {
                return(result);
            }

            var completionContext = new CSharpCompletionContext(document, offset, projectContent, usings, variables);

            var completionFactory = new CSharpCompletionDataFactory(completionContext.TypeResolveContextAtCaret, completionContext);
            var cce = new CSharpCompletionEngine(
                completionContext.Document,
                completionContext.CompletionContextProvider,
                completionFactory,
                completionContext.ProjectContent,
                completionContext.TypeResolveContextAtCaret
                );

            cce.EolMarker        = Environment.NewLine;
            cce.FormattingPolicy = FormattingOptionsFactory.CreateSharpDevelop();


            var completionChar = completionContext.Document.GetCharAt(completionContext.Offset - 1);
            int startPos, triggerWordLength;
            IEnumerable <ICSharpCode.NRefactory.Completion.ICompletionData> completionData;

            if (controlSpace)
            {
                if (!cce.TryGetCompletionWord(completionContext.Offset, out startPos, out triggerWordLength))
                {
                    startPos          = completionContext.Offset;
                    triggerWordLength = 0;
                }
                completionData = cce.GetCompletionData(startPos, true);
                //this outputs tons of available entities
                //if (triggerWordLength == 0)
                //    completionData = completionData.Concat(cce.GetImportCompletionData(startPos));
            }
            else
            {
                startPos = completionContext.Offset;

                if (char.IsLetterOrDigit(completionChar) || completionChar == '_')
                {
                    if (startPos > 1 && char.IsLetterOrDigit(completionContext.Document.GetCharAt(startPos - 2)))
                    {
                        return(result);
                    }
                    completionData = cce.GetCompletionData(startPos, false);
                    startPos--;
                    triggerWordLength = 1;
                }
                else
                {
                    completionData    = cce.GetCompletionData(startPos, false);
                    triggerWordLength = 0;
                }
            }

            result.TriggerWordLength = triggerWordLength;
            result.TriggerWord       = completionContext.Document.GetText(completionContext.Offset - triggerWordLength, triggerWordLength);
            Debug.Print("Trigger word: '{0}'", result.TriggerWord);

            //cast to AvalonEdit completion data and add to results
            foreach (var completion in completionData)
            {
                var cshellCompletionData = completion as ICSharpCode.CodeCompletion.DataItems.CompletionData;
                if (cshellCompletionData != null)
                {
                    cshellCompletionData.TriggerWord       = result.TriggerWord;
                    cshellCompletionData.TriggerWordLength = result.TriggerWordLength;
                    result.CompletionData.Add(cshellCompletionData);
                }
            }

            //method completions
            if (!controlSpace)
            {
                // Method Insight
                var pce = new CSharpParameterCompletionEngine(
                    completionContext.Document,
                    completionContext.CompletionContextProvider,
                    completionFactory,
                    completionContext.ProjectContent,
                    completionContext.TypeResolveContextAtCaret
                    );

                var parameterDataProvider = pce.GetParameterDataProvider(completionContext.Offset, completionChar);
                result.OverloadProvider = parameterDataProvider as IOverloadProvider;
            }

            return(result);
        }
Example #8
0
        public void Update(IDocument document, int offset)
        {
            var completionContext = new CSharpCompletionContext(document, offset, context.ProjectContent, context.OriginalUsings, context.OriginalVariables, context.OriginalNamespace);

            Update(completionContext);
        }
Example #9
0
 public CSharpCompletionDataFactory(CSharpTypeResolveContext contextAtCaret, CSharpCompletionContext context)
 {
     Debug.Assert(contextAtCaret != null);
     this.contextAtCaret = contextAtCaret;
     this.context        = context;
 }
        public void Update(CSharpCompletionContext completionContext)
        {
            var completionFactory = new CSharpCompletionDataFactory(completionContext.TypeResolveContextAtCaret, completionContext);
            var pce = new CSharpParameterCompletionEngine(
                completionContext.Document,
                completionContext.CompletionContextProvider,
                completionFactory,
                completionContext.ProjectContent,
                completionContext.TypeResolveContextAtCaret
            );

            var completionChar = completionContext.Document.GetCharAt(completionContext.Offset - 1);
            var docText = completionContext.Document.Text;
            Debug.Print("Update Completion char: '{0}'", completionChar);
            int parameterIndex = pce.GetCurrentParameterIndex(startOffset, completionContext.Offset);
            if (parameterIndex < 0)
            {
                RequestClose = true;
                return;
            }
            else
            {
                if (parameterIndex > items[selectedIndex].Method.Parameters.Count)
                {
                    var newItem = items.FirstOrDefault(i => parameterIndex <= i.Method.Parameters.Count);
                    SelectedIndex = items.IndexOf(newItem);
                }
                if (parameterIndex > 0)
                    parameterIndex--; // NR returns 1-based parameter index
                foreach (var item in items)
                {
                    item.HighlightParameter(parameterIndex);
                }
            }
        }
 public void Update(IDocument document, int offset)
 {
     var completionContext = new CSharpCompletionContext(document, offset, context.ProjectContent, context.OriginalUsings, context.OriginalVariables);
     Update(completionContext);
 }
Example #12
0
        public CodeCompletionResult GetCompletions(IDocument document, int offset, bool controlSpace, string usings, string variables = null)
        {
            var result = new CodeCompletionResult();

            if (String.IsNullOrEmpty(document.FileName))
                return result;

            var completionContext = new CSharpCompletionContext(document, offset, projectContent, usings, variables);

            var completionFactory = new CSharpCompletionDataFactory(completionContext.TypeResolveContextAtCaret, completionContext);
            var cce = new CSharpCompletionEngine(
                completionContext.Document,
                completionContext.CompletionContextProvider,
                completionFactory,
                completionContext.ProjectContent,
                completionContext.TypeResolveContextAtCaret
                );

            cce.EolMarker = Environment.NewLine;
            cce.FormattingPolicy = FormattingOptionsFactory.CreateSharpDevelop();

            var completionChar = completionContext.Document.GetCharAt(completionContext.Offset - 1);
            int startPos, triggerWordLength;
            IEnumerable<ICSharpCode.NRefactory.Completion.ICompletionData> completionData;
            if (controlSpace)
            {
                if (!cce.TryGetCompletionWord(completionContext.Offset, out startPos, out triggerWordLength))
                {
                    startPos = completionContext.Offset;
                    triggerWordLength = 0;
                }
                completionData = cce.GetCompletionData(startPos, true);
                //this outputs tons of available entities
                //if (triggerWordLength == 0)
                //    completionData = completionData.Concat(cce.GetImportCompletionData(startPos));
            }
            else
            {
                startPos = completionContext.Offset;

                if (char.IsLetterOrDigit(completionChar) || completionChar == '_')
                {
                    if (startPos > 1 && char.IsLetterOrDigit(completionContext.Document.GetCharAt(startPos - 2)))
                        return result;
                    completionData = cce.GetCompletionData(startPos, false);
                    startPos--;
                    triggerWordLength = 1;
                }
                else
                {
                    completionData = cce.GetCompletionData(startPos, false);
                    triggerWordLength = 0;
                }
            }

            result.TriggerWordLength = triggerWordLength;
            result.TriggerWord = completionContext.Document.GetText(completionContext.Offset - triggerWordLength, triggerWordLength);
            Debug.Print("Trigger word: '{0}'", result.TriggerWord);

            //cast to AvalonEdit completion data and add to results
            foreach (var completion in completionData)
            {
                var cshellCompletionData = completion as ICSharpCode.CodeCompletion.DataItems.CompletionData;
                if (cshellCompletionData != null)
                {
                    cshellCompletionData.TriggerWord = result.TriggerWord;
                    cshellCompletionData.TriggerWordLength = result.TriggerWordLength;

                    if (completion is ICSharpCode.CodeCompletion.DataItems.EntityCompletionData)
                    {
                        string typename = String.Empty;

                        var entity = cshellCompletionData as ICSharpCode.CodeCompletion.DataItems.EntityCompletionData;

                        if (entity.Entity is ICSharpCode.NRefactory.TypeSystem.Implementation.DefaultResolvedTypeDefinition)
                        {
                            var def = entity.Entity as ICSharpCode.NRefactory.TypeSystem.Implementation.DefaultResolvedTypeDefinition;

                            typename = def.FullTypeName.ReflectionName;
                        }
                        else
                        {
                            typename = entity.Entity.DeclaringType.FullName;
                        }

                        Type type = Type.GetType(typename);

                        if (!AllowedType(type))
                        {
                            continue;
                        }
                    }

                    result.CompletionData.Add(cshellCompletionData);

                    // piggyback 'region' preprocessor to add our own
                    if (cshellCompletionData.DisplayText == "region")
                    {
                        DataItems.CompletionData import = new DataItems.CompletionData("import");
                        import.CompletionCategory = cshellCompletionData.CompletionCategory;
                        import.Image = cshellCompletionData.Image;
                        result.CompletionData.Add(import);
                    }
                }
            }

            //method completions
            if (!controlSpace)
            {
                // Method Insight
                var pce = new CSharpParameterCompletionEngine(
                    completionContext.Document,
                    completionContext.CompletionContextProvider,
                    completionFactory,
                    completionContext.ProjectContent,
                    completionContext.TypeResolveContextAtCaret
                );

                var parameterDataProvider = pce.GetParameterDataProvider(completionContext.Offset, completionChar);
                result.OverloadProvider = parameterDataProvider as IOverloadProvider;
            }

            return result;
        }