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

Commit 4cf07fb

Browse files
author
Mikhail Arkhipov
authored
Merge pull request #125 from MikhailArkhipov/master
Add document URI to the completion extensibility
2 parents 291b59d + 31c0f68 commit 4cf07fb

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,38 @@
1414
// See the Apache Version 2.0 License for specific language governing
1515
// permissions and limitations under the License.
1616

17+
using System;
1718
using System.Collections.Generic;
1819
using Microsoft.PythonTools.Interpreter;
1920
using Microsoft.PythonTools.Parsing.Ast;
2021

2122
namespace Microsoft.PythonTools.Analysis {
2223
public interface IModuleAnalysis {
24+
/// <summary>
25+
/// Module document/file URI. Can be null if there is no associated document.
26+
/// </summary>
27+
Uri DocumentUri { get; }
28+
29+
/// <summary>
30+
/// Analysis version
31+
/// </summary>
2332
int Version { get; }
33+
2434
IModuleContext InterpreterContext { get; }
35+
36+
/// <summary>
37+
/// Python analyzer
38+
/// </summary>
2539
PythonAnalyzer ProjectState { get; }
40+
41+
/// <summary>
42+
/// Scope of the analysis
43+
/// </summary>
2644
IScope Scope { get; }
45+
46+
/// <summary>
47+
/// Module name.
48+
/// </summary>
2749
string ModuleName { get; }
2850

2951
/// <summary>

src/Analysis/Engine/Impl/ModuleAnalysis.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ public sealed class ModuleAnalysis : IModuleAnalysis {
4141
private static readonly IEnumerable<IOverloadResult> GetSignaturesError =
4242
new[] { new OverloadResult(new ParameterResult[0], "Unknown", "IntellisenseError_Sigs", null) };
4343

44-
internal ModuleAnalysis(AnalysisUnit unit, InterpreterScope scope, int version) {
44+
internal ModuleAnalysis(AnalysisUnit unit, InterpreterScope scope, Uri documentUri, int version) {
4545
_unit = unit;
4646
Scope = scope;
47+
DocumentUri = documentUri;
4748
Version = version;
4849
}
4950

5051
#region Public API
52+
public Uri DocumentUri { get; }
5153
public int Version { get; }
5254
/// <summary>
5355
/// Evaluates the given expression in at the provided line number and returns the values

src/Analysis/Engine/Impl/ProjectEntry.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ where lastDot > 0
315315
Analysis = new ModuleAnalysis(
316316
_unit,
317317
((ModuleScope)_unit.Scope).CloneForPublish(),
318+
DocumentUri,
318319
AnalysisVersion
319320
);
320321
}

src/Analysis/Engine/Test/LanguageServerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ public Task<IReadOnlyDictionary<string, object>> ExecuteCommand(string command,
644644
#endregion
645645

646646
#region ICompletionExtension
647-
public Task HandleCompletionAsync(IModuleAnalysis analysis, PythonAst tree, SourceLocation location, CompletionList completions, CancellationToken token) {
647+
public Task HandleCompletionAsync(Uri documentUri, IModuleAnalysis analysis, PythonAst tree, SourceLocation location, CompletionList completions, CancellationToken token) {
648648
Assert.IsNotNull(tree);
649649
Assert.IsNotNull(analysis);
650650
for (int i = 0; i < completions.items.Length; ++i) {

src/LanguageServer/Impl/Extensions/ICompletionExtension.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// See the Apache Version 2.0 License for specific language governing
1515
// permissions and limitations under the License.
1616

17+
using System;
1718
using System.Threading;
1819
using System.Threading.Tasks;
1920
using Microsoft.PythonTools;
@@ -22,6 +23,6 @@
2223

2324
namespace Microsoft.Python.LanguageServer.Extensions {
2425
public interface ICompletionExtension {
25-
Task HandleCompletionAsync(IModuleAnalysis analysis, PythonAst tree, SourceLocation location, CompletionList completions, CancellationToken token);
26+
Task HandleCompletionAsync(Uri documentUri, IModuleAnalysis analysis, PythonAst tree, SourceLocation location, CompletionList completions, CancellationToken token);
2627
}
2728
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public override async Task<CompletionList> Completion(CompletionParams @params,
9898
}
9999

100100
await InvokeExtensionsAsync((ext, token)
101-
=> (ext as ICompletionExtension)?.HandleCompletionAsync(analysis, tree, @params.position, res, cancellationToken), cancellationToken);
101+
=> (ext as ICompletionExtension)?.HandleCompletionAsync(uri, analysis, tree, @params.position, res, cancellationToken), cancellationToken);
102102

103103
return res;
104104
}

0 commit comments

Comments
 (0)