|
| 1 | +package intellij |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "log/slog" |
| 6 | + |
| 7 | + "github.com/xinnjie/onekeymap-cli/internal/mappings" |
| 8 | + "github.com/xinnjie/onekeymap-cli/pkg/pluginapi" |
| 9 | +) |
| 10 | + |
| 11 | +type intellijVariantPlugin struct { |
| 12 | + *intellijPlugin |
| 13 | + |
| 14 | + editorType pluginapi.EditorType |
| 15 | +} |
| 16 | + |
| 17 | +func newIntellijVariantPlugin( |
| 18 | + editorType pluginapi.EditorType, |
| 19 | + mappingConfig *mappings.MappingConfig, |
| 20 | + logger *slog.Logger, |
| 21 | +) pluginapi.Plugin { |
| 22 | + return &intellijVariantPlugin{ |
| 23 | + intellijPlugin: newIntellijPlugin(mappingConfig, logger), |
| 24 | + editorType: editorType, |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +// EditorType implements pluginapi.Plugin. |
| 29 | +func (p *intellijVariantPlugin) EditorType() pluginapi.EditorType { |
| 30 | + return p.editorType |
| 31 | +} |
| 32 | + |
| 33 | +// Importer implements pluginapi.Plugin. |
| 34 | +func (p *intellijVariantPlugin) Importer() (pluginapi.PluginImporter, error) { |
| 35 | + return p.intellijPlugin.Importer() |
| 36 | +} |
| 37 | + |
| 38 | +// Exporter implements pluginapi.Plugin. |
| 39 | +func (p *intellijVariantPlugin) Exporter() (pluginapi.PluginExporter, error) { |
| 40 | + return p.intellijPlugin.Exporter() |
| 41 | +} |
| 42 | + |
| 43 | +// ConfigDetect implements pluginapi.Plugin. |
| 44 | +func (p *intellijVariantPlugin) ConfigDetect( |
| 45 | + opts pluginapi.ConfigDetectOptions, |
| 46 | +) (paths []string, installed bool, err error) { |
| 47 | + switch p.editorType { |
| 48 | + case pluginapi.EditorTypePyCharm: |
| 49 | + return detectConfigForIDE("PyCharm", "PyCharm*", "pycharm", opts) |
| 50 | + case pluginapi.EditorTypeIntelliJCommunity: |
| 51 | + return detectConfigForIDE("IntelliJ IDEA Community", "IdeaIC*", "idea1", opts) |
| 52 | + case pluginapi.EditorTypeWebStorm: |
| 53 | + return detectConfigForIDE("WebStorm", "WebStorm*", "webstorm", opts) |
| 54 | + case pluginapi.EditorTypeClion: |
| 55 | + return detectConfigForIDE("CLion", "CLion*", "clion", opts) |
| 56 | + case pluginapi.EditorTypePhpStorm: |
| 57 | + return detectConfigForIDE("PhpStorm", "PhpStorm*", "phpstorm", opts) |
| 58 | + case pluginapi.EditorTypeRubyMine: |
| 59 | + return detectConfigForIDE("RubyMine", "RubyMine*", "rubymine", opts) |
| 60 | + case pluginapi.EditorTypeGoLand: |
| 61 | + return detectConfigForIDE("GoLand", "GoLand*", "goland", opts) |
| 62 | + case pluginapi.EditorTypeIntelliJ: |
| 63 | + return detectConfigForIDE("IntelliJ IDEA", "IntelliJIdea*", "idea", opts) |
| 64 | + default: |
| 65 | + return nil, false, fmt.Errorf("unknown editor type: %s", p.editorType) |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +// NewPycharm creates a PyCharm plugin instance. |
| 70 | +func NewPycharm(mappingConfig *mappings.MappingConfig, logger *slog.Logger) pluginapi.Plugin { |
| 71 | + return newIntellijVariantPlugin(pluginapi.EditorTypePyCharm, mappingConfig, logger) |
| 72 | +} |
| 73 | + |
| 74 | +// NewIntelliJCommunity creates an IntelliJ Community plugin instance. |
| 75 | +func NewIntelliJCommunity(mappingConfig *mappings.MappingConfig, logger *slog.Logger) pluginapi.Plugin { |
| 76 | + return newIntellijVariantPlugin(pluginapi.EditorTypeIntelliJCommunity, mappingConfig, logger) |
| 77 | +} |
| 78 | + |
| 79 | +// NewWebStorm creates a WebStorm plugin instance. |
| 80 | +func NewWebStorm(mappingConfig *mappings.MappingConfig, logger *slog.Logger) pluginapi.Plugin { |
| 81 | + return newIntellijVariantPlugin(pluginapi.EditorTypeWebStorm, mappingConfig, logger) |
| 82 | +} |
| 83 | + |
| 84 | +// NewClion creates a CLion plugin instance. |
| 85 | +func NewClion(mappingConfig *mappings.MappingConfig, logger *slog.Logger) pluginapi.Plugin { |
| 86 | + return newIntellijVariantPlugin(pluginapi.EditorTypeClion, mappingConfig, logger) |
| 87 | +} |
| 88 | + |
| 89 | +// NewPhpStorm creates a PhpStorm plugin instance. |
| 90 | +func NewPhpStorm(mappingConfig *mappings.MappingConfig, logger *slog.Logger) pluginapi.Plugin { |
| 91 | + return newIntellijVariantPlugin(pluginapi.EditorTypePhpStorm, mappingConfig, logger) |
| 92 | +} |
| 93 | + |
| 94 | +// NewRubyMine creates a RubyMine plugin instance. |
| 95 | +func NewRubyMine(mappingConfig *mappings.MappingConfig, logger *slog.Logger) pluginapi.Plugin { |
| 96 | + return newIntellijVariantPlugin(pluginapi.EditorTypeRubyMine, mappingConfig, logger) |
| 97 | +} |
| 98 | + |
| 99 | +// NewGoLand creates a GoLand plugin instance. |
| 100 | +func NewGoLand(mappingConfig *mappings.MappingConfig, logger *slog.Logger) pluginapi.Plugin { |
| 101 | + return newIntellijVariantPlugin(pluginapi.EditorTypeGoLand, mappingConfig, logger) |
| 102 | +} |
0 commit comments