@@ -10,6 +10,7 @@ import (
1010
1111 "github.com/tailscale/hujson"
1212 "github.com/xinnjie/onekeymap-cli/internal/diff"
13+ "github.com/xinnjie/onekeymap-cli/internal/export"
1314 "github.com/xinnjie/onekeymap-cli/internal/keymap"
1415 "github.com/xinnjie/onekeymap-cli/internal/mappings"
1516 "github.com/xinnjie/onekeymap-cli/pkg/pluginapi"
@@ -83,29 +84,18 @@ func (e *vscodeExporter) Export(
8384 opts pluginapi.PluginExportOption ,
8485) (* pluginapi.PluginExportReport , error ) {
8586 // Decode existing config for non-destructive merge
86- var existingKeybindings []vscodeKeybinding
87- if opts .ExistingConfig != nil {
88- // Read all content first to apply hujson.Standardize
89- rawData , err := io .ReadAll (opts .ExistingConfig )
90- if err != nil {
91- return nil , fmt .Errorf ("failed to read existing config: %w" , err )
92- }
93- // Strip comments and trailing commas using hujson
94- standardizedData , err := hujson .Standardize (rawData )
95- if err != nil {
96- return nil , fmt .Errorf ("failed to standardize JSON: %w" , err )
97- }
98- if err := json .Unmarshal (standardizedData , & existingKeybindings ); err != nil {
99- return nil , fmt .Errorf ("failed to decode existing config: %w" , err )
100- }
87+ existingKeybindings , err := e .parseExistingConfig (opts .ExistingConfig )
88+ if err != nil {
89+ return nil , err
10190 }
10291
10392 var unmanagedKeybindings []vscodeKeybinding
10493 if len (existingKeybindings ) > 0 {
10594 unmanagedKeybindings = e .identifyUnmanagedKeybindings (existingKeybindings )
10695 }
10796
108- managedKeybindings := e .generateManagedKeybindings (setting )
97+ marker := export .NewMarker (setting )
98+ managedKeybindings := e .generateManagedKeybindings (setting , marker )
10999
110100 finalKeybindings := e .mergeKeybindings (managedKeybindings , unmanagedKeybindings )
111101
@@ -124,9 +114,36 @@ func (e *vscodeExporter) Export(
124114 return & pluginapi.PluginExportReport {
125115 BaseEditorConfig : existingKeybindings ,
126116 ExportEditorConfig : finalKeybindings ,
117+ SkipReport : marker .Report (),
127118 }, nil
128119}
129120
121+ func (e * vscodeExporter ) parseExistingConfig (reader io.Reader ) ([]vscodeKeybinding , error ) {
122+ var existingKeybindings []vscodeKeybinding
123+ if reader == nil {
124+ return existingKeybindings , nil
125+ }
126+
127+ // Read all content first to apply hujson.Standardize
128+ rawData , err := io .ReadAll (reader )
129+ if err != nil {
130+ return nil , fmt .Errorf ("failed to read existing config: %w" , err )
131+ }
132+
133+ if len (rawData ) > 0 {
134+ // Strip comments and trailing commas using hujson
135+ standardizedData , err := hujson .Standardize (rawData )
136+ if err != nil {
137+ return nil , fmt .Errorf ("failed to standardize JSON: %w" , err )
138+ }
139+ if err := json .Unmarshal (standardizedData , & existingKeybindings ); err != nil {
140+ return nil , fmt .Errorf ("failed to decode existing config: %w" , err )
141+ }
142+ }
143+
144+ return existingKeybindings , nil
145+ }
146+
130147// identifyUnmanagedKeybindings performs reverse lookup to identify keybindings
131148// that are not managed by onekeymap.
132149func (e * vscodeExporter ) identifyUnmanagedKeybindings (existingKeybindings []vscodeKeybinding ) []vscodeKeybinding {
@@ -160,17 +177,30 @@ func (e *vscodeExporter) findMappingByVSCodeKeybinding(kb vscodeKeybinding) *map
160177}
161178
162179// generateManagedKeybindings generates VSCode keybindings from KeymapSetting.
163- func (e * vscodeExporter ) generateManagedKeybindings (setting * keymapv1.Keymap ) []vscodeKeybinding {
180+ func (e * vscodeExporter ) generateManagedKeybindings (
181+ setting * keymapv1.Keymap ,
182+ marker * export.Marker ,
183+ ) []vscodeKeybinding {
164184 var vscodeKeybindings []vscodeKeybinding
165185
166186 for _ , km := range setting .GetActions () {
167187 mapping := e .mappingConfig .Get (km .GetName ())
168188 if mapping == nil {
189+ for _ , b := range km .GetBindings () {
190+ if b != nil && b .GetKeyChords () != nil {
191+ marker .MarkSkippedForReason (km .GetName (), b .GetKeyChords (), pluginapi .ErrActionNotSupported )
192+ }
193+ }
169194 continue
170195 }
171196
172197 vscodeConfigs := mapping .VSCode
173198 if len (vscodeConfigs ) == 0 {
199+ for _ , b := range km .GetBindings () {
200+ if b != nil && b .GetKeyChords () != nil {
201+ marker .MarkSkippedForReason (km .GetName (), b .GetKeyChords (), pluginapi .ErrActionNotSupported )
202+ }
203+ }
174204 continue
175205 }
176206
@@ -182,8 +212,14 @@ func (e *vscodeExporter) generateManagedKeybindings(setting *keymapv1.Keymap) []
182212 keys , err := FormatKeybinding (binding )
183213 if err != nil {
184214 e .logger .Warn ("Skipping keybinding with un-formattable key" , "action" , km .GetName (), "error" , err )
215+ marker .MarkSkippedForReason (
216+ km .GetName (),
217+ b .GetKeyChords (),
218+ & pluginapi.NotSupportedError {Note : err .Error ()},
219+ )
185220 continue
186221 }
222+ marker .MarkExported (km .GetName (), b .GetKeyChords ())
187223 for _ , vscodeConfig := range vscodeConfigs {
188224 if vscodeConfig .Command == "" {
189225 continue
0 commit comments