-
-
Notifications
You must be signed in to change notification settings - Fork 178
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
Add syntax highlighting for .tscn/.tres/.godot
files
#196
Comments
I've always wanted to write a TextMate grammar from scratch. This one sounds fun. The shader language is probably similar enough to use an existing grammar with minimal problems, but autocompletion or inline documention might need a language server or something. |
There is no LSP for the Godot shader language yet, although the list of built-in functions is known in advance (and is similar to GLSL). Using an existing GLSL grammar as a base should work well 🙂 For |
I put together a grammar that works on The colors are mostly similar to the gdscript grammar, and if anybody thinks it would look better tagged a different way I can certainly swap them around. Godot 4 resource files appears to work, except for missing the new type names(Vector2i, PackedStringArray, PackedInt32Array, etc). Is there a master list of the new types somewhere? If somebody could point me to it, I can add them easily. And finally, here's extremely simple GDShader support. I basically just set up gdshader as an alias to glsl. I also configured highlighting for gdshader code embedded in a gdresource file. (The right side of the below screenshot.) |
@DaelonSuzuka Looks great! Feel free to open a pull request for this 🙂
See the diff of godotengine/godot-docs#5605 for a list of changes. Or here: https://github.com/godotengine/godot-docs/blob/13819832265a71d6e7abc2888df13a9dc6ee6146/_extensions/gdscript.py#L295-L332 |
Thanks! There's still some cleaning up to do, but I should have it in by the weekend.
Awesome, that's exactly what I needed. I'll put these in for now, and revisit this topic later and look closer for incompatibilities. I also plan to come back and make a real grammar for GDShaders, but I figured just deferring to glsl was better than nothing. |
This issue can be closed since #342 was merged. |
Hi. I just noticed these changes have been published. It has, IMO, better syntax for .tscn/.tres/etc files. All the code is under 0BSD so feel free to use whatever you want. In case you want to test it, make sure to rename the extension folder, so VSCode prioritizes it in gdshader language id clash (it uses alphabetic order for extension conflicts), e.g.: |
@AlfishSoftware Whoa, that's fantastic. Some of these features were on the roadmap already, so I massively appreciate your willingness to share.
I had already (barely) started working on some scene/resource analysis tools, and after skimming your extension I think this will be a huge springboard. I'll definitely be in touch when I get deeper into that. |
I need to ask something (since I don't know of any official spec for tres|tscn|etc syntax). In the It appeared when I made tests with VisualScript, e.g.: [sub_resource type="VisualScriptPropertyGet" id="VisualScriptPropertyGet_58mo7"]
property = &"text"
[sub_resource type="VisualScript" id="VisualScript_urosk"]
resource_name = "MyScript"
data = {
"base_type": &"Node", EDIT: Ah I see now that it's a interned StringName value from Godot 4. I'll assume it uses the same escaping rules, and that there's no other alternative string syntax (since NodePath still uses function-like syntax); please correct me if I'm wrong. |
There's a specification for TSCN/TRES but it's not updated for 4.0 yet: https://docs.godotengine.org/en/stable/development/file_formats/tscn.html
This is correct, however, I think using |
My implementation is now released and I've published it on OpenVSX. I have made major improvements on how inline code (GDScript and GDShader) is tokenized inside .tscn/.tres files. |
I was able to spend some time exploring your provider class last month. I'm still learning how to read JS/TS(especially other people's JS/TS), but I learned a TON really fast. Thank you again for sharing your work so freely! The image preview in the hover looks really good, I'll definitely have to update my local copy. I added some extra hovers and implemented the DocumentLinkProvider interface for gdresource and gdscript files: hovers and links exampleCode_KKCiRTkaTj.mp4I also figured out how to find codeasync function resPathOfDocument(document: vscode.TextDocument) {
const files = await vscode.workspace.findFiles("**/project.godot");
if (!files) {
return document.uri.path.replace(/^(?:.*\/)+/, "");
}
const project_dir = files[0].fsPath.replace("project.godot", "");
const relative = document.uri.path.substring(project_dir.length); // extremely lazy relative path calculation, very bad
return "res:/" + relative;
}
async function resPathToUri(resPath: string, document: vscode.TextDocument) {
const files = await vscode.workspace.findFiles("**/project.godot");
if (!files) {
return resPath;
}
const project_dir = files[0].fsPath.replace("project.godot", "");
return Uri.joinPath(Uri.file(project_dir), resPath.substring(6));
} |
I was doing it mostly for my own use at first (wasn't even sure if I would end up publishing it) so I didn't bother a lot with adding comments to the code. I'll keep that in mind. That looks cool!
Yeah, I went with lazy implementation for now, but the proper way to do it is simple:
I might work on that next, since there's still a few other things that also need fixing (like font previews) EDIT: v0.0.2 of my implementation now has proper project detection that works regardless of open workspace or folder |
Shouldn't this be closed by now? Since it seems to be implemented. |
Probably, yeah. |
This is low-priority, but it'd be nice to have a dedicated highlighter for Godot scenes and resources. The automatically-detected "Properties" syntax highlighting does its job decently, but a specially tailored highlighter could do better. For instance, it could handle slashes in property names and highlight built-in Godot types.
See also #70 which is about
.shader
files.The text was updated successfully, but these errors were encountered: