context_grep 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96859b0b047ac62b6a29e725518cb98c50f59e28fa0d06dfde0dd5e78a8eebfb
4
- data.tar.gz: ba8f1bd226679c2686dec7c6f021e24ff6210df494a964068cfefa619a5b5c9c
3
+ metadata.gz: f0da5e25812952e719c642974b5a7cdec355f50ce0e0d1acc954fd38cf10e93c
4
+ data.tar.gz: 451808e55032fbd2f64fd138de7427c365cd140055324260e60887e687034526
5
5
  SHA512:
6
- metadata.gz: f80962f5e919f9353357db5dfbae871dc55195cb859ff54ca12f133aa4e7e2930e9717f3d8f4d0ec2893fda4e9eda41c2f05144985487b11e9564b2996d6f785
7
- data.tar.gz: 2646c563e45f9c8996708cfc9d40bc06ecae1fe998757f7606f8b26f51a58f164d8cc8029de57fbf86c3efb6192e68ba496235cd4d2467f4851d9453e785fd76
6
+ metadata.gz: 50675d9cd5800cf45270d7458493739b94a074df3b6fa76014d1d4fe8086f4d846161f32af14576130f53905d816617c2278dcdc3b8362c8a47b3659cfe9bc2d
7
+ data.tar.gz: 979ced1ef8bdfb26c1fc7c5d094d549d3cd5c688aabb6b4499a2127980e30915e9af6aab12ceab1b29a0a743bcca23f63941680cac91de147b7fd3fb4cf4aa5f
data/context_grep.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "context_grep"
3
- spec.version = "0.1.0"
3
+ spec.version = "0.2.0"
4
4
  spec.summary = "grep results with syntactic parent chains"
5
5
 
6
6
  spec.author = "Victor Maslov aka Nakilon"
data/lib/context_grep.rb CHANGED
@@ -34,24 +34,31 @@ def ContextGrep pattern
34
34
  require "zip"
35
35
  ::FileUtils.mkdir_p ::TreeStand.config.parser_path
36
36
  zip_filename = ::File.join ::TreeStand.config.parser_path, "temp.zip"
37
+ lambda do
37
38
  "https://github.com/Faveod/tree-sitter-parsers/releases/download/v5.0/tree-sitter-parsers-5.0-#{
38
39
  "Darwin" == ::Etc.uname[:sysname] ? "macos" : "linux"
39
40
  }-#{
40
41
  ::RbConfig::CONFIG["host_cpu"] =~ /x86_64|amd64/ ? "x64" : "arm64"
41
42
  }.zip".tap do |url|
42
- puts "downloading #{url} to #{::TreeStand.config.parser_path}"
43
+ ::STDERR.puts "downloading #{url} to #{::TreeStand.config.parser_path}"
43
44
  ::File.binwrite zip_filename, ::URI.open(url, &:read)
44
45
  end
45
46
  ::Zip::File.open(zip_filename) do |zip|
46
47
  for entry in zip
47
48
  next if entry.directory?
48
49
  target_path = ::File.join ::TreeStand.config.parser_path, ::File.basename(entry.name)
49
- ::FileUtils.rm_f target_path
50
+ next if ::File.exists? target_path
50
51
  entry.extract target_path
52
+ begin
53
+ return ::TreeStand::Parser.new ts_name
54
+ rescue ::TreeSitter::ParserNotFoundError
55
+ ::FileUtils.rm_f target_path
56
+ end
51
57
  end
52
58
  end
53
- ::FileUtils.rm zip_filename
54
- ::TreeStand::Parser.new ts_name
59
+ ensure
60
+ ::FileUtils.rm_f zip_filename
61
+ end.call
55
62
  end.parse_string(src).root_node
56
63
  ]
57
64
  nodes = {}
@@ -69,7 +76,7 @@ def ContextGrep pattern
69
76
  if ::ENV["COGREP_DEBUGTYPES"]
70
77
  s = node.ts_node.start_point.row + 1
71
78
  e = node.ts_node.end_point.row + 1
72
- puts "#{::File.basename file} #{node.type.inspect} #{s}-#{e}: #{src.lines[s - 1]}"
79
+ ::STDERR.puts "#{::File.basename file} #{node.type.inspect} #{s}-#{e}: #{src.lines[s - 1]}"
73
80
  end
74
81
  lines.push node.ts_node.start_point.row unless %i{ program body_statement translation_unit }.include? node.type
75
82
  end while node = nodes[node]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: context_grep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Maslov aka Nakilon
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir:
10
10
  - exe
11
11
  cert_chain: []
12
- date: 2026-03-20 00:00:00.000000000 Z
12
+ date: 2026-04-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: github-linguist