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

Add ignoredGlobs option to linter #1291

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion src/languageserverinstance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ mutable struct LanguageServerInstance
lint_options::StaticLint.LintOptions
lint_missingrefs::Symbol
lint_disableddirs::Vector{String}
lint_ignoredglobs::Vector{String}
completion_mode::Symbol
inlay_hints::Bool
inlay_hints_variable_types::Bool
Expand Down Expand Up @@ -85,7 +86,8 @@ mutable struct LanguageServerInstance
true,
StaticLint.LintOptions(),
:all,
LINT_DIABLED_DIRS,
LINT_DISABLED_DIRS,
LINT_IGNORED_GLOBS,
:qualify, # options: :import or :qualify, anything else turns this off
false,
true,
Expand Down
11 changes: 9 additions & 2 deletions src/requests/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,17 @@ end

function load_folder(path::String, server)
if load_rootpath(path)
ignoredGlobs = Regex.(joinpath.(Ref(path), server.lint_ignoredglobs))
try
for (root, _, files) in walkdir(path, onerror=x -> x)
if any(occursin.(ignoredGlobs, Ref(root)))
continue
end
for file in files
filepath = joinpath(root, file)
if any(occursin.(ignoredGlobs, Ref(filepath)))
continue
end
if isvalidjlfile(filepath)
uri = filepath2uri(filepath)
if hasdocument(server, uri)
Expand Down Expand Up @@ -196,6 +203,8 @@ function initialized_notification(params::InitializedParams, server::LanguageSer
)
end

request_julia_config(server, conn)

if server.workspaceFolders !== nothing
server.workspace = JuliaWorkspace(Set(filepath2uri.(server.workspaceFolders)))

Expand All @@ -212,8 +221,6 @@ function initialized_notification(params::InitializedParams, server::LanguageSer
end
end

request_julia_config(server, conn)

if server.number_of_outstanding_symserver_requests > 0
create_symserver_progress_ui(server)
end
Expand Down
11 changes: 8 additions & 3 deletions src/requests/workspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ end
isnothing(::Nothing) = true
end

const LINT_DIABLED_DIRS = ["test", "docs"]
const LINT_DISABLED_DIRS = ["test", "docs"]
const LINT_IGNORED_GLOBS = ["\\..*"]

function request_julia_config(server::LanguageServerInstance, conn)
(ismissing(server.clientCapabilities.workspace) || server.clientCapabilities.workspace.configuration !== true) && return
Expand All @@ -111,29 +112,33 @@ function request_julia_config(server::LanguageServerInstance, conn)
ConfigurationItem(missing, "julia.inlayHints.static.enabled"),
ConfigurationItem(missing, "julia.inlayHints.static.variableTypes.enabled"),
ConfigurationItem(missing, "julia.inlayHints.static.parameterNames.enabled"),
ConfigurationItem(missing, "julia.lint.ignoredGlobs"),
]))

new_runlinter = something(response[11], true)
new_SL_opts = StaticLint.LintOptions(response[1:10]...)

new_lint_missingrefs = Symbol(something(response[12], :all))
new_lint_disableddirs = something(response[13], LINT_DIABLED_DIRS)
new_lint_disableddirs = something(response[13], LINT_DISABLED_DIRS)
new_completion_mode = Symbol(something(response[14], :import))
inlayHints = something(response[15], true)
inlayHintsVariableTypes = something(response[16], true)
inlayHintsParameterNames = Symbol(something(response[17], :literals))
new_lint_ignoredglobs = something(response[18], LINT_IGNORED_GLOBS)

rerun_lint = begin
any(getproperty(server.lint_options, opt) != getproperty(new_SL_opts, opt) for opt in fieldnames(StaticLint.LintOptions)) ||
server.runlinter != new_runlinter ||
server.lint_missingrefs != new_lint_missingrefs ||
server.lint_disableddirs != new_lint_disableddirs
server.lint_disableddirs != new_lint_disableddirs ||
server.lint_ignoredglobs != new_lint_ignoredglobs
end

server.lint_options = new_SL_opts
server.runlinter = new_runlinter
server.lint_missingrefs = new_lint_missingrefs
server.lint_disableddirs = new_lint_disableddirs
server.lint_ignoredglobs = new_lint_ignoredglobs
server.completion_mode = new_completion_mode
server.inlay_hints = inlayHints
server.inlay_hints_variable_types = inlayHintsVariableTypes
Expand Down
33 changes: 33 additions & 0 deletions test/test_juliaworkspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,36 @@ end
jw = delete_file(jw, project_file_uri)
@test !haskey(jw._packages, project_uri)
end

@testitem "load_folder" begin
using LanguageServer: filepath2uri, load_folder, hasdocument

include("test_shared_server.jl")
pkg_root = abspath(joinpath(@__DIR__, ".."))

filepath = "test/test_juliaworkspace.jl"

empty!(server._documents)
load_folder(pkg_root, server)

uri = filepath2uri(joinpath(pkg_root, filepath))
@test hasdocument(server, uri)

server.lint_ignoredglobs = [
"\\..*",
filepath,
]
empty!(server._documents)
load_folder(pkg_root, server)

@test !hasdocument(server, uri)

server.lint_ignoredglobs = [
"\\..*",
"test",
]
empty!(server._documents)
load_folder(pkg_root, server)

@test !hasdocument(server, uri)
end
Loading