From 8fa2ff3580246639c5a25a2ab613ee6bc658593c Mon Sep 17 00:00:00 2001 From: ZacNugent Date: Mon, 27 Jan 2020 07:20:45 +0000 Subject: [PATCH] alternative approach to safe folder loading --- src/requests/init.jl | 54 +++++++++++++++++++++++++----------- src/requests/textdocument.jl | 8 ++++-- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/requests/init.jl b/src/requests/init.jl index 9d29b001..fbef81c5 100644 --- a/src/requests/init.jl +++ b/src/requests/init.jl @@ -70,28 +70,50 @@ function load_folder(wf::WorkspaceFolder, server) load_folder(path, server) end -function load_folder(path::String, server) - if load_rootpath(path) - for (root, dirs, files) in walkdir(path, onerror = x->x) - for file in files - filepath = joinpath(root, file) - if hasreadperm(filepath) && isvalidjlfile(filepath) - !isfile(filepath) && continue - uri = filepath2uri(filepath) - if URI2(uri) in keys(server.documents) - continue - else - content = read(filepath, String) - server.documents[URI2(uri)] = Document(uri, content, true, server) - doc = server.documents[URI2(uri)] - parse_all(doc, server) - end +function load_folder(dir::String, server) + if !isempty(dir) && isdir(dir) && hasreadperm(dir) && !has_too_many_files(dir) + for file in readdir(dir) + filepath = joinpath(dir, file) + !hasreadperm(filepath) && continue + if isfile(filepath) && isvalidjlfile(filepath) + uri = filepath2uri(filepath) + if URI2(uri) in keys(server.documents) + continue + else + content = read(filepath, String) + server.documents[URI2(uri)] = Document(uri, content, true, server) + doc = server.documents[URI2(uri)] + parse_all(doc, server) end + elseif isdir(filepath) + load_folder(filepath, server) end end end end +# function load_folder(path::String, server) +# if load_rootpath(path) +# for (root, dirs, files) in walkdir(path, onerror = x->x) +# for file in files +# filepath = joinpath(root, file) +# if hasreadperm(filepath) && isvalidjlfile(filepath) +# !isfile(filepath) && continue +# uri = filepath2uri(filepath) +# if URI2(uri) in keys(server.documents) +# continue +# else +# content = read(filepath, String) +# server.documents[URI2(uri)] = Document(uri, content, true, server) +# doc = server.documents[URI2(uri)] +# parse_all(doc, server) +# end +# end +# end +# end +# end +# end + JSONRPC.parse_params(::Type{Val{Symbol("initialize")}}, params) = InitializeParams(params) function process(r::JSONRPC.Request{Val{Symbol("initialize")},InitializeParams}, server) diff --git a/src/requests/textdocument.jl b/src/requests/textdocument.jl index 043a8b3b..df842144 100644 --- a/src/requests/textdocument.jl +++ b/src/requests/textdocument.jl @@ -390,11 +390,13 @@ end function search_for_parent(dir::String, file::String, drop = 3, parents = String[]) drop<1 && return parents !isdir(dir) && return parents + !hasreadperm(dir) && return parents for f in readdir(dir) - if endswith(f, ".jl") + fpath = joinpath(dir, f) + if endswith(f, ".jl") && hasreadperm(fpath) && isvalidjlfile(fpath) # Could be sped up? - s = read(joinpath(dir, f), String) - occursin(file, s) && push!(parents, joinpath(dir, f)) + s = read(fpath, String) + occursin(file, s) && push!(parents, fpath) end end search_for_parent(splitdir(dir)[1], file, drop - 1, parents)