Skip to content

Commit daf31cb

Browse files
committed
LSP: add folding range and selection range protocol types
Add protocol type definitions for LSP folding range and selection range features. These additions include client capabilities, server options, request/response interfaces, and supporting types for both features.
1 parent 987550e commit daf31cb

File tree

4 files changed

+236
-12
lines changed

4 files changed

+236
-12
lines changed

LSP/src/LSP.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ include("language-features/code-action.jl")
2929
include("language-features/inlay-hint.jl")
3030
include("language-features/formatting.jl")
3131
include("language-features/rename.jl")
32+
include("language-features/folding-range.jl")
33+
include("language-features/selection-range.jl")
3234
include("workspace-features/workspace-folders.jl")
3335
include("workspace-features/files.jl")
3436
include("workspace-features/did-change-watched-files.jl")
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
"""
2+
A set of predefined range kinds.
3+
"""
4+
@namespace FoldingRangeKind::String begin
5+
"""
6+
Folding range for a comment
7+
"""
8+
Comment = "comment"
9+
"""
10+
Folding range for imports or includes
11+
"""
12+
Imports = "imports"
13+
"""
14+
Folding range for a region (e.g. `#region`)
15+
"""
16+
Region = "region"
17+
end
18+
19+
@interface FoldingRangeClientCapabilities begin
20+
"""
21+
Whether implementation supports dynamic registration for folding range
22+
providers. If this is set to `true` the client supports the new
23+
`FoldingRangeRegistrationOptions` return value for the corresponding
24+
server capability as well.
25+
"""
26+
dynamicRegistration::Union{Nothing, Bool} = nothing
27+
28+
"""
29+
The maximum number of folding ranges that the client prefers to receive
30+
per document. The value serves as a hint, servers are free to follow the
31+
limit.
32+
"""
33+
rangeLimit::Union{Nothing, UInt} = nothing
34+
35+
"""
36+
If set, the client signals that it only supports folding complete lines.
37+
If set, client will ignore specified `startCharacter` and `endCharacter`
38+
properties in a FoldingRange.
39+
"""
40+
lineFoldingOnly::Union{Nothing, Bool} = nothing
41+
42+
"""
43+
Specific options for the folding range kind.
44+
45+
# Tags
46+
- since - 3.17.0
47+
"""
48+
foldingRangeKind::Union{Nothing, @interface begin
49+
"""
50+
The folding range kind values the client supports. When this
51+
property exists the client also guarantees that it will
52+
handle values outside its set gracefully and falls back
53+
to a default value when unknown.
54+
"""
55+
valueSet::Union{Nothing, Vector{FoldingRangeKind.Ty}} = nothing
56+
end} = nothing
57+
58+
"""
59+
Specific options for the folding range.
60+
61+
# Tags
62+
- since - 3.17.0
63+
"""
64+
foldingRange::Union{Nothing, @interface begin
65+
"""
66+
If set, the client signals that it supports setting collapsedText on
67+
folding ranges to display custom labels instead of the default text.
68+
69+
# Tags
70+
- since - 3.17.0
71+
"""
72+
collapsedText::Union{Nothing, Bool} = nothing
73+
end} = nothing
74+
end
75+
76+
@interface FoldingRangeOptions @extends WorkDoneProgressOptions begin
77+
end
78+
79+
@interface FoldingRangeRegistrationOptions @extends TextDocumentRegistrationOptions, FoldingRangeOptions begin
80+
end
81+
82+
"""
83+
Represents a folding range. To be valid, start and end line must be bigger
84+
than zero and smaller than the number of lines in the document. Clients
85+
are free to ignore invalid ranges.
86+
"""
87+
@interface FoldingRange begin
88+
89+
"""
90+
The zero-based start line of the range to fold. The folded area starts
91+
after the line's last character. To be valid, the end must be zero or
92+
larger and smaller than the number of lines in the document.
93+
"""
94+
startLine::UInt
95+
96+
"""
97+
The zero-based character offset from where the folded range starts. If
98+
not defined, defaults to the length of the start line.
99+
"""
100+
startCharacter::Union{Nothing, UInt} = nothing
101+
102+
"""
103+
The zero-based end line of the range to fold. The folded area ends with
104+
the line's last character. To be valid, the end must be zero or larger
105+
and smaller than the number of lines in the document.
106+
"""
107+
endLine::UInt
108+
109+
"""
110+
The zero-based character offset before the folded range ends. If not
111+
defined, defaults to the length of the end line.
112+
"""
113+
endCharacter::Union{Nothing, UInt} = nothing
114+
115+
"""
116+
Describes the kind of the folding range such as `comment` or `region`.
117+
The kind is used to categorize folding ranges and used by commands like
118+
'Fold all comments'. See [FoldingRangeKind](#FoldingRangeKind) for an
119+
enumeration of standardized kinds.
120+
"""
121+
kind::Union{Nothing, FoldingRangeKind.Ty} = nothing
122+
123+
"""
124+
The text that the client should show when the specified range is
125+
collapsed. If not defined or not supported by the client, a default
126+
will be chosen by the client.
127+
128+
# Tags
129+
- since - 3.17.0 - proposed
130+
"""
131+
collapsedText::Union{Nothing, String} = nothing
132+
end
133+
134+
@interface FoldingRangeParams @extends WorkDoneProgressParams, PartialResultParams begin
135+
"""
136+
The text document.
137+
"""
138+
textDocument::TextDocumentIdentifier
139+
end
140+
141+
"""
142+
The folding range request is sent from the client to the server to return all
143+
folding ranges found in a given text document.
144+
145+
# Tags
146+
- since - 3.10.0
147+
"""
148+
@interface FoldingRangeRequest @extends RequestMessage begin
149+
method::String = "textDocument/foldingRange"
150+
params::FoldingRangeParams
151+
end
152+
153+
@interface FoldingRangeResponse @extends ResponseMessage begin
154+
result::Union{Vector{FoldingRange}, Null, Nothing}
155+
end
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
@interface SelectionRangeClientCapabilities begin
2+
"""
3+
Whether implementation supports dynamic registration for selection range
4+
providers. If this is set to `true` the client supports the new
5+
`SelectionRangeRegistrationOptions` return value for the corresponding
6+
server capability as well.
7+
"""
8+
dynamicRegistration::Union{Nothing, Bool} = nothing
9+
end
10+
11+
@interface SelectionRangeOptions @extends WorkDoneProgressOptions begin
12+
end
13+
14+
@interface SelectionRangeRegistrationOptions @extends TextDocumentRegistrationOptions, SelectionRangeOptions begin
15+
end
16+
17+
@interface SelectionRangeParams @extends WorkDoneProgressParams, PartialResultParams begin
18+
"""
19+
The text document.
20+
"""
21+
textDocument::TextDocumentIdentifier
22+
23+
"""
24+
The positions inside the text document.
25+
"""
26+
positions::Vector{Position}
27+
end
28+
29+
@interface SelectionRange begin
30+
"""
31+
The [`Range`](@ref) of this selection range.
32+
"""
33+
range::Range
34+
35+
"""
36+
The parent selection range containing this range. Therefore
37+
`parent.range` must contain `this.range`.
38+
"""
39+
parent::Union{Nothing, SelectionRange} = nothing
40+
end
41+
42+
"""
43+
The selection range request is sent from the client to the server to return
44+
suggested selection ranges at an array of given positions. A selection range is
45+
a range around the cursor position which the user might be interested in
46+
selecting.
47+
48+
A selection range in the return array is for the position in the provided
49+
parameters at the same index. Therefore `positions[i]` must be contained in
50+
`result[i].range`. To allow for results where some positions have selection
51+
ranges and others do not, `result[i].range` is allowed to be the empty range at
52+
`positions[i]`.
53+
54+
Typically, but not necessary, selection ranges correspond to the nodes of the
55+
syntax tree.
56+
57+
# Tags
58+
- since - 3.15.0
59+
"""
60+
@interface SelectionRangeRequest @extends RequestMessage begin
61+
method::String = "textDocument/selectionRange"
62+
params::SelectionRangeParams
63+
end
64+
65+
@interface SelectionRangeResponse @extends ResponseMessage begin
66+
result::Union{Vector{SelectionRange}, Null, Nothing}
67+
end

