private void ReadHeaders() { using (var index = new Index()) { while (headerQueue.Any()) { _context.HeaderFilename = headerQueue.First(); Console.Write('.'); var unsavedFiles = new UnsavedFile[] {}; using (_context.TranslationUnit = index.CreateTranslationUnit(_context.HeaderFilename, clangOptions.ToArray(), unsavedFiles, TranslationUnitFlags.SkipFunctionBodies)) { var cur = _context.TranslationUnit.Cursor; cur.VisitChildren(HeaderVisitor); } _context.TranslationUnit = null; headerQueue.Remove(_context.HeaderFilename); } } Console.WriteLine(); Console.WriteLine("Read complete - headers: {0}, classes: {1}", project.HeaderDefinitions.Count, project.ClassDefinitions.Count); }
public void UnRegisterLanguageService() { ShutdownBackgroundWorkers(); UnsavedFile unsavedFile = null; lock (UnsavedFiles) { unsavedFile = UnsavedFiles.BinarySearch(ProjectFile.Location); } if (unsavedFile != null) { lock (UnsavedFiles) { UnsavedFiles.Remove(unsavedFile); } } if (LanguageService != null && ProjectFile != null) { LanguageService.UnregisterSourceFile(Editor, ProjectFile); } TextDocument.TextChanged -= TextDocument_TextChanged; }
private void TextDocument_TextChanged(object sender, EventArgs e) { UnsavedFile unsavedFile = null; lock (UnsavedFiles) { unsavedFile = UnsavedFiles.BinarySearch(ProjectFile.Location); } if (unsavedFile == null) { lock (UnsavedFiles) { UnsavedFiles.InsertSorted(new UnsavedFile(ProjectFile.Location, TextDocument.Text)); } } else { unsavedFile.Contents = TextDocument.Text; } IsDirty = true; TextChanged?.Invoke(this, new EventArgs()); }
public async Task <SignatureHelp> SignatureHelp(ISourceFile file, UnsavedFile buffer, List <UnsavedFile> unsavedFiles, int line, int column, int offset, string methodName) { SignatureHelp result = null; var clangUnsavedFiles = new List <ClangUnsavedFile>(); unsavedFiles.Add(buffer); foreach (var unsavedFile in unsavedFiles) { if (Platform.CompareFilePath(unsavedFile.FileName, buffer.FileName) != 0) { clangUnsavedFiles.Add(new ClangUnsavedFile(unsavedFile.FileName, unsavedFile.Contents)); } } var symbols = await GetSymbolsAsync(file, unsavedFiles, methodName); if (symbols.Count > 0) { result = new SignatureHelp(); result.Offset = offset; foreach (var symbol in symbols) { result.Signatures.Add(SignatureFromSymbol(symbol)); } } return(result); }
public Task <SignatureHelp> SignatureHelp(ISourceFile file, UnsavedFile buffer, List <UnsavedFile> unsavedFiles, int line, int column, int offset, string methodName) { //STUB! //return new SignatureHelp(); return(Task.FromResult <SignatureHelp>(null)); }
public void Save() { if (ProjectFile != null && TextDocument != null && IsDirty) { System.IO.File.WriteAllText(ProjectFile.Location, TextDocument.Text); IsDirty = false; if (unsavedFile != null) { UnsavedFiles.Remove(unsavedFile); unsavedFile = null; } } }
private void UnRegisterLanguageService() { _languageServiceDisposables?.Dispose(); if (_scopeLineBackgroundRenderer != null) { TextArea.TextView.BackgroundRenderers.Remove(_scopeLineBackgroundRenderer); } if (_textColorizer != null) { TextArea.TextView.LineTransformers.Remove(_textColorizer); _textColorizer = null; } if (_diagnosticMarkersRenderer != null) { TextArea.TextView.BackgroundRenderers.Remove(_diagnosticMarkersRenderer); _diagnosticMarkersRenderer = null; } ShutdownBackgroundWorkers(); UnsavedFile unsavedFile = null; lock (UnsavedFiles) { unsavedFile = UnsavedFiles.BinarySearch(SourceFile.Location); } if (unsavedFile != null) { lock (UnsavedFiles) { UnsavedFiles.Remove(unsavedFile); } } if (LanguageService != null) { LanguageService.UnregisterSourceFile(DocumentAccessor); } Document.TextChanged -= TextDocument_TextChanged; TextArea.TextEntering -= TextArea_TextEntering; TextArea.TextEntered -= TextArea_TextEntered; _intellisenseManager = null; }
void ReadHeader(string headerFile) { Console.Write('.'); var unsavedFiles = new UnsavedFile[] { }; using (_context.TranslationUnit = index.CreateTranslationUnit(headerFile, clangOptions.ToArray(), unsavedFiles, TranslationUnitFlags.SkipFunctionBodies)) { var cur = _context.TranslationUnit.Cursor; _context.Namespace = ""; cur.VisitChildren(HeaderVisitor); } _context.TranslationUnit = null; headerQueue.Remove(headerFile); }
public void UnRegisterLanguageService() { ShutdownBackgroundWorkers(); if (unsavedFile != null) { UnsavedFiles.Remove(unsavedFile); unsavedFile = null; } if (LanguageService != null && ProjectFile != null) { LanguageService.UnregisterSourceFile(Editor, ProjectFile); } }
public void TestMemberCompletion() { const string completionLine = "instance."; const string edited = "#include <iostream>\n" + "#include \"fake-class.h\"\n" + "int main() {\n" + "FakeClass instance;\n" + completionLine + "\n" + "}\n"; var unsavedFile = new UnsavedFile(edited, MainCpp, edited.Length); uint line = (uint)edited.Substring(0, edited.IndexOf(completionLine)).Count(character => character == '\n') + 1; uint column = (uint)completionLine.Length + 1; var completions = Main.CodeCompleteAt(line, column, new[] { unsavedFile }, CodeCompletion.Options.IncludeBriefComments).OrderBy(completion => completion.Priority).Take(10); Assert.AreEqual(5, completions.Count()); }
public static void CreateTestFiles() { System.IO.File.WriteAllText(FakeClassCpp, Resources.fake_class_cpp); System.IO.File.WriteAllText(FakeClassH, Resources.fake_class_h); System.IO.File.WriteAllText(OpaqueClassH, Resources.opaque_class_h); System.IO.File.WriteAllText(MainCpp, Resources.fake_main_cpp); System.IO.File.WriteAllText(KitchenSinkCpp, Resources.kitchen_sink); var args = new[] { Options.Weverything }; var unsavedFiles = new UnsavedFile[] { }; var options = TranslationUnitFlags.IncludeBriefCommentsInCodeCompletion | TranslationUnitFlags.DetailedPreprocessingRecord; Index = new Index(); Main = Index.CreateTranslationUnit(MainCpp, args, unsavedFiles, options); Class = Index.CreateTranslationUnit(FakeClassCpp, args, unsavedFiles, options); KitchenSink = Index.CreateTranslationUnit(KitchenSinkCpp, args, unsavedFiles, options); }
public async Task <SignatureHelp> SignatureHelp(ISourceFile file, UnsavedFile buffer, List <UnsavedFile> unsavedFiles, int line, int column, int offset, string methodName) { SignatureHelp result = null; var dataAssociation = GetAssociatedData(file); result = await dataAssociation.Solution.Server.SignatureHelp(file.FilePath, unsavedFiles.FirstOrDefault()?.Contents, line, column); if (result != null) { result.NormalizeSignatureData(); result.Offset = offset; } return(result); }
private void ParseHeader(HeaderDefinition header) { _context.Header = header; var unsavedFiles = new UnsavedFile[] { }; using (_context.TranslationUnit = _context.Index.CreateTranslationUnit( header.FullPath, GetClangOptions(), unsavedFiles, TranslationUnitFlags.SkipFunctionBodies)) { var tuCursor = _context.TranslationUnit.Cursor; tuCursor.VisitChildren(HeaderVisitor); _context.TranslationUnit = null; } _context.Header = null; }
public void UnRegisterLanguageService() { if (_scopeLineBackgroundRenderer != null) { TextArea.TextView.BackgroundRenderers.Remove(_scopeLineBackgroundRenderer); } if (_textColorizer != null) { TextArea.TextView.LineTransformers.Remove(_textColorizer); _textColorizer = null; } if (_diagnosticMarkersRenderer != null) { TextArea.TextView.BackgroundRenderers.Remove(_diagnosticMarkersRenderer); _diagnosticMarkersRenderer = null; } ShutdownBackgroundWorkers(); UnsavedFile unsavedFile = null; lock (UnsavedFiles) { unsavedFile = UnsavedFiles.BinarySearch(SourceFile.Location); } if (unsavedFile != null) { lock (UnsavedFiles) { UnsavedFiles.Remove(unsavedFile); } } if (LanguageService != null) { LanguageService.UnregisterSourceFile(this, SourceFile); } Document.TextChanged -= TextDocument_TextChanged; }
public void UnsavedFiles_Can_Be_Binary_Searched() { List<UnsavedFile> UnsavedFiles = new List<UnsavedFile>(); var expected1 = new UnsavedFile("c:\\abc/", "my contents"); var expected2 = new UnsavedFile("c:/ghi/", "my contents"); UnsavedFiles.InsertSorted(new UnsavedFile("C:\\hij/", "my contents")); UnsavedFiles.InsertSorted(new UnsavedFile("c:\\bcd", "my contents")); UnsavedFiles.InsertSorted(expected1); UnsavedFiles.InsertSorted(expected2); UnsavedFiles.InsertSorted(new UnsavedFile("c:\\cde\\", "my contents")); UnsavedFiles.InsertSorted(new UnsavedFile("C:\\fgh", "my contents")); var found = UnsavedFiles.BinarySearch("c:\\abc"); Assert.Equal(expected1, found); found = UnsavedFiles.BinarySearch("c:\\ghi"); Assert.Equal(expected2, found); }
private void TextDocument_TextChanged(object sender, EventArgs e) { if (unsavedFile == null) { unsavedFile = new UnsavedFile(ProjectFile.Location, TextDocument.Text); UnsavedFiles.Add(unsavedFile); } else { unsavedFile.Contents = TextDocument.Text; } IsDirty = true; if (TextChanged != null) { TextChanged(this, new EventArgs()); } }
public void UnsavedFiles_Can_Be_Binary_Searched() { List <UnsavedFile> unsavedFiles = new List <UnsavedFile>(); var expected1 = new UnsavedFile("c:\\abc/", "my contents"); var expected2 = new UnsavedFile("c:/ghi/", "my contents"); unsavedFiles.InsertSorted(new UnsavedFile("C:\\hij/", "my contents")); unsavedFiles.InsertSorted(new UnsavedFile("c:\\bcd", "my contents")); unsavedFiles.InsertSorted(expected1); unsavedFiles.InsertSorted(expected2); unsavedFiles.InsertSorted(new UnsavedFile("c:\\cde\\", "my contents")); unsavedFiles.InsertSorted(new UnsavedFile("C:\\fgh", "my contents")); var found = unsavedFiles.BinarySearch("c:\\abc"); Assert.Equal(expected1, found); found = unsavedFiles.BinarySearch("c:\\ghi"); Assert.Equal(expected2, found); }
private void TextDocument_TextChanged(object sender, EventArgs e) { UnsavedFile unsavedFile = null; lock (UnsavedFiles) { unsavedFile = UnsavedFiles.BinarySearch(SourceFile.Location); } if (unsavedFile == null) { lock (UnsavedFiles) { UnsavedFiles.InsertSorted(new UnsavedFile(SourceFile.Location, Document.Text)); } } else { unsavedFile.Contents = Document.Text; } }
public void UnRegisterLanguageService() { foreach (var backgroundRenderer in _languageServiceBackgroundRenderers) { TextArea.TextView.BackgroundRenderers.Remove(backgroundRenderer); } _languageServiceBackgroundRenderers.Clear(); foreach (var transformer in _languageServiceDocumentLineTransformers) { TextArea.TextView.LineTransformers.Remove(transformer); } _languageServiceDocumentLineTransformers.Clear(); ShutdownBackgroundWorkers(); UnsavedFile unsavedFile = null; lock (UnsavedFiles) { unsavedFile = UnsavedFiles.BinarySearch(SourceFile.Location); } if (unsavedFile != null) { lock (UnsavedFiles) { UnsavedFiles.Remove(unsavedFile); } } if (LanguageService != null) { LanguageService.UnregisterSourceFile(this, SourceFile); } Document.TextChanged -= TextDocument_TextChanged; }
void ReadHeader(string headerFile) { Console.Write('.'); var unsavedFiles = new UnsavedFile[] { }; if (headerFile.EndsWith("PosixThreadSupport.h")) { List <string> clangOptionsPThread = new List <string>(clangOptions); clangOptionsPThread.Add("-DUSE_PTHREADS"); currentTU = index.CreateTranslationUnit(headerFile, clangOptionsPThread.ToArray(), unsavedFiles, TranslationUnitFlags.SkipFunctionBodies); } else { currentTU = index.CreateTranslationUnit(headerFile, clangOptions.ToArray(), unsavedFiles, TranslationUnitFlags.SkipFunctionBodies); } var cur = currentTU.Cursor; cur.VisitChildren(HeaderVisitor); currentTU.Dispose(); currentTU = null; headerQueue.Remove(headerFile); }
internal static extern int clang_reparseTranslationUnit(IntPtr tu, uint numUnsavedFiles, UnsavedFile[] unsavedFiles, int options);
internal static extern int clang_indexSourceFile(IndexingSession session, IntPtr clientData, IndexerCallbacks[] cbs, uint cbsSize, uint indexOptions, string fileName, string[] cmdLineArgs, int cmdLineCount, UnsavedFile[] unsavedFiles, uint numUnsavedFiles, out IntPtr translationUnit, uint tuOptions);
internal static extern IntPtr clang_createTranslationUnitFromSourceFile(IntPtr index, string sourceFilename, int numClangCommandLineArgs, string[] clangCommandLineArgs, uint numUnsavedFiles, UnsavedFile[] unsavedFiles);
internal static extern IntPtr clang_parseTranslationUnit(IntPtr index, string sourceFilename, string[] clangCommandLineArgs, int numClangCommandLineArgs, UnsavedFile[] unsavedFiles, uint numUnsavedFiles, int options);
public Task <SignatureHelp> SignatureHelp(ISourceFile file, UnsavedFile buffer, List <UnsavedFile> unsavedFiles, int line, int column, int offset, string methodName) { throw new NotImplementedException(); }
public async Task<SignatureHelp> SignatureHelp(ISourceFile file, UnsavedFile buffer, List<UnsavedFile> unsavedFiles, int line, int column, int offset, string methodName) { SignatureHelp result = null; var clangUnsavedFiles = new List<ClangUnsavedFile>(); unsavedFiles.Add(buffer); foreach (var unsavedFile in unsavedFiles) { if (Platform.CompareFilePath(unsavedFile.FileName, buffer.FileName) != 0) { clangUnsavedFiles.Add(new ClangUnsavedFile(unsavedFile.FileName, unsavedFile.Contents)); } } var symbols = await GetSymbolsAsync(file, unsavedFiles, methodName); if (symbols.Count > 0) { result = new SignatureHelp(); result.Offset = offset; foreach (var symbol in symbols) { result.Signatures.Add(SignatureFromSymbol(symbol)); } } return result; }
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(); }
public async Task<SignatureHelp> SignatureHelp(ISourceFile file, UnsavedFile buffer, List<UnsavedFile> unsavedFiles, int line, int column, int offset, string methodName) { SignatureHelp result = null; var dataAssociation = GetAssociatedData(file); result = await dataAssociation.Solution.Server.SignatureHelp(file.FilePath, unsavedFiles.FirstOrDefault()?.Contents, line, column); if (result != null) { result.NormalizeSignatureData(); result.Offset = offset; } return result; }