From c4756cec78151a2cf95464ffec02f1fc2f1cc51c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20=E9=87=91=E5=8F=AF=E6=98=8E?= Date: Tue, 3 Oct 2023 16:51:05 +0200 Subject: [PATCH 1/5] feat(svelte): use html parser to generalize JS frameworks with script elements --- ftplugin/svelte.vim | 2 +- helper/Cargo.lock | 316 ++++++++++---------------- helper/Cargo.toml | 2 +- helper/src/config.rs | 2 +- helper/src/docblock.rs | 4 +- helper/src/{svelte => html}/mod.rs | 0 helper/src/{svelte => html}/parser.rs | 16 +- helper/src/lib.rs | 2 +- 8 files changed, 137 insertions(+), 207 deletions(-) rename helper/src/{svelte => html}/mod.rs (100%) rename helper/src/{svelte => html}/parser.rs (78%) diff --git a/ftplugin/svelte.vim b/ftplugin/svelte.vim index c5477f1c..46365345 100644 --- a/ftplugin/svelte.vim +++ b/ftplugin/svelte.vim @@ -1,7 +1,7 @@ let s:save_cpo = &cpoptions set cpoptions&vim -let b:doge_parser = 'svelte' +let b:doge_parser = 'html' let b:doge_insert = 'above' let b:doge_supported_doc_standards = ['jsdoc'] diff --git a/helper/Cargo.lock b/helper/Cargo.lock index 96db6b06..0cf82ba1 100644 --- a/helper/Cargo.lock +++ b/helper/Cargo.lock @@ -4,48 +4,38 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.20" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" -dependencies = [ - "memchr", -] - -[[package]] -name = "aho-corasick" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" +checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab" dependencies = [ "memchr", ] [[package]] name = "anstream" -version = "0.3.2" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", - "is-terminal", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.1" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" [[package]] name = "anstyle-parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" dependencies = [ "utf8parse", ] @@ -61,9 +51,9 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "1.0.1" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" dependencies = [ "anstyle", "windows-sys", @@ -75,12 +65,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitflags" -version = "2.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" - [[package]] name = "block-buffer" version = "0.10.4" @@ -92,9 +76,9 @@ dependencies = [ [[package]] name = "bstr" -version = "1.6.0" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6798148dccfbff0fae41c7574d2fa8f1ef3492fba0face179de5d8d447d67b05" +checksum = "4c2f7349907b712260e64b0afe2f84692af14a454be26187d9df565c7f69266a" dependencies = [ "memchr", "serde", @@ -102,9 +86,12 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.79" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] [[package]] name = "cfg-if" @@ -114,20 +101,19 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.3.11" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1640e5cc7fb47dbb8338fd471b105e7ed6c3cb2aeb00c2e067127ffd3764a05d" +checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" dependencies = [ "clap_builder", "clap_derive", - "once_cell", ] [[package]] name = "clap_builder" -version = "4.3.11" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98c59138d527eeaf9b53f35a77fcc1fad9d883116070c63d5de1c7dc7b00c72b" +checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" dependencies = [ "anstream", "anstyle", @@ -137,9 +123,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.3.2" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8cd2b2a819ad6eec39e8f1d6b53001af1e5469f8c177579cdaeb313115b825f" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" dependencies = [ "heck", "proc-macro2", @@ -149,9 +135,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" [[package]] name = "colorchoice" @@ -190,30 +176,9 @@ dependencies = [ [[package]] name = "equivalent" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1" - -[[package]] -name = "errno" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" -dependencies = [ - "errno-dragonfly", - "libc", - "windows-sys", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "fnv" @@ -233,11 +198,11 @@ dependencies = [ [[package]] name = "globset" -version = "0.4.10" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc" +checksum = "759c97c1e17c55525b57192c06a267cda0ac5210b222d6b82189a2338fa1c13d" dependencies = [ - "aho-corasick 0.7.20", + "aho-corasick", "bstr", "fnv", "log", @@ -250,16 +215,16 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc" dependencies = [ - "bitflags 1.3.2", + "bitflags", "ignore", "walkdir", ] [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" [[package]] name = "heck" @@ -267,12 +232,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -[[package]] -name = "hermit-abi" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" - [[package]] name = "ignore" version = "0.4.20" @@ -292,30 +251,19 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.0" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" dependencies = [ "equivalent", "hashbrown", ] -[[package]] -name = "is-terminal" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" -dependencies = [ - "hermit-abi", - "rustix", - "windows-sys", -] - [[package]] name = "itoa" -version = "1.0.8" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b02a5381cc465bd3041d84623d0fa3b66738b52b8e2fc3bab8ad63ab032f4a" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "lazy_static" @@ -325,27 +273,21 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.147" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" - -[[package]] -name = "linux-raw-sys" -version = "0.4.3" +version = "0.2.148" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" +checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" [[package]] name = "log" -version = "0.4.19" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "once_cell" @@ -355,19 +297,20 @@ checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "pest" -version = "2.7.0" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f73935e4d55e2abf7f130186537b19e7a4abc886a0252380b59248af473a3fc9" +checksum = "c022f1e7b65d6a24c0dbbd5fb344c66881bc01f3e5ae74a1c8100f2f985d98a4" dependencies = [ + "memchr", "thiserror", "ucd-trie", ] [[package]] name = "pest_derive" -version = "2.7.0" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aef623c9bbfa0eedf5a0efba11a5ee83209c326653ca31ff019bec3a95bfff2b" +checksum = "35513f630d46400a977c4cb58f78e1bfbe01434316e60c37d27b9ad6139c66d8" dependencies = [ "pest", "pest_generator", @@ -375,9 +318,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.0" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3e8cba4ec22bada7fc55ffe51e2deb6a0e0db2d0b7ab0b103acc80d2510c190" +checksum = "bc9fc1b9e7057baba189b5c626e2d6f40681ae5b6eb064dc7c7834101ec8123a" dependencies = [ "pest", "pest_meta", @@ -388,9 +331,9 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.7.0" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01f71cb40bd8bb94232df14b946909e14660e33fc05db3e50ae2a82d7ea0ca0" +checksum = "1df74e9e7ec4053ceb980e7c0c8bd3594e977fde1af91daba9c928e8e8c6708d" dependencies = [ "once_cell", "pest", @@ -399,29 +342,29 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.63" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.29" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] [[package]] name = "regex" -version = "1.9.1" +version = "1.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" +checksum = "ebee201405406dbf528b8b672104ae6d6d63e6d118cb10e4d51abbc7b58044ff" dependencies = [ - "aho-corasick 1.0.2", + "aho-corasick", "memchr", "regex-automata", "regex-syntax", @@ -429,39 +372,26 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.1" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaecc05d5c4b5f7da074b9a0d1a0867e71fd36e7fc0482d8bcfe8e8fc56290" +checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9" dependencies = [ - "aho-corasick 1.0.2", + "aho-corasick", "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab07dc67230e4a4718e70fd5c20055a4334b121f1f9db8fe63ef39ce9b8c846" - -[[package]] -name = "rustix" -version = "0.38.3" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac5ffa1efe7548069688cd7028f32591853cd7b5b756d41bcffd2353e4fc75b4" -dependencies = [ - "bitflags 2.3.3", - "errno", - "libc", - "linux-raw-sys", - "windows-sys", -] +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "ryu" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe232bdf6be8c8de797b22184ee71118d63780ea42ac85b61d1baa6d3b782ae9" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "same-file" @@ -474,18 +404,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.167" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7daf513456463b42aa1d94cff7e0c24d682b429f020b9afa4f5ba5c40a22b237" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.167" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b69b106b68bc8054f0e974e70d19984040f8a5cf9215ca82626ea4853f82c4b9" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", @@ -494,9 +424,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.100" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f1e14e89be7aa4c4b78bdbdc9eb5bf8517829a600ae8eaa39a6e1d960b5185c" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ "itoa", "ryu", @@ -505,9 +435,9 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.9.22" +version = "0.9.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "452e67b9c20c37fa79df53201dc03839651086ed9bbe92b3ca585ca9fdaa7d85" +checksum = "1a49e178e4452f45cb61d0cd8cebc1b0fafd3e41929e996cef79aa3aca91f574" dependencies = [ "indexmap", "itoa", @@ -518,9 +448,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.7" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if", "cpufeatures", @@ -535,9 +465,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "2.0.23" +version = "2.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59fb7d6d8281a51045d62b8eb3a7d1ce347b76f312af50cd3dc0af39c87c1737" +checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" dependencies = [ "proc-macro2", "quote", @@ -546,9 +476,9 @@ dependencies = [ [[package]] name = "tera" -version = "1.19.0" +version = "1.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5ab29bb4f3e256ae6ad5c3e2775aa1f8829f2c0c101fc407bfd3a6df15c60c5" +checksum = "970dff17c11e884a4a09bc76e3a17ef71e01bb13447a11e85226e254fe6d10b8" dependencies = [ "globwalk", "lazy_static", @@ -557,24 +487,23 @@ dependencies = [ "regex", "serde", "serde_json", - "thread_local", "unic-segment", ] [[package]] name = "thiserror" -version = "1.0.43" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a35fc5b8971143ca348fa6df4f024d4d55264f3468c71ad1c2f365b0a4d58c42" +checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.43" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" +checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" dependencies = [ "proc-macro2", "quote", @@ -583,10 +512,11 @@ dependencies = [ [[package]] name = "thread_local" -version = "1.1.4" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" dependencies = [ + "cfg-if", "once_cell", ] @@ -636,6 +566,15 @@ dependencies = [ "tree-sitter", ] +[[package]] +name = "tree-sitter-html" +version = "0.20.0" +source = "git+https://github.com/tree-sitter/tree-sitter-html?rev=d742025#d742025fa2d8e6100f134a6ea990443aa1f074b3" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-java" version = "0.20.0" @@ -708,15 +647,6 @@ dependencies = [ "tree-sitter", ] -[[package]] -name = "tree-sitter-svelte" -version = "0.10.2" -source = "git+https://github.com/Himujjal/tree-sitter-svelte?rev=697bb51#697bb515471871e85ff799ea57a76298a71a9cca" -dependencies = [ - "cc", - "tree-sitter", -] - [[package]] name = "tree-sitter-typescript" version = "0.20.2" @@ -728,9 +658,9 @@ dependencies = [ [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "ucd-trie" @@ -790,15 +720,15 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.10" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22049a19f4a68748a168c0fc439f9516686aa045927ff767eca0a85101fb6e73" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unsafe-libyaml" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1865806a559042e51ab5414598446a5871b561d21b6764f2eabb0dd481d880a6" +checksum = "f28467d3e1d3c6586d8f25fa243f544f5800fec42d97032474e17222c2b75cfa" [[package]] name = "utf8parse" @@ -827,6 +757,7 @@ dependencies = [ "tree-sitter-c", "tree-sitter-c-sharp", "tree-sitter-cpp", + "tree-sitter-html", "tree-sitter-java", "tree-sitter-lua", "tree-sitter-php", @@ -835,15 +766,14 @@ dependencies = [ "tree-sitter-ruby", "tree-sitter-rust", "tree-sitter-scala", - "tree-sitter-svelte", "tree-sitter-typescript", ] [[package]] name = "walkdir" -version = "2.3.3" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" dependencies = [ "same-file", "winapi-util", @@ -867,9 +797,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" dependencies = [ "winapi", ] @@ -891,9 +821,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.48.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -906,42 +836,42 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_i686_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_x86_64_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" diff --git a/helper/Cargo.toml b/helper/Cargo.toml index db7d09bf..7a37da7b 100644 --- a/helper/Cargo.toml +++ b/helper/Cargo.toml @@ -28,4 +28,4 @@ tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typ tree-sitter-php = { git = "https://github.com/tree-sitter/tree-sitter-php", rev = "d43130f" } tree-sitter-r = { git = "https://github.com/r-lib/tree-sitter-r", rev = "c55f8b4" } tree-sitter-scala = { git = "https://github.com/tree-sitter/tree-sitter-scala", rev = "f14629b" } -tree-sitter-svelte = { git = "https://github.com/Himujjal/tree-sitter-svelte", rev = "697bb51" } +tree-sitter-html = { git = "https://github.com/tree-sitter/tree-sitter-html", rev = "d742025" } diff --git a/helper/src/config.rs b/helper/src/config.rs index 2eb8f066..ad4de29e 100644 --- a/helper/src/config.rs +++ b/helper/src/config.rs @@ -27,7 +27,7 @@ pub fn load_doc_config_str<'a>(parser_name: &'a str, doc_name: &'a str) -> &'a s "php_phpdoc" => include_str!("php/docs/phpdoc.yaml"), "typescript_jsdoc" => include_str!("typescript/docs/jsdoc.yaml"), - "svelte_jsdoc" => include_str!("typescript/docs/jsdoc.yaml"), + "html_jsdoc" => include_str!("typescript/docs/jsdoc.yaml"), "lua_ldoc" => include_str!("lua/docs/ldoc.yaml"), "java_javadoc" => include_str!("java/docs/javadoc.yaml"), "ruby_YARD" => include_str!("ruby/docs/YARD.yaml"), diff --git a/helper/src/docblock.rs b/helper/src/docblock.rs index 8ede1f3a..71cbb8e9 100644 --- a/helper/src/docblock.rs +++ b/helper/src/docblock.rs @@ -19,7 +19,7 @@ use crate::rust::parser::RustParser; use crate::typescript::parser::TypescriptParser; use crate::r::parser::RParser; use crate::scala::parser::ScalaParser; -use crate::svelte::parser::SvelteParser; +use crate::html::parser::HtmlParser; fn replace_indent_placeholders(docblock: &str, use_tabs: bool, indent: usize) -> String { @@ -142,7 +142,7 @@ pub fn generate( "typescript" => Box::new(TypescriptParser::new(code, line, &node_types, options)) as Box, "r" => Box::new(RParser::new(code, line, &node_types)) as Box, "scala" => Box::new(ScalaParser::new(code, line, &node_types)) as Box, - "svelte" => Box::new(SvelteParser::new(code, line, &node_types, options)) as Box, + "html" => Box::new(HtmlParser::new(code, line, &node_types, options)) as Box, _ => panic!("Unsupported parser: {}", &parser_name), }; diff --git a/helper/src/svelte/mod.rs b/helper/src/html/mod.rs similarity index 100% rename from helper/src/svelte/mod.rs rename to helper/src/html/mod.rs diff --git a/helper/src/svelte/parser.rs b/helper/src/html/parser.rs similarity index 78% rename from helper/src/svelte/parser.rs rename to helper/src/html/parser.rs index 4f25bf05..e50eaa46 100644 --- a/helper/src/svelte/parser.rs +++ b/helper/src/html/parser.rs @@ -7,7 +7,7 @@ use crate::traverse; use crate::base_parser::BaseParser; use crate::typescript::parser::TypescriptParser; -pub struct SvelteParser<'a> { +pub struct HtmlParser<'a> { code: &'a str, tree: tree_sitter::Tree, line: &'a usize, @@ -15,7 +15,7 @@ pub struct SvelteParser<'a> { options: &'a HashMap<&'a str, bool>, } -impl<'a> BaseParser for SvelteParser<'a> { +impl<'a> BaseParser for HtmlParser<'a> { fn parse(&self) -> Option, String>> { self.parse_node(&self.tree.root_node()) } @@ -25,10 +25,10 @@ impl<'a> BaseParser for SvelteParser<'a> { } } -impl<'a> SvelteParser<'a> { +impl<'a> HtmlParser<'a> { pub fn new(code: &'a str, line: &'a usize, node_types: &'a [&'a str], options: &'a HashMap<&'a str, bool>) -> Self { let mut parser = Parser::new(); - parser.set_language(tree_sitter_svelte::language()).unwrap(); + parser.set_language(tree_sitter_html::language()).unwrap(); let tree = parser.parse(code, None).unwrap(); @@ -45,16 +45,16 @@ impl<'a> SvelteParser<'a> { None } - fn parse_script_element(&self, node: &Node) -> Option, String>> { - let raw_text = node - .children(&mut node.walk()) + fn parse_script_element(&self, script_element_node: &Node) -> Option, String>> { + let raw_text = script_element_node + .children(&mut script_element_node.walk()) .filter(|node| node.kind() == "raw_text") .next() .and_then(|node| Some(self.get_node_text(&node))) .unwrap(); // The new line must be based on the script tag starting position. - let line = self.line - (node.start_position().row + 1); + let line = self.line - script_element_node.start_position().row; // Parse the inner content of the script tag with the TS parser. let ts_parser = TypescriptParser::new(&raw_text, &line, self.node_types, self.options); diff --git a/helper/src/lib.rs b/helper/src/lib.rs index a7f9705e..31ac0957 100644 --- a/helper/src/lib.rs +++ b/helper/src/lib.rs @@ -17,4 +17,4 @@ pub mod cpp; pub mod typescript; pub mod r; pub mod scala; -pub mod svelte; +pub mod html; From c91c8c8d6c9242b6a07932f2638a7b884e08df76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20=E9=87=91=E5=8F=AF=E6=98=8E?= Date: Tue, 3 Oct 2023 17:36:58 +0200 Subject: [PATCH 2/5] feat(html parser): only parse the script element surrounding the cursor --- helper/src/html/parser.rs | 6 +++++- test/filetypes/svelte/hello-world.vader | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/helper/src/html/parser.rs b/helper/src/html/parser.rs index e50eaa46..bd2eead4 100644 --- a/helper/src/html/parser.rs +++ b/helper/src/html/parser.rs @@ -37,7 +37,11 @@ impl<'a> HtmlParser<'a> { fn parse_node(&self, node: &Node) -> Option, String>> { for child_node in traverse::PreOrder::new(node.walk()) { - if child_node.kind() == "script_element" { + // Parse the script element that is surrounding the cursor. + if child_node.kind() == "script_element" && + child_node.start_position().row <= self.line - 1 && + child_node.end_position().row >= self.line - 1 + { return self.parse_script_element(&child_node); } } diff --git a/test/filetypes/svelte/hello-world.vader b/test/filetypes/svelte/hello-world.vader index 8df102d4..151cf776 100644 --- a/test/filetypes/svelte/hello-world.vader +++ b/test/filetypes/svelte/hello-world.vader @@ -5,6 +5,13 @@ Given svelte (hello world example with template and script tag): + + + Do (trigger doge): - :9\ + :16\ \ - :20\ + :27\ \ Expect typescript (generated comment with generated comment inside + + + + + +Do (trigger doge): + :9\ + \ + :17\ + \ + +Expect html (generated comments at the javascript functions): + + + + Test + + + + + + diff --git a/test/filetypes/svelte/hello-world.vader b/test/filetypes/svelte/hello-world.vader index 151cf776..4f873a53 100644 --- a/test/filetypes/svelte/hello-world.vader +++ b/test/filetypes/svelte/hello-world.vader @@ -31,7 +31,7 @@ Do (trigger doge): :27\ \ -Expect typescript (generated comment with generated comment inside + + + +Do (trigger doge): + :10\ + \ + :21\ + \ + +Expect vue (generated comment with generated comment inside + + From af4c73e79388d037c12262648876785884d6456f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20=E9=87=91=E5=8F=AF=E6=98=8E?= Date: Tue, 3 Oct 2023 18:45:26 +0200 Subject: [PATCH 5/5] fix(html): make sure html ftplugin does not get triggered with other filetypes --- ftplugin/html.vim | 5 +++++ helper/src/config.rs | 3 +-- plugin/doge.vim | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ftplugin/html.vim b/ftplugin/html.vim index a06afa5e..c6249591 100644 --- a/ftplugin/html.vim +++ b/ftplugin/html.vim @@ -1,6 +1,11 @@ let s:save_cpo = &cpoptions set cpoptions&vim +" The HTML filetype also gets triggerred for PHP files (and perhaps others). +if &filetype !=? 'html' + finish +endif + let b:doge_parser = 'html' let b:doge_insert = 'above' diff --git a/helper/src/config.rs b/helper/src/config.rs index ad4de29e..f50eaf25 100644 --- a/helper/src/config.rs +++ b/helper/src/config.rs @@ -26,8 +26,7 @@ pub fn load_doc_config_str<'a>(parser_name: &'a str, doc_name: &'a str) -> &'a s "c_kernel_doc" => include_str!("c/docs/kernel_doc.yaml"), "php_phpdoc" => include_str!("php/docs/phpdoc.yaml"), - "typescript_jsdoc" => include_str!("typescript/docs/jsdoc.yaml"), - "html_jsdoc" => include_str!("typescript/docs/jsdoc.yaml"), + "typescript_jsdoc" | "html_jsdoc" => include_str!("typescript/docs/jsdoc.yaml"), "lua_ldoc" => include_str!("lua/docs/ldoc.yaml"), "java_javadoc" => include_str!("java/docs/javadoc.yaml"), "ruby_YARD" => include_str!("ruby/docs/YARD.yaml"), diff --git a/plugin/doge.vim b/plugin/doge.vim index bd116255..6eae9e62 100644 --- a/plugin/doge.vim +++ b/plugin/doge.vim @@ -100,8 +100,8 @@ let g:doge_filetype_aliases = doge#utils#deepextend({ \ 'typescript', \ 'typescript.tsx', \ ], -\ 'java': ['groovy'], \ 'html': ['svelte', 'vue'], +\ 'java': ['groovy'], \}, get(g:, 'doge_filetype_aliases', {}), 1) if !exists('g:doge_buffer_mappings')