feat(doc-value): Add respect quote value

This commit is contained in:
Myzel394 2024-10-15 14:20:27 +02:00
parent b0d8e80736
commit 0e18169a3f
No known key found for this signature in database
GPG Key ID: ED20A1D1D423AF3F
3 changed files with 23 additions and 4 deletions

View File

@ -42,6 +42,9 @@ type ArrayValue struct {
// This is used to extract the value from the user input, // This is used to extract the value from the user input,
// because you may want to preprocess the value before checking for duplicates // because you may want to preprocess the value before checking for duplicates
DuplicatesExtractor *(func(string) string) DuplicatesExtractor *(func(string) string)
// If true, array ArrayValue ignores the `Separator` if it's within quotes
RespectQuotes bool
} }
func (v ArrayValue) GetTypeDescription() []string { func (v ArrayValue) GetTypeDescription() []string {
@ -53,6 +56,7 @@ func (v ArrayValue) GetTypeDescription() []string {
) )
} }
// TODO: Add support for quotes
func (v ArrayValue) DeprecatedCheckIsValid(value string) []*InvalidValue { func (v ArrayValue) DeprecatedCheckIsValid(value string) []*InvalidValue {
errors := []*InvalidValue{} errors := []*InvalidValue{}
values := strings.Split(value, v.Separator) values := strings.Split(value, v.Separator)
@ -122,9 +126,24 @@ func (v ArrayValue) getCurrentValue(line string, cursor uint32) (string, uint32)
MIN := uint32(0) MIN := uint32(0)
MAX := uint32(len(line) - 1) MAX := uint32(len(line) - 1)
var cursorSearchStart = cursor
var cursorSearchEnd = cursor
var start uint32 var start uint32
var end uint32 var end uint32
// Hello,world,how,are,you
// Hello,"world,how",are,you
if v.RespectQuotes {
quotes := utils.GetQuoteRanges(line)
quote := quotes.GetQuoteForIndex(int(cursor))
if quote != nil {
cursorSearchStart = uint32(quote[0])
cursorSearchEnd = uint32(quote[1])
}
}
// hello,w[o]rld,and,more // hello,w[o]rld,and,more
// [h]ello,world // [h]ello,world
// hello,[w]orld // hello,[w]orld
@ -135,7 +154,7 @@ func (v ArrayValue) getCurrentValue(line string, cursor uint32) (string, uint32)
relativePosition, found := utils.FindPreviousCharacter( relativePosition, found := utils.FindPreviousCharacter(
line, line,
v.Separator, v.Separator,
int(cursor), int(cursorSearchStart),
) )
if found { if found {
@ -151,7 +170,7 @@ func (v ArrayValue) getCurrentValue(line string, cursor uint32) (string, uint32)
relativePosition, found = utils.FindNextCharacter( relativePosition, found = utils.FindNextCharacter(
line, line,
v.Separator, v.Separator,
int(start), int(cursorSearchEnd),
) )
if found { if found {

View File

@ -30,7 +30,7 @@ func checkIsUsingDoubleQuotes(
singleQuotePosition := strings.Index(value.Raw, "'") singleQuotePosition := strings.Index(value.Raw, "'")
// Single quote // Single quote
if singleQuotePosition != -1 && !quoteRanges.IsCharInside(singleQuotePosition) { if singleQuotePosition != -1 && !quoteRanges.IsIndexInsideQuotes(singleQuotePosition) {
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{ ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
Range: valueRange.ToLSPRange(), Range: valueRange.ToLSPRange(),
Message: "ssh_config does not support single quotes. Use double quotes (\") instead.", Message: "ssh_config does not support single quotes. Use double quotes (\") instead.",

View File

@ -30,7 +30,7 @@ func checkIsUsingDoubleQuotes(
singleQuotePosition := strings.Index(value.Raw, "'") singleQuotePosition := strings.Index(value.Raw, "'")
// Single quote // Single quote
if singleQuotePosition != -1 && !quoteRanges.IsCharInside(singleQuotePosition) { if singleQuotePosition != -1 && !quoteRanges.IsIndexInsideQuotes(singleQuotePosition) {
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{ ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
Range: valueRange.ToLSPRange(), Range: valueRange.ToLSPRange(),
Message: "sshd_config does not support single quotes. Use double quotes (\") instead.", Message: "sshd_config does not support single quotes. Use double quotes (\") instead.",