Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,31 @@
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
},
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/NetStackBeautifier.VSCExt/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/NetStackBeautifier.VSCExt/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
1 change: 1 addition & 0 deletions src/NetStackBeautifier.Core/Models/FrameFullClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public record FrameFullClass
{
public IEnumerable<string> NameSections { get; init; } = Enumerable.Empty<string>();
public IEnumerable<string> GenericParameterTypes { get; init; } = Enumerable.Empty<string>();
public IEnumerable<string> RawGenericParameterTypes { get; init; } = Enumerable.Empty<string>();

/// <summary>
/// Gets the full class name.
Expand Down
6 changes: 6 additions & 0 deletions src/NetStackBeautifier.Core/Models/FrameMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,11 @@ public record FrameMethod
/// </summary>
/// <typeparam name="string"></typeparam>
public IEnumerable<string> GenericParameterTypes{get; init;} = Enumerable.Empty<string>();

/// <summary>
/// Generic types.
/// </summary>
/// <typeparam name="string"></typeparam>
public IEnumerable<string> RawGenericParameterTypes{get; init;} = Enumerable.Empty<string>();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between RawGenericParameterTypes compare to GenericParameterTypes?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned below this simple includes the unprocessed GenericParameterTypes so that the pre-beautified stack can be highlighted correctly. The idea is to piggyback off the parsing we're doing for the beautification, otherwise we'd be essentially re-parsing the callstack from our extension to determine the semantic highlighting rules.

It could certainly be more intuitive though, maybe all of the parsed entities should simple return a Beautified{Entity} and a Full{Entity} where Entity is a generic parameter type, method param, etc.

}
}
2 changes: 1 addition & 1 deletion src/NetStackBeautifier.Core/Models/FrameParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ namespace NetStackBeautifier.Core
/// <summary>
/// A parameter.
/// </summary>
public record FrameParameter(string ParameterType, string ParameterName);
public record FrameParameter(string ParameterType, string ParameterName, string RawParameterType, string FullParameterName);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is FullParameterName? How is it different than ParameterName? Why do we need them?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do some transformations on the parameter names depending on the types. For example int32 becomes simply int. This ensures that the unprocessed value is returned so that the starting call stack can be highlighted correctly.

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ protected override Task<FrameItem> BeautifyImpAsync(FrameItem line, Cancellation
int tCount = 0;

List<string> result = new List<string>();
List<string> rawResult = new List<string>();
foreach (string item in line.FullClass.GenericParameterTypes)
{
rawResult.Add(item);
if (string.Equals(item, "System.__Canon", StringComparison.OrdinalIgnoreCase))
{
result.Add(GetT(++tCount));
Expand All @@ -43,6 +45,7 @@ protected override Task<FrameItem> BeautifyImpAsync(FrameItem line, Cancellation
FullClass = line.FullClass with
{
GenericParameterTypes = result,
RawGenericParameterTypes = rawResult
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected override Task<FrameItem> BeautifyImpAsync(FrameItem line, Cancellation
{
paramName = "n" + order++;
}
newParamList.Add(new FrameParameter("int", paramName));
newParamList.Add(new FrameParameter("int", paramName, parameter.ParameterType, parameter.ParameterName));
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ protected override Task<FrameItem> BeautifyImpAsync(FrameItem line, Cancellation
{
Name = newMethodName,
GenericParameterTypes = line.Method.GenericParameterTypes.NullAsEmpty().Any() ? line.Method.GenericParameterTypes : GenerateTypeParameter(genericMethodCount),
RawGenericParameterTypes = line.Method.GenericParameterTypes
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected override IFrameLine CreateFrameItem(string line)
string? parameterType = parameterDescriptor.Split(' ', StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
if (!string.IsNullOrEmpty(parameterType))
{
methodParameters.Add(new FrameParameter(parameterType.Trim(), string.Empty));
methodParameters.Add(new FrameParameter(parameterType.Trim(), string.Empty, parameterType, String.Empty));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private FrameItem CreateFrame(string line)
Name = methodName,
Parameters = ParseParameters(mainPartsMatch.Groups[6].Value),
GenericParameterTypes = methodTypeParameters,
RawGenericParameterTypes = methodTypeParameters
},
FileInfo = frameFileInfo,
AssemblySignature = assemblyInfo,
Expand Down Expand Up @@ -132,7 +133,7 @@ private IEnumerable<FrameParameter> ParseParameters(string input)
{
throw new InvalidCastException($"Unexpected parameter pair: {pair}, input string: {input}");
}
yield return new FrameParameter(typeAndNameTokens[0], typeAndNameTokens[1]);
yield return new FrameParameter(typeAndNameTokens[0], typeAndNameTokens[1], typeAndNameTokens[0], typeAndNameTokens[1]);
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/NetStackBeautifier.VSCExt/src/Actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';
import { getStackJson } from './BackendService';
import { generateColorizer, parseJsonStack } from './callStackLanguageService';
import { generateColorizer, parseJsonStack, StackType } from './callStackLanguageService';

export const SHOW_BEAUTIFIED_DOCUMENT = 'stackbeauty.showBeautified';

Expand All @@ -24,11 +24,14 @@ export async function createBeautifiedDocument(context: vscode.ExtensionContext)

const stackJson = await getStackJson(selectedText);
if (stackJson && stackJson.length) {
generateColorizer(stackJson);
const parsedStack = parseJsonStack(stackJson);
vscode.languages.setTextDocumentLanguage(vscode.window.activeTextEditor.document, 'callstack');
generateColorizer(stackJson, vscode.window.activeTextEditor.document.uri.fsPath, StackType.full);
const uri = vscode.Uri.parse(`callstack: ${parsedStack}`);
const doc = await vscode.workspace.openTextDocument(uri);
vscode.languages.setTextDocumentLanguage(doc, 'callstack');
generateColorizer(stackJson, uri.fsPath);
// vscode.languages.setTextDocumentLanguage(doc, 'callstack');
await vscode.window.showTextDocument(doc, {
preview: false,
viewColumn: vscode.ViewColumn.Two
Expand Down
Loading