fix(server): Overall improvements

This commit is contained in:
Myzel394 2024-10-09 11:05:18 +02:00
parent 2b04182a14
commit 30c68e0d99
No known key found for this signature in database
GPG Key ID: ED20A1D1D423AF3F
6 changed files with 50 additions and 84 deletions

View File

@ -132,7 +132,6 @@ func (v ArrayValue) getCurrentValue(line string, cursor uint32) (string, uint32)
// hello,worl[d]
// hello,world[,]
// hello[,]world,how,are,you
relativePosition, found := utils.FindPreviousCharacter(
line,
v.Separator,

View File

@ -170,13 +170,14 @@ func (v KeyEnumAssignmentValue) DeprecatedFetchCompletions(line string, cursor u
return v.FetchEnumCompletions()
}
relativePosition, found := utils.FindPreviousCharacter(
foundPosition, found := utils.FindPreviousCharacter(
line,
v.Separator,
int(cursor),
)
if found {
relativePosition := max(1, foundPosition) - 1
selectedKey := line[:uint32(relativePosition)]
line = line[uint32(relativePosition+len(v.Separator)):]
cursor -= uint32(relativePosition)

View File

@ -108,13 +108,14 @@ func (v KeyValueAssignmentValue) DeprecatedFetchCompletions(line string, cursor
return v.Key.DeprecatedFetchCompletions(line, cursor)
}
relativePosition, found := utils.FindPreviousCharacter(
foundPosition, found := utils.FindPreviousCharacter(
line,
v.Separator,
int(cursor),
)
if found {
relativePosition := max(1, foundPosition) - 1
selectedKey := line[:uint32(relativePosition)]
line = line[uint32(relativePosition+len(v.Separator)):]
cursor -= uint32(relativePosition)

View File

@ -88,42 +88,18 @@ func (c *FstabConfig) parseStatement(
fallthrough
case 5:
freq = parseField(line, input, fields[4])
if pass == nil && fields[4][1] < len(input) {
pass = createPartialField(line, input, fields[4][1], len(input))
}
fallthrough
case 4:
options = parseField(line, input, fields[3])
if freq == nil && fields[3][1] < len(input) {
freq = createPartialField(line, input, fields[3][1], len(input))
}
fallthrough
case 3:
filesystemType = parseField(line, input, fields[2])
if options == nil && fields[2][1] < len(input) {
options = createPartialField(line, input, fields[2][1], len(input))
}
fallthrough
case 2:
mountPoint = parseField(line, input, fields[1])
if filesystemType == nil && fields[1][1] < len(input) {
filesystemType = createPartialField(line, input, fields[1][1], len(input))
}
fallthrough
case 1:
spec = parseField(line, input, fields[0])
if mountPoint == nil && fields[0][1] < len(input) {
mountPoint = createPartialField(line, input, fields[0][1], len(input))
}
}
fstabLine := &FstabEntry{
@ -181,29 +157,3 @@ func parseField(
}),
}
}
func createPartialField(
line uint32,
input string,
start int,
end int,
) *FstabField {
return nil
return &FstabField{
LocationRange: common.LocationRange{
Start: common.Location{
Line: line,
Character: uint32(start),
},
End: common.Location{
Line: line,
Character: uint32(end),
},
},
Value: commonparser.ParseRawString(input[end:end], commonparser.ParseFeatures{
ParseEscapedCharacters: true,
ParseDoubleQuotes: true,
Replacements: &map[string]string{},
}),
}
}

View File

@ -39,22 +39,6 @@ var defaultOptions = []docvalues.EnumString{
"noauto",
"Can only be mounted explicitly (i.e., the -a option will not cause the filesystem to be mounted).",
),
docvalues.CreateEnumStringWithDoc(
"context",
"The context= option is useful when mounting filesystems that do not support extended attributes, such as a floppy or hard disk formatted with VFAT, or systems that are not normally running under SELinux, such as an ext3 or ext4 formatted disk from a non-SELinux workstation. You can also use context= on filesystems you do not trust, such as a floppy. It also helps in compatibility with xattr-supporting filesystems on earlier 2.4.<x> kernel versions. Even where xattrs are supported, you can save time not having to label every file by assigning the entire disk one security context.",
),
docvalues.CreateEnumStringWithDoc(
"fscontext",
"The fscontext= option works for all filesystems, regardless of their xattr support. The fscontext option sets the overarching filesystem label to a specific security context. This filesystem label is separate from the individual labels on the files. It represents the entire filesystem for certain kinds of permission checks, such as during mount or file creation. Individual file labels are still obtained from the xattrs on the files themselves. The context option actually sets the aggregate context that fscontext provides, in addition to supplying the same label for individual files.",
),
docvalues.CreateEnumStringWithDoc(
"defcontext",
"You can set the default security context for unlabeled files using defcontext= option. This overrides the value set for unlabeled files in the policy and requires a filesystem that supports xattr labeling.",
),
docvalues.CreateEnumStringWithDoc(
"rootcontext",
"The rootcontext= option allows you to explicitly label the root inode of a FS being mounted before that FS or inode becomes visible to userspace. This was found to be useful for things like stateless Linux. The special value @target can be used to assign the current context of the target mountpoint location.",
),
docvalues.CreateEnumStringWithDoc(
"defaults",
"Use the default options: rw, suid, dev, exec, auto, nouser, and async. Note that the real set of all default mount options depends on the kernel and filesystem type. See the beginning of this section for more details.",
@ -345,13 +329,21 @@ See TimeoutSec= below for details.
Added in version 233.`,
): docvalues.StringValue{},
docvalues.CreateEnumStringWithDoc(
"fscontext",
"The fscontext= option works for all filesystems, regardless of their xattr support. The fscontext option sets the overarching filesystem label to a specific security context. This filesystem label is separate from the individual labels on the files. It represents the entire filesystem for certain kinds of permission checks, such as during mount or file creation. Individual file labels are still obtained from the xattrs on the files themselves. The context option actually sets the aggregate context that fscontext provides, in addition to supplying the same label for individual files.",
): docvalues.StringValue{},
docvalues.CreateEnumStringWithDoc(
"defcontext",
"You can set the default security context for unlabeled files using defcontext= option. This overrides the value set for unlabeled files in the policy and requires a filesystem that supports xattr labeling.",
): docvalues.StringValue{},
}
func createMountOptionField(
options []docvalues.EnumString,
assignOption map[docvalues.EnumString]docvalues.DeprecatedValue,
) docvalues.DeprecatedValue {
dynamicOptions := docvalues.MergeKeyEnumAssignmentMaps(defaultAssignOptions, assignOption)
// dynamicOptions := docvalues.MergeKeyEnumAssignmentMaps(defaultAssignOptions, assignOption)
return docvalues.ArrayValue{
Separator: ",",
@ -359,20 +351,20 @@ func createMountOptionField(
SubValue: docvalues.OrValue{
Values: []docvalues.DeprecatedValue{
docvalues.KeyEnumAssignmentValue{
Values: dynamicOptions,
Values: assignOption,
ValueIsOptional: false,
Separator: "=",
},
docvalues.EnumValue{
EnforceValues: true,
Values: append(defaultOptions, options...),
Values: options,
},
},
},
}
}
var DefaultMountOptionsField = createMountOptionField([]docvalues.EnumString{}, map[docvalues.EnumString]docvalues.DeprecatedValue{})
var DefaultMountOptionsField = createMountOptionField(defaultOptions, defaultAssignOptions)
var MountOptionsMapField = map[string]docvalues.DeprecatedValue{
"adfs": createMountOptionField(

View File

@ -2,9 +2,9 @@ package handlers
import (
"config-lsp/common"
"config-lsp/doc-values"
"config-lsp/handlers/fstab/ast"
"config-lsp/handlers/fstab/fields"
"fmt"
"github.com/tliron/glsp/protocol_3_16"
)
@ -38,22 +38,45 @@ func GetCompletion(
cursor,
), nil
case ast.FstabFieldOptions:
line, cursor := getFieldSafely(entry.Fields.Options, cursor)
fileSystemType := entry.Fields.FilesystemType.Value.Value
completions := make([]protocol.CompletionItem, 0, 50)
var optionsField docvalues.DeprecatedValue
for _, completion := range fields.DefaultMountOptionsField.DeprecatedFetchCompletions(line, cursor) {
var documentation string
if foundField, found := fields.MountOptionsMapField[fileSystemType]; found {
optionsField = foundField
} else {
optionsField = fields.DefaultMountOptionsField
switch completion.Documentation.(type) {
case string:
documentation = completion.Documentation.(string)
case *string:
documentation = *completion.Documentation.(*string)
}
value, cursor := getFieldSafely(entry.Fields.Options, cursor)
completion.Documentation = protocol.MarkupContent{
Kind: protocol.MarkupKindMarkdown,
Value: documentation + "\n\n" + "From: _Default Mount Options_",
}
completions = append(completions, completion)
}
completions := optionsField.DeprecatedFetchCompletions(
value,
cursor,
)
if optionsField, found := fields.MountOptionsMapField[fileSystemType]; found {
for _, completion := range optionsField.DeprecatedFetchCompletions(line, cursor) {
var documentation string
switch completion.Documentation.(type) {
case string:
documentation = completion.Documentation.(string)
case *string:
documentation = *completion.Documentation.(*string)
}
completion.Documentation = protocol.MarkupContent{
Kind: protocol.MarkupKindMarkdown,
Value: documentation + "\n\n" + fmt.Sprintf("From: _%s_", fileSystemType),
}
completions = append(completions, completion)
}
}
return completions, nil
case ast.FstabFieldFreq: