Skip to content
Closed
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
28 changes: 22 additions & 6 deletions src/Fantomas/EditorConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,30 @@

let editorConfigParser = EditorConfigParser(EditorConfigFileCache.GetOrCreate)

// Cache parsed configurations by directory to avoid N+1 parsing
// Uses System.IO.Path.GetDirectoryName to group files by directory
let private configCache =
System.Collections.Concurrent.ConcurrentDictionary<string, FormatConfig option>()

let tryReadConfiguration (fsharpFile: string) : FormatConfig option =
let editorConfigSettings: FileConfiguration =
editorConfigParser.Parse(fileName = fsharpFile)
// Cache key: directory path (files in same directory share same .editorconfig)
let directory = System.IO.Path.GetDirectoryName fsharpFile

configCache.GetOrAdd(
directory,
fun _ ->
let editorConfigSettings: FileConfiguration =
editorConfigParser.Parse(fileName = fsharpFile)

if editorConfigSettings.Properties.Count = 0 then
None
else
Some(parseOptionsFromEditorConfig FormatConfig.Default editorConfigSettings.Properties)
if editorConfigSettings.Properties.Count = 0 then
None
else
Some(parseOptionsFromEditorConfig FormatConfig.Default editorConfigSettings.Properties)
)

let readConfiguration (fsharpFile: string) : FormatConfig =
tryReadConfiguration fsharpFile |> Option.defaultValue FormatConfig.Default

// Utility to clear cache if needed (e.g., when .editorconfig changes)
// However typically fantomas is not too-long running process.
let clearConfigurationCache () = configCache.Clear()

Check failure on line 145 in src/Fantomas/EditorConfig.fs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

The value 'clearConfigurationCache' is unused

Check failure on line 145 in src/Fantomas/EditorConfig.fs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

The value 'clearConfigurationCache' is unused

Check failure on line 145 in src/Fantomas/EditorConfig.fs

View workflow job for this annotation

GitHub Actions / build (macOS-latest)

The value 'clearConfigurationCache' is unused

Check failure on line 145 in src/Fantomas/EditorConfig.fs

View workflow job for this annotation

GitHub Actions / build (macOS-latest)

The value 'clearConfigurationCache' is unused

Check failure on line 145 in src/Fantomas/EditorConfig.fs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The value 'clearConfigurationCache' is unused

Check failure on line 145 in src/Fantomas/EditorConfig.fs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The value 'clearConfigurationCache' is unused
Loading