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

Commit 13d2202

Browse files
PTVS integration (#524)
* Clean up Completions, Find References and Hover unit tests. * Initial commit * CoreProduct buildable * Product buildable except IronPython * Move VS-specific file * add hack to prevent True/False/None/... from being use-before-def (#464) * Fix for extra paths inside workspace (#467) Fix #281: Support "go to definition" for namespace packages Fix #466: Fix "go to definition" and resolving imports The fix is to put user search paths in front of workspace directory so that modules inside extra paths can be used as roots for packages * Last port * - Add nuspec - Fix #501: PTVS-LS Integration: Fix LS hanging during file changes - Fix #502: PTVS-LS Integration: Add required *.py files to the vsix * Address CR comments
1 parent 80ce249 commit 13d2202

File tree

114 files changed

+10403
-662
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+10403
-662
lines changed

src/Analysis/Engine/Impl/Analyzer/ExpressionEvaluator.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,19 @@ public IAnalysisSet LookupAnalysisSetByName(Node node, string name, bool addRef
149149
refs = createIn.CreateVariable(node, _unit, name, addRef);
150150
res = refs.Types;
151151
} else {
152-
// ... warn the user
153-
warn = true;
152+
switch (name) {
153+
// "atom" in Python grammar.
154+
case "True":
155+
case "False":
156+
case "None":
157+
case "...":
158+
Debug.Fail($"Known good name '{name}' not found in scope");
159+
break;
160+
default:
161+
// ... warn the user
162+
warn = true;
163+
break;
164+
}
154165
}
155166
}
156167
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ namespace Microsoft.PythonTools.Analysis {
2222
/// more efficient analysis.
2323
///
2424
/// To analyze the full group you call Analyze(true) on all the items in the same group (determined
25-
/// by looking at the identity of the AnalysGroup object). Then you call AnalyzeQueuedEntries on the
25+
/// by looking at the identity of the AnalysisGroup object). Then you call AnalyzeQueuedEntries on the
2626
/// group.
2727
/// </summary>
2828
public interface IGroupableAnalysisProjectEntry {
2929
/// <summary>
3030
/// Analyzes this project entry optionally just adding it to the queue shared by the project.
3131
/// </summary>
32-
void Analyze(CancellationToken cancel, bool enqueueOnly);
32+
void PreAnalyze();
3333

3434
IGroupableAnalysisProject AnalysisGroup { get; }
3535
}

src/Analysis/Engine/Impl/DependencyResolution/PathResolverSnapshot.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,11 @@ private void CreateRootsWithDefault(string rootDirectory, string[] userSearchPat
359359
.ToArray();
360360

361361
var filteredInterpreterSearchPaths = interpreterSearchPaths.Select(FixPath)
362-
.Except(filteredUserSearchPaths.Prepend(rootDirectory))
362+
.Except(filteredUserSearchPaths.Append(rootDirectory))
363363
.ToArray();
364364

365365
userRootsCount = filteredUserSearchPaths.Length + 1;
366-
nodes = AddRootsFromSearchPaths(ImmutableArray<Node>.Empty.Add(GetOrCreateRoot(rootDirectory)), filteredUserSearchPaths, filteredInterpreterSearchPaths);
366+
nodes = AddRootsFromSearchPaths(rootDirectory, filteredUserSearchPaths, filteredInterpreterSearchPaths);
367367

368368
string FixPath(string p) => Path.IsPathRooted(p) ? PathUtils.NormalizePath(p) : PathUtils.NormalizePath(Path.Combine(rootDirectory, p));
369369
}
@@ -381,11 +381,18 @@ private void CreateRootsWithoutDefault(string[] userSearchPaths, string[] interp
381381
.ToArray();
382382

383383
userRootsCount = filteredUserSearchPaths.Length;
384-
nodes = AddRootsFromSearchPaths(ImmutableArray<Node>.Empty, filteredUserSearchPaths, filteredInterpreterSearchPaths);
384+
nodes = AddRootsFromSearchPaths(filteredUserSearchPaths, filteredInterpreterSearchPaths);
385385
}
386386

387-
private ImmutableArray<Node> AddRootsFromSearchPaths(ImmutableArray<Node> roots, string[] userSearchPaths, string[] interpreterSearchPaths) {
388-
return roots
387+
private ImmutableArray<Node> AddRootsFromSearchPaths(string rootDirectory, string[] userSearchPaths, string[] interpreterSearchPaths) {
388+
return ImmutableArray<Node>.Empty
389+
.AddRange(userSearchPaths.Select(GetOrCreateRoot).ToArray())
390+
.Add(GetOrCreateRoot(rootDirectory))
391+
.AddRange(interpreterSearchPaths.Select(GetOrCreateRoot).ToArray());
392+
}
393+
394+
private ImmutableArray<Node> AddRootsFromSearchPaths(string[] userSearchPaths, string[] interpreterSearchPaths) {
395+
return ImmutableArray<Node>.Empty
389396
.AddRange(userSearchPaths.Select(GetOrCreateRoot).ToArray())
390397
.AddRange(interpreterSearchPaths.Select(GetOrCreateRoot).ToArray());
391398
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
// MERCHANTABILITY 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.Collections.Generic;
18+
19+
namespace Microsoft.PythonTools.Analysis.Infrastructure {
20+
internal static class StackExtensions {
21+
public static bool TryPeek<T>(this Stack<T> stack, out T result) {
22+
if (stack.Count == 0) {
23+
result = default;
24+
return false;
25+
}
26+
27+
result = stack.Peek();
28+
return true;
29+
}
30+
}
31+
}

src/Analysis/Engine/Impl/Intellisense/AnalysisQueue.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ public void Enqueue(IAnalyzable item, AnalysisPriority priority) {
137137
}
138138

139139
private async Task HandleAnalyzable(IAnalyzable item, AnalysisPriority priority, CancellationToken cancellationToken) {
140+
cancellationToken.ThrowIfCancellationRequested();
141+
140142
if (item is IGroupableAnalysisProjectEntry groupable) {
141143
var added = _enqueuedGroups.Add(groupable.AnalysisGroup);
142144
if (added) {
@@ -147,7 +149,7 @@ private async Task HandleAnalyzable(IAnalyzable item, AnalysisPriority priority,
147149
}
148150
}
149151

150-
groupable.Analyze(cancellationToken, true);
152+
groupable.PreAnalyze();
151153
} else {
152154
item.Analyze(cancellationToken);
153155
}

src/Analysis/Engine/Impl/Interpreter/Definitions/PythonMemberType.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public enum PythonMemberType {
6464
/// An instance of a namespace object that was imported from .NET.
6565
/// </summary>
6666
Namespace,
67-
6867
/// <summary>
6968
/// A constant defined in source code.
7069
/// </summary>

src/Analysis/Engine/Impl/Interpreter/InterpreterConfiguration.cs

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
using Microsoft.PythonTools.Analysis.Infrastructure;
2222

2323
namespace Microsoft.PythonTools.Interpreter {
24-
public sealed class InterpreterConfiguration : IEquatable<InterpreterConfiguration> {
24+
public class InterpreterConfiguration : IEquatable<InterpreterConfiguration> {
2525
private readonly string _description;
2626
private string _fullDescription;
2727

@@ -48,29 +48,6 @@ public InterpreterConfiguration(
4848
SitePackagesPath = sitePackagesPath ?? string.Empty;
4949
}
5050

51-
[Obsolete]
52-
public InterpreterConfiguration(
53-
string id,
54-
string description,
55-
string prefixPath = null,
56-
string path = null,
57-
string winPath = "",
58-
string pathVar = "",
59-
InterpreterArchitecture arch = default(InterpreterArchitecture),
60-
Version version = null,
61-
InterpreterUIMode uiMode = InterpreterUIMode.Normal
62-
) {
63-
Id = id;
64-
_description = description ?? "";
65-
PrefixPath = prefixPath;
66-
InterpreterPath = path;
67-
WindowsInterpreterPath = string.IsNullOrEmpty(winPath) ? path : winPath;
68-
PathEnvironmentVariable = pathVar;
69-
Architecture = arch ?? InterpreterArchitecture.Unknown;
70-
Version = version ?? new Version();
71-
UIMode = uiMode;
72-
}
73-
7451
private static string Read(Dictionary<string, object> d, string k)
7552
=> d.TryGetValue(k, out var o) ? o as string : null;
7653

@@ -155,22 +132,12 @@ public void SwitchToFullDescription() {
155132
}
156133
}
157134

158-
[Obsolete("Prefix path only applies to Windows.")]
159-
public string PrefixPath { get; }
160-
161135
/// <summary>
162136
/// Returns the path to the interpreter executable for launching Python
163137
/// applications.
164138
/// </summary>
165139
public string InterpreterPath { get; }
166-
167-
/// <summary>
168-
/// Returns the path to the interpreter executable for launching Python
169-
/// applications which are windows applications (pythonw.exe, ipyw.exe).
170-
/// </summary>
171-
[Obsolete("Python Language Server is platform-agnostic and does not use Windows-specific settings.")]
172-
public string WindowsInterpreterPath { get; }
173-
140+
174141
/// <summary>
175142
/// Gets the environment variable which should be used to set sys.path.
176143
/// </summary>
@@ -198,12 +165,6 @@ public void SwitchToFullDescription() {
198165
/// </summary>
199166
public string SitePackagesPath { get; }
200167

201-
/// <summary>
202-
/// The UI behavior of the interpreter.
203-
/// </summary>
204-
[Obsolete("Language Server does not support UI features related to the interpreter.")]
205-
public InterpreterUIMode UIMode { get; }
206-
207168
/// <summary>
208169
/// The fixed search paths of the interpreter.
209170
/// </summary>

src/Analysis/Engine/Impl/Interpreter/InterpreterUIMode.cs

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/Analysis/Engine/Impl/Interpreter/PythonInterpreterFactoryExtensions.cs

Lines changed: 0 additions & 112 deletions
This file was deleted.

src/Analysis/Engine/Impl/LocationInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
using System.Collections.Generic;
1919

2020
namespace Microsoft.PythonTools.Analysis {
21-
internal class LocationInfo : ILocationInfo, IEquatable<LocationInfo> {
21+
public class LocationInfo : ILocationInfo, IEquatable<LocationInfo> {
2222
internal static readonly LocationInfo[] Empty = new LocationInfo[0];
2323

2424
public LocationInfo(string path, Uri documentUri, int line, int column) :

0 commit comments

Comments
 (0)