diff --git a/package-lock.json b/package-lock.json index f0048c7..94e65e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ "@types/minimatch": "^5.1.2", "@types/node": "16", "@types/which": "^3.0.4", - "@zzzen/pyright-internal": "^1.2.0-dev.20240707", + "@zzzen/pyright-internal": "^1.2.0-dev.20240714", "coc.nvim": "^0.0.83-next.18", "diff-match-patch": "^1.0.5", "esbuild": "^0.23.0", @@ -667,9 +667,9 @@ } }, "node_modules/@zzzen/pyright-internal": { - "version": "1.2.0-dev.20240707", - "resolved": "https://registry.npmjs.org/@zzzen/pyright-internal/-/pyright-internal-1.2.0-dev.20240707.tgz", - "integrity": "sha512-3vMEI3LrKQ9hX49cpY7w7qaCAUEwI0RHjc/di8eP8BAQ/POZt+QPSk1gA67wrJ3ESknXfWvLn5keoXYDOVQDdA==", + "version": "1.2.0-dev.20240714", + "resolved": "https://registry.npmjs.org/@zzzen/pyright-internal/-/pyright-internal-1.2.0-dev.20240714.tgz", + "integrity": "sha512-LlYL8CzHyxuMFeTdFOGB1q5WAfL+f+30+q7xzB79dsbBdIRwaRk4h3DOm5CbA5xp3/whtANgo7ZS7rQ2BZZBmA==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 06ffe00..4e9817c 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@types/minimatch": "^5.1.2", "@types/node": "16", "@types/which": "^3.0.4", - "@zzzen/pyright-internal": "^1.2.0-dev.20240707", + "@zzzen/pyright-internal": "^1.2.0-dev.20240714", "coc.nvim": "^0.0.83-next.18", "diff-match-patch": "^1.0.5", "esbuild": "^0.23.0", diff --git a/src/parsers/inlayHints.ts b/src/parsers/inlayHints.ts index 9f52bf4..1b9f14f 100644 --- a/src/parsers/inlayHints.ts +++ b/src/parsers/inlayHints.ts @@ -22,7 +22,7 @@ function isLeftSideOfAssignment(node: ParseNode): boolean { if (node.parent?.nodeType !== ParseNodeType.Assignment) { return false; } - return node.start < (node.parent as AssignmentNode).rightExpression.start; + return node.start < (node.parent as AssignmentNode).d.rightExpr.start; } export class TypeInlayHintsWalker extends ParseTreeWalker { @@ -38,7 +38,7 @@ export class TypeInlayHintsWalker extends ParseTreeWalker { inlayHintType: 'variable', startOffset: node.start, endOffset: node.start + node.length - 1, - value: node.value, + value: node.d.value, }); } return super.visitName(node); @@ -48,9 +48,9 @@ export class TypeInlayHintsWalker extends ParseTreeWalker { if (isLeftSideOfAssignment(node)) { this.featureItems.push({ inlayHintType: 'variable', - startOffset: node.memberName.start, - endOffset: node.memberName.start + node.memberName.length - 1, - value: node.memberName.value, + startOffset: node.d.member.start, + endOffset: node.d.member.start + node.d.member.length - 1, + value: node.d.member.d.value, }); } return super.visitMemberAccess(node); @@ -62,7 +62,7 @@ export class TypeInlayHintsWalker extends ParseTreeWalker { return false; } const result = getCallNodeAndActiveParameterIndex(node, node.start, this._parseResults.tokenizerOutput.tokens); - if (!result?.callNode || result.callNode.arguments[result.activeIndex].name) { + if (!result?.callNode || result.callNode.d.args[result.activeIndex].d.name) { return false; } this.featureItems.push({ @@ -77,12 +77,12 @@ export class TypeInlayHintsWalker extends ParseTreeWalker { override visitFunction(node: FunctionNode): boolean { // If the code describes a type, do not add the item. // Add item only if "node.returnTypeAnnotation" does not exist. - if (!node.returnTypeAnnotation) { + if (!node.d.returnAnnotation) { this.featureItems.push({ inlayHintType: 'functionReturn', - startOffset: node.name.start, - endOffset: node.suite.start, - value: node.name.value, + startOffset: node.d.name.start, + endOffset: node.d.suite.start, + value: node.d.name.d.value, }); } return super.visitFunction(node); diff --git a/src/parsers/semanticTokens.ts b/src/parsers/semanticTokens.ts index 13ef18a..844da81 100644 --- a/src/parsers/semanticTokens.ts +++ b/src/parsers/semanticTokens.ts @@ -31,7 +31,7 @@ type SemanticTokenItem = { export class SemanticTokensWalker extends ParseTreeWalker { public semanticItems: SemanticTokenItem[] = []; - private addItem(node: ParseNodeBase, type: string, modifiers: string[] = []) { + private addItem(node: ParseNodeBase, type: string, modifiers: string[] = []) { const item: SemanticTokenItem = { type, start: node.start, length: node.length, modifiers }; if (this.semanticItems.some((x) => x.type === item.type && x.start === item.start && x.length === item.length)) { return; @@ -48,24 +48,24 @@ export class SemanticTokensWalker extends ParseTreeWalker { visitFor(node: ForNode): boolean { if (node.nodeType === ParseNodeType.For) { - this.addItem(node.targetExpression, SemanticTokenTypes.variable); + this.addItem(node.d.targetExpr, SemanticTokenTypes.variable); } return super.visitFor(node); } visitFormatString(node: FormatStringNode): boolean { - node.fieldExpressions.map((f) => this.addItem(f, SemanticTokenTypes.variable)); + node.d.fieldExprs.map((f) => this.addItem(f, SemanticTokenTypes.variable)); return super.visitFormatString(node); } visitCall(node: CallNode): boolean { // TODO: hard-code, treat first-letter UpperCase as class - if (node.leftExpression.nodeType === 38) { - const value = node.leftExpression.value; + if (node.d.leftExpr.nodeType === 38) { + const value = node.d.leftExpr.d.value; if (value[0] === value[0].toUpperCase()) { - this.addItem(node.leftExpression, SemanticTokenTypes.class); + this.addItem(node.d.leftExpr, SemanticTokenTypes.class); } else { - this.addItem(node.leftExpression, SemanticTokenTypes.function); + this.addItem(node.d.leftExpr, SemanticTokenTypes.function); } } return super.visitCall(node); @@ -74,45 +74,45 @@ export class SemanticTokensWalker extends ParseTreeWalker { visitClass(node: ClassNode): boolean { // @ts-ignore if (node.arguments.length === 1 && node.arguments[0].valueExpression.value === 'Enum') { - this.addItem(node.name, SemanticTokenTypes.enum); + this.addItem(node.d.name, SemanticTokenTypes.enum); - for (const m of node.suite.statements) { + for (const m of node.d.suite.d.statements) { // @ts-ignore this.addItem(m.statements[0].leftExpression, SemanticTokenTypes.enumMember); } return super.visitClass(node); } - this.addItem(node.name, SemanticTokenTypes.class, [SemanticTokenModifiers.definition]); + this.addItem(node.d.name, SemanticTokenTypes.class, [SemanticTokenModifiers.definition]); return super.visitClass(node); } visitMemberAccess(node: MemberAccessNode): boolean { if (node.parent?.nodeType === ParseNodeType.Call) { - this.addItem(node.memberName, SemanticTokenTypes.function); + this.addItem(node.d.member, SemanticTokenTypes.function); return super.visitMemberAccess(node); } - this.addItem(node.memberName, SemanticTokenTypes.property); + this.addItem(node.d.member, SemanticTokenTypes.property); return super.visitMemberAccess(node); } visitDecorator(node: DecoratorNode): boolean { - this.addItem(node.expression, SemanticTokenTypes.decorator); + this.addItem(node.d.expr, SemanticTokenTypes.decorator); let nameNode: NameNode | undefined; - switch (node.expression.nodeType) { + switch (node.d.expr.nodeType) { case ParseNodeType.Call: - if (node.expression.leftExpression.nodeType === ParseNodeType.MemberAccess) { - nameNode = node.expression.leftExpression.memberName; - } else if (node.expression.leftExpression.nodeType === ParseNodeType.Name) { - nameNode = node.expression.leftExpression; + if (node.d.expr.d.leftExpr.nodeType === ParseNodeType.MemberAccess) { + nameNode = node.d.expr.d.leftExpr.d.member; + } else if (node.d.expr.d.leftExpr.nodeType === ParseNodeType.Name) { + nameNode = node.d.expr.d.leftExpr; } break; case ParseNodeType.MemberAccess: - nameNode = node.expression.memberName; + nameNode = node.d.expr.d.member; break; case ParseNodeType.Name: - nameNode = node.expression; + nameNode = node.d.expr; break; } if (nameNode) { @@ -122,68 +122,76 @@ export class SemanticTokensWalker extends ParseTreeWalker { } visitImport(node: ImportNode): boolean { - node.list.map((x) => this.addItem(x, SemanticTokenTypes.namespace)); + for (const x of node.d.list) { + if (x.d.alias) { + this.addItem(x.d.alias, SemanticTokenTypes.namespace); + } + } return super.visitImport(node); } visitImportAs(node: ImportAsNode): boolean { - if (node.alias?.value.length) { - this.addItem(node.alias, SemanticTokenTypes.namespace); + if (node.d.alias?.d.value.length) { + this.addItem(node.d.alias, SemanticTokenTypes.namespace); } - node.module.nameParts.map((x) => this.addItem(x, SemanticTokenTypes.namespace)); + node.d.module.d.nameParts.map((x) => this.addItem(x, SemanticTokenTypes.namespace)); return super.visitImportAs(node); } visitImportFrom(node: ImportFromNode): boolean { - node.module.nameParts.map((x) => this.addItem(x, SemanticTokenTypes.namespace)); - node.imports.map((x) => this.addItem(x, SemanticTokenTypes.namespace)); + node.d.module.d.nameParts.map((x) => this.addItem(x, SemanticTokenTypes.namespace)); + for (const x of node.d.imports) { + if (x.d.alias) { + this.addItem(x.d.alias, SemanticTokenTypes.namespace); + } + } return super.visitImportFrom(node); } visitImportFromAs(node: ImportFromAsNode): boolean { - if (node.alias?.value.length) { - this.addItem(node.alias, SemanticTokenTypes.namespace); + if (node.d.alias?.d.value.length) { + this.addItem(node.d.alias, SemanticTokenTypes.namespace); } return super.visitImportFromAs(node); } visitParameter(node: ParameterNode): boolean { - if (!node.name) return super.visitParameter(node); + if (!node.d.name) return super.visitParameter(node); - this.addItem(node.name, SemanticTokenTypes.parameter); - if (node.typeAnnotation) { - this.addItem(node.typeAnnotation, SemanticTokenTypes.typeParameter); + this.addItem(node.d.name, SemanticTokenTypes.parameter); + if (node.d.annotation) { + this.addItem(node.d.annotation, SemanticTokenTypes.typeParameter); } return super.visitParameter(node); } visitTypeParameter(node: TypeParameterNode): boolean { - this.addItem(node.name, SemanticTokenTypes.typeParameter); + this.addItem(node.d.name, SemanticTokenTypes.typeParameter); return super.visitTypeParameter(node); } visitTypeAnnotation(node: TypeAnnotationNode): boolean { - if (node.typeAnnotation) { - this.addItem(node.typeAnnotation, SemanticTokenTypes.typeParameter); + if (node.d.annotation) { + this.addItem(node.d.annotation, SemanticTokenTypes.typeParameter); } return super.visitTypeAnnotation(node); } visitFunction(node: FunctionNode): boolean { const modifiers = [SemanticTokenModifiers.definition]; - if (node.isAsync) { + if (node.d.isAsync) { modifiers.push(SemanticTokenModifiers.async); } const type = node.parent?.parent?.nodeType === 10 ? SemanticTokenTypes.method : SemanticTokenTypes.function; - this.addItem(node.name, type, modifiers); + this.addItem(node.d.name, type, modifiers); - for (const p of node.parameters) { - if (!p.name) continue; + for (const p of node.d.params) { + if (!p.d.name) continue; - this.addItem(p.name, SemanticTokenTypes.parameter); - if (p.typeAnnotation) { - this.addItem(p.typeAnnotation, SemanticTokenTypes.typeParameter); + this.addItem(p.d.name, SemanticTokenTypes.parameter); + if (p.d.annotation) { + this.addItem(p.d.annotation, SemanticTokenTypes.typeParameter); } } diff --git a/src/parsers/testFramework.ts b/src/parsers/testFramework.ts index b9bc20c..bf2e4ea 100644 --- a/src/parsers/testFramework.ts +++ b/src/parsers/testFramework.ts @@ -19,7 +19,7 @@ export class TestFrameworkWalker extends ParseTreeWalker { } override visitFunction(node: FunctionNode): boolean { - if (node.name.value.startsWith('test_')) { + if (node.d.name.d.value.startsWith('test_')) { if (node.parent && printParseNodeType(node.parent.nodeType) === 'Suite') { const parentSuiteNode = node.parent as SuiteNode; if (parentSuiteNode.parent && printParseNodeType(parentSuiteNode.parent.nodeType) === 'Class') { @@ -33,7 +33,7 @@ export class TestFrameworkWalker extends ParseTreeWalker { } this.featureItems.push({ - value: classNode.name.value + combineString + node.name.value, + value: classNode.d.name.d.value + combineString + node.d.name.d.value, startOffset: node.start, endOffset: node.start + node.length - 1, }); @@ -41,7 +41,7 @@ export class TestFrameworkWalker extends ParseTreeWalker { } else { if (this.testFramework === 'pytest') { this.featureItems.push({ - value: node.name.value, + value: node.d.name.d.value, startOffset: node.start, endOffset: node.start + node.length - 1, });