@gram-data/tree-sitter-gram 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ [package]
2
+ name = "gram_zed_extension"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ license = "MIT"
6
+ publish = false
7
+ repository = "https://github.com/gram-data/tree-sitter-gram"
8
+ build = "build.rs"
9
+
10
+ [lib]
11
+ path = "src/lib.rs"
12
+ crate-type = ["cdylib"]
13
+
14
+ [dependencies]
15
+ zed_extension_api = "0.7"
16
+
17
+ # Standalone workspace root so this crate is not treated as a stray member of the
18
+ # repository workspace (see root `Cargo.toml` `[workspace]`).
19
+ [workspace]
20
+ members = ["."]
@@ -5,6 +5,7 @@ A [Zed](https://zed.dev) extension providing syntax highlighting and language su
5
5
  ## Features
6
6
 
7
7
  - **Syntax Highlighting**: Full syntax highlighting for all Gram constructs including subjects, nodes, relationships, and data types
8
+ - **Language server**: When [`gram-lsp`](../../tools/lsp/) is on your `PATH`, Zed starts it for `.gram` files (diagnostics, hover, definitions, references, completions)
8
9
  - **Subject Pattern Matching**: Automatic matching for `()`, `[]`, and `{}`
9
10
  - **File Type Detection**: Automatic recognition of `.gram` files
10
11
  - **Smart Indentation**: Proper indentation handling for nested structures
@@ -40,7 +41,7 @@ Then restart Zed.
40
41
 
41
42
  ## Usage
42
43
 
43
- Once installed, the extension automatically provides syntax highlighting for any file with a `.gram` extension.
44
+ Once installed, the extension provides syntax highlighting for `.gram` files. With `gram-lsp` installed and on `PATH`, Zed also attaches the language server automatically.
44
45
 
45
46
  ### Example Gram Syntax
46
47
 
@@ -108,14 +109,25 @@ To work on this extension:
108
109
  - Select the `editors/zed` directory
109
110
  - Restart Zed
110
111
 
111
- 3. Make changes to the extension files
112
- 4. Restart Zed to see changes
112
+ 3. Build the Wasm extension once after Rust changes (Zed loads the cdylib):
113
+
114
+ ```bash
115
+ rustup target add wasm32-wasip1
116
+ cd editors/zed && cargo check --target wasm32-wasip1
117
+ ```
118
+
119
+ 4. Make changes to the extension files
120
+ 5. Restart Zed to see changes
113
121
 
114
122
  ### Extension Structure
115
123
 
116
124
  ```
117
125
  editors/zed/
118
- ├── extension.toml # Extension metadata; points at grammar repo (repository + rev)
126
+ ├── Cargo.toml # Wasm extension crate (zed_extension_api)
127
+ ├── build.rs # Embeds `extension.toml` version for release asset lookup
128
+ ├── Cargo.lock
129
+ ├── src/lib.rs # `language_server_command`: PATH, then GitHub release download
130
+ ├── extension.toml # Extension metadata; grammar repo + `[language_servers.gram-lsp]`
119
131
  ├── languages/
120
132
  │ └── gram/
121
133
  │ ├── config.toml # Zed language config (brackets, suffixes, etc.)
@@ -144,6 +156,12 @@ After either command, `extension.toml` is updated in place. For local dev you ty
144
156
 
145
157
  **If Zed shows an old version (e.g. 0.1.11) after installing the dev extension:** Zed may be using a cached clone of the grammar (at an old rev) or an older copy of the extension. Try: (1) Uninstall the Gram extension from Zed’s Extensions panel. (2) Delete the grammar cache: remove `editors/zed/grammars/` if it exists (Zed recreates it when needed). (3) Run `npm run zed:dev` again so `extension.toml` has the current version and rev. (4) In Zed, run “Install Dev Extension” and select `editors/zed` again. Restart Zed and recheck the extension version.
146
158
 
159
+ ### Bundled `gram-lsp` (GitHub Releases)
160
+
161
+ Zed extensions ship a **Wasm** adapter only; native `gram-lsp` binaries cannot be embedded in that bundle. Instead, when `gram-lsp` is **not** on `PATH`, the extension downloads a platform archive from **this repo’s GitHub Release** whose tag is **`v` + `version` from `extension.toml`** (for example `v0.3.5` for `version = "0.3.5"`).
162
+
163
+ Maintainers: pushing a **`v*`** tag runs **`.github/workflows/gram-lsp-release-assets.yml`**, which builds `gram-lsp` for common targets and uploads `gram-lsp-{target}.tar.gz` to the matching GitHub Release. Filenames must stay in sync with `editors/zed/src/lib.rs`. Keep `extension.toml`’s `version` aligned with the tag you ship to the Zed extension registry (for example tag `v0.3.5` and `version = "0.3.5"`) so installs download the intended binaries.
164
+
147
165
  ## Contributing
148
166
 
149
167
  Contributions are welcome! Please see the main [repository](https://github.com/gram-data/tree-sitter-gram) for contribution guidelines.
@@ -156,7 +174,7 @@ To improve syntax highlighting and editor behavior:
156
174
 
157
175
  ## License
158
176
 
159
- This extension is part of the tree-sitter-gram project and is licensed under the ISC License. See the main repository's [LICENSE](../../LICENSE) file for details.
177
+ This extension is part of the tree-sitter-gram project and is licensed under the MIT License. See the main repository's [LICENSE](../../LICENSE) file for details.
160
178
 
161
179
  ## Learn More
162
180
 
@@ -0,0 +1,26 @@
1
+ //! Expose `extension.toml`'s `version = "…"` as `env!("GRAM_EXT_VERSION")` for release lookups.
2
+
3
+ use std::env;
4
+ use std::fs;
5
+ use std::path::PathBuf;
6
+
7
+ fn main() {
8
+ let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));
9
+ let ext_toml = manifest_dir.join("extension.toml");
10
+ println!("cargo:rerun-if-changed={}", ext_toml.display());
11
+
12
+ let content = fs::read_to_string(&ext_toml).unwrap_or_else(|e| panic!("read {}: {e}", ext_toml.display()));
13
+ let version = parse_version(&content)
14
+ .unwrap_or_else(|| panic!("{}: missing `version = \"…\"` line", ext_toml.display()));
15
+ println!("cargo:rustc-env=GRAM_EXT_VERSION={version}");
16
+ }
17
+
18
+ fn parse_version(toml: &str) -> Option<String> {
19
+ for line in toml.lines() {
20
+ let line = line.trim();
21
+ if let Some(rest) = line.strip_prefix("version = \"") {
22
+ return rest.split('"').next().map(str::to_string);
23
+ }
24
+ }
25
+ None
26
+ }
@@ -1,11 +1,16 @@
1
1
  id = "gram"
