Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions internal/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,19 @@ func validateParsedSettings() error {
}
}
} else {
if _, e := glob.Compile(k); e != nil {
err = errors.New("Error with glob setting " + k + ": " + e.Error())
tk := strings.TrimPrefix(k, "glob:")
if _, e := glob.Compile(tk); e != nil {
err = errors.New("Error with glob setting " + tk + ": " + e.Error())
delete(parsedSettings, k)
continue
}
if !strings.HasPrefix(k, "glob:") {
// Support non-prefixed glob settings but internally convert
// them to prefixed ones for simplicity.
delete(parsedSettings, k)
k = "glob:" + k
parsedSettings[k] = v
}
for k1, v1 := range v.(map[string]any) {
if _, ok := defaults[k1]; ok {
if e := verifySetting(k1, v1, defaults[k1]); e != nil {
Expand Down Expand Up @@ -256,6 +264,9 @@ func ReadSettings() error {
func ParsedSettings() map[string]any {
s := make(map[string]any)
for k, v := range parsedSettings {
if strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
continue
}
s[k] = v
}
return s
Expand Down Expand Up @@ -309,8 +320,9 @@ func InitGlobalSettings() error {
// Must be called after ReadSettings
func UpdatePathGlobLocals(settings map[string]any, path string) {
for k, v := range parsedSettings {
if strings.HasPrefix(reflect.TypeOf(v).String(), "map") && !strings.HasPrefix(k, "ft:") {
g, _ := glob.Compile(k)
if strings.HasPrefix(reflect.TypeOf(v).String(), "map") && strings.HasPrefix(k, "glob:") {
tk := strings.TrimPrefix(k, "glob:")
g, _ := glob.Compile(tk)
if g.MatchString(path) {
for k1, v1 := range v.(map[string]any) {
settings[k1] = v1
Expand Down
18 changes: 18 additions & 0 deletions runtime/help/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,21 @@ all files except Go files, and `tabsize` 4 for all files except Ruby files:

Or similarly you can match with globs:

```json
{
"glob:*.go": {
"tabstospaces": false
},
"glob:*.rb": {
"tabsize": 2
},
"tabstospaces": true,
"tabsize": 4
}
```

You can also omit the `glob:` prefix before globs:

```json
{
"*.go": {
Expand All @@ -681,3 +696,6 @@ Or similarly you can match with globs:
"tabsize": 4
}
```

But it is generally more recommended to use the `glob:` prefix, as it avoids
potential conflicts with option names.
Loading