mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
fix(sshd_config): Improve include
This commit is contained in:
parent
6c9ebc1b16
commit
be8c92f605
@ -71,6 +71,10 @@ func createIncludePaths(
|
||||
func parseFile(
|
||||
filePath string,
|
||||
) (*sshdconfig.SSHDocument, error) {
|
||||
if d, ok := sshdconfig.DocumentParserMap[filePath]; ok {
|
||||
return d, nil
|
||||
}
|
||||
|
||||
c := ast.NewSSHConfig()
|
||||
|
||||
content, err := os.ReadFile(filePath)
|
||||
@ -79,7 +83,11 @@ func parseFile(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.Parse(string(content))
|
||||
parseErrors := c.Parse(string(content))
|
||||
|
||||
if len(parseErrors) > 0 {
|
||||
return nil, errors.New(fmt.Sprintf("Errors in %s", filePath))
|
||||
}
|
||||
|
||||
d := &sshdconfig.SSHDocument{
|
||||
Config: c,
|
||||
@ -91,5 +99,7 @@ func parseFile(
|
||||
return nil, errors.New(fmt.Sprintf("Errors in %s", filePath))
|
||||
}
|
||||
|
||||
sshdconfig.DocumentParserMap[filePath] = d
|
||||
|
||||
return d, nil
|
||||
}
|
||||
|
@ -17,13 +17,19 @@ func TextDocumentDidOpen(
|
||||
) error {
|
||||
common.ClearDiagnostics(context, params.TextDocument.URI)
|
||||
|
||||
parser := ast.NewSSHConfig()
|
||||
document := sshdconfig.SSHDocument{
|
||||
Config: parser,
|
||||
}
|
||||
sshdconfig.DocumentParserMap[params.TextDocument.URI] = &document
|
||||
var document *sshdconfig.SSHDocument
|
||||
|
||||
errors := parser.Parse(params.TextDocument.Text)
|
||||
if foundDocument, ok := sshdconfig.DocumentParserMap[params.TextDocument.URI]; ok {
|
||||
document = foundDocument
|
||||
} else {
|
||||
config := ast.NewSSHConfig()
|
||||
document = &sshdconfig.SSHDocument{
|
||||
Config: config,
|
||||
}
|
||||
sshdconfig.DocumentParserMap[params.TextDocument.URI] = document
|
||||
}
|
||||
|
||||
errors := document.Config.Parse(params.TextDocument.Text)
|
||||
|
||||
diagnostics := utils.Map(
|
||||
errors,
|
||||
@ -34,7 +40,7 @@ func TextDocumentDidOpen(
|
||||
|
||||
diagnostics = append(
|
||||
diagnostics,
|
||||
analyzer.Analyze(&document)...,
|
||||
analyzer.Analyze(document)...,
|
||||
)
|
||||
|
||||
if len(diagnostics) > 0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user