From 048d988eb6356a1dde93a0bad5484ac04d4fea76 Mon Sep 17 00:00:00 2001 From: Maarten Pronk Date: Mon, 27 May 2024 13:01:16 +0200 Subject: [PATCH 1/2] Add ignoreDirs option. --- src/languageserverinstance.jl | 4 +++- src/requests/init.jl | 7 +++++-- src/requests/workspace.jl | 11 ++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/languageserverinstance.jl b/src/languageserverinstance.jl index a509cb53..4b0fd918 100644 --- a/src/languageserverinstance.jl +++ b/src/languageserverinstance.jl @@ -42,6 +42,7 @@ mutable struct LanguageServerInstance lint_options::StaticLint.LintOptions lint_missingrefs::Symbol lint_disableddirs::Vector{String} + lint_ignoreddirs::Vector{String} completion_mode::Symbol inlay_hints::Bool inlay_hints_variable_types::Bool @@ -85,7 +86,8 @@ mutable struct LanguageServerInstance true, StaticLint.LintOptions(), :all, - LINT_DIABLED_DIRS, + LINT_DISABLED_DIRS, + LINT_IGNORED_DIRS, :qualify, # options: :import or :qualify, anything else turns this off false, true, diff --git a/src/requests/init.jl b/src/requests/init.jl index eb5580b1..db1491c4 100644 --- a/src/requests/init.jl +++ b/src/requests/init.jl @@ -99,6 +99,9 @@ function load_folder(path::String, server) if load_rootpath(path) try for (root, _, files) in walkdir(path, onerror=x -> x) + if any(occursin.(Regex.(joinpath.(Ref(path), server.lint_ignoreddirs)), Ref(root))) + continue + end for file in files filepath = joinpath(root, file) if isvalidjlfile(filepath) @@ -196,6 +199,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))) @@ -212,8 +217,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 diff --git a/src/requests/workspace.jl b/src/requests/workspace.jl index 2caadcdf..87dcc6e7 100644 --- a/src/requests/workspace.jl +++ b/src/requests/workspace.jl @@ -88,7 +88,8 @@ end isnothing(::Nothing) = true end -const LINT_DIABLED_DIRS = ["test", "docs"] +const LINT_DISABLED_DIRS = ["test", "docs"] +const LINT_IGNORED_DIRS = ["\\..*"] function request_julia_config(server::LanguageServerInstance, conn) (ismissing(server.clientCapabilities.workspace) || server.clientCapabilities.workspace.configuration !== true) && return @@ -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.ignoredDirs"), ])) 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_ignoreddirs = something(response[18], LINT_IGNORED_DIRS) 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_ignoreddirs != new_lint_ignoreddirs 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_ignoreddirs = new_lint_ignoreddirs server.completion_mode = new_completion_mode server.inlay_hints = inlayHints server.inlay_hints_variable_types = inlayHintsVariableTypes From 6bffae8727524bdbe4639ec6088144739ffdae71 Mon Sep 17 00:00:00 2001 From: Maarten Pronk Date: Mon, 27 May 2024 15:38:40 +0200 Subject: [PATCH 2/2] Change to ignoredGlobs. --- src/languageserverinstance.jl | 4 ++-- src/requests/init.jl | 6 +++++- src/requests/workspace.jl | 10 +++++----- test/test_juliaworkspace.jl | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/languageserverinstance.jl b/src/languageserverinstance.jl index 4b0fd918..63babb1a 100644 --- a/src/languageserverinstance.jl +++ b/src/languageserverinstance.jl @@ -42,7 +42,7 @@ mutable struct LanguageServerInstance lint_options::StaticLint.LintOptions lint_missingrefs::Symbol lint_disableddirs::Vector{String} - lint_ignoreddirs::Vector{String} + lint_ignoredglobs::Vector{String} completion_mode::Symbol inlay_hints::Bool inlay_hints_variable_types::Bool @@ -87,7 +87,7 @@ mutable struct LanguageServerInstance StaticLint.LintOptions(), :all, LINT_DISABLED_DIRS, - LINT_IGNORED_DIRS, + LINT_IGNORED_GLOBS, :qualify, # options: :import or :qualify, anything else turns this off false, true, diff --git a/src/requests/init.jl b/src/requests/init.jl index db1491c4..696d939d 100644 --- a/src/requests/init.jl +++ b/src/requests/init.jl @@ -97,13 +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.(Regex.(joinpath.(Ref(path), server.lint_ignoreddirs)), Ref(root))) + 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) diff --git a/src/requests/workspace.jl b/src/requests/workspace.jl index 87dcc6e7..43809422 100644 --- a/src/requests/workspace.jl +++ b/src/requests/workspace.jl @@ -89,7 +89,7 @@ end end const LINT_DISABLED_DIRS = ["test", "docs"] -const LINT_IGNORED_DIRS = ["\\..*"] +const LINT_IGNORED_GLOBS = ["\\..*"] function request_julia_config(server::LanguageServerInstance, conn) (ismissing(server.clientCapabilities.workspace) || server.clientCapabilities.workspace.configuration !== true) && return @@ -112,7 +112,7 @@ 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.ignoredDirs"), + ConfigurationItem(missing, "julia.lint.ignoredGlobs"), ])) new_runlinter = something(response[11], true) @@ -124,21 +124,21 @@ function request_julia_config(server::LanguageServerInstance, conn) inlayHints = something(response[15], true) inlayHintsVariableTypes = something(response[16], true) inlayHintsParameterNames = Symbol(something(response[17], :literals)) - new_lint_ignoreddirs = something(response[18], LINT_IGNORED_DIRS) + 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_ignoreddirs != new_lint_ignoreddirs + 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_ignoreddirs = new_lint_ignoreddirs + server.lint_ignoredglobs = new_lint_ignoredglobs server.completion_mode = new_completion_mode server.inlay_hints = inlayHints server.inlay_hints_variable_types = inlayHintsVariableTypes diff --git a/test/test_juliaworkspace.jl b/test/test_juliaworkspace.jl index 404890cc..906ee09e 100644 --- a/test/test_juliaworkspace.jl +++ b/test/test_juliaworkspace.jl @@ -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