Skip to content

Commit 31b90b4

Browse files
committed
docs: add comments for configuration handling and conflict resolution in importer and exporter
1 parent f26f221 commit 31b90b4

4 files changed

Lines changed: 43 additions & 4 deletions

File tree

internal/plugins/vscode/export.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ func newExporterWithEditorType(
8888
}
8989
}
9090

91+
// Export (GenerateEditorConfig) generates VSCode keybindings from the keymap setting.
92+
//
93+
// Handling Existing Configurations:
94+
// It reads the existing VSCode configuration (if provided via opts.ExistingConfig) to identify
95+
// "unmanaged" keybindings—those not maintained by OneKeymap. These are preserved to support
96+
// a non-destructive export/update process.
97+
//
98+
// Conflict Resolution:
99+
// - Managed keybindings (generated from KeymapSetting) take precedence over conflicting
100+
// unmanaged keybindings from the existing configuration.
101+
// - If a keybinding in the existing configuration uses the same key combination as a
102+
// managed one, the managed one overwrites it.
103+
// - The final list is re-ordered to respect the command order of the existing configuration,
104+
// preserving the user's preferred organization where possible.
91105
func (e *vscodeLikeExporter) Export(
92106
_ context.Context,
93107
destination io.Writer,

internal/plugins/vscode/import.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,14 @@ func newImporterWithEditorType(
4545
}
4646
}
4747

48-
// Import reads a VSCode keybindings.json file and converts it to a universal KeymapSetting.
48+
// Import (AnalyzeEditorConfig) reads a VSCode keybindings.json file and converts it to a universal KeymapSetting.
49+
//
50+
// Handling Existing Configurations:
51+
// It parses the VSCode JSON configuration from the source, handling comments and trailing commas.
52+
//
53+
// Conflict Resolution:
54+
// - Unknown commands or unparsable keys are skipped and tracked in the validation report.
55+
// - Duplicate actions resulting from the import are deduplicated to ensure a clean result.
4956
func (i *vscodeLikeImporter) Import(
5057
ctx context.Context,
5158
source io.Reader,

pkg/api/exporterapi/exporter.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ import (
1313
// into an editor-specific format.
1414
type Exporter interface {
1515
// Export converts a KeymapSetting and writes it to a destination stream.
16-
// It returns a report detailing any issues encountered during the conversion.
16+
//
17+
// Handling Existing Configurations:
18+
// It reads existing configuration from the input stream (if provided via opts.OriginalConfig)
19+
// to identify user-defined or unmanaged keybindings that should be preserved.
20+
//
21+
// Conflict Resolution:
22+
// - Managed keybindings (generated from KeymapSetting) take precedence over conflicting
23+
// unmanaged keybindings from the existing configuration.
24+
// - The final output attempts to respect the structure or order of the existing configuration
25+
// where applicable.
26+
// - A report is returned detailing the changes (diff) and any issues encountered.
1727
Export(
1828
ctx context.Context,
1929
destination io.Writer,

pkg/api/importerapi/importer.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ import (
1212
// Importer defines the interface for the import service, which handles the
1313
// conversion of editor-specific keymaps into the universal format.
1414
type Importer interface {
15-
// Import converts keymaps from a source stream. It returns the converted
16-
// settings and a report detailing any conflicts or unmapped actions.
15+
// Import (corresponding to AnalyzeEditorConfig logic) converts keymaps from a source stream.
16+
//
17+
// Handling Existing Configurations:
18+
// It reads configuration from the input stream (e.g., editor specific config like keybindings.json)
19+
// and analyzes it to map keybindings to the universal format.
20+
//
21+
// Conflict Resolution:
22+
// - Conflicts during conversion (e.g., multiple keybindings mapping to the same action)
23+
// are resolved by the implementation, typically by deduplicating actions.
24+
// - Any unmapped actions or ambiguities are reported in the ImportResult.
1725
Import(ctx context.Context, opts ImportOptions) (*ImportResult, error)
1826
}
1927

0 commit comments

Comments
 (0)