Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable linting in test folders #776

Merged
merged 6 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/requests/textdocument.jl
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ end
isunsavedfile(doc::Document) = startswith(doc._uri, "untitled:") # Not clear if this is consistent across editors.

function publish_diagnostics(doc::Document, server, conn)
if server.runlinter && server.symbol_store_ready && (is_workspace_file(doc) || isunsavedfile(doc))
if server.runlinter && server.symbol_store_ready && (is_workspace_file(doc) || isunsavedfile(doc)) && !is_in_test_dir_of_package(getpath(doc))
publishDiagnosticsParams = PublishDiagnosticsParams(doc._uri, doc._version, doc.diagnostics)
else
publishDiagnosticsParams = PublishDiagnosticsParams(doc._uri, doc._version, Diagnostic[])
Expand Down
46 changes: 46 additions & 0 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,49 @@ function op_resolve_up_scopes(x, mn, scope, server)
end

maybe_lookup(x, server) = x isa SymbolServer.VarRef ? SymbolServer._lookup(x, getsymbolserver(server), true) : x # TODO: needs to go to SymbolServer

function is_in_test_dir_of_package(path::String)
try # Safe failure - attempts to read disc.
if VERSION < v"1.1"
return false
else
Copy link
Member

Choose a reason for hiding this comment

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

Maybe you just forgot to remove this check ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep!

spaths = splitpath(path)
if (i = findfirst(==("test"), spaths)) !== nothing && "src" in readdir(joinpath(spaths[1:i-1]...))
return true
end
end
return false
catch
return false
end
end


if VERSION < v"1.1"
_splitdir_nodrive(path::String) = _splitdir_nodrive("", path)
function _splitdir_nodrive(a::String, b::String)
m = match(Base.Filesystem.path_dir_splitter,b)
m === nothing && return (a,b)
a = string(a, isempty(m.captures[1]) ? m.captures[2][1] : m.captures[1])
a, String(m.captures[3])
end
splitpath(p::AbstractString) = splitpath(String(p))

function splitpath(p::String)
drive, p = splitdrive(p)
out = String[]
isempty(p) && (pushfirst!(out,p)) # "" means the current directory.
while !isempty(p)
dir, base = _splitdir_nodrive(p)
dir == p && (pushfirst!(out, dir); break) # Reached root node.
if !isempty(base) # Skip trailing '/' in basename
pushfirst!(out, base)
end
p = dir
end
if !isempty(drive) # Tack the drive back on to the first element.
out[1] = drive*out[1] # Note that length(out) is always >= 1.
end
return out
end
end
5 changes: 5 additions & 0 deletions test/test_paths.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ end
end

end

@testset "is_in_test_dir_of_package" begin
@test LanguageServer.is_in_test_dir_of_package(@__DIR__)
@test !LanguageServer.is_in_test_dir_of_package(pathof(LanguageServer))
end