From c3f589b4744fbc37951fb4a00f446f54d9387b0c Mon Sep 17 00:00:00 2001 From: ZacLN Date: Mon, 22 Jun 2020 22:12:17 +0100 Subject: [PATCH 1/3] disable linting in test folders --- src/requests/textdocument.jl | 2 +- src/utilities.jl | 46 ++++++++++++++++++++++++++++++++++++ test/test_paths.jl | 5 ++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/requests/textdocument.jl b/src/requests/textdocument.jl index a15664e1..5a369fd6 100644 --- a/src/requests/textdocument.jl +++ b/src/requests/textdocument.jl @@ -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[]) diff --git a/src/utilities.jl b/src/utilities.jl index 47de3162..576ef67a 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -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 + 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 diff --git a/test/test_paths.jl b/test/test_paths.jl index b515762a..51ea774e 100644 --- a/test/test_paths.jl +++ b/test/test_paths.jl @@ -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 From 3fc43d1983c45097decf5d2314ae2bb900575f69 Mon Sep 17 00:00:00 2001 From: ZacLN Date: Wed, 24 Jun 2020 17:47:43 +0100 Subject: [PATCH 2/3] remove version branching --- src/utilities.jl | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/utilities.jl b/src/utilities.jl index 576ef67a..1a542edd 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -334,13 +334,9 @@ maybe_lookup(x, server) = x isa SymbolServer.VarRef ? SymbolServer._lookup(x, ge function is_in_test_dir_of_package(path::String) try # Safe failure - attempts to read disc. - if VERSION < v"1.1" - return false - else - spaths = splitpath(path) - if (i = findfirst(==("test"), spaths)) !== nothing && "src" in readdir(joinpath(spaths[1:i-1]...)) - return true - end + spaths = splitpath(path) + if (i = findfirst(==("test"), spaths)) !== nothing && "src" in readdir(joinpath(spaths[1:i-1]...)) + return true end return false catch From 602c271200d96a9ee7c36d139a0c5cbb80c283f3 Mon Sep 17 00:00:00 2001 From: ZacLN Date: Wed, 1 Jul 2020 13:49:24 +0100 Subject: [PATCH 3/3] report some linting in /test --- src/requests/textdocument.jl | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/requests/textdocument.jl b/src/requests/textdocument.jl index 668a2681..16301ae6 100644 --- a/src/requests/textdocument.jl +++ b/src/requests/textdocument.jl @@ -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)) && !is_in_test_dir_of_package(getpath(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