mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
fix(server): Improve spec field analyzer
This commit is contained in:
parent
68be6e5904
commit
7a92594135
@ -48,12 +48,16 @@ func (v PathValue) GetTypeDescription() []string {
|
|||||||
|
|
||||||
func (v PathValue) DeprecatedCheckIsValid(value string) []*InvalidValue {
|
func (v PathValue) DeprecatedCheckIsValid(value string) []*InvalidValue {
|
||||||
if !utils.DoesPathExist(value) {
|
if !utils.DoesPathExist(value) {
|
||||||
|
if v.RequiredType == PathTypeExistenceOptional {
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
return []*InvalidValue{{
|
return []*InvalidValue{{
|
||||||
Err: PathDoesNotExistError{},
|
Err: PathDoesNotExistError{},
|
||||||
Start: 0,
|
Start: 0,
|
||||||
End: uint32(len(value)),
|
End: uint32(len(value)),
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
isValid := false
|
isValid := false
|
||||||
|
|
||||||
|
38
server/handlers/fstab/analyzer/spec.go
Normal file
38
server/handlers/fstab/analyzer/spec.go
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package analyzer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"config-lsp/common"
|
||||||
|
"config-lsp/handlers/fstab/ast"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
|
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||||
|
)
|
||||||
|
|
||||||
|
var volatileBlockFields = regexp.MustCompile(`^/dev/(sd|nvme|mmcblk|sr|vd|loop|cdrom)[a-zA-Z0-9]*$`)
|
||||||
|
|
||||||
|
func analyzeSpecField(
|
||||||
|
ctx *analyzerContext,
|
||||||
|
field *ast.FstabField,
|
||||||
|
) {
|
||||||
|
if field == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if field.Value.Value == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !volatileBlockFields.MatchString(field.Value.Value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
codeDescription := protocol.CodeDescription{
|
||||||
|
HRef: protocol.URI("https://wiki.archlinux.org/title/Persistent_block_device_naming"),
|
||||||
|
}
|
||||||
|
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
|
||||||
|
Range: field.ToLSPRange(),
|
||||||
|
Message: "Kernel name descriptors for block devices are not persistent and can change each boot, they should not be used in configuration files. Prefer device UUIDs or LABELs instead.",
|
||||||
|
CodeDescription: &codeDescription,
|
||||||
|
Severity: &common.SeverityWarning,
|
||||||
|
})
|
||||||
|
}
|
@ -21,6 +21,8 @@ func analyzeValuesAreValid(
|
|||||||
checkField(ctx, entry.Fields.MountPoint, fields.MountPointField)
|
checkField(ctx, entry.Fields.MountPoint, fields.MountPointField)
|
||||||
checkField(ctx, entry.Fields.FilesystemType, fields.FileSystemTypeField)
|
checkField(ctx, entry.Fields.FilesystemType, fields.FileSystemTypeField)
|
||||||
|
|
||||||
|
analyzeSpecField(ctx, entry.Fields.Spec)
|
||||||
|
|
||||||
if entry.Fields.Options != nil {
|
if entry.Fields.Options != nil {
|
||||||
mountOptions := entry.FetchMountOptionsField(true)
|
mountOptions := entry.FetchMountOptionsField(true)
|
||||||
|
|
||||||
|
@ -6,7 +6,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var UuidField = docvalues.RegexValue{
|
var UuidField = docvalues.RegexValue{
|
||||||
Regex: *regexp.MustCompile(`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}`),
|
// Can either be a UUID or UID
|
||||||
|
Regex: *regexp.MustCompile(`(?i)([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}|[a-f0-9]{4}-[a-f0-9]{4})`),
|
||||||
}
|
}
|
||||||
var LabelField = docvalues.RegexValue{
|
var LabelField = docvalues.RegexValue{
|
||||||
Regex: *regexp.MustCompile(`\S+`),
|
Regex: *regexp.MustCompile(`\S+`),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user