Skip to content

Conversation

bartwalczak
Copy link

Adds another format that can clang-format can handle.

@tiye
Copy link

tiye commented Feb 19, 2025

wish I could see this earlier, took me several hours to realize why it failed. too me and my friend quite some time to figure out the problem.

diff --git a/package.json b/package.json
index 3dc71a8..bae7ad3 100644
--- a/package.json
+++ b/package.json
@@ -34,6 +34,7 @@
     "onLanguage:objective-c",
     "onLanguage:objective-cpp",
     "onLanguage:java",
+    "onLanguage:metal",
     "onLanguage:javascript",
     "onLanguage:typescript",
     "onLanguage:proto",
@@ -100,6 +101,11 @@
           "default": true,
           "description": "enable formatting for C (requires reloading Visual Studio Code)"
         },
+        "clang-format.language.metal.enable": {
+          "type": "boolean",
+          "default": true,
+          "description": "enable formatting for Metal (requires reloading Visual Studio Code)"
+        },
         "clang-format.language.c.style": {
           "type": "string",
           "default": "",
diff --git a/src/clangMode.ts b/src/clangMode.ts
index 68ca603..8864bf9 100644
--- a/src/clangMode.ts
+++ b/src/clangMode.ts
@@ -16,6 +16,7 @@ for (let l of [
   "java",
   "javascript",
   "json",
+  "metal",
   "typescript",
   "proto",
   "proto3",
diff --git a/src/extension.ts b/src/extension.ts
index 71d19c6..578bccd 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -188,7 +188,7 @@ export class ClangDocumentFormattingEditProvider
     let ret = vscode.workspace
       .getConfiguration("clang-format")
       .get<string>(`language.${this.getLanguage(document)}.style`);
-    if (ret.trim()) {
+    if (ret && ret.trim()) {
       return ret.trim();
     }
 
@@ -206,7 +206,7 @@ export class ClangDocumentFormattingEditProvider
     let strConf = vscode.workspace
       .getConfiguration("clang-format")
       .get<string>(`language.${this.getLanguage(document)}.fallbackStyle`);
-    if (strConf.trim()) {
+    if (strConf && strConf.trim()) {
       return strConf;
     }

@bartwalczak
Copy link
Author

@tiye Thanks. I'm not sure if there's something I should do now?

@tiye
Copy link

tiye commented Mar 3, 2025

I have no idea, this repo seems to be archived. Just wish some fixes like this one could be merged.

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

Successfully merging this pull request may close these issues.

2 participants