Skip to content

Commit c4eaf33

Browse files
authored
Merge pull request #683 from julia-vscode/misc
update config & lint checks, remove unneeded fields
2 parents 7259bd6 + 103e281 commit c4eaf33

File tree

6 files changed

+50
-96
lines changed

6 files changed

+50
-96
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ JSON = "0.20, 0.21"
2626
julia = "1"
2727
CSTParser = "2.2"
2828
DocumentFormat = "2.1"
29-
StaticLint = "4.1"
29+
StaticLint = "4.2"
3030
Tokenize = "0.5.7"
3131
SymbolServer = "4.2"
3232
URIParser = "0.4.1"

src/document.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ mutable struct Document
99
cst::EXPR
1010
diagnostics::Vector{Diagnostic}
1111
_version::Int
12-
_runlinter::Bool
1312
server
1413
root::Document
1514
function Document(uri::AbstractString, text::AbstractString, workspace_file::Bool, server = nothing)
1615
path = uri2filepath(uri)
1716
cst = CSTParser.parse(text, true)
18-
doc = new(uri, path, text, nothing, nothing, false, workspace_file, cst, [], 0, true, server)
17+
doc = new(uri, path, text, nothing, nothing, false, workspace_file, cst, [], 0, server)
1918
get_line_offsets(doc)
2019
get_line_offsets2!(doc)
2120
cst.val = path

src/languageserverinstance.jl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ mutable struct LanguageServerInstance
3131
jr_endpoint::JSONRPCEndpoints.JSONRPCEndpoint
3232
workspaceFolders::Set{String}
3333
_documents::Dict{URI2,Document}
34-
35-
runlinter::Bool
36-
ignorelist::Set{String}
37-
isrunning::Bool
3834

3935
env_path::String
4036
depot_path::String
@@ -43,9 +39,11 @@ mutable struct LanguageServerInstance
4339
symbol_store::Dict{Symbol,SymbolServer.ModuleStore}
4440
symbol_extends::Dict{SymbolServer.VarRef,Vector{SymbolServer.VarRef}}
4541
symbol_store_ready::Bool
46-
# ss_task::Union{Nothing,Future}
42+
4743
format_options::DocumentFormat.FormatOptions
44+
runlinter::Bool
4845
lint_options::StaticLint.LintOptions
46+
lint_missingrefs::Symbol
4947

5048
combined_msg_queue::Channel{Any}
5149

@@ -65,9 +63,6 @@ mutable struct LanguageServerInstance
6563
JSONRPCEndpoints.JSONRPCEndpoint(pipe_in, pipe_out, err_handler),
6664
Set{String}(),
6765
Dict{URI2,Document}(),
68-
true,
69-
Set{String}(),
70-
false,
7166
env_path,
7267
depot_path,
7368
SymbolServer.SymbolServerInstance(depot_path, symserver_store_path),
@@ -76,7 +71,9 @@ mutable struct LanguageServerInstance
7671
SymbolServer.collect_extended_methods(SymbolServer.stdlibs),
7772
false,
7873
DocumentFormat.FormatOptions(),
74+
true,
7975
StaticLint.LintOptions(),
76+
:all,
8077
Channel{Any}(Inf),
8178
err_handler,
8279
:created,

