Skip to content

Commit e071959

Browse files
authored
Merge pull request #691 from non-Jedi/config-cleanup
Simplify configuration code
2 parents e8d2ac2 + 15c3505 commit e071959

File tree

4 files changed

+19
-27
lines changed

4 files changed

+19
-27
lines changed

src/languageserverinstance.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,7 @@ function Base.run(server::LanguageServerInstance)
264264
scopepass(root, doc)
265265
end
266266

267-
StaticLint.check_all(getcst(doc), server.lint_options, server)
268-
empty!(doc.diagnostics)
269-
mark_errors(doc, doc.diagnostics)
270-
publish_diagnostics(doc, server)
267+
lint!(doc, server)
271268
end
272269
end
273270
end

src/requests/textdocument.jl

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ function process(r::JSONRPC.Request{Val{Symbol("textDocument/didChange")},DidCha
8080
tdcce = first(r.params.contentChanges)
8181
new_cst = _partial_update(doc, tdcce)
8282
scopepass(getroot(doc), doc)
83-
StaticLint.check_all(getcst(doc), server.lint_options, server)
84-
empty!(doc.diagnostics)
85-
mark_errors(doc, doc.diagnostics)
86-
publish_diagnostics(doc, server)
83+
lint!(doc, server)
8784
else
8885
for tdcce in r.params.contentChanges
8986
applytextdocumentchanges(doc, tdcce)
@@ -234,11 +231,7 @@ function parse_all(doc::Document, server::LanguageServerInstance)
234231
end
235232

236233
scopepass(getroot(doc), doc)
237-
StaticLint.check_all(getcst(doc), server.lint_options, server)
238-
empty!(doc.diagnostics)
239-
mark_errors(doc, doc.diagnostics)
240-
241-
publish_diagnostics(doc, server)
234+
lint!(doc, server)
242235
end
243236

244237
function mark_errors(doc, out = Diagnostic[])

src/requests/workspace.jl

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,18 @@ function request_julia_config(server::LanguageServerInstance)
100100
ConfigurationItem(missing, "julia.lint.missingrefs")
101101
]))
102102

103-
new_DF_opts = DocumentFormat.FormatOptions([isnothing(opt) ? DocumentFormat.default_options[i] : opt for (i,opt) in enumerate(response[1:11])]...)
104-
new_SL_opts = StaticLint.LintOptions([isnothing(opt) ? StaticLint.default_options[i] : opt for (i,opt) in enumerate(response[12:21])]...)
105-
new_lintrun = isnothing(response[22]) ? true : response[22]
106-
new_missingref = isnothing(response[23]) ? :all : Symbol(response[23])
107-
103+
server.format_options = DocumentFormat.FormatOptions(response[1:11]...)
104+
server.runlinter = something(response[22], true)
105+
server.lint_missingrefs = Symbol(something(response[23], :all))
106+
107+
new_SL_opts = StaticLint.LintOptions(response[12:21]...)
108+
# TODO: implement == for StaticLint.LintOptions
108109
rerun_lint = any(getproperty(server.lint_options, opt) != getproperty(new_SL_opts, opt) for opt in fieldnames(StaticLint.LintOptions))
109-
server.format_options = new_DF_opts
110110
server.lint_options = new_SL_opts
111-
server.runlinter = new_lintrun
112-
server.lint_missingrefs = new_missingref
113111

114112
if rerun_lint
115113
for doc in getdocuments_value(server)
116-
StaticLint.check_all(getcst(doc), server.lint_options, server)
117-
empty!(doc.diagnostics)
118-
mark_errors(doc, doc.diagnostics)
119-
publish_diagnostics(doc, server)
114+
lint!(doc, server)
120115
end
121116
end
122117

@@ -147,4 +142,4 @@ function process(r::JSONRPC.Request{Val{Symbol("workspace/symbol")},WorkspaceSym
147142
end
148143

149144
return syms
150-
end
145+
end

src/staticlint.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,11 @@ getserver(file::Document) = file.server
5656
function setserver(file::Document, server::LanguageServerInstance)
5757
file.server = server
5858
return file
59-
end
59+
end
60+
61+
function lint!(doc, server)
62+
StaticLint.check_all(getcst(doc), server.lint_options, server)
63+
empty!(doc.diagnostics)
64+
mark_errors(doc, doc.diagnostics)
65+
publish_diagnostics(doc, server)
66+
end

0 commit comments

Comments
 (0)