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