Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Analysis/Engine/Impl/Definitions/IProjectEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,12 @@ public interface IProjectEntry : IAnalyzable, IVersioned, IDisposable {
Dictionary<object, object> Properties { get; }

IModuleContext AnalysisContext { get; }

/// <summary>
/// Document object corresponding to the entry.
/// Can be null for entries that are not user documents
/// such as modules.
/// </summary>
IDocument Document { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ public string Documentation {
public IModuleContext AnalysisContext => null;
public bool IsAnalyzed => true;
public void Analyze(CancellationToken cancel) { }

public IEnumerable<string> ParseErrors { get; }
public IDocument Document => null;

private static IEnumerable<string> GetChildModules(string filePath, string prefix, IPythonInterpreter interpreter) {
if (interpreter == null || string.IsNullOrEmpty(filePath)) {
Expand Down
4 changes: 4 additions & 0 deletions src/Analysis/Engine/Impl/ProjectEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ where lastDot > 0

public IGroupableAnalysisProject AnalysisGroup => ProjectState;

#region IPythonProjectEntry
public IModuleAnalysis Analysis { get; private set; }

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

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

public IDocument Document => this;
#endregion

public void Dispose() {
lock (this) {
AnalysisVersion = -1;
Expand Down
4 changes: 2 additions & 2 deletions src/Analysis/Engine/Test/AnalysisTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4403,7 +4403,7 @@ class oar(list):
var completions = await server.SendCompletion(uri, 2, 8);

completions.Should().HaveItem("append")
.Which.Should().HaveInsertText("append(self, value):\r\n\treturn super(oar, self).append(value)");
.Which.Should().HaveInsertText("append(self, value):\r\n return super(oar, self).append(value)");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we determine if it is a \t or a set of spaces? Is there a setting for it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per GetCompletionsForOverride it always uses spaces. I believe per PEP spaces are strongly preferred.

}
}

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

completions.Should().HaveItem("append")
.Which.Should().HaveInsertText("append(self, value):\r\n\treturn super().append(value)");
.Which.Should().HaveInsertText("append(self, value):\r\n return super().append(value)");
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/LanguageServer/Impl/Definitions/IPythonLanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// permissions and limitations under the License.

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.PythonTools.Analysis;
Expand All @@ -27,5 +28,7 @@ public interface IPythonLanguageServer : IPythonLanguageServerProtocol {
PythonAst GetCurrentAst(Uri documentUri);
Task<PythonAst> GetAstAsync(Uri documentUri, CancellationToken token);
Task<IModuleAnalysis> GetAnalysisAsync(Uri documentUri, CancellationToken token);
IProjectEntry GetProjectEntry(Uri documentUri);
IEnumerable<string> GetLoadedFiles();
}
}
2 changes: 0 additions & 2 deletions src/LanguageServer/Impl/Implementation/CompletionAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -899,9 +899,7 @@ private string MakeOverrideCompletionString(string indentation, IOverloadResult
var sb = new StringBuilder();

sb.AppendLine(result.Name + "(" + string.Join(", ", result.Parameters.Select((p, i) => GetSafeParameterName(p, i))) + "):");

sb.Append(indentation);
sb.Append('\t');

if (result.Parameters.Length > 0) {
var parameterString = string.Join(", ", result.Parameters.Skip(1).Select((p, i) => GetSafeArgumentName(p, i + 1)));
Expand Down
3 changes: 1 addition & 2 deletions src/LanguageServer/Impl/Implementation/ProjectFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public IEnumerable<string> GetLoadedFiles() {
return _projectFiles.Keys.Select(k => k.AbsoluteUri);
}

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

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

entry = GetEntry(document) as ProjectEntry;
entry = GetEntry(document.uri) as ProjectEntry;
if (entry == null) {
throw new LanguageServerException(LanguageServerException.UnsupportedDocumentType, "unsupported document");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ await GetModuleVariablesAsync(entry as ProjectEntry, opts, @params.query, 50, to

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

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

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

var members = await GetModuleVariablesAsync(entry as ProjectEntry, opts, string.Empty, 50, cancellationToken);
return ToDocumentSymbols(members);
Expand Down
1 change: 1 addition & 0 deletions src/LanguageServer/Impl/Implementation/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ public Task<IModuleAnalysis> GetAnalysisAsync(Uri documentUri, CancellationToken
return entry.GetAnalysisAsync(Timeout.Infinite, token);
}

public IProjectEntry GetProjectEntry(Uri documentUri) => ProjectFiles.GetEntry(documentUri);
#endregion

#region Private Helpers
Expand Down