diff --git a/doc-values/value-mask-mode.go b/doc-values/value-mask-mode.go new file mode 100644 index 0000000..945ffc8 --- /dev/null +++ b/doc-values/value-mask-mode.go @@ -0,0 +1,123 @@ +package docvalues + +import ( + protocol "github.com/tliron/glsp/protocol_3_16" + "regexp" +) + +type MaskModeInvalidError struct{} + +func (e MaskModeInvalidError) Error() string { + return "This mask is not valid. It must be a 4-digit octal number." +} + +type MaskModeValue struct{} + +func (v MaskModeValue) GetTypeDescription() []string { + return []string{ + "File mode mask", + "4-digit octal number", + "Example: 0000", + "1st digit: setuid, setgid, sticky", + "2nd digit: user permissions", + "3rd digit: group permissions", + "4th digit: other permissions", + } +} + +var maskModePattern = regexp.MustCompile("^[0-7]{4}$") + +func (v MaskModeValue) CheckIsValid(value string) []*InvalidValue { + if !maskModePattern.MatchString(value) { + return []*InvalidValue{{ + Err: MaskModeInvalidError{}, + Start: 0, + End: uint32(len(value)), + }} + } + + return []*InvalidValue{} +} + +func (v MaskModeValue) FetchCompletions(line string, cursor uint32) []protocol.CompletionItem { + kind := protocol.CompletionItemKindValue + + perm0644 := "0644" + perm0755 := "0755" + perm0777 := "0777" + perm0400 := "0400" + perm0600 := "0600" + perm0666 := "0666" + perm0700 := "0700" + perm0444 := "0444" + perm0111 := "0111" + perm0555 := "0555" + + return []protocol.CompletionItem{ + { + Label: "0000", + Documentation: "No permissions", + Kind: &kind, + }, + { + Label: "0644 (-rw-r--r--)", + InsertText: &perm0644, + Documentation: "Read/write for owner, read for others", + Kind: &kind, + }, + { + Label: "0755 (-rwxr-xr-x)", + InsertText: &perm0755, + Documentation: "Read/write/execute for owner, read/execute for others", + Kind: &kind, + }, + { + Label: "0777 (-rwxrwxrwx)", + InsertText: &perm0777, + Documentation: "Read/write/execute for all", + Kind: &kind, + }, + { + Label: "0400 (-r--------)", + InsertText: &perm0400, + Documentation: "Read for owner", + Kind: &kind, + }, + { + Label: "0600 (-rw-------)", + InsertText: &perm0600, + Documentation: "Read/write for owner", + Kind: &kind, + }, + { + Label: "0666 (-rw-rw-rw-)", + InsertText: &perm0666, + Documentation: "Read/write for all", + Kind: &kind, + }, + { + Label: "0700 (-rwx------)", + InsertText: &perm0700, + Documentation: "Read/write/execute for owner", + Kind: &kind, + }, + { + Label: "0444 (-r--r--r--)", + InsertText: &perm0444, + Documentation: "Read for all", + Kind: &kind, + }, + { + Label: "0111 (-x--x--x)", + InsertText: &perm0111, + Documentation: "Execute for all", + Kind: &kind, + }, + { + Label: "0555 (-r-xr-xr-x)", + InsertText: &perm0555, + Documentation: "Read/execute for all", + Kind: &kind, + }, + } +} diff --git a/doc-values/value-umask.go b/doc-values/value-umask.go new file mode 100644 index 0000000..ed4b54a --- /dev/null +++ b/doc-values/value-umask.go @@ -0,0 +1,112 @@ +package docvalues + +import ( + "regexp" + + protocol "github.com/tliron/glsp/protocol_3_16" +) + +type UmaskInvalidError struct{} + +func (e UmaskInvalidError) Error() string { + return "This mask is not valid. It must be a 4-digit octal number." +} + +type UmaskValue struct{} + +func (v UmaskValue) GetTypeDescription() []string { + return []string{ + "File mode mask", + "4-digit octal number", + "Example: 0000", + "1st digit: setuid, setgid, sticky", + "2nd digit: user permissions", + "3rd digit: group permissions", + "4th digit: other permissions", + } +} + +var umaskPattern = regexp.MustCompile("^[0-7]{4}$") + +func (v UmaskValue) CheckIsValid(value string) []*InvalidValue { + if !umaskPattern.MatchString(value) { + return []*InvalidValue{{ + Err: UmaskInvalidError{}, + Start: 0, + End: uint32(len(value)), + }} + } + + return []*InvalidValue{} +} + +func (v UmaskValue) FetchCompletions(line string, cursor uint32) []protocol.CompletionItem { + kind := protocol.CompletionItemKindValue + + return []protocol.CompletionItem{ + { + Label: "0000", + Documentation: "Files: rwxrwxrwx Directories: rwxrwxrwx", + Kind: &kind, + }, + { + Label: "0022", + Documentation: "Files: rwxr-xr-x Directories: rwxr-xr-x", + Kind: &kind, + }, + { + Label: "0077", + Documentation: "Files: rwx------ Directories: rwx------", + Kind: &kind, + }, + { + Label: "0177", + Documentation: "Files: rw------- Directories: rw-------", + Kind: &kind, + }, + { + Label: "0277", + Documentation: "Files: r-x------ Directories: r-x------", + }, + { + Label: "0027", + Documentation: "Files: rwxr-x--- Directories: rwxr-x---", + Kind: &kind, + }, + { + Label: "0070", + Documentation: "Files: rwx---rwx Directories: rwx---rwx", + Kind: &kind, + }, + { + Label: "0222", + Documentation: "Files: r--r--r-- Directories: r--r--r--", + Kind: &kind, + }, + { + Label: "0333", + Documentation: "Files: r--r--r-- Directories: r--r--r--", + Kind: &kind, + }, + { + Label: "0444", + Documentation: "Files: r--r--r-- Directories: r--r--r--", + Kind: &kind, + }, + { + Label: "0555", + Documentation: "Files: r-xr-xr-x Directories: r-xr-xr-x", + Kind: &kind, + }, + { + Label: "0666", + Documentation: "Files: rw-rw-rw- Directories: rw-rw-rw-", + Kind: &kind, + }, + { + Label: "0777", + Documentation: "Files: rwxrwxrwx Directories: rwxrwxrwx", + Kind: &kind, + }, + } +}