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

PTVS integration #524

Merged
merged 11 commits into from
Jan 9, 2019
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
15 changes: 13 additions & 2 deletions src/Analysis/Engine/Impl/Analyzer/ExpressionEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,19 @@ public IAnalysisSet LookupAnalysisSetByName(Node node, string name, bool addRef
refs = createIn.CreateVariable(node, _unit, name, addRef);
res = refs.Types;
} else {
// ... warn the user
warn = true;
switch (name) {
// "atom" in Python grammar.
case "True":
case "False":
case "None":
case "...":
Debug.Fail($"Known good name '{name}' not found in scope");
break;
default:
// ... warn the user
warn = true;
break;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ namespace Microsoft.PythonTools.Analysis {
/// more efficient analysis.
///
/// To analyze the full group you call Analyze(true) on all the items in the same group (determined
/// by looking at the identity of the AnalysGroup object). Then you call AnalyzeQueuedEntries on the
/// by looking at the identity of the AnalysisGroup object). Then you call AnalyzeQueuedEntries on the
/// group.
/// </summary>
public interface IGroupableAnalysisProjectEntry {
/// <summary>
/// Analyzes this project entry optionally just adding it to the queue shared by the project.
/// </summary>
void Analyze(CancellationToken cancel, bool enqueueOnly);
void PreAnalyze();

IGroupableAnalysisProject AnalysisGroup { get; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ private void CreateRootsWithDefault(string rootDirectory, string[] userSearchPat
.ToArray();

var filteredInterpreterSearchPaths = interpreterSearchPaths.Select(FixPath)
.Except(filteredUserSearchPaths.Prepend(rootDirectory))
.Except(filteredUserSearchPaths.Append(rootDirectory))
.ToArray();

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

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

userRootsCount = filteredUserSearchPaths.Length;
nodes = AddRootsFromSearchPaths(ImmutableArray<Node>.Empty, filteredUserSearchPaths, filteredInterpreterSearchPaths);
nodes = AddRootsFromSearchPaths(filteredUserSearchPaths, filteredInterpreterSearchPaths);
}

private ImmutableArray<Node> AddRootsFromSearchPaths(ImmutableArray<Node> roots, string[] userSearchPaths, string[] interpreterSearchPaths) {
return roots
private ImmutableArray<Node> AddRootsFromSearchPaths(string rootDirectory, string[] userSearchPaths, string[] interpreterSearchPaths) {
return ImmutableArray<Node>.Empty
.AddRange(userSearchPaths.Select(GetOrCreateRoot).ToArray())
.Add(GetOrCreateRoot(rootDirectory))
.AddRange(interpreterSearchPaths.Select(GetOrCreateRoot).ToArray());
}

private ImmutableArray<Node> AddRootsFromSearchPaths(string[] userSearchPaths, string[] interpreterSearchPaths) {
return ImmutableArray<Node>.Empty
.AddRange(userSearchPaths.Select(GetOrCreateRoot).ToArray())
.AddRange(interpreterSearchPaths.Select(GetOrCreateRoot).ToArray());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Python Tools for Visual Studio
// Copyright(c) Microsoft Corporation
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the License); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
// MERCHANTABILITY OR NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.

using System.Collections.Generic;

namespace Microsoft.PythonTools.Analysis.Infrastructure {
internal static class StackExtensions {
public static bool TryPeek<T>(this Stack<T> stack, out T result) {
if (stack.Count == 0) {
result = default;
return false;
}

result = stack.Peek();
return true;
}
}
}
4 changes: 3 additions & 1 deletion src/Analysis/Engine/Impl/Intellisense/AnalysisQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ public void Enqueue(IAnalyzable item, AnalysisPriority priority) {
}

private async Task HandleAnalyzable(IAnalyzable item, AnalysisPriority priority, CancellationToken cancellationToken) {
cancellationToken.ThrowIfCancellationRequested();

if (item is IGroupableAnalysisProjectEntry groupable) {
var added = _enqueuedGroups.Add(groupable.AnalysisGroup);
if (added) {
Expand All @@ -147,7 +149,7 @@ private async Task HandleAnalyzable(IAnalyzable item, AnalysisPriority priority,
}
}

groupable.Analyze(cancellationToken, true);
groupable.PreAnalyze();
} else {
item.Analyze(cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public enum PythonMemberType {
/// An instance of a namespace object that was imported from .NET.
/// </summary>
Namespace,

/// <summary>
/// A constant defined in source code.
/// </summary>
Expand Down
43 changes: 2 additions & 41 deletions src/Analysis/Engine/Impl/Interpreter/InterpreterConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
using Microsoft.PythonTools.Analysis.Infrastructure;

namespace Microsoft.PythonTools.Interpreter {
public sealed class InterpreterConfiguration : IEquatable<InterpreterConfiguration> {
public class InterpreterConfiguration : IEquatable<InterpreterConfiguration> {
private readonly string _description;
private string _fullDescription;

Expand All @@ -48,29 +48,6 @@ public InterpreterConfiguration(
SitePackagesPath = sitePackagesPath ?? string.Empty;
}

[Obsolete]
public InterpreterConfiguration(
string id,
string description,
string prefixPath = null,
string path = null,
string winPath = "",
string pathVar = "",
InterpreterArchitecture arch = default(InterpreterArchitecture),
Version version = null,
InterpreterUIMode uiMode = InterpreterUIMode.Normal
) {
Id = id;
_description = description ?? "";
PrefixPath = prefixPath;
InterpreterPath = path;
WindowsInterpreterPath = string.IsNullOrEmpty(winPath) ? path : winPath;
PathEnvironmentVariable = pathVar;
Architecture = arch ?? InterpreterArchitecture.Unknown;
Version = version ?? new Version();
UIMode = uiMode;
}

private static string Read(Dictionary<string, object> d, string k)
=> d.TryGetValue(k, out var o) ? o as string : null;

Expand Down Expand Up @@ -155,22 +132,12 @@ public void SwitchToFullDescription() {
}
}

[Obsolete("Prefix path only applies to Windows.")]
public string PrefixPath { get; }

/// <summary>
/// Returns the path to the interpreter executable for launching Python
/// applications.
/// </summary>
public string InterpreterPath { get; }

/// <summary>
/// Returns the path to the interpreter executable for launching Python
/// applications which are windows applications (pythonw.exe, ipyw.exe).
/// </summary>
[Obsolete("Python Language Server is platform-agnostic and does not use Windows-specific settings.")]
public string WindowsInterpreterPath { get; }


/// <summary>
/// Gets the environment variable which should be used to set sys.path.
/// </summary>
Expand Down Expand Up @@ -198,12 +165,6 @@ public void SwitchToFullDescription() {
/// </summary>
public string SitePackagesPath { get; }

/// <summary>
/// The UI behavior of the interpreter.
/// </summary>
[Obsolete("Language Server does not support UI features related to the interpreter.")]
public InterpreterUIMode UIMode { get; }

/// <summary>
/// The fixed search paths of the interpreter.
/// </summary>
Expand Down
56 changes: 0 additions & 56 deletions src/Analysis/Engine/Impl/Interpreter/InterpreterUIMode.cs

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion src/Analysis/Engine/Impl/LocationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
using System.Collections.Generic;

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

public LocationInfo(string path, Uri documentUri, int line, int column) :
Expand Down
Loading