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

Reload completion on file changes #98

Merged
merged 17 commits into from
May 6, 2018
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/scry/completion/dependency_graph.cr
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ module Scry::Completion::DependencyGraph
def each
@nodes.each
end

def delete(value : String)
@nodes.delete value
end
end

class Builder
Expand All @@ -84,6 +88,11 @@ module Scry::Completion::DependencyGraph
graph
end

def rebuild(graph, filename)
process_requires(filename, graph)
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)
analyzer = Analyzer.new(@workspace, text_document)
response = analyzer.run
response
Expand Down
13 changes: 12 additions & 1 deletion src/scry/workspace.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,26 @@ 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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small note: Remember: If you're doing + [expr] you're having 2 new arrays!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about 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(file)
@dependency_graph = Completion::DependencyGraph::Builder.new(@lookup_path).rebuild(@dependency_graph, file.filename)
file_dependencies = @dependency_graph[file.filename].descendants.map &.value
method_db = Completion::MethodDB.generate(file_dependencies)
@open_files[file.filename] = {file, method_db}
end

def put_file(params : DidOpenTextDocumentParams)
Expand All @@ -42,6 +52,7 @@ module Scry
def drop_file(params : TextDocumentParams)
filename = TextDocument.uri_to_filename(params.text_document.uri)
@open_files.delete(filename)
@dependency_graph.delete(filename)
end

def get_file(text_document : TextDocumentIdentifier)
Expand Down