intelligent ctags powered by tree-sitter and lexical scope-graphs

bump to 0.25

oppi.li 032ddd00 65824d1c

verified
Changed files
+176 -156
src
+98 -110
Cargo.lock
··· 1 1 # This file is automatically @generated by Cargo. 2 2 # It is not intended for manual editing. 3 - version = 3 4 - 5 - [[package]] 6 - name = "ahash" 7 - version = "0.4.8" 8 - source = "registry+https://github.com/rust-lang/crates.io-index" 9 - checksum = "0453232ace82dee0dd0b4c87a59bd90f7b53b314f3e0f61fe2ee7c8a16482289" 3 + version = 4 10 4 11 5 [[package]] 12 6 name = "aho-corasick" 13 - version = "1.1.2" 7 + version = "1.1.3" 14 8 source = "registry+https://github.com/rust-lang/crates.io-index" 15 - checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" 9 + checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" 16 10 dependencies = [ 17 11 "memchr", 18 12 ] 19 13 20 14 [[package]] 21 15 name = "cc" 22 - version = "1.0.83" 16 + version = "1.2.29" 23 17 source = "registry+https://github.com/rust-lang/crates.io-index" 24 - checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" 18 + checksum = "5c1599538de2394445747c8cf7935946e3cc27e9625f889d979bfb2aaf569362" 25 19 dependencies = [ 26 - "libc", 20 + "shlex", 27 21 ] 28 22 29 23 [[package]] 30 - name = "cfg-if" 31 - version = "1.0.0" 32 - source = "registry+https://github.com/rust-lang/crates.io-index" 33 - checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 34 - 35 - [[package]] 36 24 name = "darling" 37 - version = "0.20.6" 25 + version = "0.20.11" 38 26 source = "registry+https://github.com/rust-lang/crates.io-index" 39 - checksum = "c376d08ea6aa96aafe61237c7200d1241cb177b7d3a542d791f2d118e9cbb955" 27 + checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" 40 28 dependencies = [ 41 29 "darling_core", 42 30 "darling_macro", ··· 44 32 45 33 [[package]] 46 34 name = "darling_core" 47 - version = "0.20.6" 35 + version = "0.20.11" 48 36 source = "registry+https://github.com/rust-lang/crates.io-index" 49 - checksum = "33043dcd19068b8192064c704b3f83eb464f91f1ff527b44a4e2b08d9cdb8855" 37 + checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e" 50 38 dependencies = [ 51 39 "fnv", 52 40 "ident_case", ··· 58 46 59 47 [[package]] 60 48 name = "darling_macro" 61 - version = "0.20.6" 49 + version = "0.20.11" 62 50 source = "registry+https://github.com/rust-lang/crates.io-index" 63 - checksum = "c5a91391accf613803c2a9bf9abccdbaa07c54b4244a5b64883f9c3c137c86be" 51 + checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" 64 52 dependencies = [ 65 53 "darling_core", 66 54 "quote", ··· 69 57 70 58 [[package]] 71 59 name = "derive_builder" 72 - version = "0.20.0" 60 + version = "0.20.2" 73 61 source = "registry+https://github.com/rust-lang/crates.io-index" 74 - checksum = "0350b5cb0331628a5916d6c5c0b72e97393b8b6b03b47a9284f4e7f5a405ffd7" 62 + checksum = "507dfb09ea8b7fa618fcf76e953f4f5e192547945816d5358edffe39f6f94947" 75 63 dependencies = [ 76 64 "derive_builder_macro", 77 65 ] 78 66 79 67 [[package]] 80 68 name = "derive_builder_core" 81 - version = "0.20.0" 69 + version = "0.20.2" 82 70 source = "registry+https://github.com/rust-lang/crates.io-index" 83 - checksum = "d48cda787f839151732d396ac69e3473923d54312c070ee21e9effcaa8ca0b1d" 71 + checksum = "2d5bcf7b024d6835cfb3d473887cd966994907effbe9227e8c8219824d06c4e8" 84 72 dependencies = [ 85 73 "darling", 86 74 "proc-macro2", ··· 90 78 91 79 [[package]] 92 80 name = "derive_builder_macro" 93 - version = "0.20.0" 81 + version = "0.20.2" 94 82 source = "registry+https://github.com/rust-lang/crates.io-index" 95 - checksum = "206868b8242f27cecce124c19fd88157fbd0dd334df2587f36417bafbc85097b" 83 + checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c" 96 84 dependencies = [ 97 85 "derive_builder_core", 98 86 "syn", ··· 100 88 101 89 [[package]] 102 90 name = "dissimilar" 103 - version = "1.0.7" 91 + version = "1.0.10" 104 92 source = "registry+https://github.com/rust-lang/crates.io-index" 105 - checksum = "86e3bdc80eee6e16b2b6b0f87fbc98c04bee3455e35174c0de1a125d0688c632" 93 + checksum = "8975ffdaa0ef3661bfe02dbdcc06c9f829dfafe6a3c474de366a8d5e44276921" 106 94 107 95 [[package]] 108 96 name = "equivalent" 109 - version = "1.0.1" 97 + version = "1.0.2" 110 98 source = "registry+https://github.com/rust-lang/crates.io-index" 111 - checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" 99 + checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" 112 100 113 101 [[package]] 114 102 name = "expect-test" 115 - version = "1.4.1" 103 + version = "1.5.1" 116 104 source = "registry+https://github.com/rust-lang/crates.io-index" 117 - checksum = "30d9eafeadd538e68fb28016364c9732d78e420b9ff8853fa5e4058861e9f8d3" 105 + checksum = "63af43ff4431e848fb47472a920f14fa71c24de13255a5692e93d4e90302acb0" 118 106 dependencies = [ 119 107 "dissimilar", 120 108 "once_cell", ··· 134 122 135 123 [[package]] 136 124 name = "hashbrown" 137 - version = "0.9.1" 138 - source = "registry+https://github.com/rust-lang/crates.io-index" 139 - checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" 140 - dependencies = [ 141 - "ahash", 142 - ] 143 - 144 - [[package]] 145 - name = "hashbrown" 146 - version = "0.14.3" 125 + version = "0.15.4" 147 126 source = "registry+https://github.com/rust-lang/crates.io-index" 148 - checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" 127 + checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" 149 128 150 129 [[package]] 151 130 name = "html" ··· 170 149 171 150 [[package]] 172 151 name = "indexmap" 173 - version = "2.2.3" 152 + version = "2.10.0" 174 153 source = "registry+https://github.com/rust-lang/crates.io-index" 175 - checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177" 154 + checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" 176 155 dependencies = [ 177 156 "equivalent", 178 - "hashbrown 0.14.3", 157 + "hashbrown", 179 158 ] 180 159 181 160 [[package]] 182 161 name = "itoa" 183 - version = "1.0.10" 162 + version = "1.0.15" 184 163 source = "registry+https://github.com/rust-lang/crates.io-index" 185 - checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" 186 - 187 - [[package]] 188 - name = "libc" 189 - version = "0.2.153" 190 - source = "registry+https://github.com/rust-lang/crates.io-index" 191 - checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" 164 + checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" 192 165 193 166 [[package]] 194 167 name = "log" 195 - version = "0.4.20" 168 + version = "0.4.27" 196 169 source = "registry+https://github.com/rust-lang/crates.io-index" 197 - checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" 170 + checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" 198 171 199 172 [[package]] 200 173 name = "memchr" 201 - version = "2.7.1" 174 + version = "2.7.5" 202 175 source = "registry+https://github.com/rust-lang/crates.io-index" 203 - checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" 176 + checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" 204 177 205 178 [[package]] 206 179 name = "once_cell" 207 - version = "1.19.0" 180 + version = "1.21.3" 208 181 source = "registry+https://github.com/rust-lang/crates.io-index" 209 - checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" 182 + checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" 210 183 211 184 [[package]] 212 185 name = "petgraph" 213 - version = "0.6.4" 186 + version = "0.6.5" 214 187 source = "registry+https://github.com/rust-lang/crates.io-index" 215 - checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" 188 + checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" 216 189 dependencies = [ 217 190 "fixedbitset", 218 191 "indexmap", ··· 222 195 223 196 [[package]] 224 197 name = "proc-macro2" 225 - version = "1.0.78" 198 + version = "1.0.95" 226 199 source = "registry+https://github.com/rust-lang/crates.io-index" 227 - checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" 200 + checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" 228 201 dependencies = [ 229 202 "unicode-ident", 230 203 ] 231 204 232 205 [[package]] 233 206 name = "quote" 234 - version = "1.0.35" 207 + version = "1.0.40" 235 208 source = "registry+https://github.com/rust-lang/crates.io-index" 236 - checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" 209 + checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" 237 210 dependencies = [ 238 211 "proc-macro2", 239 212 ] 240 213 241 214 [[package]] 242 215 name = "regex" 243 - version = "1.10.3" 216 + version = "1.11.1" 244 217 source = "registry+https://github.com/rust-lang/crates.io-index" 245 - checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" 218 + checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" 246 219 dependencies = [ 247 220 "aho-corasick", 248 221 "memchr", ··· 252 225 253 226 [[package]] 254 227 name = "regex-automata" 255 - version = "0.4.5" 228 + version = "0.4.9" 256 229 source = "registry+https://github.com/rust-lang/crates.io-index" 257 - checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" 230 + checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" 258 231 dependencies = [ 259 232 "aho-corasick", 260 233 "memchr", ··· 263 236 264 237 [[package]] 265 238 name = "regex-syntax" 266 - version = "0.8.2" 239 + version = "0.8.5" 267 240 source = "registry+https://github.com/rust-lang/crates.io-index" 268 - checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" 241 + checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" 269 242 270 243 [[package]] 271 244 name = "ryu" 272 - version = "1.0.16" 245 + version = "1.0.20" 273 246 source = "registry+https://github.com/rust-lang/crates.io-index" 274 - checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" 247 + checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" 275 248 276 249 [[package]] 277 250 name = "serde" 278 - version = "1.0.196" 251 + version = "1.0.219" 279 252 source = "registry+https://github.com/rust-lang/crates.io-index" 280 - checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" 253 + checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" 281 254 dependencies = [ 282 255 "serde_derive", 283 256 ] 284 257 285 258 [[package]] 286 259 name = "serde_derive" 287 - version = "1.0.196" 260 + version = "1.0.219" 288 261 source = "registry+https://github.com/rust-lang/crates.io-index" 289 - checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" 262 + checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" 290 263 dependencies = [ 291 264 "proc-macro2", 292 265 "quote", ··· 295 268 296 269 [[package]] 297 270 name = "serde_json" 298 - version = "1.0.113" 271 + version = "1.0.140" 299 272 source = "registry+https://github.com/rust-lang/crates.io-index" 300 - checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" 273 + checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" 301 274 dependencies = [ 275 + "indexmap", 302 276 "itoa", 277 + "memchr", 303 278 "ryu", 304 279 "serde", 305 280 ] 306 281 307 282 [[package]] 283 + name = "shlex" 284 + version = "1.3.0" 285 + source = "registry+https://github.com/rust-lang/crates.io-index" 286 + checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" 287 + 288 + [[package]] 308 289 name = "smallvec" 309 - version = "1.13.1" 290 + version = "1.15.1" 310 291 source = "registry+https://github.com/rust-lang/crates.io-index" 311 - checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" 292 + checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" 312 293 313 294 [[package]] 314 295 name = "stag" ··· 327 308 ] 328 309 329 310 [[package]] 330 - name = "string-interner" 331 - version = "0.12.2" 311 + name = "streaming-iterator" 312 + version = "0.1.9" 332 313 source = "registry+https://github.com/rust-lang/crates.io-index" 333 - checksum = "383196d1876517ee6f9f0864d1fc1070331b803335d3c6daaa04bbcccd823c08" 334 - dependencies = [ 335 - "cfg-if", 336 - "hashbrown 0.9.1", 337 - ] 314 + checksum = "2b2231b7c3057d5e4ad0156fb3dc807d900806020c5ffa3ee6ff2c8c76fb8520" 338 315 339 316 [[package]] 340 317 name = "strsim" 341 - version = "0.10.0" 318 + version = "0.11.1" 342 319 source = "registry+https://github.com/rust-lang/crates.io-index" 343 - checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" 320 + checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" 344 321 345 322 [[package]] 346 323 name = "syn" 347 - version = "2.0.48" 324 + version = "2.0.104" 348 325 source = "registry+https://github.com/rust-lang/crates.io-index" 349 - checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" 326 + checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" 350 327 dependencies = [ 351 328 "proc-macro2", 352 329 "quote", ··· 355 332 356 333 [[package]] 357 334 name = "thiserror" 358 - version = "1.0.57" 335 + version = "1.0.69" 359 336 source = "registry+https://github.com/rust-lang/crates.io-index" 360 - checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" 337 + checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" 361 338 dependencies = [ 362 339 "thiserror-impl", 363 340 ] 364 341 365 342 [[package]] 366 343 name = "thiserror-impl" 367 - version = "1.0.57" 344 + version = "1.0.69" 368 345 source = "registry+https://github.com/rust-lang/crates.io-index" 369 - checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" 346 + checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" 370 347 dependencies = [ 371 348 "proc-macro2", 372 349 "quote", ··· 375 352 376 353 [[package]] 377 354 name = "tree-sitter" 378 - version = "0.20.10" 355 + version = "0.25.6" 379 356 source = "registry+https://github.com/rust-lang/crates.io-index" 380 - checksum = "e747b1f9b7b931ed39a548c1fae149101497de3c1fc8d9e18c62c1a66c683d3d" 357 + checksum = "a7cf18d43cbf0bfca51f657132cc616a5097edc4424d538bae6fa60142eaf9f0" 381 358 dependencies = [ 382 359 "cc", 383 360 "regex", 361 + "regex-syntax", 362 + "serde_json", 363 + "streaming-iterator", 364 + "tree-sitter-language", 384 365 ] 385 366 386 367 [[package]] 387 368 name = "tree-sitter-graph" 388 - version = "0.11.3" 369 + version = "0.12.0" 370 + source = "git+https://tangled.sh/@oppi.li/tree-sitter-graph#36785dff28c7a6e496d46ffa70f5d0f98d61bbf0" 389 371 dependencies = [ 390 372 "log", 391 373 "regex", 392 374 "serde", 393 375 "serde_json", 394 376 "smallvec", 395 - "string-interner", 377 + "streaming-iterator", 396 378 "thiserror", 397 379 "tree-sitter", 398 380 ] 399 381 400 382 [[package]] 383 + name = "tree-sitter-language" 384 + version = "0.1.5" 385 + source = "registry+https://github.com/rust-lang/crates.io-index" 386 + checksum = "c4013970217383f67b18aef68f6fb2e8d409bc5755227092d32efb0422ba24b8" 387 + 388 + [[package]] 401 389 name = "tree-sitter-rust" 402 - version = "0.20.4" 390 + version = "0.24.0" 403 391 source = "registry+https://github.com/rust-lang/crates.io-index" 404 - checksum = "b0832309b0b2b6d33760ce5c0e818cb47e1d72b468516bfe4134408926fa7594" 392 + checksum = "4b9b18034c684a2420722be8b2a91c9c44f2546b631c039edf575ccba8c61be1" 405 393 dependencies = [ 406 394 "cc", 407 - "tree-sitter", 395 + "tree-sitter-language", 408 396 ] 409 397 410 398 [[package]] 411 399 name = "unicode-ident" 412 - version = "1.0.12" 400 + version = "1.0.18" 413 401 source = "registry+https://github.com/rust-lang/crates.io-index" 414 - checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" 402 + checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
+4 -5
Cargo.toml
··· 3 3 version = "0.1.0" 4 4 edition = "2021" 5 5 6 - # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 - 8 6 [lib] 9 7 10 8 [dependencies] ··· 12 10 serde = {version = "1.0.188", features = ["derive"]} 13 11 once_cell = "1.19.0" 14 12 thiserror = "1.0.56" 15 - tree-sitter-graph = { path = "../tree-sitter-graph/"} 16 - tree-sitter-rust = "0.20.4" 17 - tree-sitter = "0.20" 13 + tree-sitter-graph = { git = "https://tangled.sh/@oppi.li/tree-sitter-graph"} 14 + # tree-sitter-graph = { path = "../tree-sitter-graph"} 15 + tree-sitter-rust = "0.24" 16 + tree-sitter = "0.25" 18 17 derive_builder = "0.20.0" 19 18 expect-test = "1.4.1" 20 19 html = "0.6.3"
+4 -2
src/bin/html.rs
··· 7 7 fn main() { 8 8 let src = include_str!("html.rs"); 9 9 10 + let language = tree_sitter_rust::LANGUAGE; 11 + 10 12 let sg = StagBuilder::default() 11 13 .with_source(src) 12 14 .with_stag_file(stag::RUST) 13 - .with_language(tree_sitter_rust::language()) 15 + .with_language(language.into()) 14 16 .execute() 15 17 .unwrap(); 16 18 17 19 let mut parser = Parser::new(); 18 - let _ = parser.set_language(tree_sitter_rust::language()); 20 + let _ = parser.set_language(&language.into()); 19 21 20 22 let tree = parser.parse(&src, None).unwrap(); 21 23 let root = tree.root_node();
+3 -3
src/debug.rs
··· 1 1 use std::fmt; 2 2 3 - use crate::stag::{EdgeKind, NodeKind}; 3 + use crate::stag::{EdgeKind, Node}; 4 4 use crate::text_range::TextRange; 5 5 6 6 use petgraph::{ ··· 74 74 } 75 75 } 76 76 77 - fn build(&mut self, graph: &Graph<NodeKind, EdgeKind>, start: NodeIndex<u32>, src: &[u8]) { 77 + fn build(&mut self, graph: &Graph<Node, EdgeKind>, start: NodeIndex<u32>, src: &[u8]) { 78 78 let mut defs = graph 79 79 .edges_directed(start, Direction::Incoming) 80 80 .filter(|edge| *edge.weight() == EdgeKind::DefToScope) ··· 152 152 self.scopes = scopes; 153 153 } 154 154 155 - pub fn new(graph: &Graph<NodeKind, EdgeKind>, start: NodeIndex<u32>, src: &[u8]) -> Self { 155 + pub fn new(graph: &Graph<Node, EdgeKind>, start: NodeIndex<u32>, src: &[u8]) -> Self { 156 156 let mut scope_debug = Self::empty(graph[start].range()); 157 157 scope_debug.build(graph, start, src); 158 158 scope_debug
+67 -36
src/stag.rs
··· 41 41 42 42 pub fn execute(&self) -> Result<ScopeGraph, StagError> { 43 43 let mut parser = tree_sitter::Parser::new(); 44 - let language = self.language.ok_or(ConfigError::MissingLanguage)?; 45 - parser.set_language(language)?; 44 + let language = self.language.clone().ok_or(ConfigError::MissingLanguage)?; 45 + parser.set_language(&language)?; 46 46 47 47 let file = File::from_str( 48 48 language, ··· 163 163 } 164 164 } 165 165 166 - /// The type of a node in the ScopeGraph 166 + /// A node in the ScopeGraph 167 + #[derive(Serialize, Deserialize, Debug, Clone)] 168 + pub struct Node { 169 + kind: NodeKind, 170 + metadata: Metadata, 171 + } 172 + 173 + impl Node { 174 + pub fn new(kind: NodeKind) -> Self { 175 + Self { 176 + kind, 177 + metadata: Default::default(), 178 + } 179 + } 180 + 181 + pub fn scope(s: LocalScope) -> Self { 182 + Self::new(NodeKind::Scope(s)) 183 + } 184 + 185 + pub fn local_def(d: LocalDef) -> Self { 186 + Self::new(NodeKind::Def(d)) 187 + } 188 + 189 + pub fn reference(r: Reference) -> Self { 190 + Self::new(NodeKind::Ref(r)) 191 + } 192 + 193 + pub fn import(i: LocalImport) -> Self { 194 + Self::new(NodeKind::Import(i)) 195 + } 196 + 197 + /// Produce the range spanned by this node 198 + pub fn range(&self) -> TextRange { 199 + match &self.kind { 200 + NodeKind::Scope(l) => l.range, 201 + NodeKind::Def(d) => d.range, 202 + NodeKind::Ref(r) => r.range, 203 + NodeKind::Import(i) => i.range, 204 + } 205 + } 206 + } 207 + 208 + #[derive(Serialize, Deserialize, Default, Debug, Clone)] 209 + struct Metadata {} 210 + 211 + /// The kind of a lexical node in the ScopeGraph 167 212 #[derive(Serialize, Deserialize, Debug, Clone)] 168 213 pub enum NodeKind { 169 214 /// A scope node ··· 179 224 Ref(Reference), 180 225 } 181 226 182 - impl NodeKind { 183 - /// Construct a scope node from a range 184 - pub fn scope(range: TextRange) -> Self { 185 - Self::Scope(LocalScope::new(range)) 186 - } 187 - 188 - /// Produce the range spanned by this node 189 - pub fn range(&self) -> TextRange { 190 - match self { 191 - Self::Scope(l) => l.range, 192 - Self::Def(d) => d.range, 193 - Self::Ref(r) => r.range, 194 - Self::Import(i) => i.range, 195 - } 196 - } 197 - } 198 - 199 227 /// Describes the relation between two nodes in the ScopeGraph 200 228 #[derive(Serialize, Deserialize, PartialEq, Eq, Copy, Clone, Debug)] 201 229 pub enum EdgeKind { ··· 219 247 #[derive(Debug, Serialize, Deserialize, Clone)] 220 248 pub struct ScopeGraph { 221 249 /// The raw graph 222 - pub graph: Graph<NodeKind, EdgeKind>, 250 + pub graph: Graph<Node, EdgeKind>, 223 251 224 252 // Graphs do not have the concept of a `root`, but lexical scopes follow the syntax 225 253 // tree, and as a result, have a "root" node. The root_idx points to a scope node that ··· 230 258 impl ScopeGraph { 231 259 pub fn new(range: TextRange) -> Self { 232 260 let mut graph = Graph::new(); 233 - let root_idx = graph.add_node(NodeKind::scope(range)); 261 + let root_idx = graph.add_node(Node::scope(LocalScope::new(range))); 234 262 Self { graph, root_idx } 235 263 } 236 264 237 - pub fn get_node(&self, node_idx: NodeIndex) -> Option<&NodeKind> { 265 + pub fn get_node(&self, node_idx: NodeIndex) -> Option<&Node> { 238 266 self.graph.node_weight(node_idx) 239 267 } 240 268 241 269 /// Insert a local scope into the scope-graph 242 - fn insert_local_scope(&mut self, new: LocalScope) { 270 + fn insert_local_scope(&mut self, new: LocalScope) -> Option<NodeIndex> { 243 271 if let Some(parent_scope) = self.scope_by_range(new.range, self.root_idx) { 244 - let new_scope = NodeKind::Scope(new); 272 + let new_scope = Node::scope(new); 245 273 let new_idx = self.graph.add_node(new_scope); 246 274 self.graph 247 275 .add_edge(new_idx, parent_scope, EdgeKind::ScopeToScope); 276 + Some(new_idx) 277 + } else { 278 + None 248 279 } 249 280 } 250 281 251 282 /// Insert a def into the scope-graph 252 283 fn insert_local_def(&mut self, new: LocalDef) { 253 284 if let Some(defining_scope) = self.scope_by_range(new.range, self.root_idx) { 254 - let new_def = NodeKind::Def(new); 285 + let new_def = Node::local_def(new); 255 286 let new_idx = self.graph.add_node(new_def); 256 287 self.graph 257 288 .add_edge(new_idx, defining_scope, EdgeKind::DefToScope); ··· 261 292 /// Insert a def into the scope-graph, at the root scope 262 293 #[allow(unused)] 263 294 fn insert_global_def(&mut self, new: LocalDef) { 264 - let new_def = NodeKind::Def(new); 295 + let new_def = Node::local_def(new); 265 296 let new_idx = self.graph.add_node(new_def); 266 297 self.graph 267 298 .add_edge(new_idx, self.root_idx, EdgeKind::DefToScope); ··· 270 301 /// Insert an import into the scope-graph 271 302 fn insert_local_import(&mut self, new: LocalImport) { 272 303 if let Some(defining_scope) = self.scope_by_range(new.range, self.root_idx) { 273 - let new_imp = NodeKind::Import(new); 304 + let new_imp = Node::import(new); 274 305 let new_idx = self.graph.add_node(new_imp); 275 306 self.graph 276 307 .add_edge(new_idx, defining_scope, EdgeKind::ImportToScope); ··· 291 322 .filter(|edge| *edge.weight() == EdgeKind::DefToScope) 292 323 .map(|edge| edge.source()) 293 324 { 294 - if let NodeKind::Def(def) = &self.graph[local_def] { 325 + if let NodeKind::Def(def) = &self.graph[local_def].kind { 295 326 if new.text == def.text { 296 327 match (def.symbol.as_ref(), new.symbol.as_ref()) { 297 328 // both contain symbols, but they don't belong to the same namepspace ··· 318 349 .filter(|edge| *edge.weight() == EdgeKind::ImportToScope) 319 350 .map(|edge| edge.source()) 320 351 { 321 - if let NodeKind::Import(import) = &self.graph[local_import] { 352 + if let NodeKind::Import(import) = &self.graph[local_import].kind { 322 353 if new.text == import.text { 323 354 possible_imports.push(local_import); 324 355 } ··· 328 359 } 329 360 330 361 if !possible_defs.is_empty() || !possible_imports.is_empty() { 331 - let new_ref = NodeKind::Ref(new); 362 + let new_ref = Node::reference(new); 332 363 let ref_idx = self.graph.add_node(new_ref); 333 364 for def_idx in possible_defs { 334 365 self.graph.add_edge(ref_idx, def_idx, EdgeKind::RefToDef); ··· 384 415 let iterator = 385 416 self.graph 386 417 .node_indices() 387 - .filter_map(|node_idx| match &self.graph[node_idx] { 418 + .filter_map(|node_idx| match &self.graph[node_idx].kind { 388 419 NodeKind::Scope(_) => None, 389 420 NodeKind::Def(d) => Some(d.range), 390 421 NodeKind::Ref(r) => Some(r.range), ··· 471 502 } 472 503 473 504 pub fn is_definition(&self, node_idx: NodeIndex) -> bool { 474 - matches!(self.graph[node_idx], NodeKind::Def(_)) 505 + matches!(self.graph[node_idx].kind, NodeKind::Def(_)) 475 506 } 476 507 477 508 pub fn is_reference(&self, node_idx: NodeIndex) -> bool { 478 - matches!(self.graph[node_idx], NodeKind::Ref(_)) 509 + matches!(self.graph[node_idx].kind, NodeKind::Ref(_)) 479 510 } 480 511 481 512 pub fn is_scope(&self, node_idx: NodeIndex) -> bool { 482 - matches!(self.graph[node_idx], NodeKind::Scope(_)) 513 + matches!(self.graph[node_idx].kind, NodeKind::Scope(_)) 483 514 } 484 515 485 516 pub fn is_import(&self, node_idx: NodeIndex) -> bool { 486 - matches!(self.graph[node_idx], NodeKind::Import(_)) 517 + matches!(self.graph[node_idx].kind, NodeKind::Import(_)) 487 518 } 488 519 } 489 520