public TooltipItem GetItem(TextEditor editor, int offset) { // Note: Normally, the document already should be open var doc = IdeApp.Workbench.OpenDocument(editor.Document.FileName); if (doc == null) { return(null); } // Due the first note, the AST already should exist var ast = doc.ParsedDocument.LanguageAST as IAbstractSyntaxTree; if (ast == null) { return(null); } // Get code cache var codeCache = DCodeCompletionSupport.EnumAvailableModules(doc); // Create editor context var line = editor.GetLineByOffset(offset); var EditorContext = new EditorData { CaretOffset = offset, CaretLocation = new CodeLocation(offset - line.Offset, editor.OffsetToLineNumber(offset)), ModuleCode = editor.Text, ParseCache = codeCache, SyntaxTree = ast as DModule, ImportCache = DResolver.ResolveImports(ast as DModule, codeCache) }; // Let the engine build all contents var ttContents = DCodeCompletionSupport.BuildToolTip(EditorContext); // Create tool tip item if (ttContents != null) { return(new TooltipItem(ttContents, offset, 1)); } return(null); }
public static void BuildCompletionData(Document EditorDocument, IAbstractSyntaxTree SyntaxTree, CodeCompletionContext ctx, CompletionDataList l, string EnteredText) { var caretOffset = ctx.TriggerOffset - EnteredText.Length; var caretLocation = new CodeLocation(ctx.TriggerLineOffset - EnteredText.Length, ctx.TriggerLine); string lastCompletionResultPath = ""; var codeCache = EnumAvailableModules(EditorDocument); var ccs = new DCodeCompletionSupport(new CompletionDataGenerator { CompletionDataList = l }); var edData = new EditorData { CaretLocation = caretLocation, CaretOffset = caretOffset, ModuleCode = EditorDocument.Editor.Text, SyntaxTree = SyntaxTree as DModule, ParseCache = codeCache, ImportCache = DResolver.ResolveImports(SyntaxTree as DModule, codeCache) }; ccs.BuildCompletionData(edData, EnteredText, out lastCompletionResultPath); }