hind 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/exe/hind +6 -0
- data/lib/hind/cli.rb +141 -0
- data/lib/hind/lsif/edge.rb +36 -0
- data/lib/hind/lsif/generator.rb +182 -0
- data/lib/hind/lsif/global_state.rb +30 -0
- data/lib/hind/lsif/vertex.rb +31 -0
- data/lib/hind/lsif/visitor.rb +63 -0
- data/lib/hind/lsif.rb +11 -0
- data/lib/hind/parser.rb +13 -0
- data/lib/hind/scip/generator.rb +13 -0
- data/lib/hind/scip/visitor.rb +14 -0
- data/lib/hind/scip.rb +4 -0
- data/lib/hind/version.rb +5 -0
- data/lib/hind.rb +11 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b3c0df71c84060e0417139c2d3458f1f889af0cb78b8323220ef67304b82c332
|
4
|
+
data.tar.gz: 8d707849d54508dfc120a47113552c87d216d5b69665dbee1e0f8477a625bfc0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9238a787be39b18fe96da0ad5a311dbef75aebf3c178fb7c90d1618cf1fd4747d82c717cec3cde0720131cf5fe1e5d236d0d9bdde3c697ec5a45de333dd24b0e
|
7
|
+
data.tar.gz: 5327651b3056ab53c9fa6e22cbe86d5a94129fff76cc3a96747a5c27bb8774ba113e8e10008b828ed63c708e9dd34ac4c99d633347fef7a20d517d38ad400fb7
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Aboobacker MK
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Hind
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hind`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
```bash
|
14
|
+
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
15
|
+
```
|
16
|
+
|
17
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hind.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/exe/hind
ADDED
data/lib/hind/cli.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'json'
|
3
|
+
require 'pathname'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
module Hind
|
7
|
+
class CLI < Thor
|
8
|
+
class_option :verbose, type: :boolean, aliases: '-v', desc: 'Enable verbose output'
|
9
|
+
class_option :config, type: :string, aliases: '-c', desc: 'Path to configuration file'
|
10
|
+
|
11
|
+
desc 'lsif', 'Generate LSIF index'
|
12
|
+
method_option :directory, type: :string, aliases: '-d', default: '.', desc: 'Root directory to process'
|
13
|
+
method_option :output, type: :string, aliases: '-o', default: 'dump.lsif', desc: 'Output file path'
|
14
|
+
method_option :glob, type: :string, aliases: '-g', default: '**/*.rb', desc: 'File pattern to match'
|
15
|
+
method_option :force, type: :boolean, aliases: '-f', desc: 'Overwrite output file if it exists'
|
16
|
+
method_option :exclude, type: :array, aliases: '-e', desc: 'Patterns to exclude'
|
17
|
+
def lsif
|
18
|
+
validate_directory(options[:directory])
|
19
|
+
validate_output_file(options[:output], options[:force])
|
20
|
+
|
21
|
+
files = find_files(options[:directory], options[:glob], options[:exclude])
|
22
|
+
abort "No files found matching pattern '#{options[:glob]}'" if files.empty?
|
23
|
+
|
24
|
+
say "Found #{files.length} files to process", :green if options[:verbose]
|
25
|
+
|
26
|
+
begin
|
27
|
+
generate_lsif(files, options)
|
28
|
+
say "\nLSIF data has been written to: #{options[:output]}", :green if options[:verbose]
|
29
|
+
rescue StandardError => e
|
30
|
+
abort "Error generating LSIF: #{e.message}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'scip', 'Generate SCIP index'
|
35
|
+
method_option :directory, type: :string, aliases: '-d', default: '.', desc: 'Root directory to process'
|
36
|
+
method_option :output, type: :string, aliases: '-o', default: 'index.scip', desc: 'Output file path'
|
37
|
+
method_option :glob, type: :string, aliases: '-g', default: '**/*.rb', desc: 'File pattern to match'
|
38
|
+
method_option :force, type: :boolean, aliases: '-f', desc: 'Overwrite output file if it exists'
|
39
|
+
method_option :exclude, type: :array, aliases: '-e', desc: 'Patterns to exclude'
|
40
|
+
def scip
|
41
|
+
validate_directory(options[:directory])
|
42
|
+
validate_output_file(options[:output], options[:force])
|
43
|
+
|
44
|
+
files = find_files(options[:directory], options[:glob], options[:exclude])
|
45
|
+
abort "No files found matching pattern '#{options[:glob]}'" if files.empty?
|
46
|
+
|
47
|
+
say "Found #{files.length} files to process", :green if options[:verbose]
|
48
|
+
|
49
|
+
begin
|
50
|
+
generate_scip(files, options)
|
51
|
+
say "\nSCIP data has been written to: #{options[:output]}", :green if options[:verbose]
|
52
|
+
rescue StandardError => e
|
53
|
+
abort "Error generating SCIP: #{e.message}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
desc 'version', 'Show version'
|
58
|
+
def version
|
59
|
+
say "Hind version #{Hind::VERSION}"
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def validate_directory(directory)
|
65
|
+
abort "Error: Directory '#{directory}' does not exist" unless Dir.exist?(directory)
|
66
|
+
end
|
67
|
+
|
68
|
+
def validate_output_file(output, force)
|
69
|
+
if File.exist?(output) && !force
|
70
|
+
abort "Error: Output file '#{output}' already exists. Use --force to overwrite."
|
71
|
+
end
|
72
|
+
|
73
|
+
# Ensure output directory exists
|
74
|
+
FileUtils.mkdir_p(File.dirname(output))
|
75
|
+
end
|
76
|
+
|
77
|
+
def find_files(directory, glob, exclude_patterns)
|
78
|
+
pattern = File.join(directory, glob)
|
79
|
+
files = Dir.glob(pattern)
|
80
|
+
|
81
|
+
if exclude_patterns
|
82
|
+
exclude_patterns.each do |exclude|
|
83
|
+
files.reject! { |f| File.fnmatch?(exclude, f) }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
files
|
88
|
+
end
|
89
|
+
|
90
|
+
def generate_lsif(files, options)
|
91
|
+
global_state = Hind::LSIF::GlobalState.new
|
92
|
+
vertex_id = 1
|
93
|
+
initial = true
|
94
|
+
|
95
|
+
File.open(options[:output], 'w') do |output_file|
|
96
|
+
files.each do |file|
|
97
|
+
if options[:verbose]
|
98
|
+
say "Processing file: #{file}", :cyan
|
99
|
+
end
|
100
|
+
|
101
|
+
relative_path = Pathname.new(file).relative_path_from(Pathname.new(options[:directory])).to_s
|
102
|
+
|
103
|
+
begin
|
104
|
+
generator = Hind::LSIF::Generator.new(
|
105
|
+
{
|
106
|
+
uri: relative_path,
|
107
|
+
vertex_id: vertex_id,
|
108
|
+
initial: initial,
|
109
|
+
projectRoot: options[:directory]
|
110
|
+
},
|
111
|
+
global_state
|
112
|
+
)
|
113
|
+
|
114
|
+
output = generator.generate(File.read(file))
|
115
|
+
vertex_id = output.last[:id].to_i + 1
|
116
|
+
output_file.puts(output.map(&:to_json).join("\n"))
|
117
|
+
initial = false
|
118
|
+
rescue StandardError => e
|
119
|
+
warn "Warning: Failed to process file '#{file}': #{e.message}"
|
120
|
+
next
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def generate_scip(files, options)
|
127
|
+
raise NotImplementedError, "SCIP generation not yet implemented"
|
128
|
+
# Similar to generate_lsif but using SCIP generator
|
129
|
+
end
|
130
|
+
|
131
|
+
def load_config(config_path)
|
132
|
+
return {} unless config_path && File.exist?(config_path)
|
133
|
+
|
134
|
+
begin
|
135
|
+
YAML.load_file(config_path) || {}
|
136
|
+
rescue StandardError => e
|
137
|
+
abort "Error loading config file: #{e.message}"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Hind
|
2
|
+
module LSIF
|
3
|
+
class Edge
|
4
|
+
attr_reader :id, :label, :out_v, :in_v, :property, :document
|
5
|
+
|
6
|
+
def initialize(id, label, out_v, in_v, property = nil, document = nil)
|
7
|
+
@id = id
|
8
|
+
@label = label
|
9
|
+
@out_v = out_v
|
10
|
+
@in_v = in_v
|
11
|
+
@property = property
|
12
|
+
@document = document
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_json
|
16
|
+
json = {
|
17
|
+
id: @id,
|
18
|
+
type: 'edge',
|
19
|
+
label: @label,
|
20
|
+
outV: @out_v
|
21
|
+
}
|
22
|
+
|
23
|
+
if @in_v.is_a?(Array)
|
24
|
+
json[:inVs] = @in_v
|
25
|
+
else
|
26
|
+
json[:inV] = @in_v
|
27
|
+
end
|
28
|
+
|
29
|
+
json[:property] = @property if @property
|
30
|
+
json[:document] = @document if @document
|
31
|
+
|
32
|
+
json
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'prism'
|
4
|
+
require 'json'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
module Hind
|
8
|
+
module LSIF
|
9
|
+
class Generator
|
10
|
+
LSIF_VERSION = '0.4.3'
|
11
|
+
|
12
|
+
attr_reader :global_state, :document_id, :metadata
|
13
|
+
|
14
|
+
def initialize(metadata = {}, global_state = nil)
|
15
|
+
@vertex_id = metadata[:vertex_id] || 1
|
16
|
+
@metadata = {
|
17
|
+
language: 'ruby',
|
18
|
+
projectRoot: Dir.pwd
|
19
|
+
}.merge(metadata)
|
20
|
+
|
21
|
+
@global_state = global_state || GlobalState.new
|
22
|
+
@document_ids = {}
|
23
|
+
@lsif_data = []
|
24
|
+
|
25
|
+
initialize_project if metadata[:initial]
|
26
|
+
end
|
27
|
+
|
28
|
+
def generate(code, file_metadata = {})
|
29
|
+
@metadata = @metadata.merge(file_metadata)
|
30
|
+
setup_document
|
31
|
+
|
32
|
+
ast = Parser.new(code).parse
|
33
|
+
visitor = Visitor.new(self)
|
34
|
+
visitor.visit(ast)
|
35
|
+
|
36
|
+
finalize_document
|
37
|
+
update_cross_file_references
|
38
|
+
|
39
|
+
@lsif_data
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_range(start_location, end_location)
|
43
|
+
range_id = emit_vertex('range', {
|
44
|
+
start: {
|
45
|
+
line: start_location.start_line - 1,
|
46
|
+
character: start_location.start_column
|
47
|
+
},
|
48
|
+
end: {
|
49
|
+
line: end_location.end_line - 1,
|
50
|
+
character: end_location.end_column
|
51
|
+
}
|
52
|
+
})
|
53
|
+
|
54
|
+
file_path = File.join(@metadata[:projectRoot], @metadata[:uri])
|
55
|
+
@global_state.add_range(file_path, range_id)
|
56
|
+
range_id
|
57
|
+
end
|
58
|
+
|
59
|
+
def emit_vertex(label, data = nil)
|
60
|
+
vertex = Vertex.new(@vertex_id, label, data)
|
61
|
+
@lsif_data << vertex.to_json
|
62
|
+
@vertex_id += 1
|
63
|
+
@vertex_id - 1
|
64
|
+
end
|
65
|
+
|
66
|
+
def emit_edge(label, out_v, in_v, property = nil)
|
67
|
+
return unless out_v && valid_in_v?(in_v)
|
68
|
+
|
69
|
+
edge = Edge.new(@vertex_id, label, out_v, in_v, property, edge_document(label))
|
70
|
+
@lsif_data << edge.to_json
|
71
|
+
@vertex_id += 1
|
72
|
+
@vertex_id - 1
|
73
|
+
end
|
74
|
+
|
75
|
+
def add_to_global_state(qualified_name, result_set_id, range_id)
|
76
|
+
file_path = File.join(@metadata[:projectRoot], @metadata[:uri])
|
77
|
+
@global_state.result_sets[qualified_name] = result_set_id
|
78
|
+
@global_state.add_definition(qualified_name, file_path, range_id)
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def initialize_project
|
84
|
+
emit_vertex('metaData', {
|
85
|
+
version: LSIF_VERSION,
|
86
|
+
projectRoot: path_to_uri(@metadata[:projectRoot]),
|
87
|
+
positionEncoding: 'utf-16',
|
88
|
+
toolInfo: {
|
89
|
+
name: 'hind',
|
90
|
+
version: VERSION
|
91
|
+
}
|
92
|
+
})
|
93
|
+
|
94
|
+
@global_state.project_id = emit_vertex('project', { kind: 'ruby' })
|
95
|
+
end
|
96
|
+
|
97
|
+
def setup_document
|
98
|
+
file_path = File.join(@metadata[:projectRoot], @metadata[:uri])
|
99
|
+
|
100
|
+
@document_id = emit_vertex('document', {
|
101
|
+
uri: path_to_uri(file_path),
|
102
|
+
languageId: 'ruby'
|
103
|
+
})
|
104
|
+
@document_ids[file_path] = @document_id
|
105
|
+
|
106
|
+
emit_edge('contains', @global_state.project_id, [@document_id]) if @global_state.project_id
|
107
|
+
end
|
108
|
+
|
109
|
+
def finalize_document
|
110
|
+
file_path = File.join(@metadata[:projectRoot], @metadata[:uri])
|
111
|
+
ranges = @global_state.ranges[file_path]
|
112
|
+
|
113
|
+
if ranges&.any?
|
114
|
+
emit_edge('contains', @document_id, ranges)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def update_cross_file_references
|
119
|
+
@global_state.references.each do |qualified_name, references|
|
120
|
+
definition = @global_state.definitions[qualified_name]
|
121
|
+
next unless definition
|
122
|
+
|
123
|
+
result_set_id = @global_state.result_sets[qualified_name]
|
124
|
+
next unless result_set_id
|
125
|
+
|
126
|
+
ref_result_id = emit_vertex('referenceResult')
|
127
|
+
emit_edge('textDocument/references', result_set_id, ref_result_id)
|
128
|
+
|
129
|
+
# Collect all reference range IDs
|
130
|
+
all_refs = references.map { |ref| ref[:range_id] }
|
131
|
+
all_refs << definition[:range_id]
|
132
|
+
|
133
|
+
# Group references by document
|
134
|
+
reference_documents = references.group_by { |ref| ref[:file] }
|
135
|
+
reference_documents.each_key do |file_path|
|
136
|
+
document_id = @document_ids[file_path]
|
137
|
+
next unless document_id
|
138
|
+
|
139
|
+
emit_edge('item', ref_result_id, all_refs, 'references')
|
140
|
+
end
|
141
|
+
|
142
|
+
# Handle definition document if not already included
|
143
|
+
def_document_id = @document_ids[definition[:file]]
|
144
|
+
if def_document_id && references.none? { |ref| ref[:file] == definition[:file] }
|
145
|
+
emit_edge('item', ref_result_id, all_refs, 'references')
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def valid_in_v?(in_v)
|
151
|
+
return false unless in_v
|
152
|
+
return in_v.any? if in_v.is_a?(Array)
|
153
|
+
true
|
154
|
+
end
|
155
|
+
|
156
|
+
def edge_document(label)
|
157
|
+
label == 'item' ? @document_id : nil
|
158
|
+
end
|
159
|
+
|
160
|
+
def path_to_uri(path)
|
161
|
+
normalized_path = path.gsub('\\', '/')
|
162
|
+
normalized_path = normalized_path.sub(%r{^file://}, '')
|
163
|
+
absolute_path = File.expand_path(normalized_path)
|
164
|
+
"file://#{absolute_path}"
|
165
|
+
end
|
166
|
+
|
167
|
+
def make_hover_content(text)
|
168
|
+
{
|
169
|
+
contents: [{
|
170
|
+
language: 'ruby',
|
171
|
+
value: strip_code_block(text)
|
172
|
+
}]
|
173
|
+
}
|
174
|
+
end
|
175
|
+
|
176
|
+
def strip_code_block(text)
|
177
|
+
# Strip any existing code block markers and normalize
|
178
|
+
text.gsub(/```.*\n?/, '').strip
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Hind
|
2
|
+
module LSIF
|
3
|
+
class GlobalState
|
4
|
+
attr_reader :result_sets, :definitions, :references, :ranges
|
5
|
+
attr_accessor :project_id
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@result_sets = {} # {qualified_name => result_set_id}
|
9
|
+
@definitions = {} # {qualified_name => {file: file_path, range_id: id}}
|
10
|
+
@references = {} # {qualified_name => [{file: file_path, range_id: id}]}
|
11
|
+
@ranges = {} # {file_path => [range_ids]}
|
12
|
+
@project_id = nil # Store project ID for reuse across files
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_range(file_path, range_id)
|
16
|
+
@ranges[file_path] ||= []
|
17
|
+
@ranges[file_path] << range_id
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_definition(qualified_name, file_path, range_id)
|
21
|
+
@definitions[qualified_name] = { file: file_path, range_id: range_id }
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_reference(qualified_name, file_path, range_id)
|
25
|
+
@references[qualified_name] ||= []
|
26
|
+
@references[qualified_name] << { file: file_path, range_id: range_id }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Hind
|
2
|
+
module LSIF
|
3
|
+
class Vertex
|
4
|
+
attr_reader :id, :label, :data
|
5
|
+
|
6
|
+
def initialize(id, label, data = nil)
|
7
|
+
@id = id
|
8
|
+
@label = label
|
9
|
+
@data = data
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_json
|
13
|
+
json = {
|
14
|
+
id: @id,
|
15
|
+
type: 'vertex',
|
16
|
+
label: @label
|
17
|
+
}
|
18
|
+
|
19
|
+
if @data
|
20
|
+
if %w[hoverResult definitionResult referenceResult].include?(@label)
|
21
|
+
json[:result] = @data
|
22
|
+
else
|
23
|
+
json.merge!(@data)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
json
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Hind
|
2
|
+
module LSIF
|
3
|
+
class Visitor
|
4
|
+
def initialize(generator)
|
5
|
+
@generator = generator
|
6
|
+
@current_scope = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def visit(node)
|
10
|
+
return unless node
|
11
|
+
|
12
|
+
method_name = "visit_#{node.class.name.split('::').last.downcase}"
|
13
|
+
if respond_to?(method_name)
|
14
|
+
send(method_name, node)
|
15
|
+
else
|
16
|
+
visit_children(node)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def visit_children(node)
|
21
|
+
node.child_nodes.each { |child| visit(child) if child }
|
22
|
+
end
|
23
|
+
|
24
|
+
def visit_defnode(node)
|
25
|
+
method_name = node.name.to_s
|
26
|
+
qualified_name = current_scope_name.empty? ? method_name : "#{current_scope_name}##{method_name}"
|
27
|
+
|
28
|
+
range_id = @generator.create_range(node.location, node.location)
|
29
|
+
result_set_id = @generator.emit_vertex('resultSet')
|
30
|
+
@generator.emit_edge('next', range_id, result_set_id)
|
31
|
+
|
32
|
+
def_result_id = @generator.emit_vertex('definitionResult')
|
33
|
+
@generator.emit_edge('textDocument/definition', result_set_id, def_result_id)
|
34
|
+
@generator.emit_edge('item', def_result_id, [range_id], 'definitions')
|
35
|
+
|
36
|
+
# Add hover information
|
37
|
+
sig = []
|
38
|
+
sig << "def #{qualified_name}"
|
39
|
+
sig << "(#{node.parameters.slice})" if node.parameters
|
40
|
+
|
41
|
+
hover_id = @generator.emit_vertex('hoverResult', {
|
42
|
+
contents: [{
|
43
|
+
language: 'ruby',
|
44
|
+
value: sig.join
|
45
|
+
}]
|
46
|
+
})
|
47
|
+
@generator.emit_edge('textDocument/hover', result_set_id, hover_id)
|
48
|
+
|
49
|
+
@generator.add_to_global_state(qualified_name, result_set_id, range_id)
|
50
|
+
|
51
|
+
visit_children(node)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Additional visitor methods...
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def current_scope_name
|
59
|
+
@current_scope.join('::')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/hind/lsif.rb
ADDED
data/lib/hind/parser.rb
ADDED
data/lib/hind/scip.rb
ADDED
data/lib/hind/version.rb
ADDED
data/lib/hind.rb
ADDED
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hind
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aboobacker MK
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-02-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: prism
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.19.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.19.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: zeitwerk
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.6'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '13.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '13.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description: A tool to generate LSIF and SCIP index files for Ruby codebases
|
98
|
+
email:
|
99
|
+
- aboobackervyd@gmail.com
|
100
|
+
executables:
|
101
|
+
- hind
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
107
|
+
- exe/hind
|
108
|
+
- lib/hind.rb
|
109
|
+
- lib/hind/cli.rb
|
110
|
+
- lib/hind/lsif.rb
|
111
|
+
- lib/hind/lsif/edge.rb
|
112
|
+
- lib/hind/lsif/generator.rb
|
113
|
+
- lib/hind/lsif/global_state.rb
|
114
|
+
- lib/hind/lsif/vertex.rb
|
115
|
+
- lib/hind/lsif/visitor.rb
|
116
|
+
- lib/hind/parser.rb
|
117
|
+
- lib/hind/scip.rb
|
118
|
+
- lib/hind/scip/generator.rb
|
119
|
+
- lib/hind/scip/visitor.rb
|
120
|
+
- lib/hind/version.rb
|
121
|
+
homepage: https://github.com/tachyons/hind
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata:
|
125
|
+
allowed_push_host: https://rubygems.org
|
126
|
+
homepage_uri: https://github.com/tachyons/hind
|
127
|
+
source_code_uri: https://github.com/tachyons/hind
|
128
|
+
changelog_uri: https://github.com/tachyons/hind/blob/main/CHANGELOG.md
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 2.7.0
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubygems_version: 3.5.3
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: LSIF and SCIP generator for Ruby
|
148
|
+
test_files: []
|