Class: Ibex::LSP::WorkspaceAnalyzer
- Inherits:
-
Object
- Object
- Ibex::LSP::WorkspaceAnalyzer
- Defined in:
- lib/ibex/lsp/workspace_analyzer.rb
Overview
Parses workspace sources, discovers safe include closures, and renders diagnostics.
Constant Summary collapse
- GLOB_CHARACTERS =
: Regexp
/[*?\[\]{}]/- WINDOWS_ABSOLUTE =
: Regexp
%r{\A(?:[A-Za-z]:[\\/]|\\\\)}
Instance Method Summary collapse
- #analyze(path) ⇒ Object
- #closure(root) ⇒ Object
-
#initialize(workspace, loader) ⇒ WorkspaceAnalyzer
constructor
A new instance of WorkspaceAnalyzer.
- #resolve(root) ⇒ Object
Constructor Details
#initialize(workspace, loader) ⇒ WorkspaceAnalyzer
Returns a new instance of WorkspaceAnalyzer.
19 20 21 22 |
# File 'lib/ibex/lsp/workspace_analyzer.rb', line 19 def initialize(workspace, loader) @workspace = workspace @loader = loader end |
Instance Method Details
#analyze(path) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/ibex/lsp/workspace_analyzer.rb', line 25 def analyze(path) source = @loader.read(path) return analyze_fragment(path, source) if fragment_source?(source, path) analyze_root(path, source) rescue Ibex::Error, SystemCallError => e source ||= readable_source(path) { source: source, document: nil, diagnostics: [diagnostic(e., source, path)] } end |
#closure(root) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ibex/lsp/workspace_analyzer.rb', line 36 def closure(root) files = [] #: Array[String] analyzed = {} #: Hash[String, analyzed_document] visiting = [root] until visiting.empty? path = visiting.pop next unless path next if analyzed.key?(path) current = analyze(path) analyzed[path] = current files << path dependencies(current.fetch(:document)).reverse_each do |target| visiting << target unless analyzed.key?(target) end end [files, analyzed] end |
#resolve(root) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/ibex/lsp/workspace_analyzer.rb', line 56 def resolve(root) resolution = Frontend::Resolver.new(root, mode: :extended, loader: @loader).resolve [resolution, []] rescue Ibex::Error, SystemCallError => e [nil, [diagnostic(e., source_for_error(e., root), file_for_error(e., root))]] end |