context_grep 0.2.0 → 0.3.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 +4 -4
- data/context_grep.gemspec +1 -1
- data/exe/cogrep +2 -2
- data/lib/context_grep.rb +18 -14
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 86a3e25d8dad634fca9c8be38197f010b2e5f7da79fa46b10ae69c997b125c7e
|
|
4
|
+
data.tar.gz: ee785480697fb08af1e14136645b4ef1c5d4bedd6f97ec3ec7430cf46545356e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fc53dfb8a429f22c2f5726f897d63e63ffa1742da7f67e32d9eab56101caf043f3526fde19a2c8d598a2ee597f9771ca9b0f405441657849cb2f79c6a6942ffe
|
|
7
|
+
data.tar.gz: 901039c3e85e39ca4bf62e5cca9b036f6c39883bbada7a132cf6d94262d0bbef59673c46171770f83739a95bfed687f982c0a100d84229f06c5a67bdfb684e50
|
data/context_grep.gemspec
CHANGED
data/exe/cogrep
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
-
abort "usage:\tcogrep
|
|
2
|
+
abort "usage:\tcogrep PATTERN [PATH]" unless 1 == ARGV.size || 2 == ARGV.size
|
|
3
3
|
require_relative "../lib/context_grep"
|
|
4
|
-
ContextGrep(ARGV
|
|
4
|
+
ContextGrep(*ARGV).each do |file, lines|
|
|
5
5
|
puts file
|
|
6
6
|
for lineno, line in lines
|
|
7
7
|
puts "%4s %s" % [lineno, line]
|
data/lib/context_grep.rb
CHANGED
|
@@ -3,8 +3,11 @@ require "pathname" # undefined method `Pathname' for TreeSitter:Module (NoMetho
|
|
|
3
3
|
require "tree_stand"
|
|
4
4
|
::TreeStand.config.parser_path = ::File.expand_path "~/.context_grep"
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
require "fileutils"
|
|
7
|
+
ZIP_FILENAME = ::File.join ::TreeStand.config.parser_path, "temp.zip"
|
|
8
|
+
def ContextGrep what, where = "."
|
|
9
|
+
|
|
10
|
+
`#{system("rg --version >/dev/null 2>&1") ? "rg -n" : "grep -nrI"} #{what} #{where} 2>/dev/null`
|
|
8
11
|
.scan(/^([^:]+):(\d+):/).group_by(&:first).map do |file, group|
|
|
9
12
|
lang = ::Linguist::FileBlob.new(file).language
|
|
10
13
|
next ::STDERR.puts "unsupported grammar #{lang} at #{file}" unless ts_name = {
|
|
@@ -23,27 +26,27 @@ def ContextGrep pattern
|
|
|
23
26
|
"Python" => "python",
|
|
24
27
|
"Ruby" => "ruby",
|
|
25
28
|
"Rust" => "rust",
|
|
29
|
+
"XML" => "xml",
|
|
26
30
|
}[lang.name]
|
|
27
31
|
src = ::File.read file
|
|
28
32
|
stack = [
|
|
29
33
|
begin
|
|
30
34
|
::TreeStand::Parser.new ts_name
|
|
31
35
|
rescue ::TreeSitter::ParserNotFoundError
|
|
32
|
-
# require "fileutils"
|
|
33
|
-
require "open-uri"
|
|
34
|
-
require "zip"
|
|
35
36
|
::FileUtils.mkdir_p ::TreeStand.config.parser_path
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
require "etc"
|
|
38
|
+
require "open-uri"
|
|
38
39
|
"https://github.com/Faveod/tree-sitter-parsers/releases/download/v5.0/tree-sitter-parsers-5.0-#{
|
|
39
40
|
"Darwin" == ::Etc.uname[:sysname] ? "macos" : "linux"
|
|
40
41
|
}-#{
|
|
41
42
|
::RbConfig::CONFIG["host_cpu"] =~ /x86_64|amd64/ ? "x64" : "arm64"
|
|
42
43
|
}.zip".tap do |url|
|
|
43
44
|
::STDERR.puts "downloading #{url} to #{::TreeStand.config.parser_path}"
|
|
44
|
-
::File.binwrite
|
|
45
|
-
end
|
|
46
|
-
|
|
45
|
+
::File.binwrite ZIP_FILENAME, ::URI.open(url, &:read)
|
|
46
|
+
end unless File.exist? ZIP_FILENAME
|
|
47
|
+
require "zip"
|
|
48
|
+
lambda do
|
|
49
|
+
::Zip::File.open(ZIP_FILENAME) do |zip|
|
|
47
50
|
for entry in zip
|
|
48
51
|
next if entry.directory?
|
|
49
52
|
target_path = ::File.join ::TreeStand.config.parser_path, ::File.basename(entry.name)
|
|
@@ -55,10 +58,9 @@ def ContextGrep pattern
|
|
|
55
58
|
::FileUtils.rm_f target_path
|
|
56
59
|
end
|
|
57
60
|
end
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
end.call
|
|
61
|
+
end
|
|
62
|
+
nil
|
|
63
|
+
end.call or next ::STDERR.puts "can't find grammar library for #{lang} at #{file}"
|
|
62
64
|
end.parse_string(src).root_node
|
|
63
65
|
]
|
|
64
66
|
nodes = {}
|
|
@@ -85,4 +87,6 @@ def ContextGrep pattern
|
|
|
85
87
|
]
|
|
86
88
|
end.compact
|
|
87
89
|
|
|
90
|
+
ensure
|
|
91
|
+
::FileUtils.rm_f ZIP_FILENAME
|
|
88
92
|
end
|
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.
|
|
4
|
+
version: 0.3.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-04-
|
|
12
|
+
date: 2026-04-03 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: github-linguist
|