public void TypeRefFinding() { var modA = DParser.ParseString(@"module modA; class A(T) { int n; static int prop; static A!float statA; } void main() { auto a = new A!int(); a.n; A.prop = 3; int b = A.prop + 4; A!double.statA.statA = new A!double(); } "); var ed = new EditorData { SyntaxTree = modA, ParseCache = new LegacyParseCacheView(new RootPackage[0]) }; var res = TypeReferenceFinder.Scan(ed, System.Threading.CancellationToken.None, null); Assert.That(res.Count, Is.GreaterThan(6)); }
public static EditorData CreateEditorData(Document EditorDocument, DModule Ast, CodeCompletionContext ctx, char triggerChar = '\0') { bool removeChar = char.IsLetter(triggerChar) || triggerChar == '_'; var deltaOffset = 0;//removeChar ? 1 : 0; var caretOffset = ctx.TriggerOffset - (removeChar ? 1 : 0); var caretLocation = new CodeLocation(ctx.TriggerLineOffset - deltaOffset, ctx.TriggerLine); var codeCache = CreateCacheList(EditorDocument); var ed = new EditorData { CaretLocation = caretLocation, CaretOffset = caretOffset, ModuleCode = removeChar ? EditorDocument.Editor.Text.Remove(ctx.TriggerOffset - 1, 1) : EditorDocument.Editor.Text, SyntaxTree = Ast, ParseCache = codeCache }; if (EditorDocument.HasProject) { var cfg = EditorDocument.Project.GetConfiguration(IdeApp.Workspace.ActiveConfiguration); if (cfg is DProjectConfiguration) { var dcfg = cfg as DProjectConfiguration; ed.GlobalDebugIds = dcfg.CustomDebugIdentifiers; ed.IsDebug = dcfg.DebugMode; ed.DebugLevel = dcfg.DebugLevel; ed.GlobalVersionIds = dcfg.GlobalVersionIdentifiers; double d; ulong v; if (Double.TryParse(EditorDocument.Project.Version, out d)) ed.VersionNumber = (ulong)d; else if (UInt64.TryParse(EditorDocument.Project.Version, out v)) ed.VersionNumber = v; } else if (cfg is DubProjectConfiguration) { var versions = new List<string>(VersionIdEvaluation.GetOSAndCPUVersions()); var dcfg = cfg as DubProjectConfiguration; ed.IsDebug = dcfg.DebugMode; HandleDubSettingsConditionExtraction(versions, (dcfg.ParentItem as DubProject).CommonBuildSettings); HandleDubSettingsConditionExtraction(versions, dcfg.BuildSettings); ed.GlobalVersionIds = versions.ToArray(); } } if (ed.GlobalVersionIds == null) { ed.GlobalVersionIds = VersionIdEvaluation.GetOSAndCPUVersions(); } return ed; }
public static EditorData GenEditorData(int caretLine, int caretPos, string focusedModuleCode, params string[] otherModuleCodes) { var cache = CreateCache(otherModuleCodes); var ed = new EditorData { ParseCache = cache }; UpdateEditorData(ed, caretLine, caretPos, focusedModuleCode); return ed; }
public static void UpdateEditorData(EditorData ed, int caretLine, int caretPos, string focusedModuleCode) { var mod = DParser.ParseString(focusedModuleCode); var pack = ed.ParseCache[0] as MutableRootPackage; pack.AddModule(mod); ed.ModuleCode = focusedModuleCode; ed.SyntaxTree = mod; ed.CaretLocation = new CodeLocation(caretPos, caretLine); ed.CaretOffset = DocumentHelper.LocationToOffset(focusedModuleCode, caretLine, caretPos); }
public static void UpdateEditorData(EditorData ed, int caretLine, int caretPos, string focusedModuleCode) { var mod = DParser.ParseString(focusedModuleCode); var pack = (ed.ParseCache as LegacyParseCacheView).EnumRootPackagesSurroundingModule(null).First() as MutableRootPackage; pack.AddModule(mod); ed.ModuleCode = focusedModuleCode; ed.SyntaxTree = mod; ed.CaretLocation = new CodeLocation(caretPos, caretLine); ed.CaretOffset = DocumentHelper.LocationToOffset(focusedModuleCode, caretLine, caretPos); }
public static INode GetNode(EditorData ed, string id, ref ResolutionContext ctxt) { if (ctxt == null) ctxt = ResolutionContext.Create (ed, true); DToken tk; var bt = DParser.ParseBasicType (id, out tk); var t = TypeDeclarationResolver.ResolveSingle(bt, ctxt); var n = (t as DSymbol).Definition; Assert.That (n, Is.Not.Null); return n; }
public static EditorData CreateEditorData(Document EditorDocument, DModule Ast, CodeCompletionContext ctx, char triggerChar = '\0') { bool removeChar = char.IsLetter(triggerChar) || triggerChar == '_' || triggerChar == '@'; var deltaOffset = 0;//removeChar ? 1 : 0; var caretOffset = ctx.TriggerOffset - (removeChar ? 1 : 0); var caretLocation = new CodeLocation(ctx.TriggerLineOffset - deltaOffset, ctx.TriggerLine); var codeCache = CreateCacheList(EditorDocument); var ed = new EditorData { CaretLocation = caretLocation, CaretOffset = caretOffset, ModuleCode = removeChar ? EditorDocument.Editor.Text.Remove(ctx.TriggerOffset - 1, 1) : EditorDocument.Editor.Text, SyntaxTree = Ast, ParseCache = codeCache }; if (EditorDocument.HasProject) { var cfg = EditorDocument.Project.GetConfiguration(Ide.IdeApp.Workspace.ActiveConfiguration) as DProjectConfiguration; if (cfg != null) { ed.GlobalDebugIds = cfg.CustomDebugIdentifiers; ed.IsDebug = cfg.DebugMode; ed.DebugLevel = cfg.DebugLevel; ed.GlobalVersionIds = cfg.GlobalVersionIdentifiers; double d; int v; if (Double.TryParse(EditorDocument.Project.Version, out d)) ed.VersionNumber = (int)d; else if (Int32.TryParse(EditorDocument.Project.Version, out v)) ed.VersionNumber = v; } } if (ed.GlobalVersionIds == null) { ed.GlobalVersionIds = VersionIdEvaluation.GetOSAndCPUVersions(); } return ed; }
public static EditorData GetEditorData(MonoDevelop.Ide.Gui.Document doc = null) { var ed = new EditorData(); if (doc == null) doc = IdeApp.Workbench.ActiveDocument; if (doc == null || doc.FileName == FilePath.Null) return null; var editor = doc.GetContent<ITextBuffer>(); if (editor == null) return null; int line, column; editor.GetLineColumnFromPosition(editor.CursorPosition, out line, out column); ed.CaretLocation = new CodeLocation(column, line); ed.CaretOffset = editor.CursorPosition; var ast = doc.ParsedDocument as ParsedDModule; if(ast==null) return null; ed.SyntaxTree = ast.DDom as DModule; ed.ModuleCode = editor.Text; if (ed.SyntaxTree == null) return null; var Project = doc.Project as DProject; // Encapsule editor data for resolving ed.ParseCache = Project != null ? Project.ParseCache : ParseCacheList.Create(DCompilerService.Instance.GetDefaultCompiler().ParseCache); return ed; }
public override TooltipItem GetItem(TextEditor editor, int offset) { // Note: Normally, the document already should be open var doc=IdeApp.Workbench.GetDocument(editor.Document.FileName); if (doc == null || !(doc.ParsedDocument is ParsedDModule)) return null; // Due the first note, the AST already should exist var ast = (doc.ParsedDocument as ParsedDModule).DDom; if (ast == null) return null; // Get code cache var codeCache = DResolverWrapper.CreateCacheList(doc); // Create editor context var line=editor.GetLineByOffset(offset); var ed = new EditorData { CaretOffset=offset, CaretLocation = new CodeLocation(offset - line.Offset, editor.OffsetToLineNumber(offset)), ModuleCode = editor.Text, ParseCache = codeCache, SyntaxTree = ast }; // Let the engine build all contents DResolver.NodeResolutionAttempt att; var rr = DResolver.ResolveTypeLoosely(ed, out att); // Create tool tip item if (rr != null) return new TooltipItem(rr, offset, 1); return null; }
public override TooltipItem GetItem(TextEditor editor, int offset) { // Note: Normally, the document already should be open var doc=IdeApp.Workbench.GetDocument(editor.Document.FileName); if (doc == null || !(doc.ParsedDocument is ParsedDModule)) return null; // Due the first note, the AST already should exist var ast = (doc.ParsedDocument as ParsedDModule).DDom; 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 }; // Let the engine build all contents var ttContents= AbstractTooltipProvider.BuildToolTip(EditorContext); // Create tool tip item if (ttContents != null) return new TooltipItem(ttContents, offset, 1); return null; }
public static EditorData CreateEditorData(Document EditorDocument, DModule Ast, CodeCompletionContext ctx, char triggerChar = '\0') { bool removeChar = char.IsLetter(triggerChar) || triggerChar == '_'; var deltaOffset = 0;//removeChar ? 1 : 0; var caretOffset = ctx.TriggerOffset - (removeChar ? 1 : 0); var caretLocation = new CodeLocation(ctx.TriggerLineOffset - deltaOffset, ctx.TriggerLine); var codeCache = CreateParseCacheView(EditorDocument); var ed = new EditorData { CaretLocation = caretLocation, CaretOffset = caretOffset, ModuleCode = removeChar ? EditorDocument.Editor.Text.Remove(ctx.TriggerOffset - 1, 1) : EditorDocument.Editor.Text, SyntaxTree = Ast, ParseCache = codeCache }; if (EditorDocument.HasProject) { var versions = new List<string>(); var debugConstants = new List<string> (); var cfg = EditorDocument.Project.GetConfiguration(IdeApp.Workspace.ActiveConfiguration); if (cfg is DProjectConfiguration) { var dcfg = cfg as DProjectConfiguration; ed.IsDebug = dcfg.DebugMode; ed.DebugLevel = dcfg.DebugLevel; double d; ulong v; if (Double.TryParse(EditorDocument.Project.Version, out d)) ed.VersionNumber = (ulong)d; else if (UInt64.TryParse(EditorDocument.Project.Version, out v)) ed.VersionNumber = v; } else if (cfg is DubProjectConfiguration) { versions.AddRange(VersionIdEvaluation.GetOSAndCPUVersions()); var dcfg = cfg as DubProjectConfiguration; ed.IsDebug = dcfg.DebugMode; } foreach (var prj in GetProjectDependencyHierarchyToCurrentStartupProject(EditorDocument.Project, cfg.Selector)) if(prj is AbstractDProject) ExtractVersionDebugConstantsFromProject (prj as AbstractDProject, versions, debugConstants); ed.GlobalDebugIds = debugConstants.ToArray (); ed.GlobalVersionIds = versions.ToArray (); } if (ed.GlobalVersionIds == null || ed.GlobalVersionIds.Length == 0) { ed.GlobalVersionIds = VersionIdEvaluation.GetOSAndCPUVersions(); } return ed; }
public void GetTip(string filename, int startLine, int startIndex, int endLine, int endIndex) { IAbstractSyntaxTree ast = null; if (!_modules.TryGetValue(filename, out ast)) throw new COMException("module not found", 1); _tipStart = new CodeLocation(startLine, startIndex); _tipEnd = new CodeLocation(startLine, startIndex + 1); _tipText = ""; EditorData editorData = new EditorData(); editorData.CaretLocation = _tipStart; editorData.SyntaxTree = ast as DModule; editorData.ModuleCode = _sources[filename]; editorData.CaretOffset = getCodeOffset(editorData.ModuleCode, _tipStart); AbstractTooltipContent[] content = AbstractTooltipProvider.BuildToolTip(editorData); if(content == null || content.Length == 0) _tipText = ""; else foreach (var c in content) _tipText += c.Title + ":" + c.Description + "\n"; //MessageBox.Show("GetTip()"); //throw new NotImplementedException(); }
public void GetSemanticExpansions(string filename, string tok, uint line, uint idx, string expr) { IAbstractSyntaxTree ast = null; if (!_modules.TryGetValue(filename, out ast)) throw new COMException("module not found", 1); CodeLocation loc = new CodeLocation((int)idx, (int) line); EditorData editorData = new EditorData(); editorData.CaretLocation = loc; editorData.SyntaxTree = ast as DModule; editorData.ModuleCode = _sources[filename]; editorData.CaretOffset = getCodeOffset(editorData.ModuleCode, loc); VDServerCompletionDataGenerator cdgen = new VDServerCompletionDataGenerator(); AbstractCompletionProvider provider = AbstractCompletionProvider.BuildCompletionData(cdgen, editorData, tok); _expansions = cdgen.expansions; //MessageBox.Show("GetSemanticExpansions()"); //throw new NotImplementedException(); }
public bool UpdateTypeResolutionContext () { if (!NeedsResolutionContextUpdate && resolutionCtx != null) return true; NeedsResolutionContextUpdate = false; var ff = DebuggingService.CurrentCallStack.GetFrame(Backtrace.CurrentFrameIndex); var document = Ide.IdeApp.Workbench.OpenDocument (ff.SourceLocation.FileName); if (document == null) return false; var codeLocation = new CodeLocation (ff.SourceLocation.Column, ff.SourceLocation.Line); // Only create new if the cursor location is different from the previous if (firstFrameEditorData != null && firstFrameEditorData.SyntaxTree.FileName == ff.SourceLocation.FileName && firstFrameEditorData.CaretLocation.Line == codeLocation.Line) return true; firstFrameEditorData = DResolverWrapper.CreateEditorData (document); firstFrameEditorData.CaretLocation = codeLocation; resolutionCtx = ResolutionContext.Create (firstFrameEditorData, false); CodeCompletion.DoTimeoutableCompletionTask (null, resolutionCtx, () => resolutionCtx.Push (firstFrameEditorData)); return true; }
public override bool Matches(object actual) { var code = actual as string; if (code == null) return false; code += "\n"; var m = DParser.ParseString (code); var cache = ResolutionTests.CreateCache (); cache.FirstPackage().AddModule (m); var ed = new EditorData{ ModuleCode = code, CaretOffset = code.Length-1, CaretLocation = DocumentHelper.OffsetToLocation(code,code.Length-1), SyntaxTree = m, ParseCache = cache }; var gen = new TestCompletionDataGen (null, null); var res = CodeCompletion.GenerateCompletionData (ed, gen, 'a'); return neg ? !res : res; }
void UpdateEditorData(EditorData ed,int caretLine, int caretPos, string focusedModuleCode) { var mod = DParser.ParseString (focusedModuleCode); var pack = ed.ParseCache [0] as MutableRootPackage; pack.AddModule (mod); pack.UfcsCache.CacheModuleMethods (mod, ResolutionContext.Create(ed)); ed.ModuleCode = focusedModuleCode; ed.SyntaxTree = mod; ed.CaretLocation = new CodeLocation (caretPos, caretLine); ed.CaretOffset = DocumentHelper.LocationToOffset (focusedModuleCode, caretLine, caretPos); }