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

Commit 92c7953

Browse files
author
Mikhail Arkhipov
authored
Merge pull request #103 from MikhailArkhipov/enc
Add ability to get document content from API
2 parents 39a1aed + 081f131 commit 92c7953

9 files changed

Lines changed: 21 additions & 9 deletions

File tree

src/Analysis/Engine/Impl/Definitions/IProjectEntry.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,12 @@ public interface IProjectEntry : IAnalyzable, IVersioned, IDisposable {
4545
Dictionary<object, object> Properties { get; }
4646

4747
IModuleContext AnalysisContext { get; }
48+
49+
/// <summary>
50+
/// Document object corresponding to the entry.
51+
/// Can be null for entries that are not user documents
52+
/// such as modules.
53+
/// </summary>
54+
IDocument Document { get; }
4855
}
4956
}

src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonModule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ public string Documentation {
185185
public IModuleContext AnalysisContext => null;
186186
public bool IsAnalyzed => true;
187187
public void Analyze(CancellationToken cancel) { }
188-
189188
public IEnumerable<string> ParseErrors { get; }
189+
public IDocument Document => null;
190190

191191
private static IEnumerable<string> GetChildModules(string filePath, string prefix, IPythonInterpreter interpreter) {
192192
if (interpreter == null || string.IsNullOrEmpty(filePath)) {

src/Analysis/Engine/Impl/ProjectEntry.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ where lastDot > 0
320320

321321
public IGroupableAnalysisProject AnalysisGroup => ProjectState;
322322

323+
#region IPythonProjectEntry
323324
public IModuleAnalysis Analysis { get; private set; }
324325

325326
public string FilePath { get; }
@@ -340,6 +341,9 @@ where lastDot > 0
340341

341342
public Dictionary<object, object> Properties { get; } = new Dictionary<object, object>();
342343

344+
public IDocument Document => this;
345+
#endregion
346+
343347
public void Dispose() {
344348
lock (this) {
345349
AnalysisVersion = -1;

src/Analysis/Engine/Test/AnalysisTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4403,7 +4403,7 @@ class oar(list):
44034403
var completions = await server.SendCompletion(uri, 2, 8);
44044404

44054405
completions.Should().HaveItem("append")
4406-
.Which.Should().HaveInsertText("append(self, value):\r\n\treturn super(oar, self).append(value)");
4406+
.Which.Should().HaveInsertText("append(self, value):\r\n return super(oar, self).append(value)");
44074407
}
44084408
}
44094409

@@ -4419,7 +4419,7 @@ class oar(list):
44194419
var completions = await server.SendCompletion(uri, 2, 8);
44204420

44214421
completions.Should().HaveItem("append")
4422-
.Which.Should().HaveInsertText("append(self, value):\r\n\treturn super().append(value)");
4422+
.Which.Should().HaveInsertText("append(self, value):\r\n return super().append(value)");
44234423
}
44244424
}
44254425

src/LanguageServer/Impl/Definitions/IPythonLanguageServer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// permissions and limitations under the License.
1616

1717
using System;
18+
using System.Collections.Generic;
1819
using System.Threading;
1920
using System.Threading.Tasks;
2021
using Microsoft.PythonTools.Analysis;
@@ -27,5 +28,7 @@ public interface IPythonLanguageServer : IPythonLanguageServerProtocol {
2728
PythonAst GetCurrentAst(Uri documentUri);
2829
Task<PythonAst> GetAstAsync(Uri documentUri, CancellationToken token);
2930
Task<IModuleAnalysis> GetAnalysisAsync(Uri documentUri, CancellationToken token);
31+
IProjectEntry GetProjectEntry(Uri documentUri);
32+
IEnumerable<string> GetLoadedFiles();
3033
}
3134
}

src/LanguageServer/Impl/Implementation/CompletionAnalysis.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,9 +899,7 @@ private string MakeOverrideCompletionString(string indentation, IOverloadResult
899899
var sb = new StringBuilder();
900900

901901
sb.AppendLine(result.Name + "(" + string.Join(", ", result.Parameters.Select((p, i) => GetSafeParameterName(p, i))) + "):");
902-
903902
sb.Append(indentation);
904-
sb.Append('\t');
905903

906904
if (result.Parameters.Length > 0) {
907905
var parameterString = string.Join(", ", result.Parameters.Skip(1).Select((p, i) => GetSafeArgumentName(p, i + 1)));

src/LanguageServer/Impl/Implementation/ProjectFiles.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public IEnumerable<string> GetLoadedFiles() {
5151
return _projectFiles.Keys.Select(k => k.AbsoluteUri);
5252
}
5353

54-
public IProjectEntry GetEntry(TextDocumentIdentifier document) => GetEntry(document.uri);
5554
public IProjectEntry GetEntry(Uri documentUri, bool throwIfMissing = true) {
5655
ThrowIfDisposed();
5756

@@ -65,7 +64,7 @@ public IProjectEntry GetEntry(Uri documentUri, bool throwIfMissing = true) {
6564
public void GetEntry(TextDocumentIdentifier document, int? expectedVersion, out ProjectEntry entry, out PythonAst tree) {
6665
ThrowIfDisposed();
6766

68-
entry = GetEntry(document) as ProjectEntry;
67+
entry = GetEntry(document.uri) as ProjectEntry;
6968
if (entry == null) {
7069
throw new LanguageServerException(LanguageServerException.UnsupportedDocumentType, "unsupported document");
7170
}

src/LanguageServer/Impl/Implementation/Server.WorkspaceSymbols.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ await GetModuleVariablesAsync(entry as ProjectEntry, opts, @params.query, 50, to
4545

4646
public override async Task<SymbolInformation[]> DocumentSymbol(DocumentSymbolParams @params, CancellationToken token) {
4747
var opts = GetMemberOptions.ExcludeBuiltins | GetMemberOptions.DeclaredOnly;
48-
var entry = ProjectFiles.GetEntry(@params.textDocument);
48+
var entry = ProjectFiles.GetEntry(@params.textDocument.uri);
4949

5050
var members = await GetModuleVariablesAsync(entry as ProjectEntry, opts, string.Empty, 50, token);
5151
return members
@@ -57,7 +57,7 @@ public override async Task<SymbolInformation[]> DocumentSymbol(DocumentSymbolPar
5757

5858
public override async Task<DocumentSymbol[]> HierarchicalDocumentSymbol(DocumentSymbolParams @params, CancellationToken cancellationToken) {
5959
var opts = GetMemberOptions.ExcludeBuiltins | GetMemberOptions.DeclaredOnly;
60-
var entry = ProjectFiles.GetEntry(@params.textDocument);
60+
var entry = ProjectFiles.GetEntry(@params.textDocument.uri);
6161

6262
var members = await GetModuleVariablesAsync(entry as ProjectEntry, opts, string.Empty, 50, cancellationToken);
6363
return ToDocumentSymbols(members);

src/LanguageServer/Impl/Implementation/Server.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ public Task<IModuleAnalysis> GetAnalysisAsync(Uri documentUri, CancellationToken
361361
return entry.GetAnalysisAsync(Timeout.Infinite, token);
362362
}
363363

364+
public IProjectEntry GetProjectEntry(Uri documentUri) => ProjectFiles.GetEntry(documentUri);
364365
#endregion
365366

366367
#region Private Helpers

0 commit comments

Comments
 (0)