Skip to content

Commit

Permalink
pull-pylance-with-pyright-1.1.387 (#9363)
Browse files Browse the repository at this point in the history
Co-authored-by: Rich Chiodo <[email protected]>
  • Loading branch information
bschnurr and rchiodo authored Oct 30, 2024
1 parent e6fe8cb commit 0ce78f8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
17 changes: 1 addition & 16 deletions packages/pyright-internal/src/analyzer/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { DiagnosticLevel } from '../common/configOptions';
import { assert, assertNever, fail } from '../common/debug';
import { CreateTypeStubFileAction, Diagnostic } from '../common/diagnostic';
import { DiagnosticRule } from '../common/diagnosticRules';
import { DocStringService } from '../common/docStringService';
import { stripFileExtension } from '../common/pathUtils';
import { convertTextRangeToRange } from '../common/positionUtils';
import { TextRange, getEmptyRange } from '../common/textRange';
Expand Down Expand Up @@ -256,11 +255,7 @@ export class Binder extends ParseTreeWalker {
// the current function.
private _codeFlowComplexity = 0;

constructor(
fileInfo: AnalyzerFileInfo,
private _docStringService: DocStringService,
private _moduleSymbolOnly = false
) {
constructor(fileInfo: AnalyzerFileInfo, private _moduleSymbolOnly = false) {
super();

this._fileInfo = fileInfo;
Expand Down Expand Up @@ -542,15 +537,6 @@ export class Binder extends ParseTreeWalker {
if (paramNode.d.name) {
const symbol = this._bindNameToScope(this._currentScope, paramNode.d.name);

// Extract the parameter docString from the function docString
let docString = ParseTreeUtils.getDocString(node?.d.suite?.d.statements ?? []);
if (docString !== undefined) {
docString = this._docStringService.extractParameterDocumentation(
docString,
paramNode.d.name.d.value
);
}

if (symbol) {
const paramDeclaration: ParamDeclaration = {
type: DeclarationType.Param,
Expand All @@ -559,7 +545,6 @@ export class Binder extends ParseTreeWalker {
range: convertTextRangeToRange(paramNode, this._fileInfo.lines),
moduleName: this._fileInfo.moduleName,
isInExceptSuite: this._isInExceptSuite,
docString: docString,
};

symbol.addDeclaration(paramDeclaration);
Expand Down
4 changes: 0 additions & 4 deletions packages/pyright-internal/src/analyzer/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ export interface ParamDeclaration extends DeclarationBase {
type: DeclarationType.Param;
node: ParameterNode;

// Documentation specified in the function's docstring (if any) can be
// associated with the parameter
docString?: string;

// Inferred parameters can be inferred from pieces of an actual NameNode, so this
// value represents the actual 'name' as the user thinks of it.
inferredName?: string;
Expand Down
6 changes: 1 addition & 5 deletions packages/pyright-internal/src/analyzer/sourceFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -823,11 +823,7 @@ export class SourceFile {
);
AnalyzerNodeInfo.setFileInfo(this._writableData.parserOutput!.parseTree, fileInfo);

const binder = new Binder(
fileInfo,
this.serviceProvider.docStringService(),
configOptions.indexGenerationMode
);
const binder = new Binder(fileInfo, configOptions.indexGenerationMode);
this._writableData.isBindingInProgress = true;
binder.bindModule(this._writableData.parserOutput!.parseTree);

Expand Down
34 changes: 30 additions & 4 deletions packages/pyright-internal/src/languageService/hoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,35 @@ export function convertHoverResults(hoverResults: HoverResults | null, format: M
};
}

export function addParameterResultsPart(
serviceProvider: ServiceProvider,
paramNameNode: NameNode,
resolvedDecl: Declaration | undefined,
format: MarkupKind,
parts: HoverTextPart[]
) {
// See if we have a docstring for the parent function.
let docString: string | undefined = undefined;
const funcNode = ParseTreeUtils.getEnclosingFunction(resolvedDecl?.node || paramNameNode);
if (funcNode) {
docString = ParseTreeUtils.getDocString(funcNode?.d.suite?.d.statements ?? []);
if (docString) {
// Compute the docstring now.
docString = serviceProvider
.docStringService()
.extractParameterDocumentation(docString, paramNameNode.d.value, format);
}
}
if (!docString) {
return;
}

parts.push({
python: false,
text: docString,
});
}

export function addDocumentationResultsPart(
serviceProvider: ServiceProvider,
docString: string | undefined,
Expand Down Expand Up @@ -376,10 +405,7 @@ export class HoverProvider {

case DeclarationType.Param: {
this._addResultsPart(parts, '(parameter) ' + node.d.value + this._getTypeText(node), /* python */ true);

if (resolvedDecl.docString) {
this._addResultsPart(parts, resolvedDecl.docString);
}
addParameterResultsPart(this._program.serviceProvider, node, resolvedDecl, this._format, parts);
this._addDocumentationPart(parts, node, resolvedDecl);
break;
}
Expand Down

0 comments on commit 0ce78f8

Please sign in to comment.