Skip to content

Commit

Permalink
Merge pull request #776 from julia-vscode/disable-test-lint
Browse files Browse the repository at this point in the history
disable linting in test folders
  • Loading branch information
davidanthoff authored Jul 1, 2020
2 parents 15ae206 + e8141d1 commit d9c4678
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
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

0 comments on commit d9c4678

Please sign in to comment.