Skip to content

Commit a454535

Browse files
committed
Step into LSP 3.x.
1 parent 71aa252 commit a454535

File tree

2 files changed

+223
-4
lines changed

2 files changed

+223
-4
lines changed

LanguageServer.VsCode/Contracts/InitializationRequest.cs

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ public class TextDocumentCapability
136136
/// The server provides hover support.
137137
/// </summary>
138138
[JsonProperty]
139-
public DynamicClientCapability Hover { get; set; }
139+
public TextDocumentHoverCapability Hover { get; set; }
140140

141141
/// <summary>
142142
/// The server provides signature help support.
143143
/// </summary>
144144
[JsonProperty]
145-
public DynamicClientCapability SignatureHelp { get; set; }
145+
public TextDocumentSignatureHelpCapability SignatureHelp { get; set; }
146146

147147
/// <summary>
148148
/// The server provides goto definition support.
@@ -237,12 +237,26 @@ public class TextDocumentSynchronizationCapability : DynamicClientCapability
237237

238238
public class TextDocumentCompletionCapability : DynamicClientCapability
239239
{
240+
241+
/// <summary>
242+
/// The client supports the following <see cref="Contracts.CompletionItem"/> specific capabilities.
243+
/// </summary>
240244
[JsonProperty]
241-
public TextDocumentCompletionCapabilityItem CompletionItem { get; set; }
245+
public TextDocumentCompletionItemCapability CompletionItem { get; set; }
246+
247+
[JsonProperty]
248+
public TextDocumentCompletionItemKindCapability CompletionItemKind { get; set; }
249+
250+
/// <summary>
251+
/// The client supports to send additional context information for a
252+
/// <c>textDocument/completion</c> request.
253+
/// </summary>
254+
[JsonProperty]
255+
public bool ContextSupport { get; set; }
242256
}
243257

