Myzel394 98f76fd839
fix(server): Improve structure analyzer for ssh_config
Signed-off-by: Myzel394 <github.7a2op@simplelogin.co>
2025-03-16 00:23:54 +01:00

46 lines
1.1 KiB
Go

package analyzer
import (
"config-lsp/common"
commonparser "config-lsp/common/parser"
"config-lsp/utils"
"strings"
protocol "github.com/tliron/glsp/protocol_3_16"
)
func checkIsUsingDoubleQuotes(
ctx *analyzerContext,
value commonparser.ParsedString,
valueRange common.LocationRange,
) {
quoteRanges := utils.GetQuoteRanges(value.Raw)
invertedRanges := quoteRanges.GetInvertedRanges(len(value.Raw))
for _, rang := range invertedRanges {
text := value.Raw[rang[0]:rang[1]]
if strings.Contains(text, "'") {
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
Range: valueRange.ToLSPRange(),
Message: "ssh_config does not support single quotes. Use double quotes (\") instead.",
Severity: &common.SeverityError,
})
}
}
}
func checkQuotesAreClosed(
ctx *analyzerContext,
value commonparser.ParsedString,
valueRange common.LocationRange,
) {
if strings.Count(value.Raw, "\"")%2 != 0 {
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
Range: valueRange.ToLSPRange(),
Message: "There are unclosed quotes here. Make sure all quotes are closed.",
Severity: &common.SeverityError,
})
}
}