Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions src/JETLS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
mutable struct FullAnalysisResult
staled::Bool
last_analysis::Float64
actual2virtual::JET.Actual2Virtual
const uri2diagnostics::Dict{URI,Vector{Diagnostic}}
const analyzed_file_infos::Dict{URI,JET.AnalyzedFileInfo}
const successfully_analyzed_file_infos::Dict{URI,JET.AnalyzedFileInfo}
Expand Down Expand Up @@ -117,9 +118,14 @@
end
end

const DEFAULT_DOCUMENT_SELECTOR = DocumentFilter[
DocumentFilter(; language = "julia")
]

include("utils.jl")
include("registration.jl")
include("completions.jl")
include("signature-help.jl")
include("diagnostics.jl")

"""
Expand Down Expand Up @@ -247,6 +253,8 @@
return handle_CompletionRequest(server, msg)
elseif msg isa CompletionResolveRequest
return handle_CompletionResolveRequest(server, msg)
elseif msg isa SignatureHelpRequest
return handle_SignatureHelpRequest(server, msg)
elseif JETLS_DEV_MODE
if isdefined(msg, :method)
id = getfield(msg, :method)
Expand Down Expand Up @@ -314,12 +322,22 @@
:textDocument, :completion, :dynamicRegistration) !== true
completionProvider = completion_options()
if JETLS_DEV_MODE
@info "Registering completion with `InitializeResponse`"
@info "Registering 'textDocument/completion' with `InitializeResponse`"
end
else
completionProvider = nothing # will be registered dynamically
end

if getpath(params.capabilities,
:textDocument, :signatureHelp, :dynamicRegistration) !== true
signatureHelpProvider = signature_help_options()
if JETLS_DEV_MODE
@info "Registering 'textDocument/signatureHelp' with `InitializeResponse`"
end
else
signatureHelpProvider = nothing # will be registered dynamically

Check warning on line 338 in src/JETLS.jl

View check run for this annotation

Codecov / codecov/patch

src/JETLS.jl#L338

Added line #L338 was not covered by tests
end

result = InitializeResult(;
capabilities = ServerCapabilities(;
positionEncoding = PositionEncodingKind.UTF16,
Expand All @@ -329,6 +347,7 @@
save = SaveOptions(;
includeText = true)),
completionProvider,
signatureHelpProvider,
),
serverInfo = (;
name = "JETLS",
Expand Down Expand Up @@ -357,14 +376,26 @@
:textDocument, :completion, :dynamicRegistration) === true
push!(registrations, completion_registration())
if JETLS_DEV_MODE
@info "Dynamically registering completion upon `InitializedNotification`"
@info "Dynamically registering 'textDocument/completion' upon `InitializedNotification`"
end
else
# NOTE If completion's `dynamicRegistration` is not supported,
# it needs to be registered along with initialization in the `InitializeResponse`,
# since `CompletionRegistrationOptions` does not extend `StaticRegistrationOptions`.
end

if getpath(state.init_params.capabilities,
:textDocument, :signatureHelp, :dynamicRegistration) === true
push!(registrations, signature_help_registration())
if JETLS_DEV_MODE
@info "Dynamically registering 'textDocument/signatureHelp' upon `InitializedNotification`"

Check warning on line 391 in src/JETLS.jl

View check run for this annotation

Codecov / codecov/patch

src/JETLS.jl#L389-L391

Added lines #L389 - L391 were not covered by tests
end
else
# NOTE If completion's `dynamicRegistration` is not supported,
# it needs to be registered along with initialization in the `InitializeResponse`,
# since `SignatureHelpRegistrationOptions` does not extend `StaticRegistrationOptions`.
end

register(server, registrations)
end

Expand Down Expand Up @@ -500,7 +531,7 @@
uri2diagnostics = jet_result_to_diagnostics(keys(analyzed_file_infos), result)
successfully_analyzed_file_infos = copy(analyzed_file_infos)
is_full_analysis_successful(result) || empty!(successfully_analyzed_file_infos)
analysis_result = FullAnalysisResult(false, time(), uri2diagnostics, analyzed_file_infos, successfully_analyzed_file_infos)
analysis_result = FullAnalysisResult(false, time(), result.res.actual2virtual, uri2diagnostics, analyzed_file_infos, successfully_analyzed_file_infos)
return AnalysisContext(entry, analysis_result)
end

Expand Down Expand Up @@ -528,6 +559,9 @@
jet_result_to_diagnostics!(uri2diagnostics, result)
analysis_context.result.staled = false
analysis_context.result.last_analysis = time()
if is_full_analysis_successful(result)
analysis_context.result.actual2virtual = result.res.actual2virtual
end
end

# TODO This reverse map recording should respect the changes made in `include` chains
Expand Down
1 change: 1 addition & 0 deletions src/LSP/LSP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ include("lifecycle-messages/exit.jl")
include("document-synchronization.jl")
include("language-features/diagnostics.jl")
include("language-features/completions.jl")
include("language-features/signature-help.jl")
include("workspace-features/workspace-folders.jl")
include("workspace-features/files.jl")
include("capabilities.jl")
Expand Down
10 changes: 6 additions & 4 deletions src/LSP/capabilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

completionProvider::Union{CompletionOptions, Nothing} = nothing

signatureHelpProvider::Union{SignatureHelpOptions, Nothing} = nothing

"Workspace specific server capabilities"
workspace::Union{Nothing, @interface begin
"""
Expand Down Expand Up @@ -80,10 +82,10 @@ end
# """
# hover::Union{HoverClientCapabilities, Nothing} = nothing

