-
Notifications
You must be signed in to change notification settings - Fork 14
/
parse_yaml.go
63 lines (51 loc) · 1.4 KB
/
parse_yaml.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
// "fmt"
"flag"
"fmt"
"os"
yamlparser "github.com/CircleCI-Public/circleci-yaml-language-server/pkg/parser"
languageservice "github.com/CircleCI-Public/circleci-yaml-language-server/pkg/services"
"github.com/CircleCI-Public/circleci-yaml-language-server/pkg/utils"
"go.lsp.dev/protocol"
"go.lsp.dev/uri"
)
func main() {
filepath := ".circleci/config.yml"
// filepath := "examples/config1.yml"
// filepath := "/home/adib/circleci/circle/.circleci/config.yml"
schemaRef := flag.String("schema", "", "Location of the schema")
flag.Parse()
schema := *schemaRef
if schema == "" {
schema = os.Getenv("SCHEMA_LOCATION")
if schema == "" {
fmt.Print("No schema defined")
return
}
}
content, err := os.ReadFile(filepath)
if err != nil {
fmt.Printf("Unable to read file \"%s\"", filepath)
panic(err)
}
context := &utils.LsContext{
Api: utils.ApiContext{
Token: "XXXXXXXXXXXX",
HostUrl: "https://circleci.com",
},
}
yamlparser.ParseFile(content, context)
cache := utils.CreateCache()
cache.FileCache.SetFile(utils.CachedFile{
TextDocument: protocol.TextDocumentItem{
URI: uri.File(filepath),
Text: string(content),
},
Project: utils.Project{},
EnvVariables: make([]string, 0),
})
fileURI := uri.File(filepath)
languageservice.DiagnosticFile(fileURI, cache, context, schema)
// fmt.Printf("S-expression:\n%v\n\n", node.RootNode)
}