244258
[JsonObject(MemberSerialization.OptIn)]
245-
public class TextDocumentCompletionCapabilityItem
259+
public class TextDocumentCompletionItemCapability
246260
{
247261
/// <summary>
248262
/// Client supports snippets as insert text.
@@ -255,5 +269,74 @@ public class TextDocumentCompletionCapabilityItem
255269
/// </remarks>
256270
[JsonProperty]
257271
public bool SnippetSupport { get; set; }
272+
273+
/// <summary>Client supports commit <see cref="CompletionItem.CommitCharacters"/> on a completion item.</summary>
274+
[JsonProperty]
275+
public bool CommitCharactersSupport { get; set; }
276+
277+
/// <summary>
278+
/// Client supports the follow content formats for the documentation
279+
/// property.The order describes the preferred format of the client.
280+
/// </summary>
281+
[JsonProperty]
282+
public IList<MarkupKind> DocumentationFormat { get; set; }
283+
}
284+
285+
[JsonObject(MemberSerialization.OptIn)]
286+
public class TextDocumentCompletionItemKindCapability
287+
{
288+
/// <summary>
289+
/// The completion item kind values the client supports. When this
290+
/// property exists the client also guarantees that it will
291+
/// handle values outside its set gracefully and falls back
292+
/// to a default value when unknown.
293+
/// </summary>
294+
/// <remarks>
295+
/// If this property is not present, the client only supports
296+
/// the completion items kinds from `Text` to `Reference` as defined in
297+
/// the initial version of the protocol.
298+
/// </remarks>
299+
[JsonProperty]
300+
public IEnumerable<CompletionItemKind> ValueSet { get; set; }
301+
258302
}
303+
304+
/// <summary>
305+
/// Capabilities specific to the `textDocument/hover`.
306+
/// </summary>
307+
[JsonObject(MemberSerialization.OptIn)]
308+
public class TextDocumentHoverCapability : DynamicClientCapability
309+
{
310+
/// <summary>
311+
/// Client supports the follow content formats for the content property.
312+
/// The order describes the preferred format of the client.
313+
/// </summary>
314+
[JsonProperty]
315+
public IList<MarkupKind> ContentFormat { get; set; }
316+
}
317+
318+
/// <summary>
319+
/// Capabilities specific to the `textDocument/signatureHelp`.
320+
/// </summary>
321+
[JsonObject(MemberSerialization.OptIn)]
322+
public class TextDocumentSignatureHelpCapability : DynamicClientCapability
323+
{
324+
/// <summary>
325+
/// The client supports the following <see cref="SignatureInformation"/> specific properties.
326+
/// </summary>
327+
[JsonProperty]
328+
public TextDocumentSignatureInformationCapability SignatureInformation { get; set; }
329+
}
330+
331+
[JsonObject(MemberSerialization.OptIn)]
332+
public class TextDocumentSignatureInformationCapability
333+
{
334+
/// <summary>
335+
/// Client supports the follow content formats for the documentation
336+
/// property. The order describes the preferred format of the client.
337+
/// </summary>
338+
[JsonProperty]
339+
public IList<MarkupKind> DocumentationFormat { get; set; }
340+
}
341+
259342
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Newtonsoft.Json;
5+
6+
namespace LanguageServer.VsCode.Contracts
7+
{
8+
/// <summary>
9+
/// A `MarkupContent` literal represents a string value which content is interpreted base on its
10+
/// kind flag. Currently the protocol supports <c>plaintext</c> and <c>markdown</c> as markup kinds.
11+
/// If the kind is `markdown` then the value can contain fenced code blocks like in GitHub issues.
12+
/// See <a href="https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting">https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting</a>.
13+
/// </summary>
14+
[JsonObject]
15+
public class MarkupContent
16+
{
17+
18+
/// <exception cref="ArgumentNullException"><paramref name="kind"/> is <c>null</c>.</exception>
19+
public MarkupContent(MarkupKind kind, string value)
20+
{
21+
Kind = kind ?? throw new ArgumentNullException(nameof(kind));
22+
Value = value;
23+
}
24+
25+
/// <summary>The type of the Markup.</summary>
26+
[JsonProperty]
27+
public MarkupKind Kind { get; }
28+
29+
/// <summary>The content itself.</summary>
30+
[JsonProperty]
31+
public string Value { get; }
32+
33+
}
34+
35+
/// <summary>
36+
/// Describes the content type that a client supports in various
37+
/// result literals like <see cref="Hover"/>, <see cref="ParameterInformation"/> or <see cref="CompletionItem"/>.
38+
/// </summary>
39+
/// <remarks>
40+
/// Please note that <see cref="MarkupKind"/> must not start with a `$`. This kinds
41+
/// are reserved for internal usage.
42+
/// </remarks>
43+
[JsonConverter(typeof(MarkupKindJsonConverter))]
44+
public sealed class MarkupKind : IEquatable<MarkupKind>
45+
{
46+
47+
/// <summary>
48+
/// Plain text is supported as a content format.
49+
/// </summary>
50+
public static MarkupKind PlainText{ get; } = new MarkupKind("plaintext");
51+
52+
/// <summary>
53+
/// Markdown is supported as a content format.
54+
/// </summary>
55+
public static MarkupKind Markdown { get; } = new MarkupKind("markdown");
56+
57+
public MarkupKind(string value)
58+
{
59+
Value = value;
60+
}
61+
62+
/// <summary>
63+
/// Gets the string representation of the markup kind.
64+
/// </summary>
65+
public string Value { get; }
66+
67+
/// <inheritdoc />
68+
public override string ToString()
69+
{
70+
return Value;
71+
}
72+
73+
/// <inheritdoc />
74+
public bool Equals(MarkupKind other)
75+
{
76+
if (ReferenceEquals(null, other)) return false;
77+
if (ReferenceEquals(this, other)) return true;
78+
return string.Equals(Value, other.Value);
79+
}
80+
81+
/// <inheritdoc />
82+
public override bool Equals(object obj)
83+
{
84+
if (ReferenceEquals(null, obj)) return false;
85+
if (ReferenceEquals(this, obj)) return true;
86+
return obj is MarkupKind && Equals((MarkupKind)obj);
87+
}
88+
89+
/// <inheritdoc />
90+
public override int GetHashCode()
91+
{
92+
return Value.GetHashCode();
93+
}
94+
95+
public static bool operator ==(MarkupKind left, MarkupKind right)
96+
{
97+
return Equals(left, right);
98+
}
99+
100+
public static bool operator !=(MarkupKind left, MarkupKind right)
101+
{
102+
return !Equals(left, right);
103+
}
104+
}
105+
106+
/// <summary>
107+
/// Used to convert <see cref="MarkupKind"/> into JSON.
108+
/// </summary>
109+
public class MarkupKindJsonConverter : JsonConverter
110+
{
111+
112+
/// <inheritdoc />
113+
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
114+
{
115+
var v = (MarkupKind)value;
116+
writer.WriteValue(v);
117+
}
118+
119+
/// <inheritdoc />
120+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
121+
{
122+
var v = reader.ReadAsString();
123+
if (v == null) return null;
124+
if (v == "plaintext") return MarkupKind.PlainText;
125+
if (v == "markdown") return MarkupKind.Markdown;
126+
return new MarkupKind(v);
127+
}
128+
129+
/// <inheritdoc />
130+
public override bool CanConvert(Type objectType)
131+
{
132+
return objectType == typeof(MarkupKind);
133+
}
134+
}
135+
136+
}

0 commit comments

Comments
 (0)