Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull Pylance with Pyright 1.1.391 #9668

Closed
Closed
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
14,002 changes: 5,681 additions & 8,321 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"devDependencies": {
"@types/glob": "^7.2.0",
"@types/node": "^22.7.0",
"@types/node": "^22.10.5",
"@types/yargs": "^16.0.9",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
Expand All @@ -32,7 +32,7 @@
"eslint-plugin-simple-import-sort": "^10.0.0",
"glob": "^7.2.3",
"jsonc-parser": "^3.3.1",
"lerna": "^8.1.8",
"lerna": "^8.1.9",
"npm-check-updates": "^16.14.20",
"p-queue": "^6.6.2",
"prettier": "2.8.8",
Expand Down
1,370 changes: 849 additions & 521 deletions packages/pyright-internal/package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions packages/pyright-internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
"devDependencies": {
"@types/command-line-args": "^5.2.3",
"@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.13",
"@types/lodash": "^4.17.7",
"@types/node": "^22.7.0",
"@types/jest": "^29.5.14",
"@types/lodash": "^4.17.14",
"@types/node": "^22.10.5",
"@types/tmp": "^0.2.6",
"copy-webpack-plugin": "^11.0.0",
"esbuild-loader": "^3.2.0",
Expand All @@ -51,7 +51,7 @@
"ts-jest": "^29.2.5",
"ts-loader": "^9.5.1",
"typescript": "~5.5.4",
"webpack": "^5.94.0",
"webpack": "^5.97.1",
"webpack-cli": "^5.1.4",
"word-wrap": "1.2.5"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { TokenType } from '../parser/tokenizerTypes';
import * as AnalyzerNodeInfo from './analyzerNodeInfo';
import { ModuleNameAndType } from './importResolver';
import { ImportResult, ImportType } from './importResult';
import { findTokenAfter, getTokenAt } from './parseTreeUtils';
import { getTokenAfter, getTokenAt } from './parseTreeUtils';
import * as SymbolNameUtils from './symbolNameUtils';

export interface ImportStatement {
Expand Down Expand Up @@ -797,8 +797,8 @@ function getEditsPreservingFirstCommentAfterCommaIfExist(
return [{ start: offsetOfPreviousNodeEnd, length }];
}

const commaToken = findTokenAfter(
parseFileResults.tokenizerOutput,
const commaToken = getTokenAfter(
parseFileResults.tokenizerOutput.tokens,
TextRange.getEnd(previousNode),
(t) => t.type === TokenType.Comma
);
Expand Down
47 changes: 29 additions & 18 deletions packages/pyright-internal/src/analyzer/parseTreeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1909,6 +1909,35 @@ export function getTokenAtLeft(
return tokens.getItemAt(index);
}

export function getTokenIndexAfter(
tokens: TextRangeCollection<Token>,
position: number,
predicate: (t: Token) => boolean
) {
const index = tokens.getItemAtPosition(position);
if (index < 0) {
return -1;
}

for (let i = index; i < tokens.length; i++) {
const token = tokens.getItemAt(i);
if (predicate(token)) {
return i;
}
}

return -1;
}

export function getTokenAfter(tokens: TextRangeCollection<Token>, position: number, predicate: (t: Token) => boolean) {
const index = getTokenIndexAfter(tokens, position, predicate);
if (index < 0) {
return undefined;
}

return tokens.getItemAt(index);
}

export function isWhitespace(token: Token) {
return token.type === TokenType.NewLine || token.type === TokenType.Indent || token.type === TokenType.Dedent;
}
Expand Down Expand Up @@ -1941,24 +1970,6 @@ export function getIndexOfTokenOverlapping(tokens: TextRangeCollection<Token>, p
return TextRange.overlaps(token, position) ? index : -1;
}

export function findTokenAfter(tokenizerOutput: TokenizerOutput, offset: number, predicate: (t: Token) => boolean) {
const tokens = tokenizerOutput.tokens;

const index = tokens.getItemAtPosition(offset);
if (index < 0) {
return undefined;
}

for (let i = index; i < tokens.length; i++) {
const token = tokens.getItemAt(i);
if (predicate(token)) {
return token;
}
}

return undefined;
}

export function getCommentsAtTokenIndex(tokens: TextRangeCollection<Token>, index: number) {
let token = getTokenAtIndex(tokens, index);
if (!token) {
Expand Down
12 changes: 12 additions & 0 deletions packages/pyright-internal/src/tests/harness/fourslash/testState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,18 @@ export class TestState {
this.workspace.service.invalidateAndForceReanalysis(InvalidatedReason.Reanalyzed);
this.analyze();

// calling `analyze` should have parse and bind all or open user files. make sure that's true at least for open files.
for (const info of this.program.getOpened()) {
if (!info.sourceFile.getModuleSymbolTable()) {
this.console.error(
`Module symbol missing?: ${info.sourceFile.getUri()}, bound: ${!info.sourceFile.isBindingRequired}`
);

// Make sure it is bound.
this.program.getBoundSourceFile(info.sourceFile.getUri());
}
}

// Local copy to use in capture.
const serviceProvider = this.serviceProvider;
for (const range of this.getRanges()) {
Expand Down
Loading
Loading