Skip to content

Commit

Permalink
Add the SourceCodeMappings option. Fix SourceLink relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
JaneySprings committed Apr 25, 2024
1 parent 9f5fe9c commit 2f55153
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 14 deletions.
12 changes: 6 additions & 6 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ stages:
steps:
- task: UseDotNet@2
inputs:
version: '8.x'
version: '9.x'
- script: dotnet tool restore
displayName: 'Restore .NET tools'
- script: npm install
Expand Down Expand Up @@ -62,7 +62,7 @@ stages:
steps:
- task: UseDotNet@2
inputs:
version: '8.x'
version: '9.x'
- script: dotnet tool restore
displayName: 'Restore .NET tools'
- script: npm install
Expand Down Expand Up @@ -91,7 +91,7 @@ stages:
steps:
- task: UseDotNet@2
inputs:
version: '8.x'
version: '9.x'
- script: dotnet tool restore
displayName: 'Restore .NET tools'
- script: npm install
Expand Down Expand Up @@ -161,7 +161,7 @@ stages:
steps:
- task: UseDotNet@2
inputs:
version: '8.x'
version: '9.x'
- script: dotnet tool restore
displayName: 'Restore .NET tools'
- script: dotnet cake --target=test --configuration=release
Expand All @@ -183,7 +183,7 @@ stages:
steps:
- task: UseDotNet@2
inputs:
version: '8.x'
version: '9.x'
- script: dotnet tool restore
displayName: 'Restore .NET tools'
- script: dotnet cake --target=test --configuration=release
Expand All @@ -205,7 +205,7 @@ stages:
steps:
- task: UseDotNet@2
inputs:
version: '8.x'
version: '9.x'
- script: dotnet tool restore
displayName: 'Restore .NET tools'
- script: dotnet cake --target=test --configuration=release
Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,13 @@
"Decimal",
"Hexadecimal"
]
},
"dotnetMeteor.debuggerOptions.sourceCodeMappings": {
"type": "object",
"description": "%configuration.description.debuggerOptions.sourceCodeMappings%",
"additionalProperties": {
"type": "string"
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@
"configuration.description.debuggerOptions.stepOverPropertiesAndOperators": "Specifies whether the debugger should step over properties and operators.",
"configuration.description.debuggerOptions.searchMicrosoftSymbolServer": "Search for symbols on the Microsoft Symbol Server.",
"configuration.description.debuggerOptions.searchNuGetSymbolServer": "Search for symbols on the NuGet Symbol Server.",
"configuration.description.debuggerOptions.integerDisplayFormat": "Specifies the format of displayed integers in the debugging window."
"configuration.description.debuggerOptions.integerDisplayFormat": "Specifies the format of displayed integers in the debugging window.",
"configuration.description.debuggerOptions.sourceCodeMappings": "Modifies locations for the debugged source code by replacing values on the left with values on the right."
}
4 changes: 4 additions & 0 deletions src/DotNet.Meteor.Debug/DebugOptions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Immutable;
using System.Text.Json.Serialization;
using DotNet.Meteor.Debug.Extensions;
using Mono.Debugging.Client;
Expand Down Expand Up @@ -56,6 +57,9 @@ public class DebugOptions {
[JsonPropertyName("search_nuget_symbol_server")]
public bool SearchNuGetSymbolServer { get; set; } = ServerExtensions.DefaultDebuggerOptions.SearchNuGetSymbolServer;

[JsonPropertyName("source_code_mappings")]
public ImmutableDictionary<string, string> SourceCodeMappings { get; set; } = ServerExtensions.DefaultDebuggerOptions.SourceCodeMappings;

internal static IntegerDisplayFormat GetIntegerDisplayFormat(string value) {
if (value == Mono.Debugging.Client.IntegerDisplayFormat.Decimal.ToString())
return Mono.Debugging.Client.IntegerDisplayFormat.Decimal;
Expand Down
7 changes: 4 additions & 3 deletions src/DotNet.Meteor.Debug/DebugSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,12 @@ public class DebugSession : Session {
}
DebugProtocol.Source source = null;
if (!string.IsNullOrEmpty(frame.SourceLocation.FileName) && File.Exists(frame.SourceLocation.FileName)) {
string remappedSourcePath = session.RemapSourceLocation(frame.SourceLocation);
if (!string.IsNullOrEmpty(remappedSourcePath) && File.Exists(remappedSourcePath)) {
source = new DebugProtocol.Source() {
Name = Path.GetFileName(frame.SourceLocation.FileName),
Name = Path.GetFileName(remappedSourcePath),
PresentationHint = Source.PresentationHintValue.Normal,
Path = frame.SourceLocation.FileName,
Path = remappedSourcePath,
SourceReference = 0
};
}
Expand Down
11 changes: 11 additions & 0 deletions src/DotNet.Meteor.Debug/Extensions/MonoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ public static class MonoExtensions {
options.UseExternalTypeResolver = useExternalTypeResolver;
return frame.GetExpressionValue(expression, options);
}
public static string RemapSourceLocation(this SoftDebuggerSession session, SourceLocation location) {
if (location == null || string.IsNullOrEmpty(location.FileName))
return null;

foreach (var remap in session.Options.SourceCodeMappings) {
if (location.FileName.Contains(remap.Key))
return location.FileName.Replace(remap.Key, remap.Value);
}

return location.FileName;
}

public static void SetUserAssemblyNames(this SoftDebuggerStartInfo startInfo, string assembliesDirectory, DebuggerSessionOptions options) {
var includeSymbolServers = options.SearchMicrosoftSymbolServer || options.SearchNuGetSymbolServer;
Expand Down
7 changes: 6 additions & 1 deletion src/DotNet.Meteor.Debug/Extensions/SymbolServerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ public static class SymbolServerExtensions {
}
public static string DownloadSourceFile(SourceLink link) {
var sourcesDirectory = Path.Combine(tempDirectory, "sources");
var outputFilePath = Path.Combine(sourcesDirectory, link.RelativeFilePath);
if (!Uri.TryCreate(link.Uri, UriKind.Absolute, out var sourceLinkUri)) {
DebuggerLoggingService.CustomLogger.LogMessage($"Invalid source link '{link.Uri}'");
return null;
}

var outputFilePath = Path.Combine(sourcesDirectory, sourceLinkUri.LocalPath.TrimStart('/'));
if (File.Exists(outputFilePath))
return outputFilePath;

Expand Down
1 change: 1 addition & 0 deletions src/DotNet.Meteor.Debug/LaunchConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public class LaunchConfiguration {
debuggerOptions.StepOverPropertiesAndOperators = options.StepOverPropertiesAndOperators;
debuggerOptions.SearchMicrosoftSymbolServer = options.SearchMicrosoftSymbolServer;
debuggerOptions.SearchNuGetSymbolServer = options.SearchNuGetSymbolServer;
debuggerOptions.SourceCodeMappings = options.SourceCodeMappings;

return debuggerOptions;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mono.Debugger
3 changes: 2 additions & 1 deletion src/VSCode.Extension/configurationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export class ConfigurationController {
ellipsized_length: ConfigurationController.getSettingOrDefault<number>(res.configIdDebuggerOptionsEllipsizedLength),
project_assemblies_only: ConfigurationController.getSettingOrDefault<boolean>(res.configIdDebuggerOptionsProjectAssembliesOnly),
step_over_properties_and_operators: ConfigurationController.getSettingOrDefault<boolean>(res.configIdDebuggerOptionsStepOverPropertiesAndOperators),
search_microsoft_symbol_server: ConfigurationController.getSettingOrDefault<boolean>(res.configIdDebuggerOptionsSearchMicrosoftSymbolServer)
search_microsoft_symbol_server: ConfigurationController.getSettingOrDefault<boolean>(res.configIdDebuggerOptionsSearchMicrosoftSymbolServer),
source_code_mappings: ConfigurationController.getSettingOrDefault<any>(res.configIdDebuggerOptionsSourceCodeMappings)
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/VSCode.Extension/resources/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ export const configIdDebuggerOptionsEllipsizedLength = `${configIdDebuggerOption
export const configIdDebuggerOptionsProjectAssembliesOnly = `${configIdDebuggerOptions}.projectAssembliesOnly`;
export const configIdDebuggerOptionsStepOverPropertiesAndOperators = `${configIdDebuggerOptions}.stepOverPropertiesAndOperators`;
export const configIdDebuggerOptionsSearchMicrosoftSymbolServer = `${configIdDebuggerOptions}.searchMicrosoftSymbolServer`;
export const configIdDebuggerOptionsSearchNuGetSymbolServer = `${configIdDebuggerOptions}.searchNugetSymbolServer`;
export const configIdDebuggerOptionsSearchNuGetSymbolServer = `${configIdDebuggerOptions}.searchNugetSymbolServer`;
export const configIdDebuggerOptionsSourceCodeMappings = `${configIdDebuggerOptions}.sourceCodeMappings`;

0 comments on commit 2f55153

Please sign in to comment.