/
config.vim
101 lines (88 loc) · 2.9 KB
/
config.vim
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
let s:config = {}
let s:func=0
function! govim#config#Set(key,value)
if a:key == "_internal_Func"
let s:func=a:value
else
if !has_key(s:validators, a:key)
throw "Tried to set config for invalid key ".a:key
endif
let Func = s:validators[a:key]
let validRes = call(Func, [a:value])
if !validRes[0]
throw "Tried to set invalid value for key ".a:key.": ".validRes[1]
endif
let s:config[a:key] = a:value
endif
call s:pushConfig()
endfunction
function! govim#config#Unset(key)
let s:config = remove(s:config, a:key)
call s:pushConfig()
endfunction
function! govim#config#Get()
return copy(s:config)
endfunction
function! s:pushConfig()
if s:func != 0
let Func = s:func
call call(Func, [s:config])
endif
endfunction
function! s:validFormatOnSave(v)
let valid = ["", "gofmt", "goimports"]
if index(valid, a:v) < 0
return [v:false, "must be one of: ".string(valid)]
endif
return [v:true, ""]
endfunction
function! s:validQuickfixAutoDiagnosticsDisable(v)
if type(a:v) != 0 && type(a:v) != 6
return [v:false, "must be of type number or bool"
endif
return [v:true, ""]
endfunction
function! s:validQuickfixSignsDisable(v)
if type(a:v) != 0 && type(a:v) != 6
return [v:false, "must be of type number or bool"
endif
return [v:true, ""]
endfunction
function! s:validExperimentalMouseTriggeredHoverPopupOptions(v)
if has_key(a:v, "line")
if type(a:v["line"]) != 0
return [v:false, "line option must be of type number"]
endif
endif
if has_key(a:v, "col")
if type(a:v["col"]) != 0
return [v:false, "col option must be of type number"]
endif
endif
return [v:true, ""]
endfunction
function! s:validExperimentalCursorTriggeredHoverPopupOptions(v)
return s:validExperimentalMouseTriggeredHoverPopupOptions(a:v)
endfunction
function! s:validCompletionDeepCompletionsDisable(v)
if type(a:v) != 0 && type(a:v) != 6
return [v:false, "must be of type number or bool"
endif
return [v:true, ""]
endfunction
function! s:validCompletionFuzzyMatchingDisable(v)
if type(a:v) != 0 && type(a:v) != 6
return [v:false, "must be of type number or bool"
endif
return [v:true, ""]
endfunction
let s:validators = {
\ "FormatOnSave": function("s:validFormatOnSave"),
\ "QuickfixAutoDiagnosticsDisable": function("s:validQuickfixAutoDiagnosticsDisable"),
\ "CompletionDeepCompletionsDisable": function("s:validCompletionDeepCompletionsDisable"),
\ "CompletionFuzzyMatchingDisable": function("s:validCompletionFuzzyMatchingDisable"),
\ "QuickfixSignsDisable": function("s:validQuickfixSignsDisable"),
\ "ExperimentalMouseTriggeredHoverPopupOptions": function("s:validExperimentalMouseTriggeredHoverPopupOptions"),
\ "ExperimentalCursorTriggeredHoverPopupOptions": function("s:validExperimentalCursorTriggeredHoverPopupOptions"),
\ }
call govim#config#Set("FormatOnSave", "goimports")