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 4 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
20 changes: 18 additions & 2 deletions src/requests/textdocument.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,25 @@ end

isunsavedfile(doc::Document) = startswith(doc._uri, "untitled:") # Not clear if this is consistent across editors.

"""
is_diag_dependent_on_env(diag::Diagnostic)::Bool

Is this diagnostic reliant on the current environment being accurately represented?
"""
function is_diag_dependent_on_env(diag::Diagnostic)
startswith(diag.message, "Missing reference: ") ||
startswith(diag.message, "Possible method call error") ||
startswith(diag.message, "An imported")
end

function publish_diagnostics(doc::Document, server, conn)
if server.runlinter && server.symbol_store_ready && (is_workspace_file(doc) || isunsavedfile(doc))
publishDiagnosticsParams = PublishDiagnosticsParams(doc._uri, doc._version, doc.diagnostics)
if server.runlinter && server.symbol_store_ready && (is_workspace_file(doc) || isunsavedfile(doc))
if is_in_test_dir_of_package(getpath(doc))
filter!(!is_diag_dependent_on_env, doc.diagnostics)
publishDiagnosticsParams = PublishDiagnosticsParams(doc._uri, doc._version, doc.diagnostics)
else
publishDiagnosticsParams = PublishDiagnosticsParams(doc._uri, doc._version, doc.diagnostics)
end
else
publishDiagnosticsParams = PublishDiagnosticsParams(doc._uri, doc._version, Diagnostic[])
end
Expand Down
42 changes: 42 additions & 0 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,45 @@ 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.
spaths = splitpath(path)
if (i = findfirst(==("test"), spaths)) !== nothing && "src" in readdir(joinpath(spaths[1:i-1]...))
return true
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