Exemplo n.º 1
0
        public CodeEditor()
        {
            this._sourceCodeName = @"D:\llvm\tools\clang\tools\driver\driver.cpp";
            this.code            = System.IO.File.ReadAllText(this._sourceCodeName);
            this.AppendText(code);

            //var indexAction = index.CreateIndexAction(new IndexActionEventHandler());
            string includes            = @"-ID:\llvm\build\tools\clang\tools\driver -ID:\llvm\tools\clang\tools\driver -ID:\llvm\tools\clang\include -ID:\llvm\build\tools\clang\include -ID:\llvm\build\include -ID:\llvm\include -emit-ast";
            var    splitedStringArrays = includes.Split(' ');
            string astFileName         = "d:\test.ast";

            //indexAction.Index(tu, LibClang.Intertop.CXIndexOptFlags.CXIndexOpt_IndexFunctionLocalSymbols);

            this.task = new Task(() =>
            {
                this.index = new Index(true, true);
                this.index.GlobalOptFlags = LibClang.Intertop.CXGlobalOptFlags.CXGlobalOpt_ThreadBackgroundPriorityForEditing;
                CXErrorCode xErrorCode    = CXErrorCode.CXError_Success;
                if (System.IO.File.Exists(astFileName))
                {
                    this.translationUnit = index.CreateTranslationUnit(astFileName);
                }
                else
                {
                    this.translationUnit = index.Parse(this._sourceCodeName, splitedStringArrays, null,
                                                       CXTranslationUnit_Flags.CXTranslationUnit_DetailedPreprocessingRecord |
                                                       CXTranslationUnit_Flags.CXTranslationUnit_Incomplete |
                                                       CXTranslationUnit_Flags.CXTranslationUnit_IncludeBriefCommentsInCodeCompletion |
                                                       CXTranslationUnit_Flags.CXTranslationUnit_CreatePreambleOnFirstParse |
                                                       CXTranslationUnit_Flags.CXTranslationUnit_KeepGoing |
                                                       Clang.DefaultEditingTranslationUnitOptions

                                                       ,
                                                       out xErrorCode);

                    this.translationUnit.Save(astFileName, CXSaveTranslationUnit_Flags.CXSaveTranslationUnit_None);
                }

                while (true)
                {
                    this.autoResetEvent.WaitOne();
                    var unsavedFile = new UnsavedFile[] { new UnsavedFile(this._sourceCodeName, this.code) };
                    this.translationUnit.Reparse(unsavedFile, LibClang.Intertop.CXReparse_Flags.CXReparse_None);
                    CodeCompleteResults codeCompleteResults = this.translationUnit.CodeCompleteAt(this._sourceCodeName,
                                                                                                  (uint)this.line,
                                                                                                  (uint)this.column,
                                                                                                  unsavedFile,
                                                                                                  Clang.DefaultCodeCompleteFlags |
                                                                                                  CXCodeComplete_Flags.CXCodeComplete_IncludeBriefComments |
                                                                                                  CXCodeComplete_Flags.CXCodeComplete_IncludeCodePatterns |
                                                                                                  CXCodeComplete_Flags.CXCodeComplete_IncludeCompletionsWithFixIts
                                                                                                  );
                    codeCompleteResults.Sort();
                    this.autoResetEvent.Reset();

                    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        this.completions.Clear();
                        foreach (var item in codeCompleteResults.CompletionResults)
                        {
                            foreach (var chunk in item.Chunks)
                            {
                                this.completions.Add(chunk.CompletionChunkKind + ":" + chunk.Text);
                                foreach (var cChunk in chunk.Chunks)
                                {
                                    this.completions.Add(cChunk.Text);
                                }
                            }
                            this.completions.Add("-------------------------------------------------------------------------");
                        }
                    }));
                }
            });
            this.task.Start();
        }
Exemplo n.º 2
0
 public unsafe static extern uint clang_codeCompleteGetNumDiagnostics(CodeCompleteResults* results);
Exemplo n.º 3
0
 public unsafe static extern IntPtr clang_codeCompleteGetDiagnostic(CodeCompleteResults* results, uint index);
Exemplo n.º 4
0
 public unsafe static extern void clang_disposeCodeCompleteResults(CodeCompleteResults* results);