Skip to content

Commit

Permalink
Merge branch 'master' into fix-expand-function
Browse files Browse the repository at this point in the history
  • Loading branch information
pfitzseb authored Oct 23, 2023
2 parents 8f27280 + 98be4d8 commit 39b8aa9
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 45 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ make use of the Julia Language Server for various code editing features:
- [Sublime Text](https://github.com/tomv564/LSP)
- [Kakoune](../../wiki/Kakoune)
- [Helix](https://uncomfyhalomacro.pl/blog/14/)
- [Kate](../../wiki/Kate)
- [Others](https://microsoft.github.io/language-server-protocol/implementors/tools/)

## Installation and Usage
Expand Down
10 changes: 7 additions & 3 deletions src/languageserverinstance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,15 @@ function relintserver(server)
# only do a pass on documents once
root = getroot(doc)
if !(root in roots)
push!(roots, root)
semantic_pass(root)
if get_language_id(root) in ("julia", "markdown", "juliamarkdown")
push!(roots, root)
semantic_pass(root)
end
end
end
for doc in documents
lint!(doc, server)
if get_language_id(doc) in ("julia", "markdown", "juliamarkdown")
lint!(doc, server)
end
end
end
4 changes: 2 additions & 2 deletions src/requests/features.jl
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ function julia_getDocAt_request(params::VersionedTextDocumentPositionParams, ser

x = get_expr1(getcst(doc), get_offset(doc, params.position))
x isa EXPR && CSTParser.isoperator(x) && resolve_op_ref(x, env)
documentation = get_hover(x, "", server)
documentation = get_hover(x, "", server, x, env)

return documentation
end
Expand All @@ -542,7 +542,7 @@ function julia_getDocFromWord_request(params::NamedTuple{(:word,),Tuple{String}}
# this would ideally use the Damerau-Levenshtein distance or even something fancier:
score = _score(needle, sym)
if score < 2
val = get_hover(val, "", server)
val = get_hover(val, "", server, nothing, getenv(server))
if !isempty(val)
nfound += 1
push!(matches, score => val)
Expand Down
79 changes: 43 additions & 36 deletions src/requests/hover.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,48 +150,55 @@ function get_hover(f::SymbolServer.FunctionStore, documentation::String, server,
end

if expr !== nothing && env !== nothing
method_count = 0
tls = StaticLint.retrieve_toplevel_scope(expr)
itr = func -> StaticLint.iterate_over_ss_methods(f, tls, env, func)
else
itr = func -> begin
for m in f.methods
func(m)
end
end
end

totalio = IOBuffer()
StaticLint.iterate_over_ss_methods(f, tls, env, function (m)
method_count += 1

io = IOBuffer()
print(io, m.name, "(")
nsig = length(m.sig)
for (i, sig) = enumerate(m.sig)
if sig[1] Symbol("#unused#")
print(io, sig[1])
end
print(io, "::", sig[2])
i nsig && print(io, ", ")
method_count = 0
totalio = IOBuffer()
itr() do m
method_count += 1

io = IOBuffer()
print(io, m.name, "(")
nsig = length(m.sig)
for (i, sig) = enumerate(m.sig)
if sig[1] Symbol("#unused#")
print(io, sig[1])
end
print(io, ")")
sig = String(take!(io))

path = replace(m.file, "\\" => "\\\\")
text = string(path, ':', m.line)
link = text

if server.clientInfo !== missing && isabspath(m.file)
clientname = lowercase(server.clientInfo.name)
if occursin("code", clientname) || occursin("sublime", clientname)
link = string(filepath2uri(m.file), "#", m.line)
text = string(basename(path), ':', m.line)
end
print(io, "::", sig[2])
i nsig && print(io, ", ")
end
print(io, ")")
sig = String(take!(io))

path = replace(m.file, "\\" => "\\\\")
text = string(path, ':', m.line)
link = text

if server.clientInfo !== missing && isabspath(m.file)
clientname = lowercase(server.clientInfo.name)
if occursin("code", clientname) || occursin("sublime", clientname)
link = string(filepath2uri(m.file), "#", m.line)
text = string(basename(path), ':', m.line)
end
println(totalio, "$(method_count). `$(sig)` in `$(m.mod)` at [$(text)]($(link))\n")
return false
end)

documentation = string(
documentation,
"`$(f.name)` is a function with **$(method_count)** method$(method_count == 1 ? "" : "s")\n",
String(take!(totalio))
)
end
println(totalio, "$(method_count). `$(sig)` in `$(m.mod)` at [$(text)]($(link))\n")
return false
end

documentation = string(
documentation,
"`$(f.name)` is a function with **$(method_count)** method$(method_count == 1 ? "" : "s")\n",
String(take!(totalio))
)

return documentation
end

Expand Down
8 changes: 5 additions & 3 deletions src/requests/textdocument.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function textDocument_didChange_notification(params::DidChangeTextDocumentParams

if get_language_id(doc) in ("markdown", "juliamarkdown")
parse_all(doc, server)
else
else get_language_id(doc) == "julia"
cst0, cst1 = getcst(doc), CSTParser.parse(get_text(doc), true)
r1, r2, r3 = CSTParser.minimal_reparse(s0, get_text(doc), cst0, cst1, inds = true)
for i in setdiff(1:length(cst0.args), r1 , r3) # clean meta from deleted expr
Expand All @@ -116,10 +116,12 @@ function parse_all(doc::Document, server::LanguageServerInstance)
ps = CSTParser.ParseState(get_text(doc))
doc.cst, ps = CSTParser.parse(ps, true)
end
if t > 10
if t > 1
# warn to help debugging in the wild
@warn "CSTParser took a long time ($(round(Int, t)) seconds) to parse $(repr(getpath(doc)))"
end
else
return
end
sizeof(get_text(doc)) == getcst(doc).fullspan || @error "CST does not match input string length."
if headof(doc.cst) === :file
Expand Down Expand Up @@ -212,7 +214,7 @@ end


function publish_diagnostics(doc::Document, server, conn)
diagnostics = if server.runlinter && server.symbol_store_ready && (is_workspace_file(doc) || isunsavedfile(doc))
diagnostics = if server.runlinter && (is_workspace_file(doc) || isunsavedfile(doc))
pkgpath = getpath(doc)
if any(is_in_target_dir_of_package.(Ref(pkgpath), server.lint_disableddirs))
filter!(!is_diag_dependent_on_env, doc.diagnostics)
Expand Down
2 changes: 1 addition & 1 deletion src/staticlint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function setserver(file::Document, server::LanguageServerInstance)
return file
end

function lint!(doc, server)
function lint!(doc::Document, server)
StaticLint.check_all(getcst(doc), server.lint_options, getenv(doc, server))
empty!(doc.diagnostics)
mark_errors(doc, doc.diagnostics)
Expand Down

0 comments on commit 39b8aa9

Please sign in to comment.