mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 15:05:28 +02:00
feat(doc-value): Add respect quote value
This commit is contained in:
parent
b0d8e80736
commit
0e18169a3f
@ -42,6 +42,9 @@ type ArrayValue struct {
|
||||
// This is used to extract the value from the user input,
|
||||
// because you may want to preprocess the value before checking for duplicates
|
||||
DuplicatesExtractor *(func(string) string)
|
||||
|
||||
// If true, array ArrayValue ignores the `Separator` if it's within quotes
|
||||
RespectQuotes bool
|
||||
}
|
||||
|
||||
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 {
|
||||
errors := []*InvalidValue{}
|
||||
values := strings.Split(value, v.Separator)
|
||||
@ -122,9 +126,24 @@ func (v ArrayValue) getCurrentValue(line string, cursor uint32) (string, uint32)
|
||||
MIN := uint32(0)
|
||||
MAX := uint32(len(line) - 1)
|
||||
|
||||
var cursorSearchStart = cursor
|
||||
var cursorSearchEnd = cursor
|
||||
|
||||
var start 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
|
||||
// [h]ello,world
|
||||
// hello,[w]orld
|
||||
@ -135,7 +154,7 @@ func (v ArrayValue) getCurrentValue(line string, cursor uint32) (string, uint32)
|
||||
relativePosition, found := utils.FindPreviousCharacter(
|
||||
line,
|
||||
v.Separator,
|
||||
int(cursor),
|
||||
int(cursorSearchStart),
|
||||
)
|
||||
|
||||
if found {
|
||||
@ -151,7 +170,7 @@ func (v ArrayValue) getCurrentValue(line string, cursor uint32) (string, uint32)
|
||||
relativePosition, found = utils.FindNextCharacter(
|
||||
line,
|
||||
v.Separator,
|
||||
int(start),
|
||||
int(cursorSearchEnd),
|
||||
)
|
||||
|
||||
if found {
|
||||
|
@ -30,7 +30,7 @@ func checkIsUsingDoubleQuotes(
|
||||
singleQuotePosition := strings.Index(value.Raw, "'")
|
||||
|
||||
// Single quote
|
||||
if singleQuotePosition != -1 && !quoteRanges.IsCharInside(singleQuotePosition) {
|
||||
if singleQuotePosition != -1 && !quoteRanges.IsIndexInsideQuotes(singleQuotePosition) {
|
||||
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
|
||||
Range: valueRange.ToLSPRange(),
|
||||
Message: "ssh_config does not support single quotes. Use double quotes (\") instead.",
|
||||
|
@ -30,7 +30,7 @@ func checkIsUsingDoubleQuotes(
|
||||
singleQuotePosition := strings.Index(value.Raw, "'")
|
||||
|
||||
// Single quote
|
||||
if singleQuotePosition != -1 && !quoteRanges.IsCharInside(singleQuotePosition) {
|
||||
if singleQuotePosition != -1 && !quoteRanges.IsIndexInsideQuotes(singleQuotePosition) {
|
||||
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
|
||||
Range: valueRange.ToLSPRange(),
|
||||
Message: "sshd_config does not support single quotes. Use double quotes (\") instead.",
|
||||
|
Loading…
x
Reference in New Issue
Block a user