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 <[email protected]>
Цей коміт міститься в:
Christer Söderlundтаchristerso authored and GitHub committed 2026-12-05 01:43:26 +08:00
1 джерело 194b01d74f
коміт 0ba39f732e
11 files changed
+172

No files matched your search

Створено
+11
Переглянути файл
@@ -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"
+1
Переглянути файл
@@ -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
+24
Переглянути файл
@@ -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)
+2
Переглянути файл
@@ -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"),
+10
Переглянути файл
@@ -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,
+12
Переглянути файл
@@ -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 <nixpkgs> {} }:\n# hi\nlet x = 1; in pkgs.mkShell { name = \"dev\"; }\n",
+29
Переглянути файл
@@ -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",
+18
Переглянути файл
@@ -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");
+23
Переглянути файл
@@ -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"];
+22
Переглянути файл
@@ -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",
+20
Переглянути файл
@@ -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"