@@ -20,7 +20,7 @@ interface HunkConfigResolution {
2020 input : CliInput ;
2121 globalConfigPath ?: string ;
2222 repoConfigPath ?: string ;
23- persistencePath ?: string ;
23+
2424}
2525
2626function isRecord ( value : unknown ) : value is Record < string , unknown > {
@@ -178,113 +178,8 @@ export function resolveConfiguredCliInput(
178178 } ,
179179 globalConfigPath : userConfigPath ,
180180 repoConfigPath,
181- persistencePath : repoConfigPath ?? userConfigPath ,
182181 } ;
183182}
184183
185- /** Return whether an array contains only TOML table objects. */
186- function isRecordArray ( value : unknown ) : value is Array < Record < string , unknown > > {
187- return Array . isArray ( value ) && value . every ( isRecord ) ;
188- }
189-
190- /** Serialize one inline TOML value, including scalar arrays. */
191- function serializeTomlValue ( value : unknown ) : string | undefined {
192- if ( typeof value === "string" ) {
193- return JSON . stringify ( value ) ;
194- }
195-
196- if ( typeof value === "boolean" || typeof value === "number" ) {
197- return String ( value ) ;
198- }
199-
200- if ( Array . isArray ( value ) && ! isRecordArray ( value ) ) {
201- const serializedItems = value . map ( ( item ) => serializeTomlValue ( item ) ) ;
202- if ( serializedItems . some ( ( item ) => item === undefined ) ) {
203- return undefined ;
204- }
205-
206- return `[${ serializedItems . join ( ", " ) } ]` ;
207- }
208-
209- return undefined ;
210- }
211-
212- /** Render one TOML object recursively while keeping scalar keys above child tables. */
213- function serializeTomlObject ( source : Record < string , unknown > , sectionName ?: string , arrayTable = false ) : string [ ] {
214- const lines : string [ ] = [ ] ;
215- const scalarEntries : Array < [ string , string ] > = [ ] ;
216- const tableEntries : Array < [ string , Record < string , unknown > ] > = [ ] ;
217- const arrayTableEntries : Array < [ string , Array < Record < string , unknown > > ] > = [ ] ;
218-
219- for ( const [ key , value ] of Object . entries ( source ) ) {
220- if ( value === undefined ) {
221- continue ;
222- }
223-
224- if ( isRecord ( value ) ) {
225- tableEntries . push ( [ key , value ] ) ;
226- continue ;
227- }
228-
229- if ( isRecordArray ( value ) ) {
230- arrayTableEntries . push ( [ key , value ] ) ;
231- continue ;
232- }
233-
234- const serialized = serializeTomlValue ( value ) ;
235- if ( serialized !== undefined ) {
236- scalarEntries . push ( [ key , serialized ] ) ;
237- }
238- }
239-
240- if ( sectionName ) {
241- lines . push ( `${ arrayTable ? "[[" : "[" } ${ sectionName } ${ arrayTable ? "]]" : "]" } ` ) ;
242- }
243-
244- for ( const [ key , value ] of scalarEntries ) {
245- lines . push ( `${ key } = ${ value } ` ) ;
246- }
247-
248- for ( const [ key , value ] of tableEntries ) {
249- if ( lines . length > 0 ) {
250- lines . push ( "" ) ;
251- }
252-
253- lines . push ( ...serializeTomlObject ( value , sectionName ? `${ sectionName } .${ key } ` : key ) ) ;
254- }
255-
256- for ( const [ key , values ] of arrayTableEntries ) {
257- for ( const value of values ) {
258- if ( lines . length > 0 ) {
259- lines . push ( "" ) ;
260- }
261-
262- lines . push ( ...serializeTomlObject ( value , sectionName ? `${ sectionName } .${ key } ` : key , true ) ) ;
263- }
264- }
265-
266- return lines ;
267- }
268-
269- /** Persist the current view defaults while preserving any existing profile sections. */
270- export function persistViewPreferences ( path : string , preferences : PersistedViewPreferences ) {
271- const existing = readTomlRecord ( path ) ;
272-
273- existing . mode = preferences . mode ;
274- existing . line_numbers = preferences . showLineNumbers ;
275- existing . wrap_lines = preferences . wrapLines ;
276- existing . hunk_headers = preferences . showHunkHeaders ;
277- existing . agent_notes = preferences . showAgentNotes ;
278-
279- if ( preferences . theme ) {
280- existing . theme = preferences . theme ;
281- } else {
282- delete existing . theme ;
283- }
284-
285- fs . mkdirSync ( dirname ( path ) , { recursive : true } ) ;
286- fs . writeFileSync ( path , `${ serializeTomlObject ( existing ) . join ( "\n" ) . trim ( ) } \n` ) ;
287- }
288-
289184export const CONFIG_DEFAULTS = DEFAULT_VIEW_PREFERENCES ;
290185export const CONFIG_SECTION_KEYS = CONFIG_SECTION_NAMES ;
0 commit comments