hind 0.1.12 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47976412f00e1ef73ece58033efbfbdc363deeafd8c02b773b8d4416808819f9
4
- data.tar.gz: 1712f5118a6d4fe4fd05cc25cd425288fa1fffe0bba8368ac9d020249332229b
3
+ metadata.gz: edc5339a6fe71b30f48781500d996901bef7732b5d6ed6a54ce561d057edce19
4
+ data.tar.gz: 8dd64ea610eaf53314e918d91846d42839b522550e2b29a2a626228f7c459fbd
5
5
  SHA512:
6
- metadata.gz: ed15005304b079cefc8525fcd7fb534af2ab743f8fc4e68fdade9deb54d8e1e94a11a02441e815e6cb453ce4399ef91a0ae077f929b75b341e569de57fba8759
7
- data.tar.gz: '08c465616f3f62a28882a80e1b637341604ac2725d8dd1b1ef7c4b8d908ada3c53ff5d53534573bbdb12aeab988e26944f75f297ef12afe9376b9a762d4560e8'
6
+ metadata.gz: d85651252a56a48c32c3285205cea32d0aa99e8098b396168cb1bf3357b61a9deff6ef90ceecee3b891761205bcb1d420235d4859b780629555080c040d9b25e
7
+ data.tar.gz: e69fa976556441508e1f46f7bb2636989a3cb810922636b1e460e3fa68130c7dc60538e55609349365506bf3fe21807a379c4afd5f54f4272582f02071164eef
data/lib/hind/cli.rb CHANGED
@@ -49,22 +49,6 @@ module Hind
49
49
  }
50
50
  )
51
51
 
52
- # Create file content map with relative paths
53
- file_contents = {}
54
- files.each do |file|
55
- absolute_path = File.expand_path(file)
56
- relative_path = Pathname.new(absolute_path)
57
- .relative_path_from(Pathname.new(generator.metadata[:projectRoot]))
58
- .to_s
59
-
60
- begin
61
- file_contents[relative_path] = File.read(absolute_path)
62
- rescue => e
63
- warn "Warning: Failed to read file '#{file}': #{e.message}"
64
- next
65
- end
66
- end
67
-
68
52
  File.open(options[:output], 'w') do |output_file|
69
53
  say 'First pass: Collecting declarations...', :cyan if options[:verbose]
70
54
 
@@ -76,28 +60,54 @@ module Hind
76
60
  end
77
61
 
78
62
  # First pass: Process all files to collect declarations
79
- declaration_data = generator.collect_declarations(file_contents)
63
+ declaration_data = {}
64
+ files.each do |file|
65
+ absolute_path = File.expand_path(file)
66
+ relative_path = Pathname.new(absolute_path)
67
+ .relative_path_from(Pathname.new(generator.metadata[:projectRoot]))
68
+ .to_s
69
+
70
+ begin
71
+ content = File.read(absolute_path)
72
+ file_declaration_data = generator.collect_file_declarations(content, relative_path)
73
+ declaration_data.merge!(file_declaration_data)
74
+ rescue => e
75
+ warn "Warning: Failed to read file '#{file}': #{e.message}"
76
+ next
77
+ end
78
+ end
80
79
 
81
- say "Found #{declaration_data[:declarations].size} declarations (classes, modules, constants)", :cyan if options[:verbose]
80
+ say "Found #{declaration_data[:declarations]&.size} declarations (classes, modules, constants)", :cyan if options[:verbose]
82
81
 
83
82
  # Write declaration LSIF data next
84
- if declaration_data[:lsif_data]&.any?
83
+ if declaration_data[:lsif_data].any?
85
84
  output_file.puts(declaration_data[:lsif_data].map(&:to_json).join("\n"))
86
85
  end
87
86
 
88
87
  say 'Processing files for references...', :cyan if options[:verbose]
89
88
 
90
89
  # Second pass: Process each file for references
91
- file_contents.each do |relative_path, content|
90
+ files.each do |file|
91
+ absolute_path = File.expand_path(file)
92
+ relative_path = Pathname.new(absolute_path)
93
+ .relative_path_from(Pathname.new(generator.metadata[:projectRoot]))
94
+ .to_s
95
+
92
96
  if options[:verbose]
93
97
  say "Processing file: #{relative_path}", :cyan
94
98
  end
95
99
 
96
- reference_lsif_data = generator.process_file(
97
- content: content,
98
- uri: relative_path
99
- )
100
- output_file.puts(reference_lsif_data.map(&:to_json).join("\n"))
100
+ begin
101
+ content = File.read(absolute_path)
102
+ reference_lsif_data = generator.process_file(
103
+ content: content,
104
+ uri: relative_path
105
+ )
106
+ output_file.puts(reference_lsif_data.map(&:to_json).join("\n"))
107
+ rescue => e
108
+ warn "Warning: Failed to read file '#{file}': #{e.message}"
109
+ next
110
+ end
101
111
  end
102
112
  end
103
113
  end
@@ -32,24 +32,22 @@ module Hind
32
32
  initialize_project if metadata[:initial]
33
33
  end
34
34
 
35
- def collect_declarations(files)
36
- files.each do |path, content|
37
- @current_uri = path
38
- @document_id = nil
39
- @current_document_id = nil
40
-
41
- begin
42
- ast = Parser.new(content).parse
43
- setup_document
44
- visitor = DeclarationVisitor.new(self, path)
45
- visitor.visit(ast)
46
- finalize_document_state
47
- rescue => e
48
- warn "Warning: Failed to collect declarations from '#{path}': #{e.message}"
49
- end
35
+ def collect_file_declarations(content, path)
36
+ @current_uri = path
37
+ @document_id = nil
38
+ @current_document_id = nil
39
+
40
+ begin
41
+ ast = Parser.new(content).parse
42
+ setup_document
43
+ visitor = DeclarationVisitor.new(self, path)
44
+ visitor.visit(ast)
45
+ finalize_document_state
46
+ rescue => e
47
+ warn "Warning: Failed to collect declarations from '#{path}': #{e.message}"
50
48
  end
51
49
 
52
- # Store the last used vertex ID and reset reference index
50
+ # Store the last used vertex ID and reference index
53
51
  @last_vertex_id = @vertex_id
54
52
  @last_reference_index = @lsif_data.length
55
53
 
@@ -98,12 +96,12 @@ module Hind
98
96
  setup_document if @document_id.nil?
99
97
  current_doc_id = @document_id
100
98
 
101
- range_id = if declaration[:type] == :constant_write
99
+ range_id = if declaration[:type] == :constant
102
100
  create_range(declaration[:node].name_loc)
103
101
  elsif declaration[:type] == :module
104
- create_range(declaration[:node].module_keyword_loc)
102
+ create_range(declaration[:node].constant_path.location)
105
103
  elsif declaration[:type] == :class
106
- create_range(declaration[:node].constant_path)
104
+ create_range(declaration[:node].constant_path.location)
107
105
  else
108
106
  create_range(declaration[:node].location)
109
107
  end
@@ -153,6 +151,10 @@ module Hind
153
151
 
154
152
  @global_state.add_reference(reference[:name], @current_uri, range_id, current_doc_id)
155
153
  emit_edge('next', range_id, declaration[:result_set_id])
154
+
155
+ reference_result = emit_vertex('referenceResult')
156
+ emit_edge('textDocument/references', declaration[:result_set_id], reference_result)
157
+ emit_edge('item', reference_result, [range_id], 'references', @document_id)
156
158
  end
157
159
 
158
160
  private
data/lib/hind/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hind
4
- VERSION = '0.1.12'
4
+ VERSION = '0.1.14'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hind
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aboobacker MK