From a7133e97b74381061dfb4c530ccb9443a2ccbf1f Mon Sep 17 00:00:00 2001 From: Rajkumar Natarajan Date: Sun, 10 May 2026 19:14:01 -0700 Subject: [PATCH 1/8] issue-12: added support for haskell-debugger --- Cargo.lock | 551 ++++++++++++++++++-- Cargo.toml | 6 +- debug_adapter_schemas/haskell-debugger.json | 58 +++ extension.toml | 4 +- src/debugger.rs | 243 +++++++++ src/haskell.rs | 30 +- src/lib.rs | 2 + 7 files changed, 848 insertions(+), 46 deletions(-) create mode 100644 debug_adapter_schemas/haskell-debugger.json create mode 100644 src/debugger.rs create mode 100644 src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 77c70e2..434a3f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,37 +2,276 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + [[package]] name = "anyhow" version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" +[[package]] +name = "auditable-serde" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7bf8143dfc3c0258df908843e169b5cc5fcf76c7718bd66135ef4a9cd558c5" +dependencies = [ + "semver", + "serde", + "serde_json", + "topological-sort", +] + [[package]] name = "bitflags" version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "crc32fast" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "equivalent" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" +[[package]] +name = "flate2" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-executor" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf29c38818342a3b26b5b923639e7b1f4a61fc5e76102d4b1981c6dc7a7579d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718" + +[[package]] +name = "futures-macro" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + [[package]] name = "hashbrown" version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +dependencies = [ + "foldhash", +] [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "icu_collections" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2984d1cd16c883d7935b9e07e44071dca8d917fd52ecc02c04d5fa0b5a3f191c" dependencies = [ - "unicode-segmentation", + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c56e5ee99d6e3d33bd91c5d85458b6005a22140021cc324cea84dd0e72cff3b4" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da3be0ae77ea334f4da67c12f149704f19f81d1adf7c51cf482943e84a2bad38" + +[[package]] +name = "icu_properties" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bee3b67d0ea5c2cca5003417989af8996f8604e34fb9ddf96208a033901e70de" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14" + +[[package]] +name = "icu_provider" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", ] [[package]] @@ -41,6 +280,27 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + [[package]] name = "indexmap" version = "2.7.1" @@ -59,10 +319,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] -name = "leb128" -version = "0.2.5" +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "litemap" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" +checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" [[package]] name = "log" @@ -76,6 +342,53 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "potential_utf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564" +dependencies = [ + "zerovec", +] + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "proc-macro2" version = "1.0.94" @@ -87,9 +400,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.39" +version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1f1914ce909e1658d9907913b4b91947430c7d9be598b15a1912935b8c04801" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" dependencies = [ "proc-macro2", ] @@ -105,6 +418,9 @@ name = "semver" version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" +dependencies = [ + "serde", +] [[package]] name = "serde" @@ -138,6 +454,18 @@ dependencies = [ "serde", ] +[[package]] +name = "simd-adler32" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + [[package]] name = "smallvec" version = "1.14.0" @@ -153,11 +481,17 @@ dependencies = [ "smallvec", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + [[package]] name = "syn" -version = "2.0.99" +version = "2.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e02e925281e18ffd9d640e234264753c43edc62d64b2d4cf898f1bc5e75f3fc2" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" dependencies = [ "proc-macro2", "quote", @@ -165,16 +499,37 @@ dependencies = [ ] [[package]] -name = "unicode-ident" -version = "1.0.18" +name = "synstructure" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinystr" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d" +dependencies = [ + "displaydoc", + "zerovec", +] [[package]] -name = "unicode-segmentation" -version = "1.12.0" +name = "topological-sort" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" +checksum = "ea68304e134ecd095ac6c3574494fc62b909f416c4fca77e440530221e549d3d" + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "unicode-xid" @@ -182,78 +537,108 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "wasm-encoder" -version = "0.201.0" +version = "0.227.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9c7d2731df60006819b013f64ccc2019691deccf6e11a1804bc850cd6748f1a" +checksum = "80bb72f02e7fbf07183443b27b0f3d4144abf8c114189f2e088ed95b696a7822" dependencies = [ - "leb128", + "leb128fmt", + "wasmparser", ] [[package]] name = "wasm-metadata" -version = "0.201.0" +version = "0.227.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fd83062c17b9f4985d438603cde0a5e8c5c8198201a6937f778b607924c7da2" +checksum = "ce1ef0faabbbba6674e97a56bee857ccddf942785a336c8b47b42373c922a91d" dependencies = [ "anyhow", + "auditable-serde", + "flate2", "indexmap", "serde", "serde_derive", "serde_json", "spdx", + "url", "wasm-encoder", "wasmparser", ] [[package]] name = "wasmparser" -version = "0.201.0" +version = "0.227.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84e5df6dba6c0d7fafc63a450f1738451ed7a0b52295d83e868218fa286bf708" +checksum = "0f51cad774fb3c9461ab9bccc9c62dfb7388397b5deda31bf40e8108ccd678b2" dependencies = [ "bitflags", + "hashbrown", "indexmap", "semver", ] [[package]] name = "wit-bindgen" -version = "0.22.0" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "288f992ea30e6b5c531b52cdd5f3be81c148554b09ea416f058d16556ba92c27" +checksum = "10fb6648689b3929d56bbc7eb1acf70c9a42a29eb5358c67c10f54dbd5d695de" dependencies = [ - "bitflags", "wit-bindgen-rt", "wit-bindgen-rust-macro", ] [[package]] name = "wit-bindgen-core" -version = "0.22.0" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e85e72719ffbccf279359ad071497e47eb0675fe22106dea4ed2d8a7fcb60ba4" +checksum = "92fa781d4f2ff6d3f27f3cc9b74a73327b31ca0dc4a3ef25a0ce2983e0e5af9b" dependencies = [ "anyhow", + "heck", "wit-parser", ] [[package]] name = "wit-bindgen-rt" -version = "0.22.0" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb8738270f32a2d6739973cbbb7c1b6dd8959ce515578a6e19165853272ee64" +checksum = "c4db52a11d4dfb0a59f194c064055794ee6564eb1ced88c25da2cf76e50c5621" +dependencies = [ + "bitflags", + "futures", + "once_cell", +] [[package]] name = "wit-bindgen-rust" -version = "0.22.0" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8a39a15d1ae2077688213611209849cad40e9e5cccf6e61951a425850677ff3" +checksum = "9d0809dc5ba19e2e98661bf32fc0addc5a3ca5bf3a6a7083aa6ba484085ff3ce" dependencies = [ "anyhow", "heck", "indexmap", + "prettyplease", + "syn", "wasm-metadata", "wit-bindgen-core", "wit-component", @@ -261,11 +646,12 @@ dependencies = [ [[package]] name = "wit-bindgen-rust-macro" -version = "0.22.0" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d376d3ae5850526dfd00d937faea0d81a06fa18f7ac1e26f386d760f241a8f4b" +checksum = "ad19eec017904e04c60719592a803ee5da76cb51c81e3f6fbf9457f59db49799" dependencies = [ "anyhow", + "prettyplease", "proc-macro2", "quote", "syn", @@ -275,9 +661,9 @@ dependencies = [ [[package]] name = "wit-component" -version = "0.201.0" +version = "0.227.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "421c0c848a0660a8c22e2fd217929a0191f14476b68962afd2af89fd22e39825" +checksum = "635c3adc595422cbf2341a17fb73a319669cc8d33deed3a48368a841df86b676" dependencies = [ "anyhow", "bitflags", @@ -294,9 +680,9 @@ dependencies = [ [[package]] name = "wit-parser" -version = "0.201.0" +version = "0.227.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "196d3ecfc4b759a8573bf86a9b3f8996b304b3732e4c7de81655f875f6efdca6" +checksum = "ddf445ed5157046e4baf56f9138c124a0824d4d1657e7204d71886ad8ce2fc11" dependencies = [ "anyhow", "id-arena", @@ -310,11 +696,40 @@ dependencies = [ "wasmparser", ] +[[package]] +name = "writeable" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" + +[[package]] +name = "yoke" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + [[package]] name = "zed_extension_api" -version = "0.1.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "594fd10dd0f2f853eb243e2425e7c95938cef49adb81d9602921d002c5e6d9d9" +checksum = "0729d50b4ca0a7e28e590bbe32e3ca0194d97ef654961451a424c661a366fca0" dependencies = [ "serde", "serde_json", @@ -323,7 +738,61 @@ dependencies = [ [[package]] name = "zed_haskell" -version = "0.2.1" +version = "0.2.3" dependencies = [ "zed_extension_api", ] + +[[package]] +name = "zerofrom" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69faa1f2a1ea75661980b013019ed6687ed0e83d069bc1114e2cc74c6c04c4df" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerotrie" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index ad05cfc..d9829c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "zed_haskell" -version = "0.2.1" +version = "0.2.2" edition = "2021" publish = false license = "Apache-2.0" [lib] -path = "src/haskell.rs" +path = "src/lib.rs" crate-type = ["cdylib"] [dependencies] -zed_extension_api = "0.1.0" +zed_extension_api = "0.7" diff --git a/debug_adapter_schemas/haskell-debugger.json b/debug_adapter_schemas/haskell-debugger.json new file mode 100644 index 0000000..c3bfa80 --- /dev/null +++ b/debug_adapter_schemas/haskell-debugger.json @@ -0,0 +1,58 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Haskell Debugger (hdb)", + "description": "Launch configuration for the Well-Typed Haskell debugger (hdb). Requires GHC 9.14+ and the `hdb` executable on PATH. See https://well-typed.github.io/haskell-debugger/", + "type": "object", + "required": ["projectRoot", "entryFile"], + "properties": { + "type": { + "type": "string", + "const": "haskell-debugger", + "description": "Debug adapter id (matches VS Code `launch.json` type)." + }, + "request": { + "type": "string", + "enum": ["launch"], + "default": "launch", + "description": "hdb currently supports launch sessions only." + }, + "name": { + "type": "string", + "description": "Label for this debug session in the UI." + }, + "projectRoot": { + "type": "string", + "description": "Absolute path to the project root (Cabal/Stack/hie-bios cradle root)." + }, + "entryFile": { + "type": "string", + "description": "Path to the Haskell source file containing the entry point, relative to `projectRoot`." + }, + "entryPoint": { + "type": "string", + "description": "Name of the function to start (`main` or another top-level binding).", + "default": "main" + }, + "entryArgs": { + "type": "array", + "items": { "type": "string" }, + "description": "Arguments for the entry point. For `main`, these are passed as program arguments (`getArgs`).", + "default": [] + }, + "extraGhcArgs": { + "type": "array", + "items": { "type": "string" }, + "description": "Extra flags passed to the GHC invocation inferred by hie-bios.", + "default": [] + }, + "internalInterpreter": { + "type": "boolean", + "description": "Whether to use the internal GHCi interpreter for debugging.", + "default": false + }, + "debugServer": { + "type": "integer", + "description": "If set, Zed connects to an already-running `hdb server` on this TCP port instead of spawning `hdb`. Same as VS Code `launch.json` `debugServer`. See https://well-typed.github.io/haskell-debugger/" + } + } +} diff --git a/extension.toml b/extension.toml index 6c3e177..64cb952 100644 --- a/extension.toml +++ b/extension.toml @@ -1,7 +1,7 @@ id = "haskell" name = "Haskell" description = "Haskell support." -version = "0.2.1" +version = "0.2.2" schema_version = 1 authors = [ "Pocæus ", @@ -17,6 +17,8 @@ languages = [ # "Alex", # https://github.com/haskell/haskell-language-server/issues/4820 ] +[debug_adapters.haskell-debugger] + [grammars.haskell] repository = "https://github.com/tree-sitter/tree-sitter-haskell" commit = "8a99848fc734f9c4ea523b3f2a07df133cbbcec2" diff --git a/src/debugger.rs b/src/debugger.rs new file mode 100644 index 0000000..8f8741d --- /dev/null +++ b/src/debugger.rs @@ -0,0 +1,243 @@ +use std::path::{Component, Path}; + +use zed_extension_api::{ + self as zed, + DebugAdapterBinary, DebugConfig, DebugRequest, DebugScenario, DebugTaskDefinition, Result, + StartDebuggingRequestArguments, StartDebuggingRequestArgumentsRequest, TcpArguments, + TcpArgumentsTemplate, resolve_tcp_template, +}; +use zed::serde_json::{self, json}; + +pub(crate) const HASKELL_DEBUG_ADAPTER: &str = "haskell-debugger"; + +fn merge_haskell_debug_configuration(task: &DebugTaskDefinition) -> Result { + let mut map: serde_json::Map = + serde_json::from_str(&task.config).map_err(|err| { + format!("Invalid Haskell debug configuration (expected JSON object): {err}") + })?; + map.entry("type".to_string()) + .or_insert_with(|| json!(HASKELL_DEBUG_ADAPTER)); + map.entry("request".to_string()) + .or_insert_with(|| json!("launch")); + map.entry("name".to_string()) + .or_insert_with(|| json!(task.label.clone())); + Ok(serde_json::Value::Object(map)) +} + +fn project_root_from_config(config: &serde_json::Value) -> Option { + config + .get("projectRoot") + .and_then(|v| v.as_str()) + .map(str::to_string) +} + +fn resolve_hdb_binary( + user_path: Option, + worktree: &zed::Worktree, +) -> Result { + if let Some(path) = user_path.filter(|p| !p.is_empty()) { + return Ok(path); + } + worktree.which("hdb").ok_or_else(|| { + "Could not find `hdb` on PATH. Install the Haskell debugger from https://well-typed.github.io/haskell-debugger/" + .to_string() + }) +} + +fn entry_path_relative_to_root(project_root: &str, program: &str) -> Result { + if program.is_empty() { + return Err( + "Program path is empty. Choose the Haskell entry file (e.g. app/Main.hs).".into(), + ); + } + let root = Path::new(project_root); + let program_path = Path::new(program); + let absolute_program = if program_path.is_absolute() { + program_path.to_path_buf() + } else { + root.join(program_path) + }; + let relative = absolute_program.strip_prefix(root).map_err(|_| { + format!( + "Program path `{}` must be inside project root `{}`", + absolute_program.display(), + project_root + ) + })?; + path_components_to_string(relative) +} + +fn path_components_to_string(path: &Path) -> Result { + let mut out = String::new(); + for (i, component) in path.components().enumerate() { + match component { + Component::Normal(part) => { + if i > 0 { + out.push(std::path::MAIN_SEPARATOR); + } + out.push_str(&part.to_string_lossy()); + } + Component::CurDir => {} + Component::ParentDir => { + return Err("Program path must not contain `..`.".into()); + } + Component::RootDir | Component::Prefix(_) => { + return Err("Invalid program path.".into()); + } + } + } + if out.is_empty() { + Err("Resolved entry file path is empty.".into()) + } else { + Ok(out) + } +} + +pub(crate) fn get_dap_binary( + adapter_name: String, + task: DebugTaskDefinition, + user_provided_debug_adapter_path: Option, + worktree: &zed::Worktree, +) -> Result { + if adapter_name != HASKELL_DEBUG_ADAPTER { + return Err(format!( + "Unknown Haskell debug adapter: {adapter_name} (expected {HASKELL_DEBUG_ADAPTER})" + )); + } + + let merged = merge_haskell_debug_configuration(&task)?; + let request = dap_request_kind(adapter_name, merged.clone())?; + let configuration = serde_json::to_string(&merged) + .map_err(|err| format!("Failed to serialize debug configuration: {err}"))?; + + let cwd = project_root_from_config(&merged).or(Some(worktree.root_path())); + let envs = worktree.shell_env(); + + if let Some(debug_server) = merged.get("debugServer").and_then(|v| v.as_u64()) { + let port = u16::try_from(debug_server).map_err(|_| { + format!("`debugServer` port must fit in 16 bits, got {debug_server}") + })?; + let tcp_connection = task.tcp_connection.unwrap_or(TcpArgumentsTemplate { + host: None, + port: Some(port), + timeout: None, + }); + let tcp = resolve_tcp_template(tcp_connection)?; + return Ok(DebugAdapterBinary { + command: None, + arguments: vec![], + envs, + cwd, + connection: Some(tcp), + request_args: StartDebuggingRequestArguments { + configuration, + request, + }, + }); + } + + let tcp_connection = task.tcp_connection.unwrap_or(TcpArgumentsTemplate { + host: None, + port: None, + timeout: None, + }); + let TcpArguments { + host, + port, + timeout, + } = resolve_tcp_template(tcp_connection)?; + + let command = resolve_hdb_binary(user_provided_debug_adapter_path, worktree)?; + let mut arguments = vec![ + "server".to_string(), + "--port".to_string(), + port.to_string(), + ]; + if merged + .get("internalInterpreter") + .and_then(|v| v.as_bool()) + .unwrap_or(false) + { + arguments.push("--internal-interpreter".to_string()); + } + + Ok(DebugAdapterBinary { + command: Some(command), + arguments, + envs, + cwd, + connection: Some(TcpArguments { + host, + port, + timeout, + }), + request_args: StartDebuggingRequestArguments { + configuration, + request, + }, + }) +} + +pub(crate) fn dap_request_kind( + adapter_name: String, + config: serde_json::Value, +) -> Result { + if adapter_name != HASKELL_DEBUG_ADAPTER { + return Err(format!( + "Unknown Haskell debug adapter: {adapter_name} (expected {HASKELL_DEBUG_ADAPTER})" + )); + } + + match config.get("request").and_then(|v| v.as_str()) { + Some("attach") => Err( + "The Haskell debugger (hdb) does not support attach; use request \"launch\".".into(), + ), + Some("launch") | None => Ok(StartDebuggingRequestArgumentsRequest::Launch), + Some(other) => Err(format!( + "Unsupported `request` for Haskell debugger: {other}" + )), + } +} + +pub(crate) fn dap_config_to_scenario(config: DebugConfig) -> Result { + if config.adapter != HASKELL_DEBUG_ADAPTER { + return Err(format!( + "This extension only defines the `{HASKELL_DEBUG_ADAPTER}` debug adapter (got {}).", + config.adapter + )); + } + + match &config.request { + DebugRequest::Attach(_) => Err( + "The Haskell debugger (hdb) does not support attach in Zed; use a launch configuration." + .into(), + ), + DebugRequest::Launch(launch) => { + let project_root = launch.cwd.clone().ok_or_else(|| { + "Set working directory to your Cabal/Stack project root; it becomes `projectRoot` for hdb." + .to_string() + })?; + let entry_file = entry_path_relative_to_root(&project_root, &launch.program)?; + + let body = json!({ + "projectRoot": project_root, + "entryFile": entry_file, + "entryPoint": "main", + "entryArgs": launch.args.clone(), + "extraGhcArgs": [], + }); + + Ok(DebugScenario { + label: config.label, + adapter: config.adapter, + build: None, + config: body.to_string(), + tcp_connection: Some(TcpArgumentsTemplate { + host: None, + port: None, + timeout: None, + }), + }) + } + } +} diff --git a/src/haskell.rs b/src/haskell.rs index cac7b9c..4d5d2e7 100644 --- a/src/haskell.rs +++ b/src/haskell.rs @@ -2,7 +2,8 @@ use zed_extension_api::{ self as zed, lsp::{Symbol, SymbolKind}, settings::LspSettings, - CodeLabel, CodeLabelSpan, Result, + CodeLabel, CodeLabelSpan, DebugAdapterBinary, DebugConfig, DebugScenario, DebugTaskDefinition, + Result, StartDebuggingRequestArgumentsRequest, }; struct HaskellExtension; @@ -43,6 +44,33 @@ impl zed::Extension for HaskellExtension { }) } + fn get_dap_binary( + &mut self, + adapter_name: String, + task: DebugTaskDefinition, + user_provided_debug_adapter_path: Option, + worktree: &zed::Worktree, + ) -> Result { + crate::debugger::get_dap_binary( + adapter_name, + task, + user_provided_debug_adapter_path, + worktree, + ) + } + + fn dap_request_kind( + &mut self, + adapter_name: String, + config: zed::serde_json::Value, + ) -> Result { + crate::debugger::dap_request_kind(adapter_name, config) + } + + fn dap_config_to_scenario(&mut self, config: DebugConfig) -> Result { + crate::debugger::dap_config_to_scenario(config) + } + fn label_for_symbol( &self, _language_server_id: &zed::LanguageServerId, diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..ed7c0f7 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,2 @@ +mod debugger; +mod haskell; From 4aac9e22f6f40a0d05b4a623b342771748e31d2a Mon Sep 17 00:00:00 2001 From: RAJKUMAR NATARAJAN Date: Mon, 11 May 2026 12:49:36 -0700 Subject: [PATCH 2/8] Update src/debugger.rs Co-authored-by: Finn Evers --- src/debugger.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/debugger.rs b/src/debugger.rs index 8f8741d..128d62d 100644 --- a/src/debugger.rs +++ b/src/debugger.rs @@ -110,7 +110,7 @@ pub(crate) fn get_dap_binary( let configuration = serde_json::to_string(&merged) .map_err(|err| format!("Failed to serialize debug configuration: {err}"))?; - let cwd = project_root_from_config(&merged).or(Some(worktree.root_path())); + let cwd = project_root_from_config(&merged).or_else(|| Some(worktree.root_path())); let envs = worktree.shell_env(); if let Some(debug_server) = merged.get("debugServer").and_then(|v| v.as_u64()) { From 9b9dfcf835e5a64fd9bc6dd990bd857c7c5812e7 Mon Sep 17 00:00:00 2001 From: Rajkumar Natarajan Date: Mon, 11 May 2026 13:06:41 -0700 Subject: [PATCH 3/8] incorporate the review comments --- Cargo.lock | 103 +++++++++++++++---------- src/debugger.rs | 6 +- src/{haskell.rs => language_server.rs} | 2 +- src/lib.rs | 2 +- 4 files changed, 66 insertions(+), 47 deletions(-) rename src/{haskell.rs => language_server.rs} (98%) diff --git a/Cargo.lock b/Cargo.lock index 434a3f0..c7211e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "anyhow" -version = "1.0.97" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" [[package]] name = "auditable-serde" @@ -28,9 +28,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "2.9.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" [[package]] name = "cfg-if" @@ -179,13 +179,19 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.15.2" +version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ "foldhash", ] +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + [[package]] name = "heck" version = "0.5.0" @@ -276,9 +282,9 @@ dependencies = [ [[package]] name = "id-arena" -version = "2.2.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" [[package]] name = "idna" @@ -303,20 +309,21 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.7.1" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.17.1", "serde", + "serde_core", ] [[package]] name = "itoa" -version = "1.0.15" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] name = "leb128fmt" @@ -332,15 +339,15 @@ checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" [[package]] name = "log" -version = "0.4.26" +version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" [[package]] name = "memchr" -version = "2.7.4" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] name = "miniz_oxide" @@ -391,9 +398,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.94" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" dependencies = [ "unicode-ident", ] @@ -407,35 +414,40 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "ryu" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" - [[package]] name = "semver" -version = "1.0.26" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" dependencies = [ "serde", + "serde_core", ] [[package]] name = "serde" -version = "1.0.218" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8dfc9d19bdbf6d17e22319da49161d5d0108e4188e8b680aef6299eed22df60" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.218" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f09503e191f4e797cb8aac08e9a4a4695c5edf6a2e70e376d961ddd5c969f82b" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", @@ -444,14 +456,15 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.140" +version = "1.0.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" dependencies = [ "itoa", "memchr", - "ryu", "serde", + "serde_core", + "zmij", ] [[package]] @@ -468,15 +481,15 @@ checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" [[package]] name = "smallvec" -version = "1.14.0" +version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "spdx" -version = "0.10.8" +version = "0.10.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58b69356da67e2fc1f542c71ea7e654a361a79c938e4424392ecf4fa065d2193" +checksum = "c3e17e880bafaeb362a7b751ec46bdc5b61445a188f80e0606e68167cd540fa3" dependencies = [ "smallvec", ] @@ -527,9 +540,9 @@ checksum = "ea68304e134ecd095ac6c3574494fc62b909f416c4fca77e440530221e549d3d" [[package]] name = "unicode-ident" -version = "1.0.18" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" [[package]] name = "unicode-xid" @@ -591,7 +604,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f51cad774fb3c9461ab9bccc9c62dfb7388397b5deda31bf40e8108ccd678b2" dependencies = [ "bitflags", - "hashbrown", + "hashbrown 0.15.5", "indexmap", "semver", ] @@ -738,7 +751,7 @@ dependencies = [ [[package]] name = "zed_haskell" -version = "0.2.3" +version = "0.2.2" dependencies = [ "zed_extension_api", ] @@ -796,3 +809,9 @@ dependencies = [ "quote", "syn", ] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/src/debugger.rs b/src/debugger.rs index 128d62d..7b5dc62 100644 --- a/src/debugger.rs +++ b/src/debugger.rs @@ -106,7 +106,7 @@ pub(crate) fn get_dap_binary( } let merged = merge_haskell_debug_configuration(&task)?; - let request = dap_request_kind(adapter_name, merged.clone())?; + let request = dap_request_kind(adapter_name.as_str(), &merged)?; let configuration = serde_json::to_string(&merged) .map_err(|err| format!("Failed to serialize debug configuration: {err}"))?; @@ -179,8 +179,8 @@ pub(crate) fn get_dap_binary( } pub(crate) fn dap_request_kind( - adapter_name: String, - config: serde_json::Value, + adapter_name: &str, + config: &serde_json::Value, ) -> Result { if adapter_name != HASKELL_DEBUG_ADAPTER { return Err(format!( diff --git a/src/haskell.rs b/src/language_server.rs similarity index 98% rename from src/haskell.rs rename to src/language_server.rs index 4d5d2e7..46d7fb9 100644 --- a/src/haskell.rs +++ b/src/language_server.rs @@ -64,7 +64,7 @@ impl zed::Extension for HaskellExtension { adapter_name: String, config: zed::serde_json::Value, ) -> Result { - crate::debugger::dap_request_kind(adapter_name, config) + crate::debugger::dap_request_kind(adapter_name.as_str(), &config) } fn dap_config_to_scenario(&mut self, config: DebugConfig) -> Result { diff --git a/src/lib.rs b/src/lib.rs index ed7c0f7..e03e467 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,2 +1,2 @@ mod debugger; -mod haskell; +mod language_server; From 74f1a52bcc8eae9cf7e2f829db73a2e6b8625b5b Mon Sep 17 00:00:00 2001 From: Rajkumar Natarajan Date: Mon, 11 May 2026 13:12:49 -0700 Subject: [PATCH 4/8] version the zed-haskell version number --- Cargo.lock | 2 +- Cargo.toml | 2 +- extension.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c7211e8..a840a36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -751,7 +751,7 @@ dependencies = [ [[package]] name = "zed_haskell" -version = "0.2.2" +version = "0.2.1" dependencies = [ "zed_extension_api", ] diff --git a/Cargo.toml b/Cargo.toml index d9829c1..faab18e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zed_haskell" -version = "0.2.2" +version = "0.2.1" edition = "2021" publish = false license = "Apache-2.0" diff --git a/extension.toml b/extension.toml index 64cb952..bbc998d 100644 --- a/extension.toml +++ b/extension.toml @@ -1,7 +1,7 @@ id = "haskell" name = "Haskell" description = "Haskell support." -version = "0.2.2" +version = "0.2.1" schema_version = 1 authors = [ "Pocæus ", From 778b94cc76eba995f0f3e9cdd9f1c8a10b33c993 Mon Sep 17 00:00:00 2001 From: Rajkumar Natarajan Date: Mon, 11 May 2026 13:21:17 -0700 Subject: [PATCH 5/8] fix github actions --- src/debugger.rs | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/debugger.rs b/src/debugger.rs index 7b5dc62..7e6c7a1 100644 --- a/src/debugger.rs +++ b/src/debugger.rs @@ -1,18 +1,19 @@ use std::path::{Component, Path}; +use zed::serde_json::{self, json}; use zed_extension_api::{ - self as zed, - DebugAdapterBinary, DebugConfig, DebugRequest, DebugScenario, DebugTaskDefinition, Result, - StartDebuggingRequestArguments, StartDebuggingRequestArgumentsRequest, TcpArguments, - TcpArgumentsTemplate, resolve_tcp_template, + self as zed, resolve_tcp_template, DebugAdapterBinary, DebugConfig, DebugRequest, + DebugScenario, DebugTaskDefinition, Result, StartDebuggingRequestArguments, + StartDebuggingRequestArgumentsRequest, TcpArguments, TcpArgumentsTemplate, }; -use zed::serde_json::{self, json}; pub(crate) const HASKELL_DEBUG_ADAPTER: &str = "haskell-debugger"; -fn merge_haskell_debug_configuration(task: &DebugTaskDefinition) -> Result { - let mut map: serde_json::Map = - serde_json::from_str(&task.config).map_err(|err| { +fn merge_haskell_debug_configuration( + task: &DebugTaskDefinition, +) -> Result { + let mut map: serde_json::Map = serde_json::from_str(&task.config) + .map_err(|err| { format!("Invalid Haskell debug configuration (expected JSON object): {err}") })?; map.entry("type".to_string()) @@ -114,9 +115,8 @@ pub(crate) fn get_dap_binary( let envs = worktree.shell_env(); if let Some(debug_server) = merged.get("debugServer").and_then(|v| v.as_u64()) { - let port = u16::try_from(debug_server).map_err(|_| { - format!("`debugServer` port must fit in 16 bits, got {debug_server}") - })?; + let port = u16::try_from(debug_server) + .map_err(|_| format!("`debugServer` port must fit in 16 bits, got {debug_server}"))?; let tcp_connection = task.tcp_connection.unwrap_or(TcpArgumentsTemplate { host: None, port: Some(port), @@ -148,11 +148,7 @@ pub(crate) fn get_dap_binary( } = resolve_tcp_template(tcp_connection)?; let command = resolve_hdb_binary(user_provided_debug_adapter_path, worktree)?; - let mut arguments = vec![ - "server".to_string(), - "--port".to_string(), - port.to_string(), - ]; + let mut arguments = vec!["server".to_string(), "--port".to_string(), port.to_string()]; if merged .get("internalInterpreter") .and_then(|v| v.as_bool()) From 4bba2093793cb3ef68bee9b68cfabb1899954959 Mon Sep 17 00:00:00 2001 From: Rajkumar Date: Mon, 22 Jun 2026 23:16:45 -0700 Subject: [PATCH 6/8] incorporated the review comments --- Cargo.toml | 2 +- src/debugger.rs | 42 ++++++--------- src/haskell.rs | 114 ++++++++++++++++++++++++++++++++++++++++ src/language_server.rs | 115 +---------------------------------------- src/lib.rs | 2 - 5 files changed, 134 insertions(+), 141 deletions(-) create mode 100644 src/haskell.rs delete mode 100644 src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 47abf00..63923e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ publish = false license = "Apache-2.0" [lib] -path = "src/lib.rs" +path = "src/haskell.rs" crate-type = ["cdylib"] [dependencies] diff --git a/src/debugger.rs b/src/debugger.rs index 7e6c7a1..c5666fc 100644 --- a/src/debugger.rs +++ b/src/debugger.rs @@ -17,11 +17,11 @@ fn merge_haskell_debug_configuration( format!("Invalid Haskell debug configuration (expected JSON object): {err}") })?; map.entry("type".to_string()) - .or_insert_with(|| json!(HASKELL_DEBUG_ADAPTER)); + .or_insert(json!(HASKELL_DEBUG_ADAPTER)); map.entry("request".to_string()) - .or_insert_with(|| json!("launch")); + .or_insert(json!("launch")); map.entry("name".to_string()) - .or_insert_with(|| json!(task.label.clone())); + .or_insert(json!(task.label.clone())); Ok(serde_json::Value::Object(map)) } @@ -69,29 +69,21 @@ fn entry_path_relative_to_root(project_root: &str, program: &str) -> Result Result { - let mut out = String::new(); - for (i, component) in path.components().enumerate() { - match component { - Component::Normal(part) => { - if i > 0 { - out.push(std::path::MAIN_SEPARATOR); - } - out.push_str(&part.to_string_lossy()); + path.components() + .filter_map(|c| match c { + Component::Normal(part) => Some(Ok(part.to_string_lossy().into_owned())), + Component::CurDir => None, + Component::ParentDir => Some(Err("Program path must not contain `..`.".into())), + _ => Some(Err("Invalid program path.".into())), + }) + .collect::, _>>() + .and_then(|parts| { + if parts.is_empty() { + Err("Resolved entry file path is empty.".into()) + } else { + Ok(parts.join(std::path::MAIN_SEPARATOR_STR)) } - Component::CurDir => {} - Component::ParentDir => { - return Err("Program path must not contain `..`.".into()); - } - Component::RootDir | Component::Prefix(_) => { - return Err("Invalid program path.".into()); - } - } - } - if out.is_empty() { - Err("Resolved entry file path is empty.".into()) - } else { - Ok(out) - } + }) } pub(crate) fn get_dap_binary( diff --git a/src/haskell.rs b/src/haskell.rs new file mode 100644 index 0000000..eae2a34 --- /dev/null +++ b/src/haskell.rs @@ -0,0 +1,114 @@ +use zed_extension_api::{ + self as zed, + lsp::{Symbol, SymbolKind}, + settings::LspSettings, + CodeLabel, CodeLabelSpan, DebugAdapterBinary, DebugConfig, DebugScenario, DebugTaskDefinition, + Result, StartDebuggingRequestArgumentsRequest, +}; + +struct HaskellExtension; + +impl zed::Extension for HaskellExtension { + fn new() -> Self { + Self + } + + fn language_server_command( + &mut self, + language_server_id: &zed::LanguageServerId, + worktree: &zed::Worktree, + ) -> Result { + let lsp_settings = LspSettings::for_worktree(language_server_id.as_ref(), worktree)?; + + // If the user has specified a binary in their LSP settings, + // that takes precedence. + if let Some(binary_settings) = lsp_settings.binary { + if let Some(path) = binary_settings.path { + return Ok(zed::Command { + command: path, + args: binary_settings.arguments.unwrap_or_else(Vec::new), + env: worktree.shell_env(), + }); + } + } + + // Otherwise, default to hls installed via ghcup. + let path = worktree + .which("haskell-language-server-wrapper") + .ok_or_else(|| "hls must be installed via ghcup".to_string())?; + + Ok(zed::Command { + command: path, + args: vec!["lsp".to_string()], + env: worktree.shell_env(), + }) + } + + fn label_for_symbol( + &self, + _language_server_id: &zed::LanguageServerId, + symbol: Symbol, + ) -> Option { + let name = &symbol.name; + + let (code, display_range, filter_range) = match symbol.kind { + SymbolKind::Struct => { + let data_decl = "data "; + let code = format!("{data_decl}{name} = A"); + let display_range = 0..data_decl.len() + name.len(); + let filter_range = data_decl.len()..display_range.end; + (code, display_range, filter_range) + } + SymbolKind::Constructor => { + let data_decl = "data A = "; + let code = format!("{data_decl}{name}"); + let display_range = data_decl.len()..data_decl.len() + name.len(); + let filter_range = 0..name.len(); + (code, display_range, filter_range) + } + SymbolKind::Variable => { + let code = format!("{name} :: T"); + let display_range = 0..name.len(); + let filter_range = 0..name.len(); + (code, display_range, filter_range) + } + _ => return None, + }; + + Some(CodeLabel { + spans: vec![CodeLabelSpan::code_range(display_range)], + filter_range: filter_range.into(), + code, + }) + } + + fn get_dap_binary( + &mut self, + adapter_name: String, + task: DebugTaskDefinition, + user_provided_debug_adapter_path: Option, + worktree: &zed::Worktree, + ) -> Result { + crate::debugger::get_dap_binary( + adapter_name, + task, + user_provided_debug_adapter_path, + worktree, + ) + } + + fn dap_request_kind( + &mut self, + adapter_name: String, + config: zed::serde_json::Value, + ) -> Result { + crate::debugger::dap_request_kind(&adapter_name, &config) + } + + fn dap_config_to_scenario(&mut self, config: DebugConfig) -> Result { + crate::debugger::dap_config_to_scenario(config) + } + +} + +zed::register_extension!(HaskellExtension); diff --git a/src/language_server.rs b/src/language_server.rs index 46d7fb9..ed7c0f7 100644 --- a/src/language_server.rs +++ b/src/language_server.rs @@ -1,113 +1,2 @@ -use zed_extension_api::{ - self as zed, - lsp::{Symbol, SymbolKind}, - settings::LspSettings, - CodeLabel, CodeLabelSpan, DebugAdapterBinary, DebugConfig, DebugScenario, DebugTaskDefinition, - Result, StartDebuggingRequestArgumentsRequest, -}; - -struct HaskellExtension; - -impl zed::Extension for HaskellExtension { - fn new() -> Self { - Self - } - - fn language_server_command( - &mut self, - language_server_id: &zed::LanguageServerId, - worktree: &zed::Worktree, - ) -> Result { - let lsp_settings = LspSettings::for_worktree(language_server_id.as_ref(), worktree)?; - - // If the user has specified a binary in their LSP settings, - // that takes precedence. - if let Some(binary_settings) = lsp_settings.binary { - if let Some(path) = binary_settings.path { - return Ok(zed::Command { - command: path, - args: binary_settings.arguments.unwrap_or_else(Vec::new), - env: worktree.shell_env(), - }); - } - } - - // Otherwise, default to hls installed via ghcup. - let path = worktree - .which("haskell-language-server-wrapper") - .ok_or_else(|| "hls must be installed via ghcup".to_string())?; - - Ok(zed::Command { - command: path, - args: vec!["lsp".to_string()], - env: worktree.shell_env(), - }) - } - - fn get_dap_binary( - &mut self, - adapter_name: String, - task: DebugTaskDefinition, - user_provided_debug_adapter_path: Option, - worktree: &zed::Worktree, - ) -> Result { - crate::debugger::get_dap_binary( - adapter_name, - task, - user_provided_debug_adapter_path, - worktree, - ) - } - - fn dap_request_kind( - &mut self, - adapter_name: String, - config: zed::serde_json::Value, - ) -> Result { - crate::debugger::dap_request_kind(adapter_name.as_str(), &config) - } - - fn dap_config_to_scenario(&mut self, config: DebugConfig) -> Result { - crate::debugger::dap_config_to_scenario(config) - } - - fn label_for_symbol( - &self, - _language_server_id: &zed::LanguageServerId, - symbol: Symbol, - ) -> Option { - let name = &symbol.name; - - let (code, display_range, filter_range) = match symbol.kind { - SymbolKind::Struct => { - let data_decl = "data "; - let code = format!("{data_decl}{name} = A"); - let display_range = 0..data_decl.len() + name.len(); - let filter_range = data_decl.len()..display_range.end; - (code, display_range, filter_range) - } - SymbolKind::Constructor => { - let data_decl = "data A = "; - let code = format!("{data_decl}{name}"); - let display_range = data_decl.len()..data_decl.len() + name.len(); - let filter_range = 0..name.len(); - (code, display_range, filter_range) - } - SymbolKind::Variable => { - let code = format!("{name} :: T"); - let display_range = 0..name.len(); - let filter_range = 0..name.len(); - (code, display_range, filter_range) - } - _ => return None, - }; - - Some(CodeLabel { - spans: vec![CodeLabelSpan::code_range(display_range)], - filter_range: filter_range.into(), - code, - }) - } -} - -zed::register_extension!(HaskellExtension); +mod debugger; +mod haskell; diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index e03e467..0000000 --- a/src/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod debugger; -mod language_server; From b6f2f690baf5a4cfd43849a3c6ef3fc6feff6fb6 Mon Sep 17 00:00:00 2001 From: Rajkumar Date: Tue, 23 Jun 2026 08:45:58 -0700 Subject: [PATCH 7/8] Add debugger module in haskell.rs --- src/haskell.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/haskell.rs b/src/haskell.rs index eae2a34..563c300 100644 --- a/src/haskell.rs +++ b/src/haskell.rs @@ -1,3 +1,5 @@ +mod debugger; + use zed_extension_api::{ self as zed, lsp::{Symbol, SymbolKind}, From 60b325fc42fe60c19434eaea48eaabe56b73b291 Mon Sep 17 00:00:00 2001 From: Rajkumar Date: Tue, 23 Jun 2026 08:48:03 -0700 Subject: [PATCH 8/8] remove language_server.rs --- src/language_server.rs | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 src/language_server.rs diff --git a/src/language_server.rs b/src/language_server.rs deleted file mode 100644 index ed7c0f7..0000000 --- a/src/language_server.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod debugger; -mod haskell;