2
2
  name = "Gram Language Support"
3
- version = "0.3.5"
3
+ version = "0.3.7"
4
4
  schema_version = 1
5
5
  authors = ["Gram Data Contributors"]
6
6
  description = "Support for Gram notation - composable data patterns"
7
7
 
8
+ capabilities = [
9
+ { kind = "process:exec", command = "*", args = ["stdio"] },
10
+ { kind = "download_file", host = "github.com", path = ["gram-data", "tree-sitter-gram", "**"] },
11
+ ]
12
+
8
13
  # path = "grammars/tree-sitter-gram"
9
14
  [grammars.gram]
10
15
  repository = "https://github.com/gram-data/tree-sitter-gram"
11
- rev = "869488b6bbea325b4c4153a7a6bee97df7931a58"
16
+ rev = "746afa9e990c3deca83dc2a2638877aef4bef4fa"
@@ -12,5 +12,5 @@ word_characters = ["_"]
12
12
  [prettier]
13
13
  allowed = false
14
14
 
15
- # [language_servers]
16
- # Add language server configuration here if you develop one for Gram
15
+ # Language servers are declared in extension.toml (`[language_servers.gram-lsp]`)
16
+ # and started from `src/lib.rs`. Per-server options go in Zed settings.json under `lsp`.
@@ -0,0 +1,156 @@
1
+ //! Zed extension host glue: starts `gram-lsp` from `PATH` or downloads a release asset.
2
+
3
+ use zed_extension_api::{
4
+ self as zed,
5
+ github_release_by_tag_name,
6
+ set_language_server_installation_status,
7
+ Architecture, Command, DownloadedFileType, Extension, LanguageServerId,
8
+ LanguageServerInstallationStatus, Os, Result, Worktree, current_platform, download_file,
9
+ make_file_executable,
10
+ };
11
+
12
+ const GRAM_REPO: &str = "gram-data/tree-sitter-gram";
13
+
14
+ struct GramExtension {
15
+ /// Relative path (under the extension work dir) or absolute path from `which`.
16
+ cached_binary: Option<String>,
17
+ }
18
+
19
+ impl GramExtension {
20
+ fn rust_target_triple() -> Result<&'static str> {
21
+ match current_platform() {
22
+ (Os::Mac, Architecture::Aarch64) => Ok("aarch64-apple-darwin"),
23
+ (Os::Mac, Architecture::X8664) => Ok("x86_64-apple-darwin"),
24
+ (Os::Linux, Architecture::Aarch64) => Ok("aarch64-unknown-linux-gnu"),
25
+ (Os::Linux, Architecture::X8664) => Ok("x86_64-unknown-linux-gnu"),
26
+ (Os::Windows, Architecture::Aarch64) => Ok("aarch64-pc-windows-msvc"),
27
+ (Os::Windows, Architecture::X8664) => Ok("x86_64-pc-windows-msvc"),
28
+ (Os::Linux, Architecture::X86) | (Os::Windows, Architecture::X86) => Err(
29
+ "gram-lsp: 32-bit platforms are not supported; install gram-lsp on PATH manually"
30
+ .into(),
31
+ ),
32
+ (Os::Mac, Architecture::X86) => Err(
33
+ "gram-lsp: unexpected macOS x86 architecture; install gram-lsp on PATH manually"
34
+ .into(),
35
+ ),
36
+ }
37
+ }
38
+
39
+ fn gram_lsp_bin_name(os: Os) -> &'static str {
40
+ match os {
41
+ Os::Windows => "gram-lsp.exe",
42
+ Os::Mac | Os::Linux => "gram-lsp",
43
+ }
44
+ }
45
+
46
+ fn ensure_downloaded(
47
+ &mut self,
48
+ language_server_id: &LanguageServerId,
49
+ ) -> Result<String> {
50
+ let version = env!("GRAM_EXT_VERSION");
51
+ let extract_dir = format!("gram-lsp-{version}");
52
+ let (os, _) = current_platform();
53
+ let bin_name = Self::gram_lsp_bin_name(os);
54
+ let relative_binary = format!("{extract_dir}/{bin_name}");
55
+
56
+ let triple = Self::rust_target_triple()?;
57
+ let asset_name = format!("gram-lsp-{triple}.tar.gz");
58
+ let tag = format!("v{version}");
59
+
60
+ set_language_server_installation_status(
61
+ language_server_id,
62
+ &LanguageServerInstallationStatus::Downloading,
63
+ );
64
+
65
+ let release = match github_release_by_tag_name(GRAM_REPO, &tag) {
66
+ Ok(r) => r,
67
+ Err(e) => {
68
+ let detail = format!(
69
+ "GitHub release {tag}: {e}. Install `gram-lsp` on PATH or publish release assets (see .github/workflows/gram-lsp-release-assets.yml)."
70
+ );
71
+ set_language_server_installation_status(
72
+ language_server_id,
73
+ &LanguageServerInstallationStatus::Failed(detail.clone()),
74
+ );
75
+ return Err(format!("gram-lsp: no GitHub release for {tag}: {e}"));
76
+ }
77
+ };
78
+
79
+ let asset = match release.assets.iter().find(|a| a.name == asset_name) {
80
+ Some(a) => a,
81
+ None => {
82
+ let msg = format!(
83
+ "gram-lsp: release {tag} has no asset {asset_name}. Build with the gram-lsp-release-assets workflow."
84
+ );
85
+ set_language_server_installation_status(
86
+ language_server_id,
87
+ &LanguageServerInstallationStatus::Failed(msg.clone()),
88
+ );
89
+ return Err(msg);
90
+ }
91
+ };
92
+
93
+ if let Err(e) = download_file(
94
+ &asset.download_url,
95
+ &extract_dir,
96
+ DownloadedFileType::GzipTar,
97
+ ) {
98
+ set_language_server_installation_status(
99
+ language_server_id,
100
+ &LanguageServerInstallationStatus::Failed(e.clone()),
101
+ );
102
+ return Err(format!("gram-lsp: download failed: {e}"));
103
+ }
104
+
105
+ if let Err(e) = make_file_executable(&relative_binary) {
106
+ set_language_server_installation_status(
107
+ language_server_id,
108
+ &LanguageServerInstallationStatus::Failed(e.clone()),
109
+ );
110
+ return Err(format!("gram-lsp: chmod failed: {e}"));
111
+ }
112
+
113
+ set_language_server_installation_status(
114
+ language_server_id,
115
+ &LanguageServerInstallationStatus::None,
116
+ );
117
+
118
+ self.cached_binary = Some(relative_binary.clone());
119
+ Ok(relative_binary)
120
+ }
121
+ }
122
+
123
+ impl Extension for GramExtension {
124
+ fn new() -> Self {
125
+ Self {
126
+ cached_binary: None,
127
+ }
128
+ }
129
+
130
+ fn language_server_command(
131
+ &mut self,
132
+ language_server_id: &LanguageServerId,
133
+ worktree: &Worktree,
134
+ ) -> Result<Command> {
135
+ if language_server_id.as_ref() != "gram-lsp" {
136
+ return Err(format!(
137
+ "unsupported language server id: {}",
138
+ language_server_id.as_ref()
139
+ ));
140
+ }
141
+
142
+ if let Some(path) = &self.cached_binary {
143
+ return Ok(Command::new(path).arg("stdio"));
144
+ }
145
+
146
+ if let Some(path) = worktree.which("gram-lsp") {
147
+ self.cached_binary = Some(path.clone());
148
+ return Ok(Command::new(path).arg("stdio"));
149
+ }
150
+
151
+ let path = self.ensure_downloaded(language_server_id)?;
152
+ Ok(Command::new(path).arg("stdio"))
153
+ }
154
+ }
155
+
156
+ zed::register_extension!(GramExtension);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gram-data/tree-sitter-gram",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "subject-oriented notation for structured data",
5
5
  "homepage": "https://gram-data.github.io",
6
6
  "repository": {
package/src/parser.c CHANGED
@@ -4368,7 +4368,7 @@ TS_PUBLIC const TSLanguage *tree_sitter_gram(void) {
4368
4368
  .metadata = {
4369
4369
  .major_version = 0,
4370
4370
  .minor_version = 3,
4371
- .patch_version = 5,
4371
+ .patch_version = 7,
4372
4372
  },
4373
4373
  };
4374
4374
  return &language;
Binary file
package/tree-sitter.json CHANGED
@@ -12,7 +12,7 @@
12
12
  }
13
13
  ],
14
14
  "metadata": {
15
- "version": "0.3.5",
15
+ "version": "0.3.7",
16
16
  "license": "ISC",
17
17
  "description": "subject-oriented notation for structured data",
18
18
  "links": {