-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimdriver.go
More file actions
77 lines (64 loc) · 1.79 KB
/
vimdriver.go
File metadata and controls
77 lines (64 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"runtime"
"github.com/slzatz/vimango/vim"
)
// VimDriver represents the available Vim implementation options
type VimDriver int
const (
VimDriverGo VimDriver = iota // Pure Go implementation
VimDriverCGO // CGO implementation (libvim)
)
// VimConfig holds the configuration for Vim implementation selection
type VimConfig struct {
Driver VimDriver
}
// GetVimDriverDisplayName returns a human-readable name for the driver
func (cfg *VimConfig) GetVimDriverDisplayName() string {
switch cfg.Driver {
case VimDriverCGO:
return "libvim (CGO)"
case VimDriverGo:
return "govim (Pure Go)"
default:
return "govim (Pure Go)"
}
}
// DetermineVimDriver determines which Vim implementation to use based on:
// 1. Command line arguments
// 2. Platform constraints (Windows only supports pure Go)
// 3. Build constraints (CGO availability)
func DetermineVimDriver(args []string) *VimConfig {
cfg := &VimConfig{
Driver: VimDriverCGO, // Default to CGO if available
}
// On Windows, force pure Go implementation
if runtime.GOOS == "windows" {
cfg.Driver = VimDriverGo
return cfg
}
// If CGO vim is not available, force pure Go
if !vim.IsCGOAvailable() {
cfg.Driver = VimDriverGo
return cfg
}
// Check for --go-vim flag (forces pure Go)
for _, arg := range args {
if arg == "--go-vim" {
cfg.Driver = VimDriverGo
return cfg
}
}
// Default behavior: use CGO implementation if available
return cfg
}
// ShouldUseGoVim returns true if the Go vim implementation should be used
func (cfg *VimConfig) ShouldUseGoVim() bool {
return cfg.Driver == VimDriverGo
}
// LogVimDriverChoice logs which Vim implementation is being used
/*
func LogVimDriverChoice(cfg *VimConfig) {
fmt.Printf("Using Vim implementation: %s\n", cfg.GetVimDriverDisplayName())
}
*/