Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tracking std out prints #343

Merged
merged 11 commits into from
Jul 23, 2019
Merged

Conversation

colombod
Copy link
Member

doing Console.Write and Console.WriteLine in kernels produces values

new ValueProduced("value three", kernelCommand, new[] { new FormattedValue(null, "value three"), }));
new ValueProduced("value one", kernelCommand, false, new[] { new FormattedValue(null, "value one"), }),
new ValueProduced("value two", kernelCommand, false, new[] { new FormattedValue(null, "value two"), }),
new ValueProduced("value three", kernelCommand, false, new[] { new FormattedValue(null, "value three"), }));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why no mime type?

Copy link
Member Author

Choose a reason for hiding this comment

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

myme types are done later on when formatting on raw value is done

Copy link
Contributor

Choose a reason for hiding this comment

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

I think FormattedValue without a mime type is confusing and probably bug prone. I think this test shows that because of the redundancy -- the formatted values ARE the raw values.

Copy link
Member Author

Choose a reason for hiding this comment

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

null value is generated by the Formatter.MimeTypeFor method

Copy link
Contributor

Choose a reason for hiding this comment

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

That's the right behavior. FormattedValue.MimeType is intentionally read-only because the expectation was that the mime type must be known at the time a FormattedValue is created. It was an oversight that the constructor didn't guard against this.

WorkspaceServer.Tests/Kernel/CSharpKernelTests.cs Outdated Show resolved Hide resolved

public override void Write(char value)
{
TrackSize(() => base.Write(value));
Copy link

Choose a reason for hiding this comment

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

You're going to reallocate this delegate every time you write, consider caching it.

private async Task TrackSizeAsync(Func<Task> action)
{
WriteOccurred = true;
if (_trakingSize)
Copy link

Choose a reason for hiding this comment

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

I feel like this is trying to handle some concurrency scenario but there doesn't seem to be any synchronization?

Copy link
Member Author

Choose a reason for hiding this comment

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

is handling re-entrancy, writeLine get decombosed in base class in write(value) and then WriteLine()

data: valueProduced?.FormattedValues
?.ToDictionary(k => k.MimeType ?? "text/plain", v => v.Value))
: new DisplayData(
transient: transient,
data: valueProduced?.FormattedValues
?.ToDictionary(k => k.MimeType ?? "text/plain", v => v.Value));
Copy link
Contributor

Choose a reason for hiding this comment

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

We should no longer need a fallback here.

@@ -358,8 +358,7 @@ private static void TryRegisterDefault(string typeName, Action<object, TextWrite

public static string MimeTypeFor(Type type)
{
_mimeTypesByType.TryGetValue(type, out var mimeType);
return mimeType;
return _mimeTypesByType.TryGetValue(type, out var mimeType) ? mimeType : "text/plain";
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe extract a static property Default so we don't keep repeating this string?

namespace Microsoft.DotNet.Interactive
{
public class FormattedValue
{
public FormattedValue(string mimeType, object value)
{
MimeType = mimeType;
MimeType = mimeType ?? throw new ArgumentNullException(nameof(mimeType));
Copy link
Contributor

Choose a reason for hiding this comment

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

This should also check for empty and whitespace, which are also not valid mime types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants