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

Commit 37a3f78

Browse files
author
MikhailArkhipov
committed
Merge branch 'master' of https://github.com/Microsoft/python-language-server into depth
2 parents 15d8157 + 044a70d commit 37a3f78

34 files changed

+1081
-1598
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Apache License
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright (c) 2018 Microsoft Corporation
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,21 @@ private bool ProcessAbstractDecorators(IAnalysisSet decorator) {
109109
switch (d.Name) {
110110
case "abstractmethod":
111111
res = true;
112+
Function.IsAbstract = true;
112113
break;
113114
case "abstractstaticmethod":
114115
Function.IsStatic = true;
116+
Function.IsAbstract = true;
115117
res = true;
116118
break;
117119
case "abstractclassmethod":
118120
Function.IsClassMethod = true;
121+
Function.IsAbstract = true;
119122
res = true;
120123
break;
121124
case "abstractproperty":
122125
Function.IsProperty = true;
126+
Function.IsAbstract = true;
123127
res = true;
124128
break;
125129
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ public struct Position {
4040
public static bool operator >(Position p1, Position p2) => p1.line > p2.line || p1.line == p2.line && p1.character > p2.character;
4141
public static bool operator <(Position p1, Position p2) => p1.line < p2.line || p1.line == p2.line && p1.character < p2.character;
4242

43-
public override string ToString() => ((SourceLocation)this).ToString();
43+
public override string ToString() => $"({line}, {character})";
4444
}
4545
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ public struct Range {
2424
public static implicit operator SourceSpan(Range r) => new SourceSpan(r.start, r.end);
2525
public static implicit operator Range(SourceSpan span) => new Range { start = span.Start, end = span.End };
2626

27-
public override string ToString() => ((SourceSpan)this).ToString();
27+
public override string ToString() => $"{start} - {end}";
2828
}
2929
}

src/Analysis/Engine/Impl/Infrastructure/Extensions/StringBuilderExtensions.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ public static StringBuilder TrimEnd(this StringBuilder sb) {
2525
return sb;
2626
}
2727

28-
public static StringBuilder EnsureEndsWithSpace(this StringBuilder sb, int count = 1, bool allowLeading = false) {
29-
if (sb.Length == 0 && !allowLeading) {
28+
public static StringBuilder EnsureEndsWithWhiteSpace(this StringBuilder sb, int whiteSpaceCount = 1) {
29+
if (sb.Length == 0) {
3030
return sb;
3131
}
3232

33-
for (var i = sb.Length - 1; i >= 0 && char.IsWhiteSpace(sb[i]); i--) {
34-
count--;
33+
for (var i = sb.Length - 1; i >= 0 && whiteSpaceCount > 0 && char.IsWhiteSpace(sb[i]); i--) {
34+
whiteSpaceCount--;
3535
}
3636

37-
if (count > 0) {
38-
sb.Append(new string(' ', count));
37+
if (whiteSpaceCount > 0) {
38+
sb.Append(' ', whiteSpaceCount);
3939
}
40-
40+
4141
return sb;
4242
}
4343
}

src/Analysis/Engine/Impl/ModuleAnalysis.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,23 @@ private VariablesResult GetVariablesFromNameExpression(Expression expr, Analysis
294294
mainDefinition = mainDefinition ?? definitions.FirstOrDefault();
295295
if (mainDefinition != null) {
296296
// Drop definitions in outer scopes and convert those in inner scopes to references.
297+
// Exception is when variable is an import as in
298+
// abc = 1
299+
// import abc
300+
var imports = definitions
301+
.Where(d => d.Variable.Variable.Types.Any(t => t.TypeId == BuiltinTypeId.Module) && d.Location.DocumentUri != DocumentUri)
302+
.ToArray();
303+
297304
// Scope levels are numbered in reverse (X == main definition level, x+1 == one up).
298305
var defsToRefs = definitions
306+
.Except(imports)
299307
.Where(d => d != mainDefinition && d.ScopeLevel <= mainDefinition.ScopeLevel)
300308
.Select(v => new VariableScopePair(new AnalysisVariable(v.Variable.Variable, VariableType.Reference, v.Location), v.ScopeLevel));
301309

302310
var others = variables
303311
.Where(v => (v.VariableType == VariableType.Reference || v.VariableType == VariableType.Value) &&
304312
v.ScopeLevel <= mainDefinition.ScopeLevel);
305-
variables = new[] { mainDefinition }.Concat(others.Concat(defsToRefs));
313+
variables = new[] { mainDefinition }.Concat(imports).Concat(others.Concat(defsToRefs));
306314
}
307315

308316
return new VariablesResult(variables.Select(v => v.Variable), unit.Tree);

src/Analysis/Engine/Impl/Parsing/Tokenizer.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,9 @@ public List<TokenInfo> ReadTokens(int characterCount) {
130130
return tokens;
131131
}
132132

133-
public object CurrentState {
134-
get {
135-
return _state;
136-
}
137-
}
138-
139-
public SourceLocation CurrentPosition {
140-
get {
141-
return IndexToLocation(CurrentIndex);
142-
}
143-
}
133+
public object CurrentState => _state;
134+
public int CurrentLine => _newLineLocations.Count;
135+
public SourceLocation CurrentPosition => IndexToLocation(CurrentIndex);
144136

145137
public SourceLocation IndexToLocation(int index) {
146138
int match = _newLineLocations.BinarySearch(new NewLineLocation(index, NewLineKind.None));
@@ -2235,6 +2227,7 @@ private static void DumpToken(Token token) {
22352227
Console.WriteLine("{0} `{1}`", token.Kind, token.Image.Replace("\r", "\\r").Replace("\n", "\\n").Replace("\t", "\\t"));
22362228
}
22372229

2230+
internal NewLineLocation GetNewLineLocation(int line) => _newLineLocations.Count == line ? new NewLineLocation(CurrentIndex, NewLineKind.None) : _newLineLocations[line];
22382231
internal NewLineLocation[] GetLineLocations() => _newLineLocations.ToArray();
22392232
internal SourceLocation[] GetCommentLocations() => _commentLocations.ToArray();
22402233

@@ -2564,11 +2557,7 @@ private bool AtBeginning {
25642557
}
25652558
}
25662559

2567-
private int CurrentIndex {
2568-
get {
2569-
return _tokenStartIndex + Math.Min(_position, _end) - _start;
2570-
}
2571-
}
2560+
private int CurrentIndex => _tokenStartIndex + Math.Min(_position, _end) - _start;
25722561

25732562
private void DiscardToken() {
25742563
CheckInvariants();

src/Analysis/Engine/Impl/Values/BoundMethodInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public override IAnalysisSet Call(Node node, AnalysisUnit unit, IAnalysisSet[] a
4646
public override IPythonProjectEntry DeclaringModule => Function.DeclaringModule;
4747
public override int DeclaringVersion => Function.DeclaringVersion;
4848
public override IEnumerable<ILocationInfo> Locations => Function.Locations;
49+
public override BuiltinTypeId TypeId => BuiltinTypeId.Function;
4950

5051
public IEnumerable<KeyValuePair<string, string>> GetRichDescription() {
5152
if (Push()) {

src/Analysis/Engine/Impl/Values/BuiltinMethodInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public override string Documentation {
9898
return _doc;
9999
}
100100
}
101-
101+
public override BuiltinTypeId TypeId => BuiltinTypeId.BuiltinFunction;
102102
public override PythonMemberType MemberType => _memberType;
103103
public override string Name => _function.Name;
104104
public override ILocatedMember GetLocatedMember() => _function as ILocatedMember;

src/Analysis/Engine/Impl/Values/Definitions/IFunctionInfo.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ public interface IFunctionInfo: IAnalysisValue {
2525
bool IsClosure { get; }
2626
IPythonProjectEntry ProjectEntry { get; }
2727
}
28+
29+
public interface IFunctionInfo2 : IFunctionInfo {
30+
bool IsAbstract { get; }
31+
}
2832
}

0 commit comments

Comments
 (0)