Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Add reopen workspace and rebuild graph methods
Browse files Browse the repository at this point in the history
  • Loading branch information
faustinoaq committed Apr 30, 2018
1 parent 9e89531 commit 454b93c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/scry/completion/dependency_graph.cr
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ module Scry::Completion::DependencyGraph
graph
end

def rebuild(graph, filename)
@lookup_paths
.map { |e| File.join(File.expand_path(e), "**", "*.cr") }
.uniq
.flat_map { |d| Dir.glob(d) }
.each { |file| process_requires(file, graph) if file == filename }
graph
end

def process_requires(file, graph)
requires = parse_requires(file)
current_file_path = File.expand_path(file)
Expand Down
1 change: 1 addition & 0 deletions src/scry/context.cr
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ module Scry
when FileEventType::Deleted
PublishDiagnostic.new(@workspace, text_document.uri).clean
when FileEventType::Changed
@workspace.reopen_workspace(text_document.filename)
analyzer = Analyzer.new(@workspace, text_document)
response = analyzer.run
response
Expand Down
9 changes: 8 additions & 1 deletion src/scry/workspace.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@ module Scry
property open_files
property dependency_graph : Completion::DependencyGraph::Graph

@lookup_path : Array(String)

def initialize(root_uri, process_id, max_number_of_problems)
@root_uri = root_uri
@process_id = process_id
@max_number_of_problems = max_number_of_problems
@open_files = {} of String => {TextDocument, Completion::MethodDB}
@dependency_graph = Completion::DependencyGraph::Graph.new
@lookup_path = ENV["CRYSTAL_PATH"].split(":") + [@root_uri]
end

def open_workspace
@dependency_graph = Completion::DependencyGraph::Builder.new(ENV["CRYSTAL_PATH"].split(":") + [@root_uri]).build
@dependency_graph = Completion::DependencyGraph::Builder.new(@lookup_path).build
end

def reopen_workspace(filename)
@dependency_graph = Completion::DependencyGraph::Builder.new(@lookup_path).rebuild(@dependency_graph, filename)
end

def put_file(params : DidOpenTextDocumentParams)
Expand Down

0 comments on commit 454b93c

Please sign in to comment.