-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathsettings.js
More file actions
145 lines (112 loc) · 3.78 KB
/
settings.js
File metadata and controls
145 lines (112 loc) · 3.78 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const vscode = require('vscode')
const scope = 'keyword.other.dotenv'
// WARNING. Do not change these without also adjusting package.json
const enableAutocloakingKey = 'dotenv.enableAutocloaking'
const cloakColorKey = 'dotenv.cloakColor'
const cloakIconKey = 'dotenv.cloakIcon'
const enableSecretpeekingKey = 'dotenv.enableSecretpeeking'
const enableMonorepoSupportKey = 'dotenv.enableMonorepoSupport'
// other settings from vscode or other extensions
const editorTokenColorCustomizationsKey = 'editor.tokenColorCustomizations'
// actions
async function populateFileAssociations () {
const fileAssociationsKeys = 'files.associations'
const existingFileAssociations = userConfig().get(fileAssociationsKeys) || {}
existingFileAssociations['.env*'] = 'dotenv'
await userConfig().update(fileAssociationsKeys, existingFileAssociations, vscode.ConfigurationTarget.Global)
return true
}
async function autocloakingOff () {
await userConfig().update(enableAutocloakingKey, false, vscode.ConfigurationTarget.Global)
return false
}
async function mask () {
const value = _editorTokenColorCustomizations() || {}
value.textMateRules = _textMateRules(true)
await userConfig().update(editorTokenColorCustomizationsKey, value, vscode.ConfigurationTarget.Global)
return true
}
async function unmask () {
const value = _editorTokenColorCustomizations() || {}
value.textMateRules = _textMateRules(false)
await userConfig().update(editorTokenColorCustomizationsKey, value, vscode.ConfigurationTarget.Global)
return false
}
async function autocloakingOn () {
await userConfig().update(enableAutocloakingKey, true, vscode.ConfigurationTarget.Global)
return true
}
function userConfig () {
return vscode.workspace.getConfiguration()
}
// settings
function autocloakingEnabled () {
return !!userConfig().get(enableAutocloakingKey)
}
function secretpeekingEnabled () {
return !!userConfig().get(enableSecretpeekingKey)
}
function cloakColor () {
return userConfig().get(cloakColorKey)
}
function cloakIcon () {
return userConfig().get(cloakIconKey)
}
function monorepoSupportEnabled () {
const value = userConfig().get(enableMonorepoSupportKey)
// Default to true if not explicitly set
return value === undefined ? true : !!value
}
// other settings
function _editorTokenColorCustomizations () {
return userConfig().get(editorTokenColorCustomizationsKey)
}
function _existingTextMateRules () {
const tokenColorCustomizations = _editorTokenColorCustomizations()
if (tokenColorCustomizations) {
if (tokenColorCustomizations.textMateRules) {
return tokenColorCustomizations.textMateRules
} else {
return []
}
} else {
return []
}
}
function _textMateRules (enableMask) {
const rules = _existingTextMateRules()
const newRules = []
for (const rule of rules) {
if (rule.scope === scope) {
// removes the hide rule. re-set in next few lines.
} else {
newRules.push(rule) // preserve any other rules
}
}
if (enableMask) {
const maskRule = {
scope,
settings: { foreground: '#FF000000' } // set transparency to 0
}
newRules.push(maskRule) // add new rule
}
return newRules
}
function missingText () {
return 'MISSING from .env file'
}
module.exports.userConfig = userConfig
// actions
module.exports.autocloakingOff = autocloakingOff
module.exports.autocloakingOn = autocloakingOn
module.exports.mask = mask
module.exports.unmask = unmask
module.exports.populateFileAssociations = populateFileAssociations
// settings
module.exports.autocloakingEnabled = autocloakingEnabled
module.exports.secretpeekingEnabled = secretpeekingEnabled
module.exports.cloakColor = cloakColor
module.exports.cloakIcon = cloakIcon
module.exports.monorepoSupportEnabled = monorepoSupportEnabled
// other
module.exports.missingText = missingText