Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit b98996e

Browse files
author
Mikhail Arkhipov
authored
Merge pull request #101 from MikhailArkhipov/compat
Extensions backward compatibility
2 parents 2fbe616 + fd8d69f commit b98996e

11 files changed

Lines changed: 1412 additions & 17 deletions

File tree

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
// Python Tools for Visual Studio
2+
// Copyright(c) Microsoft Corporation
3+
// All rights reserved.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the License); you may not use
6+
// this file except in compliance with the License. You may obtain a copy of the
7+
// License at http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
10+
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
11+
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
12+
// MERCHANTABLITY OR NON-INFRINGEMENT.
13+
//
14+
// See the Apache Version 2.0 License for specific language governing
15+
// permissions and limitations under the License.
16+
17+
using System;
18+
19+
namespace Microsoft.PythonTools.Analysis.LanguageServer {
20+
public sealed class SerializeAsAttribute : Attribute {
21+
public object Value { get; }
22+
23+
public SerializeAsAttribute(object value) {
24+
Value = value;
25+
}
26+
}
27+
28+
public enum TraceLevel {
29+
[SerializeAs("off")]
30+
Off,
31+
[SerializeAs("messages")]
32+
Messages,
33+
[SerializeAs("verbose")]
34+
Verbose
35+
}
36+
37+
public enum SymbolKind {
38+
None = 0,
39+
File = 1,
40+
Module = 2,
41+
Namespace = 3,
42+
Package = 4,
43+
Class = 5,
44+
Method = 6,
45+
Property = 7,
46+
Field = 8,
47+
Constructor = 9,
48+
Enum = 10,
49+
Interface = 11,
50+
Function = 12,
51+
Variable = 13,
52+
Constant = 14,
53+
String = 15,
54+
Number = 16,
55+
Boolean = 17,
56+
Array = 18,
57+
Object = 19,
58+
Key = 20,
59+
Null = 21,
60+
EnumMember = 22,
61+
Struct = 23,
62+
Event = 24,
63+
Operator = 25,
64+
TypeParameter = 26
65+
}
66+
67+
public enum TextDocumentSyncKind : int {
68+
None = 0,
69+
Full = 1,
70+
Incremental = 2
71+
}
72+
73+
public enum MessageType : int {
74+
/// <summary>
75+
/// General language server output relevant to the user
76+
/// such as information on Python interpreter type.
77+
/// Does not conform to LSP definitions, Python LS specific.
78+
/// </summary>
79+
_General = 0,
80+
81+
/// <summary>
82+
/// Language server errors.
83+
/// </summary>
84+
Error = 1,
85+
86+
/// <summary>
87+
/// Language server warnings.
88+
/// </summary>
89+
Warning = 2,
90+
91+
/// <summary>
92+
/// Language server internal information.
93+
/// </summary>
94+
Info = 3,
95+
96+
/// <summary>
97+
/// Language server log-level diagnostic messages.
98+
/// </summary>
99+
Log = 4
100+
}
101+
102+
public enum FileChangeType : int {
103+
Created = 1,
104+
Changed = 2,
105+
Deleted = 3
106+
}
107+
108+
public enum WatchKind : int {
109+
Create = 1,
110+
Change = 2,
111+
Delete = 4
112+
}
113+
114+
public enum TextDocumentSaveReason : int {
115+
Manual = 1,
116+
AfterDelay = 2,
117+
FocusOut = 3
118+
}
119+
120+
public enum CompletionTriggerKind : int {
121+
Invoked = 1,
122+
TriggerCharacter = 2
123+
}
124+
125+
public enum InsertTextFormat : int {
126+
PlainText = 1,
127+
Snippet = 2
128+
}
129+
130+
public enum CompletionItemKind : int {
131+
None = 0,
132+
Text = 1,
133+
Method = 2,
134+
Function = 3,
135+
Constructor = 4,
136+
Field = 5,
137+
Variable = 6,
138+
Class = 7,
139+
Interface = 8,
140+
Module = 9,
141+
Property = 10,
142+
Unit = 11,
143+
Value = 12,
144+
Enum = 13,
145+
Keyword = 14,
146+
Snippet = 15,
147+
Color = 16,
148+
File = 17,
149+
Reference = 18,
150+
Folder = 19,
151+
EnumMember = 20,
152+
Constant = 21,
153+
Struct = 22,
154+
Event = 23,
155+
Operator = 24,
156+
TypeParameter = 25
157+
}
158+
159+
public enum DocumentHighlightKind : int {
160+
Text = 1,
161+
Read = 2,
162+
Write = 3
163+
}
164+
165+
// Not in the LSP spec.
166+
public enum ReferenceKind : int {
167+
Definition = 1,
168+
Reference = 2,
169+
Value = 3
170+
}
171+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Python Tools for Visual Studio
2+
// Copyright(c) Microsoft Corporation
3+
// All rights reserved.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the License); you may not use
6+
// this file except in compliance with the License. You may obtain a copy of the
7+
// License at http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
10+
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
11+
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
12+
// MERCHANTABLITY OR NON-INFRINGEMENT.
13+
//
14+
// See the Apache Version 2.0 License for specific language governing
15+
// permissions and limitations under the License.
16+
17+
using System;
18+
using Microsoft.PythonTools.Parsing.Ast;
19+
20+
namespace Microsoft.PythonTools.Analysis.LanguageServer.Extensibility {
21+
[Obsolete("Implement Microsoft.Python.LanguageServer.Extensions.ILanguageServerExtension model")]
22+
public sealed class CompletionEventArgs : EventArgs {
23+
public CompletionEventArgs(ModuleAnalysis analysis, PythonAst tree, SourceLocation location, CompletionList initialCompletionList) {
24+
Analysis = analysis;
25+
Tree = tree;
26+
Location = location;
27+
CompletionList = initialCompletionList;
28+
}
29+
30+
public ModuleAnalysis Analysis { get; }
31+
public PythonAst Tree { get; }
32+
public SourceLocation Location { get; }
33+
34+
public CompletionList CompletionList;
35+
}
36+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Python Tools for Visual Studio
2+
// Copyright(c) Microsoft Corporation
3+
// All rights reserved.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the License); you may not use
6+
// this file except in compliance with the License. You may obtain a copy of the
7+
// License at http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
10+
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
11+
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
12+
// MERCHANTABLITY OR NON-INFRINGEMENT.
13+
//
14+
// See the Apache Version 2.0 License for specific language governing
15+
// permissions and limitations under the License.
16+
17+
using System;
18+
using System.Collections.Generic;
19+
20+
namespace Microsoft.PythonTools.Analysis.LanguageServer {
21+
[Obsolete("Implement Microsoft.Python.LanguageServer.Extensions.ILanguageServerExtension model")]
22+
public interface ILanguageServerExtension {
23+
/// <summary>
24+
/// The name of the extension. Used to look up the current instance
25+
/// when processing extension command messages. If null or empty,
26+
/// the extension cannot be sent messages and may be garbage collected
27+
/// if it does not manage its own lifetime against the <see cref="IServer"/>
28+
/// instance provided to its provider.
29+
/// </summary>
30+
string Name { get; }
31+
32+
/// <summary>
33+
/// Called when an extension command arrives for this extension.
34+
/// </summary>
35+
IReadOnlyDictionary<string, object> ExecuteCommand(string command, IReadOnlyDictionary<string, object> properties);
36+
}
37+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Python Tools for Visual Studio
2+
// Copyright(c) Microsoft Corporation
3+
// All rights reserved.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the License); you may not use
6+
// this file except in compliance with the License. You may obtain a copy of the
7+
// License at http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
10+
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
11+
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
12+
// MERCHANTABLITY OR NON-INFRINGEMENT.
13+
//
14+
// See the Apache Version 2.0 License for specific language governing
15+
// permissions and limitations under the License.
16+
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Threading;
20+
using System.Threading.Tasks;
21+
22+
namespace Microsoft.PythonTools.Analysis.LanguageServer {
23+
/// <summary>
24+
/// Implemented on a class that can create a language server extension.
25+
/// This class must have a default constructor.
26+
/// </summary>
27+
[Obsolete("Implement Microsoft.Python.LanguageServer.Extensions.ILanguageServerExtension model")]
28+
public interface ILanguageServerExtensionProvider {
29+
/// <summary>
30+
/// Called when the extension is loaded for a language server.
31+
/// </summary>
32+
Task<ILanguageServerExtension> CreateAsync(
33+
IServer server,
34+
IReadOnlyDictionary<string, object> properties,
35+
CancellationToken cancellationToken
36+
);
37+
}
38+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Python Tools for Visual Studio
2+
// Copyright(c) Microsoft Corporation
3+
// All rights reserved.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the License); you may not use
6+
// this file except in compliance with the License. You may obtain a copy of the
7+
// License at http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
10+
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
11+
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
12+
// MERCHANTABLITY OR NON-INFRINGEMENT.
13+
//
14+
// See the Apache Version 2.0 License for specific language governing
15+
// permissions and limitations under the License.
16+
17+
using System;
18+
19+
namespace Microsoft.PythonTools.Analysis.LanguageServer {
20+
[Obsolete("Implement Microsoft.Python.LanguageServer.Extensions.ILanguageServerExtension model")]
21+
public interface IServer {
22+
void LogMessage(MessageType type, string message);
23+
}
24+
[Obsolete("Implement Microsoft.Python.LanguageServer.Extensions.ILanguageServerExtension model")]
25+
public interface IServer2 : IServer {
26+
}
27+
[Obsolete("Implement Microsoft.Python.LanguageServer.Extensions.ILanguageServerExtension model")]
28+
public interface IServer3 : IServer2 {
29+
}
30+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Python Tools for Visual Studio
2+
// Copyright(c) Microsoft Corporation
3+
// All rights reserved.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the License); you may not use
6+
// this file except in compliance with the License. You may obtain a copy of the
7+
// License at http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
10+
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
11+
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
12+
// MERCHANTABLITY OR NON-INFRINGEMENT.
13+
//
14+
// See the Apache Version 2.0 License for specific language governing
15+
// permissions and limitations under the License.
16+
17+
using System;
18+
using Microsoft.PythonTools.Analysis.Infrastructure;
19+
using Microsoft.PythonTools.Parsing.Ast;
20+
21+
namespace Microsoft.PythonTools.Analysis.LanguageServer {
22+
[Obsolete("Implement Microsoft.Python.LanguageServer.Extensions.ILanguageServerExtension model")]
23+
public class Server : IServer {
24+
public event EventHandler<Extensibility.CompletionEventArgs> PostProcessCompletion;
25+
26+
public void LogMessage(MessageType type, string message) { }
27+
28+
public void ProcessCompletionList(ModuleAnalysis analysis, PythonAst tree, SourceLocation location, CompletionList completions) {
29+
var evt = PostProcessCompletion;
30+
if (evt != null) {
31+
var e = new Extensibility.CompletionEventArgs(analysis, tree, location, completions);
32+
try {
33+
evt(this, e);
34+
completions = e.CompletionList;
35+
completions.items = completions.items ?? Array.Empty<CompletionItem>();
36+
} catch (Exception ex) when (!ex.IsCriticalException()) {
37+
// We do not replace res in this case.
38+
}
39+
}
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)