protected override void Update(CommandArrayInfo info) { ResolverContextStack ctxt; var rr = Resolver.DResolverWrapper.ResolveHoveredCode(out ctxt); bool noRes = true; if (rr != null && rr.Length > 0) { res = rr[rr.Length - 1]; n = DResolver.GetResultMember(res); if (n != null) { noRes = false; info.Add(IdeApp.CommandService.GetCommandInfo(RefactoryCommands.GotoDeclaration), new Action(GotoDeclaration)); info.Add(IdeApp.CommandService.GetCommandInfo(RefactoryCommands.FindReferences), new Action(FindReferences)); if (RenamingRefactoring.CanRename(n)) { info.AddSeparator(); info.Add(IdeApp.CommandService.GetCommandInfo(EditCommands.Rename), new Action(RenameSymbol)); } } } if (noRes) { info.Add(IdeApp.CommandService.GetCommandInfo(RefactoryCommands.ImportSymbol), new Action(ImportSymbol)); } info.Add(IdeApp.CommandService.GetCommandInfo(Commands.OpenDDocumentation), new Action(OpenDDoc)); }
public void GetDefinition(string filename, int startLine, int startIndex, int endLine, int endIndex) { filename = normalizePath(filename); var ast = GetModule(filename); if (ast == null) { throw new COMException("module not found", 1); } _tipStart = new CodeLocation(startIndex + 1, startLine); _tipEnd = new CodeLocation(endIndex + 1, endLine); _tipText.Clear(); _setupEditorData(); _editorData.CaretLocation = _tipEnd; _editorData.SyntaxTree = ast as DModule; _editorData.ModuleCode = _sources[filename]; // codeOffset+1 because otherwise it does not work on the first character _editorData.CaretOffset = getCodeOffset(_editorData.ModuleCode, _tipStart) + 2; ISyntaxRegion sr = DResolver.GetScopedCodeObject(_editorData); LooseResolution.NodeResolutionAttempt attempt; var rr = sr != null?LooseResolution.ResolveTypeLoosely(_editorData, sr, out attempt, true) : null; _tipText.Clear(); if (rr != null) { var n = DResolver.GetResultMember(rr, true); if (n == null) { return; } bool decl = false; var mthd = n as DMethod; if (mthd != null) { decl = mthd.Body == null; } else if (n.ContainsAttribute(DTokens.Extern)) { decl = true; } if (decl) { _tipText.Append("EXTERN:"); } _tipStart = n.Location; _tipEnd = n.EndLocation; INode node = n.NodeRoot; if (node is DModule) { _tipText.Append((node as DModule).FileName); } } }
public IEnumerable <DModule> GetImportableModulesForLastResults() { var nodesToChooseFrom = new List <DModule> (); if (lastResults == null || lastResults.Length < 1) { return(nodesToChooseFrom); } foreach (var res in lastResults) { var n = DResolver.GetResultMember(res, true); if (n != null) { var mod = n.NodeRoot as DModule; if (mod != null && !nodesToChooseFrom.Contains(mod)) { var i = Math.Max(0, nodesToChooseFrom.Count - 1); foreach (var packageMod in TryGetGenericImportingPackageForSymbol(n)) { if (!nodesToChooseFrom.Contains(packageMod)) { nodesToChooseFrom.Insert(i, packageMod); } } nodesToChooseFrom.Add(mod); } } } return(nodesToChooseFrom); }
public void GetReferences(string filename, string tok, uint line, uint idx, string expr) { filename = normalizePath(filename); var ast = GetModule(filename); if (ast == null) { throw new COMException("module not found", 1); } _request = Request.References; _result = "__pending__"; Action dg = () => { _setupEditorData(); CodeLocation loc = new CodeLocation((int)idx + 1, (int)line); _editorData.CaretLocation = loc; _editorData.SyntaxTree = ast as DModule; _editorData.ModuleCode = _sources[filename]; _editorData.CaretOffset = getCodeOffset(_editorData.ModuleCode, loc); ISyntaxRegion sr = DResolver.GetScopedCodeObject(_editorData); LooseResolution.NodeResolutionAttempt attempt; var rr = sr != null?LooseResolution.ResolveTypeLoosely(_editorData, sr, out attempt, true) : null; StringBuilder refs = new StringBuilder(); if (rr != null) { var n = DResolver.GetResultMember(rr, true); if (n != null) { var ctxt = ResolutionContext.Create(_editorData, true); if (n.ContainsAttribute(DTokens.Private) || ((n is DVariable) && (n as DVariable).IsLocal)) { GetReferencesInModule(ast, refs, n, ctxt); } else { foreach (var basePath in _imports.Split(nlSeparator, StringSplitOptions.RemoveEmptyEntries)) { foreach (var mod in GlobalParseCache.EnumModulesRecursively(basePath)) { GetReferencesInModule(mod, refs, n, ctxt); } } } } //var res = TypeReferenceFinder.Scan(_editorData, System.Threading.CancellationToken.None, null); } if (!_editorData.CancelToken.IsCancellationRequested && _request == Request.References) { _result = refs.ToString(); } }; }
public void FindReferences(bool allOverloads = false) { AbstractType res = GetResult(); INode n; if (res != null && (n = DResolver.GetResultMember(res, true)) != null) { ReferenceFinding.StartReferenceSearchAsync(n, allOverloads); } }
public void RenameSymbol() { AbstractType res = GetResult(); INode n; if (res != null && (n = DResolver.GetResultMember(res, true)) != null && DRenameRefactoring.CanRenameNode(n)) { new DRenameHandler().Start(n); } }
public void GetReferences(string filename, string tok, uint line, uint idx, string expr) { var ast = GetModule(filename); if (ast == null) { throw new COMException("module not found", 1); } _setupEditorData(); CodeLocation loc = new CodeLocation((int)idx + 1, (int)line); _editorData.CaretLocation = loc; _editorData.SyntaxTree = ast as DModule; _editorData.ModuleCode = _sources[filename]; _editorData.CaretOffset = getCodeOffset(_editorData.ModuleCode, loc); _references = null; ISyntaxRegion sr; DResolver.NodeResolutionAttempt attempt; var rr = DResolver.ResolveTypeLoosely(_editorData, out attempt, out sr); StringBuilder refs = new StringBuilder(); if (rr != null) { var n = DResolver.GetResultMember(rr, true); if (n != null) { var ctxt = ResolutionContext.Create(_editorData, true); if (n.ContainsAttribute(DTokens.Private) || ((n is DVariable) && (n as DVariable).IsLocal)) { GetReferencesInModule(ast, refs, n, ctxt); } else { foreach (var basePath in _imports.Split('\n')) { foreach (var mod in GlobalParseCache.EnumModulesRecursively(basePath)) { GetReferencesInModule(mod, refs, n, ctxt); } } } } //var res = TypeReferenceFinder.Scan(_editorData, System.Threading.CancellationToken.None, null); } _references = refs; }
/// <summary> /// Returns possible imports for current context /// </summary> IEnumerable <string> GetSolutions(Document doc) { //i had to copy-paste some code from other files ResolutionContext ctxt; var rr = Resolver.DResolverWrapper.ResolveHoveredCode(out ctxt); if (rr != null && rr.Length > 0) { var res = rr[rr.Length - 1]; var n = DResolver.GetResultMember(res); if (n != null) { //seems like this can filter function calls yield break; } } INode[] nodes; bool req; var edData = DResolverWrapper.CreateEditorData(doc); try { nodes = ImportDirectiveCreator.TryFindingSelectedIdImportIndependently(edData, out req); } catch { yield break; } if (!req || nodes == null) { yield break; } foreach (var node in nodes) { var mod = node.NodeRoot as DModule; if (mod != null && mod != edData.SyntaxTree) { yield return(mod.ModuleName); } } yield break; }
public void GetDefinition(string filename, int startLine, int startIndex, int endLine, int endIndex) { var ast = GetModule(filename); if (ast == null) { throw new COMException("module not found", 1); } _tipStart = new CodeLocation(startIndex + 1, startLine); _tipEnd = new CodeLocation(endIndex + 1, endLine); _tipText.Clear(); _setupEditorData(); _editorData.CaretLocation = _tipEnd; _editorData.SyntaxTree = ast as DModule; _editorData.ModuleCode = _sources[filename]; // codeOffset+1 because otherwise it does not work on the first character _editorData.CaretOffset = getCodeOffset(_editorData.ModuleCode, _tipStart) + 2; DResolver.NodeResolutionAttempt attempt; var rr = DResolver.ResolveTypeLoosely(_editorData, out attempt); _tipText.Clear(); if (rr != null) { var n = DResolver.GetResultMember(rr, true); if (n == null) { return; } _tipStart = n.Location; _tipEnd = n.EndLocation; INode node = n.NodeRoot; if (node is DModule) { _tipText.Append((node as DModule).FileName); } } }
void FindReferences_Upd(CommandInfo ci) { lastResults = DResolverWrapper.ResolveHoveredCode(out lastContext); if (lastResults == null || lastResults.Length == 0) { ci.Bypass = true; return; } ci.Bypass = true; foreach (var r in lastResults) { if ((firstResultNode = DResolver.GetResultMember(r)) != null) { ci.Bypass = false; return; } } }
public static void HandleLdOutput(AbstractDProject prj, BuildResult br, string linkerOutput) { var ctxt = ResolutionContext.Create(DResolverWrapper.CreateParseCacheView(prj), null, null); ctxt.ContextIndependentOptions = ResolutionOptions.IgnoreAllProtectionAttributes | ResolutionOptions.DontResolveBaseTypes | ResolutionOptions.DontResolveBaseClasses | ResolutionOptions.DontResolveAliases; foreach (Match m in ldErrorRegex.Matches(linkerOutput)) { var error = new BuildError(); var firstSymbolOccurring = ldMangleRegex.Match(m.Groups["err"].Value); if (firstSymbolOccurring.Success) { var mangledString = "_D" + firstSymbolOccurring.Groups["mangle"].Value; var associatedSymbol = DResolver.GetResultMember(Demangler.DemangleAndResolve(mangledString, ctxt)); if (associatedSymbol != null) { error.FileName = (associatedSymbol.NodeRoot as DModule).FileName; error.Line = associatedSymbol.Location.Line; error.Column = associatedSymbol.Location.Column; } } error.ErrorText = m.Groups["msg"].Value; if (string.IsNullOrWhiteSpace(error.ErrorText)) { error.ErrorText = m.Groups["err"].Value; } error.ErrorText = DemangleLdOutput(error.ErrorText); br.Append(error); } }
public void GetDefinition(string filename, int startLine, int startIndex, int endLine, int endIndex) { DModule ast = null; if (!_modules.TryGetValue(filename, out ast)) { throw new COMException("module not found", 1); } _tipStart = new CodeLocation(startIndex + 1, startLine); _tipEnd = new CodeLocation(endIndex + 1, endLine); _tipText = ""; _setupEditorData(); _editorData.CaretLocation = _tipEnd; _editorData.SyntaxTree = ast as DModule; _editorData.ModuleCode = _sources[filename]; // codeOffset+1 because otherwise it does not work on the first character _editorData.CaretOffset = getCodeOffset(_editorData.ModuleCode, _tipStart) + 2; var ctxt = ResolutionContext.Create(_editorData); var rr = DResolver.ResolveType(_editorData, ctxt); _tipText = ""; if (rr != null && rr.Length > 0) { var res = rr[rr.Length - 1]; var n = DResolver.GetResultMember(res); _tipStart = n.Location; _tipEnd = n.EndLocation; INode node = n.NodeRoot; if (node is DModule) { _tipText = (node as DModule).FileName; } } }
public static string GetReferenceUrl(AbstractType result, ResolutionContext ctxt, CodeLocation caret) { if (result != null) { var n = DResolver.GetResultMember(result); if (n != null && n.NodeRoot is IAbstractSyntaxTree) { if (IsPhobosModule(n.NodeRoot as IAbstractSyntaxTree)) { var phobos_url = "phobos/" + (n.NodeRoot as IAbstractSyntaxTree).ModuleName.Replace('.', '_') + ".html"; if (!(n is IAbstractSyntaxTree)) { phobos_url += "#" + n.Name; } return(phobos_url); } } else if (result is PrimitiveType || result is DelegateType || result is AssocArrayType) { if (result.DeclarationOrExpressionBase is ITypeDeclaration) { return(GetRefUrlFor((ITypeDeclaration)result.DeclarationOrExpressionBase)); } else if (result.DeclarationOrExpressionBase is IExpression) { return(GetRefUrlFor((IExpression)result.DeclarationOrExpressionBase)); } } } if (ctxt.ScopedStatement != null) { return(GetRefUrlFor(ctxt.ScopedStatement, caret)); } else if (ctxt.ScopedBlock is DClassLike) { var dc = ctxt.ScopedBlock as DClassLike; if (dc.ClassType == DTokens.Class) { return("class.html"); } else if (dc.ClassType == DTokens.Interface) { return("interface.html"); } else if (dc.ClassType == DTokens.Struct || dc.ClassType == DTokens.Union) { return("struct.html"); } else if (dc.ClassType == DTokens.Template) { return("template.html"); } } else if (ctxt.ScopedBlock is DEnum) { return("enum.html"); } return(null); }
internal static void GotoDeclaration(AbstractType lastResult) { GotoDeclaration(DResolver.GetResultMember(lastResult, true)); }
protected override void Update(CommandArrayInfo info) { if (caps.Update()) { if (caps.resultResolutionAttempt != LooseResolution.NodeResolutionAttempt.RawSymbolLookup) { var refactoringMenu = new CommandInfoSet { Text = GettextCatalog.GetString("Refactoring") }; if (caps.lastResults.Any(t => t is DSymbol && DRenameRefactoring.CanRenameNode((t as DSymbol).Definition))) { refactoringMenu.CommandInfos.Add(IdeApp.CommandService.GetCommandInfo(EditCommands.Rename), new Action(caps.RenameSymbol)); } if (refactoringMenu.CommandInfos.Count > 0) { info.Add(refactoringMenu); } info.Add(IdeApp.CommandService.GetCommandInfo(RefactoryCommands.GotoDeclaration), new Action(caps.GotoDeclaration)); info.Add(IdeApp.CommandService.GetCommandInfo(RefactoryCommands.FindReferences), new Action(() => caps.FindReferences(false))); if (caps.lastResults.Any(t => t is DSymbol && (t as DSymbol).Definition.Parent is DClassLike)) { info.Add(IdeApp.CommandService.GetCommandInfo(RefactoryCommands.FindAllReferences), new Action(() => caps.FindReferences(true))); } if (caps.lastResults.Any(t => { var ds = DResolver.StripMemberSymbols(t); return(ds is ClassType || ds is InterfaceType); })) { info.Add(IdeApp.CommandService.GetCommandInfo(RefactoryCommands.FindDerivedClasses), new Action(caps.FindDerivedClasses)); } } else { var importSymbolMenu = new CommandInfoSet { Text = GettextCatalog.GetString("Resolve") }; foreach (var m in caps.GetImportableModulesForLastResults()) { importSymbolMenu.CommandInfos.Add(new CommandInfo { Text = "import " + AbstractNode.GetNodePath(m, true) + ";", Icon = MonoDevelop.Ide.Gui.Stock.AddNamespace }, new object[] { RefactoryCommands.ImportSymbol, m }); } if (importSymbolMenu.CommandInfos.Count > 0) { importSymbolMenu.CommandInfos.AddSeparator(); var alreadyAddedItems = new List <DModule> (); foreach (var t in caps.lastResults) { var n = DResolver.GetResultMember(t, true); if (n == null) { continue; } var m = n.NodeRoot as DModule; if (m != null && !alreadyAddedItems.Contains(m)) { alreadyAddedItems.Add(m); importSymbolMenu.CommandInfos.Add(new CommandInfo { Text = AbstractNode.GetNodePath(n, true) }, new object[] { RefactoryCommands.QuickFix, n }); } } // To explicitly show the Ctrl+Alt+Space hint. importSymbolMenu.CommandInfos.AddSeparator(); importSymbolMenu.CommandInfos.Add(IdeApp.CommandService.GetCommandInfo(RefactoryCommands.ImportSymbol), new Action(caps.TryImportMissingSymbol)); info.Add(importSymbolMenu); } } } if (SortImportsCommandHandler.CanSortImports(caps.lastDoc)) { info.Add(IdeApp.CommandService.GetCommandInfo(RefactoryCommands.SortImports), new Action(() => SortImportsCommandHandler.SortImports(caps.lastDoc))); } }
public void GetDefinition(string filename, int startLine, int startIndex, int endLine, int endIndex) { filename = normalizePath(filename); var ast = GetModule(filename); if (ast == null) { throw new COMException("module not found", 1); } _tipStart = new CodeLocation(startIndex + 1, startLine); _tipEnd = new CodeLocation(endIndex + 1, endLine); _request = Request.Definition; _result = "__pending__"; Action dg = () => { _setupEditorData(); _editorData.CaretLocation = _tipEnd; _editorData.SyntaxTree = ast as DModule; _editorData.ModuleCode = _sources[filename]; // codeOffset+1 because otherwise it does not work on the first character _editorData.CaretOffset = getCodeOffset(_editorData.ModuleCode, _tipStart) + 2; ISyntaxRegion sr = DResolver.GetScopedCodeObject(_editorData); LooseResolution.NodeResolutionAttempt attempt; var rr = sr != null?LooseResolution.ResolveTypeLoosely(_editorData, sr, out attempt, true) : null; StringBuilder tipText = new StringBuilder(); if (rr != null) { DNode n = null; foreach (var t in AmbiguousType.TryDissolve(rr)) { n = DResolver.GetResultMember(t, true); if (n != null) { break; } } if (n != null) { if (tipText.Length > 0) { tipText.Append("\n"); } bool decl = false; var mthd = n as DMethod; if (mthd != null) { decl = mthd.Body == null; } else if (n.ContainsAttribute(DTokens.Extern)) { decl = true; } if (decl) { tipText.Append("EXTERN:"); } _tipStart = n.Location; _tipEnd = n.EndLocation; INode node = n.NodeRoot; if (node is DModule) { tipText.Append((node as DModule).FileName); } } } if (!_editorData.CancelToken.IsCancellationRequested && _request == Request.Definition) { _result = tipText.ToString(); } }; runAsync(dg); }