feat(server): Improve completions for fsck

This commit is contained in:
Myzel394 2024-11-03 19:12:37 +01:00
parent 387c2f2b61
commit 66f8b36e74
No known key found for this signature in database
GPG Key ID: ED20A1D1D423AF3F
3 changed files with 35 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package analyzer
import (
"config-lsp/common"
"config-lsp/handlers/fstab/ast"
"config-lsp/handlers/fstab/fields"
"fmt"
"strings"
@ -20,7 +21,7 @@ func analyzeFSCKField(ctx *analyzerContext) {
if entry.Fields != nil && entry.Fields.Fsck != nil && entry.Fields.Fsck.Value.Value == "1" {
fileSystem := strings.ToLower(entry.Fields.FilesystemType.Value.Value)
if fileSystem == "btrfs" || fileSystem == "xfs" {
if _, found := fields.FsckOneDisabledFilesystems[fileSystem]; found {
// From https://wiki.archlinux.org/title/Fstab
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{

View File

@ -19,3 +19,22 @@ var FsckField = docvalues.EnumValue{
),
},
}
var FsckFieldWhenDisabledFilesystems = docvalues.EnumValue{
EnforceValues: false,
Values: []docvalues.EnumString{
docvalues.CreateEnumStringWithDoc(
"0",
"Defaults to zero (dont check the filesystem) if not present.",
),
docvalues.CreateEnumStringWithDoc(
"2",
"Other filesystems [than the root filesystem] should have a fs_passno of 2.",
),
},
}
var FsckOneDisabledFilesystems = map[string]struct{}{
"btrfs": {},
"xfs": {},
}

View File

@ -4,7 +4,9 @@ import (
"config-lsp/common"
"config-lsp/handlers/fstab/ast"
"config-lsp/handlers/fstab/fields"
"config-lsp/utils"
"fmt"
"strings"
"github.com/tliron/glsp/protocol_3_16"
)
@ -87,11 +89,19 @@ func GetCompletion(
case ast.FstabFieldFsck:
value, cursor := getFieldSafely(entry.Fields.Fsck, cursor)
if entry.Fields.FilesystemType != nil &&
utils.KeyExists(fields.FsckOneDisabledFilesystems, strings.ToLower(entry.Fields.FilesystemType.Value.Value)) {
return fields.FsckFieldWhenDisabledFilesystems.DeprecatedFetchCompletions(
value,
cursor,
), nil
} else {
return fields.FsckField.DeprecatedFetchCompletions(
value,
cursor,
), nil
}
}
return nil, nil
}