From 8d99754dc90f0a60e69f9317fae1c32c9ba91cf2 Mon Sep 17 00:00:00 2001 From: ZacNugent Date: Wed, 26 Feb 2020 23:22:46 +0000 Subject: [PATCH 1/5] initial commit --- src/languageserverinstance.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/languageserverinstance.jl b/src/languageserverinstance.jl index 563d7136..baba5ae2 100644 --- a/src/languageserverinstance.jl +++ b/src/languageserverinstance.jl @@ -39,6 +39,7 @@ mutable struct LanguageServerInstance symbol_results_channel::Channel{Any} symbol_store::Dict{String,SymbolServer.ModuleStore} symbol_store_ready::Bool + workspacepackages::Dict{String,StaticLint.Binding} # ss_task::Union{Nothing,Future} format_options::DocumentFormat.FormatOptions lint_options::StaticLint.LintOptions @@ -70,6 +71,7 @@ mutable struct LanguageServerInstance Channel(Inf), deepcopy(SymbolServer.stdlibs), false, + Dict{String,StaticLint.Binding}(), DocumentFormat.FormatOptions(), StaticLint.LintOptions(), Channel{Any}(Inf), From c1a51ac74421cf32edc27a7759376b249c694369 Mon Sep 17 00:00:00 2001 From: ZacNugent Date: Sat, 14 Mar 2020 11:32:46 +0000 Subject: [PATCH 2/5] wip --- src/languageserverinstance.jl | 18 ++++++++++++++++-- src/requests/completions.jl | 10 ++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/languageserverinstance.jl b/src/languageserverinstance.jl index 2755d19f..4149d1f5 100644 --- a/src/languageserverinstance.jl +++ b/src/languageserverinstance.jl @@ -39,7 +39,7 @@ mutable struct LanguageServerInstance symbol_results_channel::Channel{Any} symbol_store::Dict{String,SymbolServer.ModuleStore} symbol_store_ready::Bool - workspacepackages::Dict{String,StaticLint.Binding} + workspacepackages::Dict{String,Document} # ss_task::Union{Nothing,Future} format_options::DocumentFormat.FormatOptions lint_options::StaticLint.LintOptions @@ -71,7 +71,7 @@ mutable struct LanguageServerInstance Channel(Inf), deepcopy(SymbolServer.stdlibs), false, - Dict{String,StaticLint.Binding}(), + Dict{String,Document}(), DocumentFormat.FormatOptions(), StaticLint.LintOptions(), Channel{Any}(Inf), @@ -112,6 +112,20 @@ end function setdocument!(server::LanguageServerInstance, uri::URI2, doc::Document) server._documents[uri] = doc + # Add possible workspace packages + path = uri2filepath(uri._uri) + for wk_folder in server.workspaceFolders + if startswith(path, wk_folder) + sub_path = splitpath(path) + first(sub_path) == "/" && popfirst!(sub_path) + length(sub_path) < 3 && continue + fname = splitext(last(sub_path))[1] + if sub_path[end-1] == "src" && sub_path[end-2] == fname + server.workspacepackages[fname] = doc + end + end + end + return doc end function deletedocument!(server::LanguageServerInstance, uri::URI2) diff --git a/src/requests/completions.jl b/src/requests/completions.jl index 9ca3f282..810b6472 100644 --- a/src/requests/completions.jl +++ b/src/requests/completions.jl @@ -334,6 +334,11 @@ function import_completions(doc, offset, rng, ppt, pt, t, is_at_end ,x, CIs, ser end end else + for (n,doc1) in server.workspacepackages + if StaticLint.has_workspace_package(server, n) + push!(CIs, CompletionItem(n, 9, MarkupContent("Workspace package: $n"), TextEdit(rng, n))) + end + end for (n,m) in StaticLint.getsymbolserver(server) startswith(n, ".") && continue push!(CIs, CompletionItem(n, 9, MarkupContent(sanitize_docstring(m.doc)), TextEdit(rng, n))) @@ -363,6 +368,11 @@ function import_completions(doc, offset, rng, ppt, pt, t, is_at_end ,x, CIs, ser end end else + for (n,doc1) in server.workspacepackages + if startswith(n, t.val) && StaticLint.has_workspace_package(server, n) + push!(CIs, CompletionItem(n, 9, MarkupContent("Workspace package: $n"), TextEdit(rng, n[nextind(n,sizeof(t.val)):end]))) # AUDIT: nextind(n,sizeof(n)) equiv to nextind(n, lastindex(n)) + end + end for (n,m) in StaticLint.getsymbolserver(server) if startswith(n, t.val) push!(CIs, CompletionItem(n, 9, MarkupContent(m isa SymbolServer.SymStore ? m.doc : n), TextEdit(rng, n[nextind(n,sizeof(t.val)):end]))) # AUDIT: nextind(n,sizeof(n)) equiv to nextind(n, lastindex(n)) From 569b6538b9781b60ac25b1bca9a79849881a9b5a Mon Sep 17 00:00:00 2001 From: ZacNugent Date: Sat, 14 Mar 2020 20:17:05 +0000 Subject: [PATCH 3/5] remove doc refs from workspacepackages on deletedoc --- src/languageserverinstance.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/languageserverinstance.jl b/src/languageserverinstance.jl index 4149d1f5..077ad887 100644 --- a/src/languageserverinstance.jl +++ b/src/languageserverinstance.jl @@ -129,6 +129,13 @@ function setdocument!(server::LanguageServerInstance, uri::URI2, doc::Document) end function deletedocument!(server::LanguageServerInstance, uri::URI2) + # clear reference to doc from workspacepackages + for (n,d) in server.workspacepackages + if d._uri == uri._uri + delete!(server.workspacepackages, n) + break + end + end delete!(server._documents, uri) end From ebbe86ae48627e0ae826a6a23947113138ec30c7 Mon Sep 17 00:00:00 2001 From: ZacNugent Date: Tue, 28 Apr 2020 11:02:22 +0100 Subject: [PATCH 4/5] fix some completions --- src/requests/completions.jl | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/requests/completions.jl b/src/requests/completions.jl index 5e0c9923..e72faad3 100644 --- a/src/requests/completions.jl +++ b/src/requests/completions.jl @@ -227,33 +227,35 @@ function is_rebinding_of_module(x) StaticLint.hasref(refof(x).val.args[3]) && refof(refof(x).val.args[3]).type === StaticLint.CoreTypes.Module && refof(refof(x).val.args[3]).val isa EXPR && typof(refof(refof(x).val.args[3]).val) === CSTParser.ModuleH# double check the rhs points to a module end +get_overlapped_binding(b::StaticLint.Binding) = b.val isa StaticLint.Binding ? get_overlapped_binding(b.val) : b function _get_dot_completion(px, spartial, rng, CIs, server) end function _get_dot_completion(px::EXPR, spartial, rng, CIs, server) if px !== nothing if refof(px) isa StaticLint.Binding - if refof(px).val isa StaticLint.SymbolServer.ModuleStore - collect_completions(refof(px).val, spartial, rng, CIs, server, true) - elseif refof(px).val isa EXPR && typof(refof(px).val) === CSTParser.ModuleH && scopeof(refof(px).val) isa StaticLint.Scope - collect_completions(scopeof(refof(px).val), spartial, rng, CIs, server, true) + binding = get_overlapped_binding(refof(px)) + if binding.val isa StaticLint.SymbolServer.ModuleStore + collect_completions(binding.val, spartial, rng, CIs, server, true) + elseif binding.val isa EXPR && typof(binding.val) === CSTParser.ModuleH && scopeof(binding.val) isa StaticLint.Scope + collect_completions(scopeof(binding.val), spartial, rng, CIs, server, true) elseif is_rebinding_of_module(px) collect_completions(scopeof(refof(refof(px).val.args[3]).val), spartial, rng, CIs, server, true) - elseif refof(px).type isa SymbolServer.DataTypeStore - for a in refof(px).type.fieldnames + elseif binding.type isa SymbolServer.DataTypeStore + for a in binding.type.fieldnames a = String(a) if startswith(a, spartial) push!(CIs, CompletionItem(a, 2, MarkupContent(a), TextEdit(rng, a[nextind(a,sizeof(spartial)):end]))) # AUDIT: nextind(n,sizeof(n)) equiv to nextind(n, lastindex(n)) end end - elseif refof(px).type isa StaticLint.Binding && refof(px).type.val isa SymbolServer.DataTypeStore - for a in refof(px).type.val.fieldnames + elseif binding.type isa StaticLint.Binding && binding.type.val isa SymbolServer.DataTypeStore + for a in binding.type.val.fieldnames a = String(a) if startswith(a, spartial) push!(CIs, CompletionItem(a, 2, MarkupContent(a), TextEdit(rng, a[nextind(a,sizeof(spartial)):end]))) # AUDIT: nextind(n,sizeof(n)) equiv to nextind(n, lastindex(n)) end end - elseif refof(px).type isa StaticLint.Binding && refof(px).type.val isa EXPR && CSTParser.defines_struct(refof(px).type.val) && scopeof(refof(px).type.val) isa StaticLint.Scope - collect_completions(scopeof(refof(px).type.val), spartial, rng, CIs, server, true) + elseif binding.type isa StaticLint.Binding && binding.type.val isa EXPR && CSTParser.defines_struct(binding.type.val) && scopeof(binding.type.val) isa StaticLint.Scope + collect_completions(scopeof(binding.type.val), spartial, rng, CIs, server, true) end elseif refof(px) isa StaticLint.SymbolServer.ModuleStore collect_completions(refof(px), spartial, rng, CIs, server, true) From a0c3147b360eac58b207e48a252d85f372ae15f2 Mon Sep 17 00:00:00 2001 From: ZacNugent Date: Mon, 4 May 2020 07:56:48 +0100 Subject: [PATCH 5/5] tighten live package identification --- src/languageserverinstance.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/languageserverinstance.jl b/src/languageserverinstance.jl index d11515a9..85a29427 100644 --- a/src/languageserverinstance.jl +++ b/src/languageserverinstance.jl @@ -119,12 +119,13 @@ function setdocument!(server::LanguageServerInstance, uri::URI2, doc::Document) # Add possible workspace packages path = uri2filepath(uri._uri) for wk_folder in server.workspaceFolders - if startswith(path, wk_folder) + if startswith(path, wk_folder) && normpath(wk_folder) == normpath(server.env_path) sub_path = splitpath(path) first(sub_path) == "/" && popfirst!(sub_path) length(sub_path) < 3 && continue fname = splitext(last(sub_path))[1] if sub_path[end-1] == "src" && sub_path[end-2] == fname + @info "Setting $path as source of 'live' package" server.workspacepackages[fname] = doc end end