From 3f5740fca1e086c56bc4526299884bee6788a0f9 Mon Sep 17 00:00:00 2001 From: Bill Burdick Date: Mon, 28 Apr 2025 12:40:29 +0300 Subject: [PATCH] add useFrmatterConfigDefaults opt: search for .JuliaFormatter.toml --- README.md | 3 +++ src/LanguageServer.jl | 2 ++ src/requests/features.jl | 17 ++++++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 576c840d..a45fd454 100644 --- a/README.md +++ b/README.md @@ -48,3 +48,6 @@ if there is no parent project. ## Development of the VSCode extension See https://github.com/julia-vscode/julia-vscode/wiki for information on how to test this package with the VSCode extension + +## LanguageServer.jl does not normally search upwards for .JuliaFormatter.toml +You can turn this on by setting the initialization option "useFormatterConfigDefaults" to true diff --git a/src/LanguageServer.jl b/src/LanguageServer.jl index d2929a5a..5d6a8010 100644 --- a/src/LanguageServer.jl +++ b/src/LanguageServer.jl @@ -15,6 +15,8 @@ import Dates export LanguageServerInstance, runserver +const INIT_OPT_USE_FORMATTER_CONFIG_DEFAULTS = "useFormatterConfigDefaults" + const g_operationId = Ref{String}("") JSON.lower(uri::URI) = string(uri) diff --git a/src/requests/features.jl b/src/requests/features.jl index fcc87cff..37b8d27b 100644 --- a/src/requests/features.jl +++ b/src/requests/features.jl @@ -130,9 +130,20 @@ function get_juliaformatter_config(doc, server) # search through workspace for a `.JuliaFormatter.toml` workspace_dirs = sort(filter(f -> startswith(path, f), collect(server.workspaceFolders)), by = length, rev = true) - config_path = length(workspace_dirs) > 0 ? - search_file(JuliaFormatter.CONFIG_FILE_NAME, path, workspace_dirs[1]) : - nothing + if ismissing(server.initialization_options) || !get(server.initialization_options, INIT_OPT_USE_FORMATTER_CONFIG_DEFAULTS, false) + config_path = length(workspace_dirs) > 0 ? + search_file(JuliaFormatter.CONFIG_FILE_NAME, path, workspace_dirs[1]) : + nothing + else + @debug "using standard formatter config file locations" + config_path = length(workspace_dirs) > 0 ? + search_file(JuliaFormatter.CONFIG_FILE_NAME, path, "/") : + nothing + if isnothing(config_path) && haskey(ENV, "HOME") + local home = ENV["HOME"] + config_path = search_file(JuliaFormatter.CONFIG_FILE_NAME, home, home) + end + end config_path === nothing && return nothing