Skip to content

Commit 10ad459

Browse files
committed
more
1 parent edf3fe5 commit 10ad459

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

src/interface.jl

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,24 @@ function setup_server(env = dirname(SymbolServer.Pkg.Types.Context().env.project
77
end
88

99
"""
10-
lint_string(s, server)
10+
lint_string(s, server; gethints = false)
1111
1212
Parse 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
2328
end
2429

2530
"""
@@ -31,12 +36,20 @@ in the project will be loaded automatically (calls to `include` with complicated
3136
are not handled, see `followinclude` for details). A `FileServer` will be returned
3237
containing 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

test/runtests.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@ function get_ids(x, ids=[])
1616
end
1717

1818
parse_and_pass(s) = StaticLint.lint_string(s, server)
19-
20-
# function parse_and_pass(s)
21-
# empty!(server.files)
22-
# f = StaticLint.File("", s, CSTParser.parse(s, true), nothing, server)
23-
# StaticLint.setroot(f, f)
24-
# StaticLint.setfile(server, "", f)
25-
# StaticLint.semantic_pass(f)
26-
# StaticLint.check_all(f.cst, StaticLint.LintOptions(), server)
27-
# return f.cst
28-
# end
29-
3019

3120
function check_resolved(s)
3221
cst = parse_and_pass(s)

0 commit comments

Comments
 (0)