Переглянути джерело

Add Gleam LSP and formatter (#5514)

Lawrence Sarpong 2 місяців тому
батько
коміт
e6a0a005d6

+ 9 - 0
packages/opencode/src/format/formatter.ts

@@ -284,3 +284,12 @@ export const latexindent: Info = {
     return Bun.which("latexindent") !== null
   },
 }
+
+export const gleam: Info = {
+  name: "gleam",
+  command: ["gleam", "format", "$FILE"],
+  extensions: [".gleam"],
+  async enabled() {
+    return Bun.which("gleam") !== null
+  },
+}

+ 1 - 0
packages/opencode/src/lsp/language.ts

@@ -34,6 +34,7 @@ export const LANGUAGE_EXTENSIONS: Record<string, string> = {
   ".gitrebase": "git-rebase",
   ".go": "go",
   ".groovy": "groovy",
+  ".gleam": "gleam",
   ".hbs": "handlebars",
   ".handlebars": "handlebars",
   ".hs": "haskell",

+ 18 - 0
packages/opencode/src/lsp/server.ts

@@ -1509,4 +1509,22 @@ export namespace LSPServer {
       }
     },
   }
+
+  export const Gleam: Info = {
+    id: "gleam",
+    extensions: [".gleam"],
+    root: NearestRoot(["gleam.toml"]),
+    async spawn(root) {
+      const gleam = Bun.which("gleam")
+      if (!gleam) {
+        log.info("gleam not found, please install gleam first")
+        return
+      }
+      return {
+        process: spawn(gleam, ["lsp"], {
+          cwd: root,
+        }),
+      }
+    },
+  }
 }

+ 1 - 0
packages/web/src/content/docs/formatters.mdx

@@ -29,6 +29,7 @@ OpenCode comes with several built-in formatters for popular languages and framew
 | dart           | .dart                                                                                                    | `dart` command available                                       |
 | ocamlformat    | .ml, .mli                                                                                                | `ocamlformat` command available and `.ocamlformat` config file |
 | terraform      | .tf, .tfvars                                                                                             | `terraform` command available                                  |
+| gleam          | .gleam                                                                                                   | `gleam` command available                                      |
 
 So if your project has `prettier` in your `package.json`, OpenCode will automatically use it.
 

+ 1 - 0
packages/web/src/content/docs/lsp.mdx

@@ -36,6 +36,7 @@ OpenCode comes with several built-in LSP servers for popular languages:
 | ocaml-lsp          | .ml, .mli                                            | `ocamllsp` command available                                 |
 | terraform          | .tf, .tfvars                                         | Auto-installs from GitHub releases                           |
 | bash               | .sh, .bash, .zsh, .ksh                               | Auto-installs bash-language-server                           |
+| gleam              | .gleam                                               | `gleam` command available                                    |
 
 LSP servers are automatically enabled when one of the above file extensions are detected and the requirements are met.