From 0ba39f732ea09eb2974007b54a100dc5df9f3ea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20S=C3=B6derlund?= Date: Fri, 4 Dec 2026 18:43:26 +0100 Subject: [PATCH] feat(languages): add Odin with OLS, its tree-sitter grammar and outline (#8095) .odin files open as Odin: highlighting from tree-sitter-odin, a Structure view from a new outline query (every name of a multi-name field listed), and OLS as the language server, installable from Language Servers settings. OLS release archives name the program after the platform (ols-x86_64-pc-windows-msvc.exe), so the installer also locates ols-*. Co-authored-by: christerso <236006+christerso@users.noreply.github.com> --- Cargo.lock | 11 ++++++++ crates/ide-language/Cargo.toml | 1 + crates/ide-language/queries/odin/outline.scm | 24 ++++++++++++++++ crates/ide-language/src/registry.rs | 2 ++ crates/ide-language/src/syntax/grammars.rs | 10 +++++++ crates/ide-language/src/syntax/highlight.rs | 12 ++++++++ crates/ide-language/src/syntax/tests.rs | 29 ++++++++++++++++++++ crates/ide-tools/src/archive.rs | 18 ++++++++++++ crates/ide-tools/src/platform.rs | 23 ++++++++++++++++ crates/ide-tools/src/registry.rs | 22 +++++++++++++++ languages/odin.toml | 20 ++++++++++++++ 11 files changed, 172 insertions(+) create mode 100644 crates/ide-language/queries/odin/outline.scm create mode 100644 languages/odin.toml diff --git a/Cargo.lock b/Cargo.lock index 15d054c1d8..956cc235eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4690,6 +4690,7 @@ dependencies = [ "tree-sitter-nix", "tree-sitter-objc", "tree-sitter-ocaml", + "tree-sitter-odin", "tree-sitter-php", "tree-sitter-prisma-io", "tree-sitter-proto", @@ -10573,6 +10574,16 @@ dependencies = [ "tree-sitter-language", ] +[[package]] +name = "tree-sitter-odin" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24db210fe9ba2237c71c5030d7b146c7025420ba72dd8013d13cd822c3a8d77a" +dependencies = [ + "cc", + "tree-sitter-language", +] + [[package]] name = "tree-sitter-php" version = "0.25.1" diff --git a/crates/ide-language/Cargo.toml b/crates/ide-language/Cargo.toml index 446497d502..478607a3ae 100644 --- a/crates/ide-language/Cargo.toml +++ b/crates/ide-language/Cargo.toml @@ -61,6 +61,7 @@ tree-sitter-dart = "0.2.0" tree-sitter-graphql = "0.3.0" tree-sitter-prisma-io = "1.6.0" tree-sitter-gdscript = "6.1.0" +tree-sitter-odin = "1.3.0" [build-dependencies] blake3.workspace = true diff --git a/crates/ide-language/queries/odin/outline.scm b/crates/ide-language/queries/odin/outline.scm new file mode 100644 index 0000000000..fa016dfc3a --- /dev/null +++ b/crates/ide-language/queries/odin/outline.scm @@ -0,0 +1,24 @@ +; The name of a declaration is its first identifier; `@(...)` attributes may come before it. +(procedure_declaration . (identifier) @name (procedure (parameters) @detail)) @def.function +(procedure_declaration . (attributes) . (identifier) @name (procedure (parameters) @detail)) @def.function +(overloaded_procedure_declaration . (identifier) @name) @def.function +(overloaded_procedure_declaration . (attributes) . (identifier) @name) @def.function +(struct_declaration . (identifier) @name) @def.struct +(struct_declaration . (attributes) . (identifier) @name) @def.struct +(union_declaration . (identifier) @name) @def.struct +(union_declaration . (attributes) . (identifier) @name) @def.struct +(bit_field_declaration . (identifier) @name) @def.struct +(bit_field_declaration . (attributes) . (identifier) @name) @def.struct +(enum_declaration . (identifier) @name) @def.enum +(enum_declaration . (attributes) . (identifier) @name) @def.enum +(enum_declaration "{" . (identifier) @name @def.enum_member) +(enum_declaration "," . (identifier) @name @def.enum_member) +(field . (identifier) @name @def.field) +; `x, y: f32` declares two fields. +(field "," . (identifier) @name @def.field) +(source_file (const_declaration . (identifier) @name) @def.constant) +(source_file (const_declaration . (attributes) . (identifier) @name) @def.constant) +(source_file (const_type_declaration . (identifier) @name) @def.constant) +(source_file (variable_declaration . (identifier) @name) @def.variable) +(source_file (var_declaration . (identifier) @name) @def.variable) +(source_file (var_declaration . (attributes) . (identifier) @name) @def.variable) diff --git a/crates/ide-language/src/registry.rs b/crates/ide-language/src/registry.rs index c04837244b..057af85327 100644 --- a/crates/ide-language/src/registry.rs +++ b/crates/ide-language/src/registry.rs @@ -73,6 +73,7 @@ const BUILTIN: &[(&str, &str)] = &[ ("objective-cpp", include_str!("../../../languages/objective-cpp.toml")), ("ocaml", include_str!("../../../languages/ocaml.toml")), ("ocaml-interface", include_str!("../../../languages/ocaml-interface.toml")), + ("odin", include_str!("../../../languages/odin.toml")), ("perl", include_str!("../../../languages/perl.toml")), ("php", include_str!("../../../languages/php.toml")), ("plaintext", include_str!("../../../languages/plaintext.toml")), @@ -1618,6 +1619,7 @@ mod tests { ("init.lua", "lua"), ("main.dart", "dart"), ("build.zig", "zig"), + ("main.odin", "odin"), ("mix.exs", "elixir"), ("Main.hs", "haskell"), ("a.ml", "ocaml"), diff --git a/crates/ide-language/src/syntax/grammars.rs b/crates/ide-language/src/syntax/grammars.rs index 24da8d82e2..b1227aaad1 100644 --- a/crates/ide-language/src/syntax/grammars.rs +++ b/crates/ide-language/src/syntax/grammars.rs @@ -279,6 +279,16 @@ pub(crate) static SPECS: &[Spec] = &[ imports: NONE, constructors: NONE, }, + Spec { + name: "odin", + language: tree_sitter_odin::LANGUAGE, + outline: outline!("odin"), + highlights: Some(Highlights { query: tree_sitter_odin::HIGHLIGHTS_QUERY, first_wins: false }), + fold_nodes: NONE, + fold_bodies: NONE, + imports: &["import_declaration"], + constructors: NONE, + }, Spec { name: "elixir", language: tree_sitter_elixir::LANGUAGE, diff --git a/crates/ide-language/src/syntax/highlight.rs b/crates/ide-language/src/syntax/highlight.rs index 075b81cc00..c921fb4c3c 100644 --- a/crates/ide-language/src/syntax/highlight.rs +++ b/crates/ide-language/src/syntax/highlight.rs @@ -503,6 +503,18 @@ mod tests { ("u32", K::Builtin), ], ), + ( + "odin", + "package main\nimport \"core:fmt\"\n// hi\nmain :: proc() {\n x: u32 = 42\n fmt.println(x)\n}\n", + &[ + ("package", K::Keyword), + ("\"core:fmt\"", K::String), + ("// hi", K::Comment), + ("proc", K::Keyword), + ("42", K::Number), + ("u32", K::Builtin), + ], + ), ( "nix", "{ pkgs ? import {} }:\n# hi\nlet x = 1; in pkgs.mkShell { name = \"dev\"; }\n", diff --git a/crates/ide-language/src/syntax/tests.rs b/crates/ide-language/src/syntax/tests.rs index 3f3e8a0ff7..fc17658528 100644 --- a/crates/ide-language/src/syntax/tests.rs +++ b/crates/ide-language/src/syntax/tests.rs @@ -932,6 +932,35 @@ fn outline_more_languages() { Function basic ", ); + check_outline( + "odin", + concat!( + "package demo\n", + "import \"core:fmt\"\n", + "Vec :: struct {\n x, y: f32,\n}\n", + "Shape :: enum {\n Circle,\n Square = 2,\n}\n", + "Value :: union {\n int,\n f32,\n}\n", + "MAX :: 10\n", + "counter: int\n", + "@(private)\n", + "length :: proc(v: Vec) -> f32 {\n helper :: proc() {}\n return v.x\n}\n", + "add :: proc{add_int, add_f32}\n", + ), + " + Struct Vec + Field x + Field y + Enum Shape + EnumMember Circle + EnumMember Square + Struct Value + Constant MAX + Variable counter + Function length + Function helper + Function add + ", + ); check_outline( "elixir", "defmodule Foo.Bar do\n def go(a), do: a\n defp priv(b) do\n b\n end\n defmacro m(x), do: x\nend\n", diff --git a/crates/ide-tools/src/archive.rs b/crates/ide-tools/src/archive.rs index 0e7a63e74c..26ca58eb7a 100644 --- a/crates/ide-tools/src/archive.rs +++ b/crates/ide-tools/src/archive.rs @@ -797,6 +797,24 @@ mod tests { assert!(found.ends_with("server/com.microsoft.java.debug.plugin-0.53.2.jar")); } + #[test] + fn locate_finds_ols_named_after_its_platform() { + // The layout of OLS's release archives: the program, odinfmt and the `builtin` folder it reads. + for (program, odinfmt, names) in [ + ("ols-x86_64-pc-windows-msvc.exe", "odinfmt-x86_64-pc-windows-msvc.exe", ["ols.exe", "ols-*.exe"]), + ("ols-x86_64-unknown-linux-gnu", "odinfmt-x86_64-unknown-linux-gnu", ["ols", "ols-*"]), + ] { + let tmp = tempfile::tempdir().unwrap(); + let root = tmp.path(); + fs::create_dir_all(root.join("builtin")).unwrap(); + fs::write(root.join("builtin/builtin.odin"), "").unwrap(); + fs::write(root.join(odinfmt), "").unwrap(); + fs::write(root.join(program), "").unwrap(); + let names = names.map(String::from); + assert_eq!(locate(root, &names).unwrap(), root.join(program)); + } + } + #[test] fn windows_shims_name_the_tool_relative_to_themselves() { let tool = Path::new("/Users/张三/AppData/Local/ai.l0ng.openidea/tools/taplo"); diff --git a/crates/ide-tools/src/platform.rs b/crates/ide-tools/src/platform.rs index 4c2c4eb5d6..2557048b61 100644 --- a/crates/ide-tools/src/platform.rs +++ b/crates/ide-tools/src/platform.rs @@ -247,6 +247,29 @@ mod tests { } } + #[test] + fn ols_assets() { + let names = [ + "ols-arm64-darwin.zip", + "ols-x86_64-darwin.zip", + "ols-arm64-unknown-linux-gnu.zip", + "ols-x86_64-unknown-linux-gnu.zip", + "ols-x86_64-pc-windows-msvc.zip", + ]; + let rules = crate::registry::find("ols").unwrap().asset_rules(); + for (os, arch, expected) in [ + (Os::Mac, Arch::Arm64, names[0]), + (Os::Mac, Arch::X64, names[1]), + (Os::Linux, Arch::Arm64, names[2]), + (Os::Linux, Arch::X64, names[3]), + (Os::Windows, Arch::X64, names[4]), + // No Arm build for Windows: the x64 one runs emulated. + (Os::Windows, Arch::Arm64, names[4]), + ] { + assert_eq!(select_asset(&names, rules, Platform { os, arch }), Some(expected)); + } + } + #[test] fn rosetta_fallback_and_missing() { let names = ["zls-x86_64-macos.tar.xz", "zls-x86_64-linux.tar.xz", "zls-x86_64-windows.zip"]; diff --git a/crates/ide-tools/src/registry.rs b/crates/ide-tools/src/registry.rs index 7fac4fa743..42c43ba5af 100644 --- a/crates/ide-tools/src/registry.rs +++ b/crates/ide-tools/src/registry.rs @@ -906,6 +906,28 @@ pub static TOOLS: &[ToolSpec] = &[ homepage: "https://github.com/zigtools/zls", needs: &[], }, + ToolSpec { + name: "ols", + display: "OLS (Odin)", + kind: LanguageServer, + commands: &["ols"], + method: Method::Release { + source: ReleaseSource::GitHub { repo: "DanielGavin/ols" }, + assets: &[ + rule(Mac, Arm64, "ols-arm64-darwin.zip"), + rule(Mac, X64, "ols-x86_64-darwin.zip"), + rule(Linux, X64, "ols-x86_64-unknown-linux-gnu.zip"), + rule(Linux, Arm64, "ols-arm64-unknown-linux-gnu.zip"), + rule(Windows, X64, "ols-x86_64-pc-windows-msvc.zip"), + ], + // The release names the program after its platform: `ols-x86_64-pc-windows-msvc.exe`. + locate: &["ols", "ols-*"], + }, + fallback: None, + version: Some(("ols", &["version"])), + homepage: "https://github.com/DanielGavin/ols", + needs: &[], + }, ToolSpec { name: "terraform-ls", display: "Terraform Language Server", diff --git a/languages/odin.toml b/languages/odin.toml new file mode 100644 index 0000000000..560614c418 --- /dev/null +++ b/languages/odin.toml @@ -0,0 +1,20 @@ +id = "odin" +name = "Odin" +extensions = ["odin"] +line-comment = "//" +block-comment = ["/*", "*/"] +indent = { tab-size = 4, insert-spaces = false } +tree-sitter = "odin" + +[[language-servers]] +name = "ols" +command = "ols" +root-markers = ["ols.json", "odinfmt.json"] +install-hint = "Install OLS (https://github.com/DanielGavin/ols/releases)" + +[debugger] +adapter = "codelldb" +command = "codelldb" +args = ["--port", "${port}"] +transport = "tcp" +install-hint = "Install CodeLLDB in Settings › Languages & Frameworks › Language Servers"