mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 15:05:28 +02:00
fix(server): Improvements
Signed-off-by: Myzel394 <github.7a2op@simplelogin.co>
This commit is contained in:
parent
9a1686a7d8
commit
429c2cd4be
6
flake.lock
generated
6
flake.lock
generated
@ -41,11 +41,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1748026106,
|
||||
"narHash": "sha256-6m1Y3/4pVw1RWTsrkAK2VMYSzG4MMIj7sqUy7o8th1o=",
|
||||
"lastModified": 1748370509,
|
||||
"narHash": "sha256-QlL8slIgc16W5UaI3w7xHQEP+Qmv/6vSNTpoZrrSlbk=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "063f43f2dbdef86376cc29ad646c45c46e93234c",
|
||||
"rev": "4faa5f5321320e49a78ae7848582f684d64783e9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -2,22 +2,12 @@ package docvalues
|
||||
|
||||
import (
|
||||
"config-lsp/utils"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
type PathDoesNotExistError struct{}
|
||||
|
||||
func (e PathDoesNotExistError) Error() string {
|
||||
return "This path does not exist"
|
||||
}
|
||||
|
||||
type PathInvalidError struct{}
|
||||
|
||||
func (e PathInvalidError) Error() string {
|
||||
return "This path is invalid"
|
||||
}
|
||||
|
||||
type PathType uint8
|
||||
|
||||
const (
|
||||
@ -53,29 +43,66 @@ func (v PathValue) DeprecatedCheckIsValid(value string) []*InvalidValue {
|
||||
return nil
|
||||
} else {
|
||||
return []*InvalidValue{{
|
||||
Err: PathDoesNotExistError{},
|
||||
Err: errors.New("This path does not exist"),
|
||||
Start: 0,
|
||||
End: uint32(len(value)),
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
isValid := false
|
||||
fileRequired := (v.RequiredType & PathTypeFile) == PathTypeFile
|
||||
directoryRequired := (v.RequiredType & PathTypeDirectory) == PathTypeDirectory
|
||||
|
||||
if (v.RequiredType & PathTypeFile) == PathTypeFile {
|
||||
isValid := true
|
||||
|
||||
// If file is expected
|
||||
if fileRequired {
|
||||
// and exists
|
||||
isValid = isValid && utils.IsPathFile(value)
|
||||
// file not expected
|
||||
} else {
|
||||
// and should not exist
|
||||
isValid = isValid && !utils.IsPathFile(value)
|
||||
}
|
||||
|
||||
if (v.RequiredType & PathTypeDirectory) == PathTypeDirectory {
|
||||
// if directory
|
||||
if directoryRequired {
|
||||
// and exists
|
||||
isValid = isValid && utils.IsPathDirectory(value)
|
||||
// directory not expected
|
||||
} else {
|
||||
// and should not exist
|
||||
isValid = isValid && !utils.IsPathDirectory(value)
|
||||
}
|
||||
|
||||
if isValid {
|
||||
return nil
|
||||
}
|
||||
|
||||
if fileRequired && directoryRequired {
|
||||
return []*InvalidValue{{
|
||||
Err: PathInvalidError{},
|
||||
Err: errors.New("This must be either a file or a directory"),
|
||||
Start: 0,
|
||||
End: uint32(len(value)),
|
||||
}}
|
||||
}
|
||||
if fileRequired {
|
||||
return []*InvalidValue{{
|
||||
Err: errors.New("This must be a file"),
|
||||
Start: 0,
|
||||
End: uint32(len(value)),
|
||||
}}
|
||||
}
|
||||
if directoryRequired {
|
||||
return []*InvalidValue{{
|
||||
Err: errors.New("This must be a directory"),
|
||||
Start: 0,
|
||||
End: uint32(len(value)),
|
||||
}}
|
||||
}
|
||||
|
||||
return []*InvalidValue{{
|
||||
Err: errors.New("This path is invalid"),
|
||||
Start: 0,
|
||||
End: uint32(len(value)),
|
||||
}}
|
||||
|
@ -370,7 +370,7 @@ See PATTERNS in ssh_config(5) for more information on patterns. This keyword may
|
||||
Note that sshd(8) will refuse to use a file if it is group/world-accessible and that the HostKeyAlgorithms option restricts which of the keys are actually used by sshd(8).
|
||||
It is possible to have multiple host key files. It is also possible to specify public host key files instead. In this case operations on the private key will be delegated to an ssh-agent(1).`,
|
||||
Value: docvalues.PathValue{
|
||||
IsOptional: true,
|
||||
IsOptional: false,
|
||||
RequiredType: docvalues.PathTypeFile,
|
||||
},
|
||||
},
|
||||
|
@ -24,7 +24,6 @@ func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionPa
|
||||
|
||||
entry, matchBlock := d.Config.FindOption(line)
|
||||
|
||||
|
||||
if entry == nil ||
|
||||
entry.Separator == nil ||
|
||||
entry.Key == nil ||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
@ -13,11 +15,21 @@ func DoesPathExist(path string) bool {
|
||||
func IsPathDirectory(path string) bool {
|
||||
info, err := os.Stat(path)
|
||||
|
||||
return err == nil && info.IsDir()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return info.IsDir()
|
||||
}
|
||||
|
||||
func IsPathFile(path string) bool {
|
||||
info, err := os.Stat(path)
|
||||
_, err := os.Stat(path)
|
||||
|
||||
return err == nil && !info.IsDir()
|
||||
print(fmt.Sprintf("Checking if path %s is a file: %v\n", path, err))
|
||||
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user