godotengine / godot-vscode-plugin

Godot development tools for VSCode
MIT License
1.47k stars 148 forks source link

Resource paths in comments are being incorrectly identified as links #621

Closed esklarski closed 2 months ago

esklarski commented 3 months ago

Godot version

4.2.1

VS Code version

1.87.1

Godot Tools VS Code extension version

2.0.0

System information

Fedora 39

Issue description

Specifically when including a Godot path: user:// or res:// in a comment. The Editor doesn't complain or do anything weird when viewing the file there. Aside from looking weird there seems to be no functional issue as everything works as expected otherwise.

See the comment just below func _ready()? Where it gets weird. It seems these tokens create a character injection issue. Screenshot from 2024-03-13 09-16-57

And here you can see it looks fine when I remove the offending text. Screenshot from 2024-03-13 09-17-09

I have tested and it seems it is only paths that mean something to Godot that cause the problem. If I include a file path like /home/user/thing:// or thing:// there is no issue. The underline seems to continue until the next quotation (") mark appears. If I remove the line where it stops in the screenshot, it underlines everything to the next quotation.

Steps to reproduce

Add a res:// or user:// into a comment.

esklarski commented 3 months ago

A workaround for those disliking the underlining is to simply add a single quotation mark after the second /

ie res://" Screenshot from 2024-03-13 10-13-55

DaelonSuzuka commented 3 months ago

So the cause of this is the document link provider. It's using a regex to search the document for resource paths. I was originally looking at code like load('res://path/to/whatever'), where the resource path was inside a string.

I actually do want it to attempt to create links for resource paths in comments, but linkifying the entire document is hilariously wrong. Detecting the end of a resource path that's NOT inside a string literal is actually rather difficult, so for now I've just changed it so that the worst case is it linkify's the rest of the current line.