LSP/src/lifecycle-messages/initialize.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,26 +135,26 @@
135135
"""
136136
renameProvider::Union{Nothing, Bool, RenameOptions} = nothing
137137

138-
# """
139-
# The server provides folding provider support.
138+
"""
139+
The server provides folding provider support.
140140
141-
# # Tags
142-
# - since - 3.10.0
143-
# """
144-
# foldingRangeProvider::Union{Nothing, Bool, FoldingRangeOptions, FoldingRangeRegistrationOptions} = nothing
141+
# Tags
142+
- since - 3.10.0
143+
"""
144+
foldingRangeProvider::Union{Nothing, Bool, FoldingRangeOptions, FoldingRangeRegistrationOptions} = nothing
145145

146146
"""
147147
The server provides execute command support.
148148
"""
149149
executeCommandProvider::Union{Nothing, ExecuteCommandOptions} = nothing
150150

151-
# """
152-
# The server provides selection range support.
151+
"""
152+
The server provides selection range support.
153153
154-
# # Tags
155-
# - since - 3.15.0
156-
# """
157-
# selectionRangeProvider::Union{Nothing, Bool, SelectionRangeOptions, SelectionRangeRegistrationOptions} = nothing
154+
# Tags
155+
- since - 3.15.0
156+
"""
157+
selectionRangeProvider::Union{Nothing, Bool, SelectionRangeOptions, SelectionRangeRegistrationOptions} = nothing
158158

159159
# """
160160
# The server provides linked editing range support.

0 commit comments

Comments
 (0)