public override Task <ICompletionDataList> HandleCodeCompletionAsync(CodeCompletionContext completionContext, CompletionTriggerInfo triggerInfo, CancellationToken token = default(CancellationToken))
        {
            var project = (CProject)DocumentContext.Project;

            if (project == null || !project.HasLibClang)
            {
                return(Task.FromResult((ICompletionDataList)null));
            }

            return(Task.Run(() => {
                var completionChar = triggerInfo.TriggerCharacter ?? ' ';
                ICompletionDataList list = new CompletionDataList();
                if (ShouldCompleteOn(completionChar))
                {
                    unsavedFiles = project.UnsavedFiles.Get();
                    bool fieldOrMethodMode = completionChar == '.' || completionChar == '>' ? true : false;
                    IntPtr pResults = project.ClangManager.CodeComplete(completionContext, unsavedFiles.ToArray(), DocumentContext.Name);
                    if (pResults.ToInt64() != 0)
                    {
                        CXCodeCompleteResults results = Marshal.PtrToStructure <CXCodeCompleteResults> (pResults);
                        for (int i = 0; i < results.NumResults; i++)
                        {
                            IntPtr iteratingPointer = results.Results + i * Marshal.SizeOf <CXCompletionResult> ();
                            CXCompletionResult resultItem = Marshal.PtrToStructure <CXCompletionResult> (iteratingPointer);
                            foreach (var cd in GetCompletionUnits(resultItem, operatorFilter, fieldOrMethodMode))
                            {
                                list.Add(cd);
                            }
                        }
                    }
                    clang.disposeCodeCompleteResults(pResults);
                }
                previous = completionChar;
                list.Sort((x, y) => x.CompareTo(y));
                return list;
            }, token));
        }
        /// <summary>
        /// Handles the parameter completion async. Invoked automatically on every keypress.
        /// Contains scenarios for veeery perverted codes like: classInstancePointer    ->
        /// classmethod  ( (	new tempClass<int>{ 1 , 2 , 3 }  ) , (new int[1]{})) , but might be not ready for everything.
        /// </summary>
        /// <returns>The parameter completion async.</returns>
        /// <param name="completionContext">Completion context.</param>
        /// <param name="completionChar">Completion char.</param>
        /// <param name="token">Token.</param>s
        public override Task <ParameterHintingResult> HandleParameterCompletionAsync(
            CodeCompletionContext completionContext,
            char completionChar,
            CancellationToken token = default(CancellationToken))
        {
            if (completionChar != '(' && completionChar != ',')
            {
                return(Task.FromResult((ParameterHintingResult)null));
            }

            var project = (CProject)DocumentContext.Project;

            if (project == null || !project.HasLibClang)
            {
                return(Task.FromResult((ParameterHintingResult)null));
            }

            return(Task.Run(() => {
                #region NEEDED_FOR_STARTOFFSET_:(

                int inParenthesis = 0;
                int nameEnd = completionContext.TriggerOffset - 1;
                char endChar = Editor.GetCharAt(nameEnd);
                char prevChar = Editor.GetCharAt(nameEnd - 1);
                while (!(prevChar != '(' && endChar == '(' && inParenthesis <= 0) &&             //multiple '('
                       nameEnd > 1)
                {
                    switch (endChar)
                    {
                    case ')':
                        inParenthesis++;
                        break;

                    case '(':
                        inParenthesis--;
                        break;
                    }
                    endChar = Editor.GetCharAt(--nameEnd);
                    prevChar = Editor.GetCharAt(nameEnd - 1);
                }

                WorkaroundWhitespaces(ref prevChar, ref nameEnd);
                WorkaroundTemplateSpecifier(ref prevChar, ref nameEnd);
                WorkaroundWhitespaces(ref prevChar, ref nameEnd);

                int nameStart = nameEnd - 1;
                //the actual name getting, march backwards while not a ., ->, space etc.
                while (!allowedChars.Contains(prevChar) && nameStart > 1)
                {
                    nameStart--;
                    prevChar = Editor.GetCharAt(nameStart - 1);
                }
                string functionName = Editor.Text.Substring(nameStart, nameEnd - nameStart);

                #endregion

                if (string.IsNullOrEmpty(functionName))
                {
                    return (ParameterHintingResult)null;
                }
                unsavedFiles = project.UnsavedFiles.Get();

                IntPtr pResults = project.ClangManager.CodeComplete(completionContext, unsavedFiles.ToArray(), DocumentContext.Name);
                CXCodeCompleteResults results = Marshal.PtrToStructure <CXCodeCompleteResults> (pResults);

                if (results.Results.ToInt64() != 0)
                {
                    var parameterInformation = new List <OverloadCandidate> ();
                    for (int i = 0; i < results.NumResults; i++)
                    {
                        IntPtr iteratingPointer = results.Results + i * Marshal.SizeOf <CXCompletionResult> ();
                        CXCompletionResult resultItem = Marshal.PtrToStructure <CXCompletionResult> (iteratingPointer);

                        if (resultItem.CursorKind == CXCursorKind.@OverloadCandidate)
                        {
                            parameterInformation.Add(GetOverloadCandidate(resultItem));
                        }
                    }
                    clang.disposeCodeCompleteResults(pResults);
                    return (ParameterHintingResult) new ParameterDataProvider(nameStart, parameterInformation);
                }
                return (ParameterHintingResult)null;
            }, token));
        }
Exemplo n.º 3
0
 internal unsafe static extern Int64 clang_codeCompleteGetContexts(CXCodeCompleteResults* results);
Exemplo n.º 4
0
 internal unsafe static extern CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults* results, uint Index);
Exemplo n.º 5
0
 internal unsafe static extern uint clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults* results);
Exemplo n.º 6
0
 internal unsafe static extern void clang_disposeCodeCompleteResults(CXCodeCompleteResults* r);