@@ -7,19 +7,24 @@ function setup_server(env = dirname(SymbolServer.Pkg.Types.Context().env.project
77end
88
99"""
10- lint_string(s, server)
10+ lint_string(s, server; gethints = false )
1111
1212Parse a string and run a semantic pass over it. This will mark scopes, bindings,
13- references, and lint hints. An annotated `EXPR` is returned.
13+ references, and lint hints. An annotated `EXPR` is returned or, if `gethints = true`,
14+ it is paired with a collected list of errors/hints.
1415"""
15- function lint_string (s:: String , server = setup_server ())
16+ function lint_string (s:: String , server = setup_server (); gethints = false )
1617 empty! (server. files)
1718 f = StaticLint. File (" " , s, CSTParser. parse (s, true ), nothing , server)
1819 StaticLint. setroot (f, f)
1920 StaticLint. setfile (server, " " , f)
2021 StaticLint. semantic_pass (f)
2122 StaticLint. check_all (f. cst, StaticLint. LintOptions (), server)
22- return f. cst
23+ if gethints
24+ return f. cst, [(x, string (haserror (x) ? LintCodeDescriptions[x. meta. error] : " Missing reference" , " at offset " , offset)) for (offset, x) in collect_hints (f. cst, server)]
25+ else
26+ return f. cst
27+ end
2328end
2429
2530"""
@@ -31,12 +36,20 @@ in the project will be loaded automatically (calls to `include` with complicated
3136are not handled, see `followinclude` for details). A `FileServer` will be returned
3237containing the `File`s of the package.
3338"""
34- function lint_file (rootpath, server = setup_server ())
39+ function lint_file (rootpath, server = setup_server (); gethints = false )
3540 empty! (server. files)
3641 root = StaticLint. loadfile (server, rootpath)
3742 StaticLint. semantic_pass (root)
3843 for (p,f) in server. files
3944 StaticLint. check_all (f. cst, StaticLint. LintOptions (), server)
4045 end
41- return root
42- end
46+ if gethints
47+ hints = []
48+ for (p,f) in server. files
49+ append! (hints, [(x, string (haserror (x) ? LintCodeDescriptions[x. meta. error] : " Missing reference" , " at offset " , offset, " of " , p)) for (offset, x) in collect_hints (f. cst, server)])
50+ end
51+ return root, hints
52+ else
53+ return root
54+ end
55+ end
0 commit comments