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

Can it be made to work with VSCode? #3

Open
LaraSQP opened this issue Jun 6, 2024 · 7 comments
Open

Can it be made to work with VSCode? #3

LaraSQP opened this issue Jun 6, 2024 · 7 comments

Comments

@LaraSQP
Copy link

LaraSQP commented Jun 6, 2024

First, thank you for developing this great addon and making it available to all.

Now, as the question says, is it possible to make it work with VSCode?

I have not been able to find out how.

Perhaps this might work? It seems to be for Visual Studio, though.

https://gist.github.com/SilentPenguin/bf24eb348c9d00c34605d1cc54318be7

@LaraSQP
Copy link
Author

LaraSQP commented Jun 6, 2024

Forgot to include some details. Apologies.

I'm using Godot 4.2.2 and VSCode 1.90

This is what shows up in the DEBUG CONSOLE

image

The first line is a call to Log.pr("mouse_position")

The second line is produced by Log.pr(object) where object is some Node2D

@russmatney
Copy link
Owner

Thanks for the issue and the screenshot! I definitely want to support vscode. I don't use it often, but I'll get it running to try to improve that output.

The quickest thing might be disabling Log.gd's color completely, which might let vscode supply it's own colors/syntax highlighting, or at least skip the [color=blah][/color] wrappers. I just pushed a commit that adds "disable_color" to log's config, so colors can be disabled like Log.disable_colors().

This issue is similar to a problem that happens in the terminal and browser, but in that case some colors are still supported - I have been opting-in to those via Log.set_colors_termsafe() in places (e.g. at the beginning of unit-tests). In this case, after some brief reading it looks like we might have to rely on vscode to colorize the output via a syntax mode in the output panel rather than supply the colors ourselves.

Calling these global Log funcs to update the config is a bit cumbersome - I'd like to add a proper 'Editor Settings' section for Log where you can specify the color scheme and toggle "disable_color", set "max_array_size", etc. I'll take a shot at that soon, hopefully today!

@russmatney
Copy link
Owner

To share some notes from my digging - I don't have much vscode experience,
so if you or anyone else wants to weigh in with some ideas, feel free.

Log.gd relies on print_rich() to print its strings. According to the docs,
print_rich converts bbcode (well, a subset of bbcode) to ansi escape codes -
this is what makes the "termsafe" color scheme work in the terminal, browser,
emacs, etc.

https://docs.godotengine.org/en/4.2/classes/[email protected]#class-globalscope-method-print-rich

When printing to standard output, the supported subset of BBCode is
converted to ANSI escape codes for the terminal emulator to display. Support for
ANSI escape codes varies across terminal emulators, especially for italic and
strikethrough. In standard output, code is represented with faint text but
without any font change. Unsupported tags are left as-is in standard output.

It looks like the godot-vscode-plugin appends to the debug console here:
https://github.com/godotengine/godot-vscode-plugin/blob/df445b8390b5575c6e2b63ca7d6bdc1763154604/src/debugger/godot4/server_controller.ts#L434

As we saw in your screenshot, the output seems to be raw strings with color
tags, so that bbcode -> ansi conversion isn't occurring yet. I thought maybe we
could get the godot debugger to do this conversion for us, but first wanted to
make sure the Debug Console would at least respect ansi escape codes.

Unfortunately that doesn't seem to work either, tho maybe my test isn't escaped
properly or something?

func _enter_tree():
	print("some ansi code?")
	print("\\033[31;1;4mHello\\033[0m")

This just prints the literal strings as we see them, so I'm not confident we'll
be able to assign colors to output in vscode's Debug Console.

I'll think and test more on this - sorry to not have a cleaner answer yet! Let
me know if you have any ideas.

@LaraSQP
Copy link
Author

LaraSQP commented Jun 6, 2024

Thank you for the quick reply and the new code.

I will get the code and manually update your addon to disable colors for now.

Regarding the Debug Console, there must be a similar addon as yours for VSCode (but unrelated to Godot). I will look for those and see how they do it.

@russmatney
Copy link
Owner

Perhaps here?

https://github.com/IBM-Cloud/vscode-log-output-colorizer https://github.com/sgbush/buildoutputcolorizer https://github.com/ericniebler/buildoutputcolorizer https://github.com/tjx666/better-colorizer

Glancing at the screenshots, these make use of the 'Output' panel, which seems to support colorization via ansi escape codes (or some other mechanism) - godot-vscode-extension uses the 'Debug Console', which is a slightly different beast.

Some digging through godot-vscode-extension's issues makes it seem like they switched from using 'output' to 'debug console' to solve a bunch of debugger-related issues. I debated about opening an issue/discussion there to see if they had ideas for this use-case - it's probably a good idea.

I got a work-in-progress of Editor Settings in place a bit ago (to make it easier to disable colors), but it needs a bit more testing before another release is ready - hopefully in the next few days I'll have a proper release for you!

@LaraSQP
Copy link
Author

LaraSQP commented Jun 7, 2024

You rock. Good karma to you.

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

No branches or pull requests

2 participants