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

Enable clangd on HLSL sources #392

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
"C++",
"clang",
"clangd",
"LLVM"
"LLVM",
"HLSL"
],
"activationEvents": [
"onLanguage:c",
"onLanguage:cpp",
"onLanguage:cuda-cpp",
"onLanguage:objective-c",
"onLanguage:objective-cpp",
"onLanguage:hlsl",
Copy link
Member

Choose a reason for hiding this comment

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

this can't be conditional, but I think this just wakes up the plugin when an HLSL file is opened, and would just waste a few resources if the documentSelector doesn't have HLSL.

"onCommand:clangd.activate",
"onCommand:clangd.install",
"onCommand:clangd.update"
Expand Down Expand Up @@ -170,6 +172,11 @@
"type": "number",
"default": 0.55,
"description": "Opacity of inactive regions (used only if clangd.inactiveRegions.useBackgroundHighlight=false)"
},
"clangd.enableHLSL": {
"type": "boolean",
"default": false,
"description": "Enable experimental HLSL Support."
}
}
},
Expand Down
5 changes: 4 additions & 1 deletion src/clangd-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ export const clangdDocumentSelector = [
{scheme: 'file', language: 'cuda-cpp'},
{scheme: 'file', language: 'objective-c'},
{scheme: 'file', language: 'objective-cpp'},
{scheme: 'file', language: 'hlsl'},
Copy link
Member

Choose a reason for hiding this comment

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

this part is "just code", I think we can make it conditional on a config option.

];

export function isClangdDocument(document: vscode.TextDocument) {
return vscode.languages.match(clangdDocumentSelector, document);
if (vscode.workspace.getConfiguration('clangd').get('enableHLSL'))
return vscode.languages.match(clangdDocumentSelector, document);
return vscode.languages.match(clangdDocumentSelector.slice(0, -1), document);
Copy link
Contributor

Choose a reason for hiding this comment

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

A couple of issues here:

  1. This is not the only use of clangdDocumentSelector; its also used here
  2. The slice() call seems a bit brittle in that if someone adds a new element at the end of the selector, it would now slice that one off

Can we instead replace clangdDocumentSelector with a function whose implementation checks the config option and adds the HLSL entry to the returned array accordingly?

Note that the use of clangdDocumentSelector in the client options probably means that flipping the config option won't have full effect until a server restart, but that's probably unavoidable (the best we could do, if we wanted to, is probably to prompt the user to restart the server when the option is flipped).

}

class ClangdLanguageClient extends vscodelc.LanguageClient {
Expand Down