Skip to content
Open
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
12 changes: 7 additions & 5 deletions packages/pyright-scip/src/treeVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ export class TreeVisitor extends ParseTreeWalker {
const symbol = this.getScipSymbol(node);
this.document.occurrences.push(
new scip.Occurrence({
symbol_roles: scip.SymbolRole.ReadAccess,
symbol_roles: scip.SymbolRole.Import | scip.SymbolRole.ReadAccess,
Copy link
Author

@maks-ivanov maks-ivanov May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if the ReadAccess role is load-bearing in these cases. If not, I would remove those

symbol: symbol.value,
range: parseNodeToRange(node.module, this.fileInfo!.lines).toLsif(),
})
Expand All @@ -500,7 +500,8 @@ export class TreeVisitor extends ParseTreeWalker {
}

override visitImportFromAs(node: ImportFromAsNode): boolean {
this.pushNewOccurrence(node, this.getScipSymbol(node));
const roles = scip.SymbolRole.Import | scip.SymbolRole.ReadAccess;
this.pushNewOccurrence(node, this.getScipSymbol(node), roles);
return false;
}

Expand All @@ -510,19 +511,20 @@ export class TreeVisitor extends ParseTreeWalker {
override visitImportAs(node: ImportAsNode): boolean {
const moduleName = _formatModuleName(node.module);
const importInfo = getImportInfo(node.module);
const roles = scip.SymbolRole.Import | scip.SymbolRole.ReadAccess;
if (
importInfo &&
importInfo.resolvedPaths[0] &&
path.resolve(importInfo.resolvedPaths[0]).startsWith(this.cwd)
) {
const symbol = Symbols.makeModuleInit(this.projectPackage, moduleName);
this.pushNewOccurrence(node.module, symbol);
this.pushNewOccurrence(node.module, symbol, roles);
} else {
const pythonPackage = this.moduleNameNodeToPythonPackage(node.module);

if (pythonPackage) {
const symbol = Symbols.makeModuleInit(pythonPackage, moduleName);
this.pushNewOccurrence(node.module, symbol);
this.pushNewOccurrence(node.module, symbol, roles);
} else {
// For python packages & modules that we cannot resolve,
// we'll just make a local for the file and note that we could not resolve this module.
Expand All @@ -534,7 +536,7 @@ export class TreeVisitor extends ParseTreeWalker {
const symbol = this.getLocalForDeclaration(node, [
`(module): ${moduleName} [unable to resolve module]`,
]);
this.pushNewOccurrence(node.module, symbol);
this.pushNewOccurrence(node.module, symbol, roles);
}
}

Expand Down
5 changes: 3 additions & 2 deletions packages/pyright-scip/src/virtualenv/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ function pipList(): PipInformation[] {

function pipBulkShow(names: string[]): string[] {
// TODO: This probably breaks with enough names. Should batch them into 512 or whatever the max for bash would be
const maxBuffer = 1024 * 1024 * 10; // 10MB
return child_process
.execSync(`${getPipCommand()} show -f ${names.join(' ')}`)
.toString()
.spawnSync(getPipCommand(), ['show', '-f', `${names.join(' ')}`], { maxBuffer })
.stdout.toString()
.split('---');
}

Expand Down