-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
[HLSL] clangd support #58026
Comments
It seems to kinda-sorta work... First step is to convince your editor to send the file to clangd. A hacky way is to set the filetype in the editor to C or something (this works in vim and VSCode at least). clangd itself doesn't pay any attention to what language the server said the file was, it uses clang's driver which looks at the file extension. At this point I can hover on things (struct names etc), it knows what float3 is and I can go-to-definition and wind up in The examples I copy/paste from the internet (I don't know HLSL) show plenty of errors, things like TEXCOORD0 are unresolved - but I see the same running clang on the command line, so I guess it's just language features that are not finished? There's an annoying "HLSL code generation is unsupported for target 'x86_64-grtev4-linux-gnu'" at the top of the file, which would be nice to suppress somehow if you want this to be useful without setting up compile_commands.json (pick a different default target, suppress the warning in -fsyntax-only mode, block that diagnostic by default in clangd...). Ideas of how to maybe further improve things:
|
@sam-mccall Than you so much for the feedback! It is extremely well timed. I actually just started playing with this yesterday myself, and was pleasantly surprised how functional it was. I encountered the same issue that you saw with the triple, and one other assert caused by a bug in some of the HLSL-specific code that I have a patch for locally. There’s a lot of the language that we haven’t yet added to clang, so I expect support will be pretty limited for a while as we’re working on that. The one area that I was a little concerned about (but seems to be working fine), is that we use an ExternalSemaSource to inject AST nodes. We had to make some changes in Clang around the MultiplexSemaSource so that we could also support reading serialized ASTs (PCH). That is another part of clang that probably could use some design adjustment since the ownership of external sources is a bit wonky. |
@sam-mccall I don't know if you have thoughts on this, but I put up a PR to enable HLSL in the clangd VSCode plugin: clangd/vscode-clangd#392 With clang-15 it doesn't work, but doesn't do anything awful. Just errors out early and moves on. For clang-16 it hits the issues you described. I'll probably try to spend some time getting this into better shape before the clang-16 release so that we can have some rudimentary support. Personally, I'm loving the go to definition and basic hover support that I'm currently getting in vim. I cannot shower enough love on clangd. It is my favorite LLVM tool I haven't contributed to (yet :D ). |
Getting HLSL to work with clangd would be awesome
The text was updated successfully, but these errors were encountered: