Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Commit b806112

Browse files
committed
Merge branch 'feature/v3_8_0'
2 parents 3667a6e + 5b6fa53 commit b806112

14 files changed

+519
-13
lines changed

LanguageServer/Infrastructure/JsonDotNet/EitherConverter.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ public EitherConverter()
2626
table[typeof(NumberOrString)] = token => (object)ToNumberOrString(token);
2727
table[typeof(LocationSingleOrArray)] = token => (object)ToLocationSingleOrArray(token);
2828
table[typeof(ChangeNotificationsOptions)] = token => (object)ToChangeNotificationsOptions(token);
29+
table[typeof(ColorProviderOptionsOrBoolean)] = token => (object)ToColorProviderOptionsOrBoolean(token);
2930
table[typeof(ProviderOptionsOrBoolean)] = token => (object)ToProviderOptionsOrBoolean(token);
3031
table[typeof(TextDocumentSync)] = token => (object)ToTextDocumentSync(token);
32+
table[typeof(CodeActionResult)] = token => (object)ToCodeActionResult(token);
3133
table[typeof(Documentation)] = token => (object)ToDocumentation(token);
3234
table[typeof(CompletionResult)] = token => (object)ToCompletionResult(token);
3335
table[typeof(HoverContents)] = token => (object)ToHoverContents(token);
@@ -106,6 +108,21 @@ private ChangeNotificationsOptions ToChangeNotificationsOptions(JToken token)
106108
}
107109
}
108110

111+
private ColorProviderOptionsOrBoolean ToColorProviderOptionsOrBoolean(JToken token)
112+
{
113+
switch (token.Type)
114+
{
115+
case JTokenType.Null:
116+
return null;
117+
case JTokenType.Boolean:
118+
return new ColorProviderOptionsOrBoolean(token.ToObject<bool>());
119+
case JTokenType.Object:
120+
return new ColorProviderOptionsOrBoolean(token.ToObject<ColorProviderOptions>());
121+
default:
122+
throw new JsonSerializationException();
123+
}
124+
}
125+
109126
private ProviderOptionsOrBoolean ToProviderOptionsOrBoolean(JToken token)
110127
{
111128
switch (token.Type)
@@ -136,6 +153,43 @@ private TextDocumentSync ToTextDocumentSync(JToken token)
136153
}
137154
}
138155