# """
# Capabilities specific to the `textDocument/signatureHelp` request.
# """
# signatureHelp::Union{SignatureHelpClientCapabilities, Nothing} = nothing
"""
Capabilities specific to the `textDocument/signatureHelp` request.
"""
signatureHelp::Union{SignatureHelpClientCapabilities, Nothing} = nothing

# """
# Capabilities specific to the `textDocument/declaration` request.
Expand Down
255 changes: 255 additions & 0 deletions src/LSP/language-features/signature-help.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
@interface SignatureHelpClientCapabilities begin
"""

Check warning on line 2 in src/LSP/language-features/signature-help.jl

View check run for this annotation

Codecov / codecov/patch

src/LSP/language-features/signature-help.jl#L2

Added line #L2 was not covered by tests
Whether signature help supports dynamic registration.
"""
dynamicRegistration::Union{Nothing, Bool} = nothing

"""
The client supports the following `SignatureInformation`
specific properties.
"""
signatureInformation::Union{Nothing, @interface begin
"""

Check warning on line 12 in src/LSP/language-features/signature-help.jl

View check run for this annotation

Codecov / codecov/patch

src/LSP/language-features/signature-help.jl#L12

Added line #L12 was not covered by tests
Client supports the follow content formats for the documentation
property. The order describes the preferred format of the client.
"""
documentationFormat::Union{Nothing, Vector{MarkupKind.Ty}} = nothing

"""
Client capabilities specific to parameter information.
"""
parameterInformation::Union{Nothing, @interface begin
"""

Check warning on line 22 in src/LSP/language-features/signature-help.jl

View check run for this annotation

Codecov / codecov/patch

src/LSP/language-features/signature-help.jl#L22

Added line #L22 was not covered by tests
The client supports processing label offsets instead of a
simple label string.

# Tags
- since - 3.14.0
"""
labelOffsetSupport::Union{Nothing, Bool} = nothing
end} = nothing

"""
The client supports the `activeParameter` property on
`SignatureInformation` literal.

# Tags
- since - 3.16.0
"""
activeParameterSupport::Union{Nothing, Bool} = nothing
end} = nothing

"""
The client supports to send additional context information for a
`textDocument/signatureHelp` request. A client that opts into
contextSupport will also support the `retriggerCharacters` on
`SignatureHelpOptions`.

# Tags
- since - 3.15.0
"""
contextSupport::Union{Nothing, Bool} = nothing
end

@interface SignatureHelpOptions @extends WorkDoneProgressOptions begin
"""
The characters that trigger signature help
automatically.
"""
triggerCharacters::Union{Nothing, Vector{String}} = nothing

"""
List of characters that re-trigger signature help.

These trigger characters are only active when signature help is already
showing. All trigger characters are also counted as re-trigger
characters.

# Tags
- since - 3.15.0
"""
retriggerCharacters::Union{Nothing, Vector{String}} = nothing
end

@interface SignatureHelpRegistrationOptions @extends TextDocumentRegistrationOptions, SignatureHelpOptions begin
end

