public void ScrollToAddress(uint address) { if (_inSourceView) { AddressInfo absAddress = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = (int)address, Type = SnesMemoryType.CpuMemory }); if (absAddress.Address >= 0) { SourceCodeLocation line = _symbolProvider?.GetSourceCodeLineInfo(absAddress); if (line != null) { foreach (SourceFileInfo fileInfo in cboSourceFile.Items) { if (line.File == fileInfo) { cboSourceFile.SelectedItem = fileInfo; ctrlCode.ScrollToLineIndex(line.LineNumber); return; } } } } ToggleView(); } ctrlCode.ScrollToAddress((int)address); }
public void ScrollToSourceLocation(SourceCodeLocation location) { if (SelectFile(location.File)) { ctrlCode.ScrollToLineIndex(location.LineNumber); } }
public VsTestTestClass(IVsTestTestRunner testRunner, Project project, VsTestUnitTest vsTestUnit) : base(vsTestUnit.FixtureTypeName) { Project = project; this.testRunner = testRunner; FixtureTypeName = vsTestUnit.FixtureTypeName; TestSourceCodeDocumentId = string.IsNullOrEmpty(vsTestUnit.FixtureTypeNamespace) ? FixtureTypeName : vsTestUnit.FixtureTypeNamespace + "." + FixtureTypeName; cts = new CancellationTokenSource(); var token = cts.Token; IdeApp.TypeSystemService.GetCompilationAsync(Project, token).ContinueWith((t) => { if (token.IsCancellationRequested) { return; } var className = TestSourceCodeDocumentId; var compilation = t.Result; if (compilation == null) { return; } var cls = compilation.GetTypeByMetadataName(className); if (cls == null) { return; } var source = cls.Locations.FirstOrDefault(l => l.IsInSource); if (source == null) { return; } var line = source.GetLineSpan(); sourceCodeLocation = new SourceCodeLocation(source.SourceTree.FilePath, line.StartLinePosition.Line, line.StartLinePosition.Character); }, token, TaskContinuationOptions.NotOnFaulted, TaskScheduler.Default).Ignore(); }
public void ScrollToSymbol(SourceSymbol symbol) { SourceCodeLocation definition = _symbolProvider?.GetSymbolDefinition(symbol); if (definition != null) { ScrollToSourceLocation(definition); } }
public static CsCodeWriter Create(Type callerType, [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string memberName = null, [CallerFilePath] string filePath = null ) { var location = new SourceCodeLocation(lineNumber, memberName, filePath) .WithGeneratorClass(callerType); var code = new CsCodeWriter { Location = location }; location = new SourceCodeLocation(0, memberName, filePath) .WithGeneratorClass(callerType); code.WriteLine("// generator : " + location); return(code); }
public void UpdateDisplay(SourceCodeLocation[] breakpoints) { string filename = mdbGui.DebuggerService.GetCurrentFilename(); if (filename == null) { this.Buffer.Text = "No source code"; currentlyLoadedSourceFile = null; return; } // Load the source file if neccessary if (currentlyLoadedSourceFile != filename) { string[] sourceCode = mdbGui.DebuggerService.ReadFile(filename); this.Buffer.Text = string.Join("\n", sourceCode); currentlyLoadedSourceFile = filename; } // Remove all current tags TextIter bufferBegin, bufferEnd; this.Buffer.GetBounds(out bufferBegin, out bufferEnd); this.Buffer.RemoveAllTags(bufferBegin, bufferEnd); // Add tag to show current line int currentLine = mdbGui.DebuggerService.GetCurrentLine(); TextIter currentLineIter = AddSourceViewTag("currentLine", currentLine); // Add tags for breakpoints foreach (SourceCodeLocation breakpoint in breakpoints) { if (breakpoint.Filename == currentlyLoadedSourceFile) { // If it is current line, do not retag it if (breakpoint.Line != currentLine) { AddSourceViewTag("breakpoint", breakpoint.Line); } } } // Scroll to current line TextMark mark = this.Buffer.CreateMark(null, currentLineIter, false); this.ScrollToMark(mark, 0, false, 0, 0); }
void Init() { TestId = test.Id?.ToString(); sourceCodeLocation = new SourceCodeLocation(test.CodeFilePath, test.LineNumber, 0); int index = test.FullyQualifiedName.LastIndexOf('.'); if (index > 0) { FixtureTypeName = test.FullyQualifiedName.Substring(0, index); index = FixtureTypeName.LastIndexOf('.'); if (index > 0) { FixtureTypeNamespace = FixtureTypeName.Substring(0, index); FixtureTypeName = FixtureTypeName.Substring(index + 1); } else { FixtureTypeNamespace = String.Empty; } } else { FixtureTypeNamespace = String.Empty; FixtureTypeName = String.Empty; } index = test.DisplayName.LastIndexOf('.'); if (index > 0) { name = test.DisplayName.Substring(index + 1); } else { name = test.DisplayName; } }
void Init() { TestId = test.Id.ToString(); TestSourceCodeDocumentId = test.FullyQualifiedName; if (!string.IsNullOrEmpty(test.CodeFilePath)) { sourceCodeLocation = new SourceCodeLocation(test.CodeFilePath, test.LineNumber, 0); } else { IdeApp.TypeSystemService.GetCompilationAsync(Project).ContinueWith((t) => { var dotIndex = test.FullyQualifiedName.LastIndexOf(".", StringComparison.Ordinal); var className = test.FullyQualifiedName.Remove(dotIndex); var methodName = test.FullyQualifiedName.Substring(dotIndex + 1); var bracketIndex = methodName.IndexOf('('); if (bracketIndex != -1) { methodName = methodName.Remove(bracketIndex).Trim(); } var compilation = t.Result; if (compilation == null) { return; } var cls = compilation.GetTypeByMetadataName(className); if (cls == null) { return; } IMethodSymbol method = null; while ((method = cls.GetMembers(methodName).OfType <IMethodSymbol> ().FirstOrDefault()) == null) { cls = cls.BaseType; if (cls == null) { return; } } if (method == null) { return; } var source = method.Locations.FirstOrDefault(l => l.IsInSource); if (source == null) { return; } var line = source.GetLineSpan(); sourceCodeLocation = new SourceCodeLocation(source.SourceTree.FilePath, line.StartLinePosition.Line, line.StartLinePosition.Character); }).Ignore(); } int index = test.FullyQualifiedName.LastIndexOf('.'); if (index > 0) { FixtureTypeName = test.FullyQualifiedName.Substring(0, index); index = FixtureTypeName.LastIndexOf('.'); if (index > 0) { FixtureTypeNamespace = FixtureTypeName.Substring(0, index); FixtureTypeName = FixtureTypeName.Substring(index + 1); } else { FixtureTypeNamespace = string.Empty; } } else { FixtureTypeNamespace = string.Empty; FixtureTypeName = string.Empty; } name = test.DisplayName; var obsoletePrefix = string.IsNullOrEmpty(FixtureTypeNamespace) ? FixtureTypeName : FixtureTypeNamespace + "." + FixtureTypeName; if (test.DisplayName.StartsWith(obsoletePrefix, StringComparison.Ordinal) && test.DisplayName [obsoletePrefix.Length] == '.') { name = test.DisplayName.Substring(obsoletePrefix.Length + 1); } }
private void UpdateResults() { string searchString = txtSearch.Text.Trim(); List <string> searchStrings = new List <string>(); searchStrings.Add(searchString.ToLower()); searchStrings.AddRange(searchString.ToLower().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); for (int i = 0; i < searchString.Length; i++) { char ch = searchString[i]; if (ch >= 'A' && ch <= 'Z') { searchString = searchString.Remove(i, 1).Insert(i, " " + (char)(ch + 'a' - 'A')); } } searchStrings.AddRange(searchString.ToLower().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); searchStrings = searchStrings.Distinct().ToList(); _resultCount = 0; int size = DebugApi.GetMemorySize(SnesMemoryType.PrgRom); byte[] cdlData = DebugApi.GetCdlData(0, (uint)size, SnesMemoryType.PrgRom); List <SearchResultInfo> searchResults = new List <SearchResultInfo>(); bool isEmptySearch = string.IsNullOrWhiteSpace(searchString); if (!isEmptySearch) { if (_symbolProvider != null) { if (_showFilesAndConstants) { foreach (SourceFileInfo file in _symbolProvider.SourceFiles) { if (Contains(file.Name, searchStrings)) { searchResults.Add(new SearchResultInfo() { Caption = Path.GetFileName(file.Name), AbsoluteAddress = null, SearchResultType = SearchResultType.File, File = file, SourceLocation = null, RelativeAddress = null, CodeLabel = null }); } } } foreach (SourceSymbol symbol in _symbolProvider.GetSymbols()) { if (Contains(symbol.Name, searchStrings)) { SourceCodeLocation def = _symbolProvider.GetSymbolDefinition(symbol); AddressInfo? addressInfo = _symbolProvider.GetSymbolAddressInfo(symbol); int value = 0; AddressInfo?relAddress = null; bool isConstant = addressInfo == null; if (!_showFilesAndConstants && isConstant) { continue; } if (addressInfo != null) { value = DebugApi.GetMemoryValue(addressInfo.Value.Type, (uint)addressInfo.Value.Address); relAddress = DebugApi.GetRelativeAddress(addressInfo.Value, CpuType.Cpu); //TODO } else { //For constants, the address field contains the constant's value value = symbol.Address ?? 0; } SearchResultType resultType = SearchResultType.Data; if (isConstant) { resultType = SearchResultType.Constant; } else if (addressInfo?.Type == SnesMemoryType.PrgRom && addressInfo.Value.Address < cdlData.Length) { if ((cdlData[addressInfo.Value.Address] & (byte)CdlFlags.JumpTarget) != 0) { resultType = SearchResultType.JumpTarget; } else if ((cdlData[addressInfo.Value.Address] & (byte)CdlFlags.SubEntryPoint) != 0) { resultType = SearchResultType.Function; } } searchResults.Add(new SearchResultInfo() { Caption = symbol.Name, AbsoluteAddress = addressInfo, Length = _symbolProvider.GetSymbolSize(symbol), SearchResultType = resultType, Value = value, File = def?.File, SourceLocation = def, RelativeAddress = relAddress, CodeLabel = LabelManager.GetLabel(symbol.Name) }); } } } else { foreach (CodeLabel label in LabelManager.GetLabels(CpuType.Cpu)) //TODO { if (Contains(label.Label, searchStrings)) { SearchResultType resultType = SearchResultType.Data; AddressInfo addressInfo = label.GetAbsoluteAddress(); if (addressInfo.Type == SnesMemoryType.PrgRom && addressInfo.Address < cdlData.Length) { if ((cdlData[addressInfo.Address] & (byte)CdlFlags.JumpTarget) != 0) { resultType = SearchResultType.JumpTarget; } else if ((cdlData[addressInfo.Address] & (byte)CdlFlags.SubEntryPoint) != 0) { resultType = SearchResultType.Function; } } AddressInfo relAddress = label.GetRelativeAddress(CpuType.Cpu); //TODO searchResults.Add(new SearchResultInfo() { Caption = label.Label, AbsoluteAddress = label.GetAbsoluteAddress(), Length = (int)label.Length, Value = label.GetValue(), SearchResultType = resultType, File = null, Disabled = !_allowOutOfScope && relAddress.Address < 0, RelativeAddress = relAddress, CodeLabel = label }); } } } } searchResults.Sort((SearchResultInfo a, SearchResultInfo b) => { int comparison = a.Disabled.CompareTo(b.Disabled); if (comparison == 0) { bool aStartsWithSearch = a.Caption.StartsWith(searchString, StringComparison.InvariantCultureIgnoreCase); bool bStartsWithSearch = b.Caption.StartsWith(searchString, StringComparison.InvariantCultureIgnoreCase); comparison = bStartsWithSearch.CompareTo(aStartsWithSearch); if (comparison == 0) { comparison = a.Caption.CompareTo(b.Caption); } } return(comparison); }); _resultCount = Math.Min(searchResults.Count, MaxResultCount); SelectedResult = 0; lblResultCount.Visible = !isEmptySearch; lblResultCount.Text = searchResults.Count.ToString() + (searchResults.Count == 1 ? " result" : " results"); if (searchResults.Count > MaxResultCount) { lblResultCount.Text += " (" + MaxResultCount.ToString() + " shown)"; } if (searchResults.Count == 0 && !isEmptySearch) { _resultCount++; searchResults.Add(new SearchResultInfo() { Caption = "No results found." }); pnlResults.BackColor = SystemColors.ControlLight; } else { pnlResults.BackColor = SystemColors.ControlDarkDark; } if (Program.IsMono) { pnlResults.Visible = false; } else { //Suspend layout causes a crash on Mono tlpResults.SuspendLayout(); } for (int i = 0; i < _resultCount; i++) { _results[i].Initialize(searchResults[i]); _results[i].Tag = searchResults[i]; _results[i].Visible = true; } for (int i = _resultCount; i < MaxResultCount; i++) { _results[i].Visible = false; } pnlResults.VerticalScroll.Value = 0; tlpResults.Height = (_results[0].Height + 1) * _resultCount; pnlResults.ResumeLayout(); if (Program.IsMono) { pnlResults.Visible = true; tlpResults.Width = pnlResults.ClientSize.Width - 17; } else { tlpResults.ResumeLayout(); tlpResults.Width = pnlResults.ClientSize.Width - 1; } }