pull pylance (#2466)

This commit is contained in:
Bill Schnurr 2021-10-20 14:42:22 -07:00 committed by GitHub
parent b3244bb446
commit 1d97208c65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 12 deletions

View File

@ -49,6 +49,10 @@ export namespace TextRange {
return position >= range.start && position <= getEnd(range);
}
export function overlapsRange(range: TextRange, other: TextRange): boolean {
return overlaps(range, other.start) || overlaps(other, range.start);
}
export function extend(range: TextRange, extension: TextRange | TextRange[] | undefined) {
if (extension) {
if (Array.isArray(extension)) {

View File

@ -3573,7 +3573,8 @@ export class Parser {
if (this._peekTokenType() !== TokenType.CloseParenthesis) {
return this._handleExpressionParseError(
ErrorExpressionCategory.MissingTupleCloseParen,
Localizer.Diagnostic.expectedCloseParen()
Localizer.Diagnostic.expectedCloseParen(),
yieldExpr
);
} else {
extendRange(yieldExpr, this._getNextToken());
@ -3593,7 +3594,8 @@ export class Parser {
if (this._peekTokenType() !== TokenType.CloseParenthesis) {
return this._handleExpressionParseError(
ErrorExpressionCategory.MissingTupleCloseParen,
Localizer.Diagnostic.expectedCloseParen()
Localizer.Diagnostic.expectedCloseParen(),
exprListResult.parseError ?? tupleOrExpression
);
} else {
const nextToken = this._getNextToken();
@ -3616,21 +3618,31 @@ export class Parser {
if (!this._consumeTokenIfType(TokenType.CloseBracket)) {
return this._handleExpressionParseError(
ErrorExpressionCategory.MissingListCloseBracket,
Localizer.Diagnostic.expectedCloseBracket()
Localizer.Diagnostic.expectedCloseBracket(),
exprListResult.parseError ?? _createList()
);
}
return _createList();
function _createList() {
const listAtom = ListNode.create(startBracket);
if (closeBracket) {
extendRange(listAtom, closeBracket);
}
if (exprListResult.list.length > 0) {
exprListResult.list.forEach((expr) => {
expr.parent = listAtom;
});
extendRange(listAtom, exprListResult.list[exprListResult.list.length - 1]);
}
listAtom.entries = exprListResult.list;
return listAtom;
}
}
private _parseTestListWithComprehension(): ListResult<ExpressionNode> {
let sawComprehension = false;

View File

@ -0,0 +1,33 @@
/// <reference path="fourslash.ts" />
// @filename: testList.py
//// a = 42
//// x = [
//// a.[|/*marker1*/|]
//// ]
// @filename: testListWithCall.py
//// b = 42
//// y = [
//// print(b.[|/*marker2*/|])
//// ]
// @filename: testListWithCallMissingClosedParens.py
//// b = 42
//// y = [
//// print(b.[|/*marker3*/|]
//// ]
{
helper.openFiles(helper.getMarkers().map((m) => m.fileName)); // @ts-ignore
await helper.verifyCompletion('included', 'markdown', {
marker1: {
completions: [{ label: 'numerator', kind: Consts.CompletionItemKind.Property }],
},
marker2: {
completions: [{ label: 'numerator', kind: Consts.CompletionItemKind.Property }],
},
marker3: {
completions: [{ label: 'numerator', kind: Consts.CompletionItemKind.Property }],
},
});
}