This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 171
/
Communication.cs
104 lines (88 loc) · 3.89 KB
/
Communication.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Runtime.Serialization;
using Microsoft.VisualStudio.LanguageServer.Protocol;
namespace Microsoft.Quantum.QsLanguageServer
{
public static class CommandIds
{
public const string ApplyEdit = "qsLanguageServer/applyEdit";
// commands for diagnostic purposes
internal const string FileContentInMemory = "qsLanguageServer/fileContentInMemory";
internal const string FileDiagnostics = "qsLanguageServer/fileDiagnostics";
internal const string ProjectInformation = "qsLanguageServer/projectInformation";
}
public class ProtocolError
{
public static class Codes
{
// specified by the LSP
public const int AwaitingInitialization = -32002;
// behavior unspecified by LSP
// -> according to JsonRpc 2.0, the error code range -32768 to -32000 is reserverd
// -> using the range -32900 to -32999 for anything not specified by the LSP should be fine
}
public int Code { get; }
public string? Message { get; }
public ProtocolError(int code, string? message = null)
{
this.Code = code;
this.Message = message;
}
public static ProtocolError AwaitingInitialization =>
new ProtocolError(Codes.AwaitingInitialization);
}
// If the workaround for ignoring CodeActionKind is no longer needed,
// please also remove the modification in the server's Initialize method
// that sets capabilities.textDocument.codeAction to null.
public static class Workarounds
{
/// <summary>
/// This is the exact version as used by earlier versions of the package.
/// We will use this one for the sake of avoiding a bug in the VS Code client
/// that will cause an issue for deserializing the CodeActionKind array.
/// </summary>
[DataContract]
public class CodeActionParams
{
[DataMember(Name = "textDocument")]
public TextDocumentIdentifier? TextDocument { get; set; }
[DataMember(Name = "range")]
public Range? Range { get; set; }
[DataMember(Name = "context")]
public CodeActionContext? Context { get; set; }
public VisualStudio.LanguageServer.Protocol.CodeActionParams? ToCodeActionParams() =>
this.TextDocument == null
? null
: new VisualStudio.LanguageServer.Protocol.CodeActionParams
{
TextDocument = this.TextDocument,
Range = this.Range ?? new Range(),
Context = this.Context?.ToCodeActionContext() ??
// Make a blank context if we're missing a code action
// context.
new VisualStudio.LanguageServer.Protocol.CodeActionContext
{
Diagnostics = new Diagnostic[] { },
},
};
}
/// <summary>
/// This is the exact version as used by earlier versions of the package.
/// We will use this one for the sake of avoiding a bug in the VS Code client
/// that will cause an issue for deserializing the CodeActionKind array.
/// </summary>
[DataContract]
public class CodeActionContext
{
[DataMember(Name = "diagnostics")]
public Diagnostic[]? Diagnostics { get; set; }
public VisualStudio.LanguageServer.Protocol.CodeActionContext ToCodeActionContext() =>
new VisualStudio.LanguageServer.Protocol.CodeActionContext
{
Diagnostics = this.Diagnostics ?? new Diagnostic[] { },
Only = null,
};
}
}
}