"""
How a signature help was triggered.

# Tags
- since - 3.15.0
"""
@namespace SignatureHelpTriggerKind::Int begin
"""
Signature help was invoked manually by the user or by a command.
"""
Invoked = 1
"""
Signature help was triggered by a trigger character.
"""
TriggerCharacter = 2
"""
Signature help was triggered by the cursor moving or by the document
content changing.
"""
ContentChange = 3
end

"""
Represents a parameter of a callable-signature. A parameter can
have a label and a doc-comment.
"""
@interface ParameterInformation begin

"""
The label of this parameter information.

Either a string or an inclusive start and exclusive end offsets within
its containing signature label. (see SignatureInformation.label). The
offsets are based on a UTF-16 string representation as `Position` and
`Range` does.

*Note*: a label of type string should be a substring of its containing
signature label. Its intended use case is to highlight the parameter
label part in the `SignatureInformation.label`.
"""
label::Union{String, Vector{UInt}} # vector should have length 2

"""
The human-readable doc-comment of this parameter. Will be shown
in the UI but can be omitted.
"""
documentation::Union{Nothing, String, MarkupContent} = nothing
end

"""
Represents the signature of something callable. A signature
can have a label, like a function-name, a doc-comment, and
a set of parameters.
"""
@interface SignatureInformation begin
"""
The label of this signature. Will be shown in
the UI.
"""
label::String

"""
The human-readable doc-comment of this signature. Will be shown
in the UI but can be omitted.
"""
documentation::Union{Nothing, String, MarkupContent} = nothing

"""
The parameters of this signature.
"""
parameters::Union{Nothing, Vector{ParameterInformation}} = nothing

"""
The index of the active parameter.

If provided, this is used in place of `SignatureHelp.activeParameter`.

# Tags
- since - 3.16.0
"""
activeParameter::Union{Nothing, UInt} = nothing
end

"""
Signature help represents the signature of something
callable. There can be multiple signature but only one
active and only one active parameter.
"""
@interface SignatureHelp begin
"""
One or more signatures. If no signatures are available the signature help
request should return `null`.
"""
signatures::Vector{SignatureInformation}

"""
The active signature. If omitted or the value lies outside the
range of `signatures` the value defaults to zero or is ignore if
the `SignatureHelp` as no signatures.

Whenever possible implementors should make an active decision about
the active signature and shouldn't rely on a default value.

In future version of the protocol this property might become
mandatory to better express this.
"""
activeSignature::Union{Nothing, UInt} = nothing

"""
The active parameter of the active signature. If omitted or the value
lies outside the range of `signatures[activeSignature].parameters`
defaults to 0 if the active signature has parameters. If
the active signature has no parameters it is ignored.
In future version of the protocol this property might become
mandatory to better express the active parameter if the
active signature does have any.
"""
activeParameter::Union{Nothing, UInt} = nothing
end

"""
Additional information about the context in which a signature help request
was triggered.

# Tags
- since - 3.15.0
"""
@interface SignatureHelpContext begin
"""
Action that caused signature help to be triggered.
"""
triggerKind::SignatureHelpTriggerKind.Ty

"""
Character that caused signature help to be triggered.

This is undefined when triggerKind !==
SignatureHelpTriggerKind.TriggerCharacter
"""
triggerCharacter::Union{Nothing, String} = nothing

"""
`true` if signature help was already showing when it was triggered.

Retriggers occur when the signature help is already active and can be
caused by actions such as typing a trigger character, a cursor move, or
document content changes.
"""
isRetrigger::Bool

"""
The currently active `SignatureHelp`.

The `activeSignatureHelp` has its `SignatureHelp.activeSignature` field
updated based on the user navigating through available signatures.
"""
activeSignatureHelp::Union{Nothing, SignatureHelp} = nothing
end

@interface SignatureHelpParams @extends TextDocumentPositionParams, WorkDoneProgressParams begin
"""
The signature help context. This is only available if the client
specifies to send this using the client capability
`textDocument.signatureHelp.contextSupport === true`

# Tags
- since - 3.15.0
"""
context::Union{Nothing, SignatureHelpContext} = nothing
end

@interface SignatureHelpRequest @extends RequestMessage begin
method::String = "textDocument/signatureHelp"
params::SignatureHelpParams
end

@interface SignatureHelpResponse @extends ResponseMessage begin
result::Union{SignatureHelp, Null}
end
Loading