156+
private CodeActionResult ToCodeActionResult(JToken token)
157+
{
158+
switch (token.Type)
159+
{
160+
case JTokenType.Null:
161+
return null;
162+
case JTokenType.Array:
163+
var array = (JArray) token;
164+
if (array.Count == 0)
165+
{
166+
return new CodeActionResult(new Command[0]);
167+
}
168+
169+
var element = (array[0] as JObject) ?? throw new JsonSerializationException();
170+
if (element.Property("edit") != null)
171+
{
172+
return new CodeActionResult(array.ToObject<CodeAction[]>());
173+
}
174+
175+
var command = element.Property("command") ?? throw new JsonSerializationException();
176+
if (command.Type == JTokenType.Object)
177+
{
178+
return new CodeActionResult(array.ToObject<CodeAction[]>());
179+
}
180+
else if (command.Type == JTokenType.String)
181+
{
182+
return new CodeActionResult(array.ToObject<Command[]>());
183+
}
184+
else
185+
{
186+
throw new JsonSerializationException();
187+
}
188+
default:
189+
throw new JsonSerializationException();
190+
}
191+
}
192+
139193
private Documentation ToDocumentation(JToken token)
140194
{
141195
switch (token.Type)

LanguageServer/Json/Either.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace LanguageServer.Json
1111
/// <item><description><see cref="NumberOrString"/></description></item>
1212
/// <item><description><see cref="LanguageServer.Parameters.LocationSingleOrArray"/></description></item>
1313
/// <item><description><see cref="LanguageServer.Parameters.General.ChangeNotificationsOptions"/></description></item>
14-
/// <item><description><see cref="LanguageServer.Parameters.General.ColorProviderCapabilities"/></description></item>
14+
/// <item><description><see cref="LanguageServer.Parameters.General.ColorProviderOptionsOrBoolean"/></description></item>
1515
/// <item><description><see cref="LanguageServer.Parameters.General.FoldingRangeProviderCapabilities"/></description></item>
1616
/// <item><description><see cref="LanguageServer.Parameters.General.ProviderOptionsOrBoolean"/></description></item>
1717
/// <item><description><see cref="LanguageServer.Parameters.General.TextDocumentSync"/></description></item>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
namespace LanguageServer.Parameters
2+
{
3+
/// <summery>
4+
/// A set of predefined code action kinds
5+
/// </summery>
6+
/// <seealso cref="LanguageServer.Parameters.General.CodeActionKindCapabilities.valueSet"/>
7+
/// <seealso cref="LanguageServer.Parameters.TextDocument.CodeActionContext.only"/>
8+
/// <seealso>Spec 3.8.0</seealso>
9+
public static class CodeActionKind
10+
{
11+
/// <summary>
12+
/// Base kind for quickfix actions: 'quickfix'
13+
/// </summary>
14+
/// <seealso>Spec 3.8.0</seealso>
15+
public const string QuickFix = "quickfix";
16+
17+
/// <summary>
18+
/// Base kind for refactoring actions: 'refactor'
19+
/// </summary>
20+
/// <seealso>Spec 3.8.0</seealso>
21+
public const string Refactor = "refactor";
22+
23+
/// <summary>
24+
/// Base kind for refactoring extraction actions: 'refactor.extract'
25+
/// </summary>
26+
/// <example>
27+
/// Example extract actions:
28+
/// <list type="bullet">
29+
/// <item><description>Extract method</description></item>
30+
/// <item><description>Extract function</description></item>
31+
/// <item><description>Extract variable</description></item>
32+
/// <item><description>Extract interface from class</description></item>
33+
/// <item><description>...</description></item>
34+
/// </list>
35+
/// </example>
36+
/// <seealso>Spec 3.8.0</seealso>
37+
public const string RefactorExtract = "refactor.extract";
38+
39+
/// <summary>
40+
/// Base kind for refactoring inline actions: 'refactor.inline'
41+
/// </summary>
42+
/// <example>
43+
/// Example inline actions:
44+
/// <list type="bullet">
45+
/// <item><description>Inline function</description></item>
46+
/// <item><description>Inline variable</description></item>
47+
/// <item><description>Inline constant</description></item>
48+
/// <item><description>...</description></item>
49+
/// </list>
50+
/// </example>
51+
/// <seealso>Spec 3.8.0</seealso>
52+
public const string RefactorInline = "refactor.inline";
53+
54+
/// <summary>
55+
/// Base kind for refactoring rewrite actions: 'refactor.rewrite'
56+
/// </summary>
57+
/// <example>
58+
/// Example rewrite actions:
59+
/// <list type="bullet">
60+
/// <item><description>Convert JavaScript function to class</description></item>
61+
/// <item><description>Add or remove parameter</description></item>
62+
/// <item><description>Encapsulate field</description></item>
63+
/// <item><description>Make method static</description></item>
64+
/// <item><description>Move method to base class</description></item>
65+
/// <item><description>...</description></item>
66+
/// </list>
67+
/// </example>
68+
/// <seealso>Spec 3.8.0</seealso>
69+
public const string RefactorRewrite = "refactor.rewrite";
70+
71+
/// <summary>
72+
/// Base kind for source actions: 'source'
73+
/// </summary>
74+
/// <remarks>
75+
/// Source code actions apply to the entire file.
76+
/// </remarks>
77+
/// <seealso>Spec 3.8.0</seealso>
78+
public const string Source = "source";
79+
80+
/// <summary>
81+
/// Base kind for an organize imports source action: 'source.organizeImports'
82+
/// </summary>
83+
/// <seealso>Spec 3.8.0</seealso>
84+
public const string SourceOrganizeImports = "source.organizeImports";
85+
}
86+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace LanguageServer.Parameters.General
2+
{
3+
/// <summary>
4+
/// For <c>initialize</c>
5+
/// </summary>
6+
/// <seealso>Spec 3.8.0</seealso>
7+
public class CodeActionCapabilities : RegistrationCapabilities
8+
{
9+
/// <summary>
10+
/// The client support code action literals as a valid
11+
/// response of the `textDocument/codeAction` request.
12+
/// </summary>
13+
/// <seealso>Spec 3.8.0</seealso>
14+
public CodeActionLiteralSupportCapabilities codeActionLiteralSupport { get; set; }
15+
}
16+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace LanguageServer.Parameters.General
2+
{
3+
/// <summary>
4+
/// For <c>initialize</c>
5+
/// </summary>
6+
/// <seealso>Spec 3.8.0</seealso>
7+
public class CodeActionKindCapabilities
8+
{
9+
/// <summary>
10+
/// The code action kind values the client supports.
11+
/// </summary>
12+
/// <remarks>
13+
/// When this property exists the client also guarantees that it will
14+
/// handle values outside its set gracefully and falls back
15+
/// to a default value when unknown.
16+
/// </remarks>
17+
/// <value>
18+
/// See <see cref="LanguageServer.Parameters.CodeActionKind"/> for an enumeration of standardized kinds.
19+
/// </value>
20+
/// <seealso>Spec 3.8.0</seealso>
21+
/// <seealso cref="LanguageServer.Parameters.CodeActionKind"/>
22+
public string[] valueSet { get; set; }
23+
}
24+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace LanguageServer.Parameters.General
2+
{
3+
/// <summary>
4+
/// For <c>initialize</c>
5+
/// </summary>
6+
/// <seealso>Spec 3.8.0</seealso>
7+
public class CodeActionLiteralSupportCapabilities
8+
{
9+
/// <summary>
10+
/// The code action kind is support with the following value set.
11+
/// </summary>
12+
/// <seealso>Spec 3.8.0</seealso>
13+
public CodeActionKindCapabilities codeActionKind { get; set; }
14+
}
15+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using LanguageServer.Json;
2+
3+
namespace LanguageServer.Parameters.General
4+
{
5+
/// <summary>
6+
/// For <c>initialize</c>
7+
/// </summary>
8+
/// <remarks>
9+
/// The original spec describes the union type of
10+
/// <c>boolean</c>, <c>ColorProviderOptions</c>, or the intersection type
11+
/// <c>(ColorProviderOptions &amp; TextDocumentRegistrationOptions &amp; StaticRegistrationOptions)</c>.
12+
/// This implementation defines <see cref="ColorProviderOptions"/> class instead of the intersection type.
13+
/// </remarks>
14+
/// <seealso>Spec 3.8.0</seealso>
15+
public class ColorProviderOptionsOrBoolean : Either
16+
{
17+
/// <summary>
18+
/// Defines an implicit conversion of a <see cref="ColorProviderOptions"/> to a <see cref="ColorProviderOptionsOrBoolean"/>
19+
/// </summary>
20+
/// <param name="value"></param>
21+
/// <returns></returns>
22+
/// <seealso>Spec 3.8.0</seealso>
23+
public static implicit operator ColorProviderOptionsOrBoolean(ColorProviderOptions value)
24+
=> new ColorProviderOptionsOrBoolean(value);
25+
26+
/// <summary>
27+
/// Defines an implicit conversion of a <see cref="bool"/> to a <see cref="ColorProviderOptionsOrBoolean"/>
28+
/// </summary>
29+
/// <param name="value"></param>
30+
/// <returns></returns>
31+
/// <seealso>Spec 3.8.0</seealso>
32+
public static implicit operator ColorProviderOptionsOrBoolean(bool value)
33+
=> new ColorProviderOptionsOrBoolean(value);
34+
35+
/// <summary>
36+
/// Initializes a new instance of <c>ColorProviderOptionsOrBoolean</c> with the specified value.
37+
/// </summary>
38+
/// <param name="value"></param>
39+
/// <seealso>Spec 3.8.0</seealso>
40+
public ColorProviderOptionsOrBoolean(ColorProviderOptions value)
41+
{
42+
Type = typeof(ColorProviderOptions);
43+
Value = value;
44+
}
45+
46+
/// <summary>
47+
/// Initializes a new instance of <c>ColorProviderOptionsOrBoolean</c> with the specified value.
48+
/// </summary>
49+
/// <param name="value"></param>
50+
/// <seealso>Spec 3.8.0</seealso>
51+
public ColorProviderOptionsOrBoolean(bool value)
52+
{
53+
Type = typeof(bool);
54+
Value = value;
55+
}
56+
57+
/// <summary>
58+
/// Returns true if its underlying value is a <see cref="ColorProviderOptions"/>.
59+
/// </summary>
60+
/// <seealso>Spec 3.8.0</seealso>
61+
public bool IsColorProviderOptions => Type == typeof(ColorProviderOptions);
62+
63+
/// <summary>
64+
/// Returns true if its underlying value is a <see cref="bool"/>.
65+
/// </summary>
66+
/// <seealso>Spec 3.8.0</seealso>
67+
public bool IsBoolean => Type == typeof(bool);
68+
69+
/// <summary>
70+
/// Gets the value of the current object if its underlying value is a <see cref="ColorProviderOptions"/>.
71+
/// </summary>
72+
/// <seealso>Spec 3.8.0</seealso>
73+
public ColorProviderOptions ColorProviderOptions => GetValue<ColorProviderOptions>();
74+
75+
/// <summary>
76+
/// Gets the value of the current object if its underlying value is a <see cref="bool"/>.
77+
/// </summary>
78+
/// <seealso>Spec 3.8.0</seealso>
79+
public bool Boolean => GetValue<bool>();
80+
}
81+
}

LanguageServer/Parameters/General/ServerCapabilities.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace LanguageServer.Parameters.General
55
/// <summary>
66
/// For <c>initialize</c>
77
/// </summary>
8+
/// <seealso>Spec 3.8.0</seealso>
89
public class ServerCapabilities
910
{
1011
/// <summary>
@@ -77,7 +78,7 @@ public class ServerCapabilities
7778
/// The server provides code actions.
7879
/// </summary>
7980
/// <remarks>
80-
/// The <c>CodeActionOptions</c> return type is only
81+
/// The <c>CodeActionOptions</c> return type (since version 3.11.0) is only
8182
/// valid if the client signals code action literal support via the property
8283
/// <c>textDocument.codeAction.codeActionLiteralSupport</c>.
8384
/// </remarks>
@@ -120,8 +121,8 @@ public class ServerCapabilities
120121
/// <summary>
121122
/// The server provides color provider support.
122123
/// </summary>
123-
/// <seealso>Spec 3.6.0</seealso>
124-
public ColorProviderOptions colorProvider { get; set; }
124+
/// <seealso>Spec 3.8.0</seealso>
125+
public ColorProviderOptionsOrBoolean colorProvider { get; set; }
125126

126127
/// <summary>
127128
/// The server provides execute command support.

LanguageServer/Parameters/General/TextDocumentClientCapabilities.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// <summary>
44
/// For <c>initialize</c>
55
/// </summary>
6-
/// <seealso>Spec 3.7.0</seealso>
6+
/// <seealso>Spec 3.8.0</seealso>
77
public class TextDocumentClientCapabilities
88
{
99
/// <summary>
@@ -80,9 +80,10 @@ public class TextDocumentClientCapabilities
8080
public RegistrationCapabilities implementation { get; set; }
8181

8282
/// <summary>
83-
/// Capabilities specific to the <c>textDocument/codeAction</c>
83+
/// Capabilities specific to the <c>textDocument/codeAction</c>.
8484
/// </summary>
85-
public RegistrationCapabilities codeAction { get; set; }
85+
/// <seealso>Spec 3.8.0</seealso>
86+
public CodeActionCapabilities codeAction { get; set; }
8687

8788
/// <summary>
8889
/// Capabilities specific to the <c>textDocument/codeLens</c>

0 commit comments

Comments
 (0)