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
6 changes: 5 additions & 1 deletion src/LanguageServer/Impl/Completion/CompletionSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
using System.Linq;
using Microsoft.Python.Analysis;
using Microsoft.Python.Analysis.Analyzer.Expressions;
using Microsoft.Python.Core;
using Microsoft.Python.Analysis.Modules;
using Microsoft.Python.Core.Text;
using Microsoft.Python.Parsing;
using Microsoft.Python.Parsing.Ast;
Expand All @@ -30,6 +30,10 @@ public CompletionSource(IDocumentationSource docSource, ServerSettings.PythonCom
}

public CompletionResult GetCompletions(IDocumentAnalysis analysis, SourceLocation location) {
if(analysis.Document.ModuleType != ModuleType.User) {
return CompletionResult.Empty;
}

var context = new CompletionContext(analysis, location, _itemSource);

ExpressionLocator.FindExpression(analysis.Ast, location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static CompletionResult GetCompletions(ScopeStatement scope, Node stateme
Expression e;

var lastToken = tokens.FirstOrDefault();
if(lastToken.Value == null) {
return CompletionResult.Empty;
}

var nextLast = tokens.ElementAtOrDefault(1).Value?.Kind ?? TokenKind.EndOfFile;
switch (lastToken.Value.Kind) {
case TokenKind.Dot:
Expand Down
1 change: 1 addition & 0 deletions src/LanguageServer/Impl/Completion/ExpressionLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static void FindExpression(PythonAst ast, SourceLocation position, FindEx
}

expression = expression ?? (statement as ExpressionStatement)?.Expression;
scope = scope ?? ast;
}

private static bool CanBackUp(PythonAst ast, Node node, Node statement, ScopeStatement scope, int column) {
Expand Down