Skip to content
Draft
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
5 changes: 5 additions & 0 deletions src/languageserverinstance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
enable_dynamic_indexing::Bool
max_concurrent_indexing_processes::Int
enable_workspace_environment_resolution::Bool
# Experiment flag: JuliaLowering-backed unused-binding lint rules
# (`julia.experimental.loweringLint`); forwarded to
# `JuliaWorkspaces.set_lowering_lint!`.
lowering_lint::Bool

clientcapability_workspace_diagnostic_refreshsupport::Bool

Expand Down Expand Up @@ -99,7 +103,7 @@

trace_value::Threads.Atomic{Int}

function LanguageServerInstance(@nospecialize(pipe_in), @nospecialize(pipe_out), env_path="", err_handler=nothing, symserver_store_path=nothing, julia_exe::Union{NamedTuple{(:path,:version),Tuple{String,VersionNumber}},Nothing}=nothing)

Check notice on line 106 in src/languageserverinstance.jl

View workflow job for this annotation

GitHub Actions / julia-ci / lint

unused_function_argument

An argument is included in a function signature but not used within its body.
endpoint = JSONRPC.JSONRPCEndpoint(pipe_in, pipe_out)

combined_queue = Channel{Any}(Inf)
Expand Down Expand Up @@ -130,6 +134,7 @@
4,
true,
false,
false,
Dict{URI,Int}(),
Dict{URI,JuliaWorkspaces.TextFile}(),
Set{URI}(),
Expand Down Expand Up @@ -170,7 +175,7 @@
try
if USE_REVISE[] && isdefined(Main, :Revise)
try
Main.Revise.revise()

Check warning on line 178 in src/languageserverinstance.jl

View workflow job for this annotation

GitHub Actions / julia-ci / lint

missing_reference

Missing reference: Revise
catch e
@warn "Reloading with Revise failed" exception = e
end
Expand All @@ -186,7 +191,7 @@
end

function request_wrapper(func, server::LanguageServerInstance)
return function (conn, params, token)

Check notice on line 194 in src/languageserverinstance.jl

View workflow job for this annotation

GitHub Actions / julia-ci / lint

unused_binding

Variable has been assigned but not used.
if server.shutdown_requested
# it's fine to always return a value here, even for notifications, because
# JSONRPC discards it anyways in that case
Expand Down
5 changes: 5 additions & 0 deletions src/requests/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ function initialized_notification(params::InitializedParams, server::LanguageSer
ConfigurationItem(missing, "julia.enableDynamicIndexing"),
ConfigurationItem(missing, "julia.maxConcurrentIndexingProcesses"),
ConfigurationItem(missing, "julia.enableWorkspaceEnvironmentResolution"),
ConfigurationItem(missing, "julia.experimental.loweringLint"),
]))

server.completion_mode = Symbol(something(response[1], :import))
Expand All @@ -243,6 +244,7 @@ function initialized_notification(params::InitializedParams, server::LanguageSer
server.enable_dynamic_indexing = something(response[7], true)
server.max_concurrent_indexing_processes = something(response[8], 4)
server.enable_workspace_environment_resolution = something(response[9], true)
server.lowering_lint = something(response[10], false)
end

# Construct JuliaWorkspace now that configuration values are available.
Expand All @@ -261,6 +263,9 @@ function initialized_notification(params::InitializedParams, server::LanguageSer
max_concurrent_djps=server.max_concurrent_indexing_processes,
resolve_workspace_environments=server.enable_workspace_environment_resolution,
)
# Apply the experiment flag from the initial configuration pull (the JW
# default is off, so only an explicit opt-in needs forwarding).
server.lowering_lint && JuliaWorkspaces.set_lowering_lint!(server.workspace, true)

# A single "bootstrap" bar covers the synchronous load below, which is
# otherwise silent (the first indexing bar only appears once add_files!
Expand Down
28 changes: 27 additions & 1 deletion src/requests/workspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ function request_julia_config(server::LanguageServerInstance, conn)
ConfigurationItem(missing, "julia.enableDynamicIndexing"),
ConfigurationItem(missing, "julia.maxConcurrentIndexingProcesses"),
ConfigurationItem(missing, "julia.enableWorkspaceEnvironmentResolution"),
ConfigurationItem(missing, "julia.experimental.loweringLint"),
]))

new_completion_mode = Symbol(something(response[1], :import))
Expand All @@ -129,12 +130,37 @@ function request_julia_config(server::LanguageServerInstance, conn)
server.inlay_hints_variable_types = inlayHintsVariableTypes
server.inlay_hints_parameter_names = inlayHintsParameterNames

# Store new settings on server; JW is not reconfigured at runtime (future work).
# Store new settings on server; JW is not reconfigured at runtime (future
# work), with the exception of the lowering-lint experiment flag below.
server.symbolcache_download = something(response[5], false)
server.symbolcache_upstream = something(response[6], JuliaWorkspaces.DEFAULT_SYMBOLCACHE_UPSTREAM)
server.enable_dynamic_indexing = something(response[7], true)
server.max_concurrent_indexing_processes = something(response[8], 4)
server.enable_workspace_environment_resolution = something(response[9], true)

set_lowering_lint!(server, something(response[10], false))
end

"""
set_lowering_lint!(server::LanguageServerInstance, enabled::Bool)

Apply the `julia.experimental.loweringLint` setting: forward it to the
workspace (switching the unused-binding lint rules between the StaticLint and
JuliaLowering engines) and republish diagnostics so the change is visible
without further edits.
"""
function set_lowering_lint!(server::LanguageServerInstance, enabled::Bool)
server.lowering_lint == enabled && return
server.lowering_lint = enabled
server.workspace === nothing && return

JuliaWorkspaces.set_lowering_lint!(server.workspace, enabled)

# Push-mode clients get a diffed sweep; pull-mode clients a refresh request.
schedule_publish_sweep!(server)
if server.clientcapability_workspace_diagnostic_refreshsupport
JSONRPC.send(server.jr_endpoint, workspace_diagnosticRefresh_request_type, nothing)
end
end

function gc_files_from_workspace(server::LanguageServerInstance)
Expand Down
27 changes: 27 additions & 0 deletions test/test_lowering_lint_config.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@testitem "julia.experimental.loweringLint switches the lint engine" setup=[TestSetup, SharedServer] begin
using LanguageServer: set_lowering_lint!
import JuliaWorkspaces

settestdoc("function f(x)\n unused_local = 1\n return x\nend\n")

unused_from_lowering() = any(
d -> d.code === :unused_binding && d.source == "JuliaWorkspaces.jl",
JuliaWorkspaces.get_diagnostic(server.workspace, uri"untitled:testdoc"))

# Off by default: nothing from the lowering producer.
@test server.lowering_lint == false
@test !unused_from_lowering()

set_lowering_lint!(server, true)
@test server.lowering_lint == true
@test unused_from_lowering()

# Idempotent and reversible.
set_lowering_lint!(server, true)
@test unused_from_lowering()
set_lowering_lint!(server, false)
@test server.lowering_lint == false
@test !unused_from_lowering()

closetestdoc()
end
Loading