src/requests/textdocument.jl

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
JSONRPC.parse_params(::Type{Val{Symbol("textDocument/didOpen")}}, params) = DidOpenTextDocumentParams(params)
22
function process(r::JSONRPC.Request{Val{Symbol("textDocument/didOpen")},DidOpenTextDocumentParams}, server)
3-
server.isrunning = true
43
uri = r.params.textDocument.uri
54
if hasdocument(server, URI2(uri))
65
doc = getdocument(server, URI2(uri))
@@ -13,7 +12,6 @@ function process(r::JSONRPC.Request{Val{Symbol("textDocument/didOpen")},DidOpenT
1312
setdocument!(server, URI2(uri), doc)
1413
doc._version = r.params.textDocument.version
1514
doc._workspace_file = any(i->startswith(uri, filepath2uri(i)), server.workspaceFolders)
16-
doc._runlinter = !is_ignored(uri, server)
1715
set_open_in_editor(doc, true)
1816

1917
try_to_load_parents(uri2filepath(uri), server)
@@ -22,30 +20,6 @@ function process(r::JSONRPC.Request{Val{Symbol("textDocument/didOpen")},DidOpenT
2220
end
2321

2422

25-
# JSONRPC.parse_params(::Type{Val{Symbol("julia/reloadText")}}, params) = DidOpenTextDocumentParams(params)
26-
# function process(r::JSONRPC.Request{Val{Symbol("julia/reloadText")},DidOpenTextDocumentParams}, server)
27-
# server.isrunning = true
28-
# uri = r.params.textDocument.uri
29-
# if hasdocument(server, URI2(uri))
30-
# doc = getdocument(server, URI2(uri))
31-
# set_text!(doc, r.params.textDocument.text)
32-
# doc._version = r.params.textDocument.version
33-
# else
34-
# doc = Document(uri, r.params.textDocument.text, false, server)
35-
# setdocument!(server, URI2(uri), doc)
36-
# doc._version = r.params.textDocument.version
37-
# if any(i->startswith(uri, filepath2uri(i)), server.workspaceFolders)
38-
# doc._workspace_file = true
39-
# end
40-
# set_open_in_editor(doc, true)
41-
# if is_ignored(uri, server)
42-
# doc._runlinter = false
43-
# end
44-
# end
45-
# get_line_offsets(doc)
46-
# parse_all(doc, server)
47-
# end
48-
4923
JSONRPC.parse_params(::Type{Val{Symbol("textDocument/didClose")}}, params) = DidCloseTextDocumentParams(params)
5024
function process(r::JSONRPC.Request{Val{Symbol("textDocument/didClose")},DidCloseTextDocumentParams}, server)
5125
uri = r.params.textDocument.uri
@@ -269,7 +243,7 @@ end
269243

270244
function mark_errors(doc, out = Diagnostic[])
271245
line_offsets = get_line_offsets(doc)
272-
errs = StaticLint.collect_hints(getcst(doc), doc.server)
246+
errs = StaticLint.collect_hints(getcst(doc), doc.server, doc.server.lint_missingrefs)
273247
n = length(errs)
274248
n == 0 && return out
275249
i = 1

src/requests/workspace.jl

Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -73,55 +73,53 @@ function process(r::JSONRPC.Request{Val{Symbol("workspace/didChangeConfiguration
7373
request_julia_config(server)
7474
end
7575

76-
function request_julia_config(server)
76+
function request_julia_config(server::LanguageServerInstance)
7777
response = JSONRPCEndpoints.send_request(server.jr_endpoint, "workspace/configuration", ConfigurationParams([
78-
(ConfigurationItem(missing, "julia.format.$opt") for opt in fieldnames(DocumentFormat.FormatOptions))...;
79-
ConfigurationItem(missing, "julia.lint.run");
80-
(ConfigurationItem(missing, "julia.lint.$opt") for opt in fieldnames(StaticLint.LintOptions))...
78+
ConfigurationItem(missing, "julia.format.indent"), # FormatOptions
79+
ConfigurationItem(missing, "julia.format.indents"),
80+
ConfigurationItem(missing, "julia.format.ops"),
81+
ConfigurationItem(missing, "julia.format.tuples"),
82+
ConfigurationItem(missing, "julia.format.curly"),
83+
ConfigurationItem(missing, "julia.format.call"),
84+
ConfigurationItem(missing, "julia.format.iterOps"),
85+
ConfigurationItem(missing, "julia.format.comments"),
86+
ConfigurationItem(missing, "julia.format.docs"),
87+
ConfigurationItem(missing, "julia.format.lineends"),
88+
ConfigurationItem(missing, "julia.format.kw"),
89+
ConfigurationItem(missing, "julia.lint.call"), # LintOptions
90+
ConfigurationItem(missing, "julia.lint.iter"),
91+
ConfigurationItem(missing, "julia.lint.nothingcomp"),
92+
ConfigurationItem(missing, "julia.lint.constif"),
93+
ConfigurationItem(missing, "julia.lint.lazyif"),
94+
ConfigurationItem(missing, "julia.lint.datadecl"),
95+
ConfigurationItem(missing, "julia.lint.typeparam"),
96+
ConfigurationItem(missing, "julia.lint.modname"),
97+
ConfigurationItem(missing, "julia.lint.pirates"),
98+
ConfigurationItem(missing, "julia.lint.useoffuncargs"),
99+
ConfigurationItem(missing, "julia.lint.run"),
100+
ConfigurationItem(missing, "julia.lint.missingrefs")
81101
]))
102+
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])
82107

83-
# TODO Make sure update_julia_config can deal with the response
84-
if length(response) == length(fieldnames(DocumentFormat.FormatOptions)) + 1 + length(fieldnames(StaticLint.LintOptions))
85-
server.format_options = DocumentFormat.FormatOptions(
86-
response[1]===nothing ? 0 : response[1],
87-
response[2]===nothing ? false : response[2],
88-
response[3]===nothing ? false : response[3],
89-
response[4]===nothing ? false : response[4],
90-
response[5]===nothing ? false : response[5],
91-
response[6]===nothing ? false : response[6],
92-
response[7]===nothing ? false : response[7],
93-
response[8]===nothing ? false : response[8],
94-
response[9]===nothing ? false : response[9],
95-
response[10]===nothing ? false : response[10],
96-
response[11]===nothing ? false : response[11])
97-
98-
N = length(fieldnames(DocumentFormat.FormatOptions)) + 1
99-
x = response[N]
100-
new_lint_opts = StaticLint.LintOptions(
101-
response[N + 1]===nothing ? false : response[N + 1],
102-
response[N + 2]===nothing ? false : response[N + 2],
103-
response[N + 3]===nothing ? false : response[N + 3],
104-
response[N + 4]===nothing ? false : response[N + 4],
105-
response[N + 5]===nothing ? false : response[N + 5],
106-
response[N + 6]===nothing ? false : response[N + 6],
107-
response[N + 7]===nothing ? false : response[N + 7],
108-
response[N + 8]===nothing ? false : response[N + 8],
109-
response[N + 9]===nothing ? false : response[N + 9],
110-
response[N + 10]===nothing ? false : response[N + 10],
111-
)
112-
113-
new_run_lint_value = x===nothing ? false : true
114-
if new_run_lint_value != server.runlinter || any(getfield(new_lint_opts, n) != getfield(server.lint_options, n) for n in fieldnames(StaticLint.LintOptions))
115-
server.lint_options = new_lint_opts
116-
server.runlinter = new_run_lint_value
117-
for doc in getdocuments_value(server)
118-
StaticLint.check_all(getcst(doc), server.lint_options, server)
119-
empty!(doc.diagnostics)
120-
mark_errors(doc, doc.diagnostics)
121-
publish_diagnostics(doc, server)
122-
end
108+
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
110+
server.lint_options = new_SL_opts
111+
server.runlinter = new_lintrun
112+
server.lint_missingrefs = new_missingref
113+
114+
if rerun_lint
115+
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)
123120
end
124121
end
122+
125123
end
126124

127125
JSONRPC.parse_params(::Type{Val{Symbol("workspace/didChangeWorkspaceFolders")}}, params) = DidChangeWorkspaceFoldersParams(params)

src/utilities.jl

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,6 @@ const DefaultTypeConstructorLoc= let def = first(methods(Int))
8686
Base.find_source_file(string(def.file)), def.line
8787
end
8888

89-
function is_ignored(uri, server)
90-
fpath = uri2filepath(uri)
91-
fpath in server.ignorelist && return true
92-
for ig in server.ignorelist
93-
if !endswith(ig, ".jl")
94-
if startswith(fpath, ig)
95-
return true
96-
end
97-
end
98-
end
99-
return false
100-
end
101-
102-
is_ignored(uri::URI2, server) = is_ignored(uri._uri, server)
10389

10490
# TODO I believe this will also remove files from documents that were added
10591
# not because they are part of the workspace, but by either StaticLint or

0 commit comments

Comments
 (0)