Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
# < definition scip-python python snapshot-util 0.1 `src.single_class`/__init__:
# < definition scip-python python snapshot-util 0.1 single_class/__init__:

class ExampleClass:
# ^^^^^^^^^^^^ definition snapshot-util 0.1 `src.single_class`/ExampleClass#
# ^^^^^^^^^^^^ definition snapshot-util 0.1 single_class/ExampleClass#
a: int
# ^ definition snapshot-util 0.1 `src.single_class`/ExampleClass#a.
# ^ definition snapshot-util 0.1 single_class/ExampleClass#a.
# ^^^ reference python-stdlib 3.11 builtins/int#
b: int
# ^ definition snapshot-util 0.1 `src.single_class`/ExampleClass#b.
# ^ definition snapshot-util 0.1 single_class/ExampleClass#b.
# ^^^ reference python-stdlib 3.11 builtins/int#
c: str
# ^ definition snapshot-util 0.1 `src.single_class`/ExampleClass#c.
# ^ definition snapshot-util 0.1 single_class/ExampleClass#c.
# ^^^ reference python-stdlib 3.11 builtins/str#

static_var = "Hello World"
# ^^^^^^^^^^ definition snapshot-util 0.1 `src.single_class`/ExampleClass#static_var.
# ^^^^^^^^^^ definition snapshot-util 0.1 single_class/ExampleClass#static_var.

def __init__(self, a: int, b: int):
# ^^^^^^^^ definition snapshot-util 0.1 `src.single_class`/ExampleClass#__init__().
# ^^^^ definition snapshot-util 0.1 `src.single_class`/ExampleClass#__init__().(self)
# ^ definition snapshot-util 0.1 `src.single_class`/ExampleClass#__init__().(a)
# ^^^^^^^^ definition snapshot-util 0.1 single_class/ExampleClass#__init__().
# ^^^^ definition snapshot-util 0.1 single_class/ExampleClass#__init__().(self)
# ^ definition snapshot-util 0.1 single_class/ExampleClass#__init__().(a)
# ^^^ reference python-stdlib 3.11 builtins/int#
# ^ definition snapshot-util 0.1 `src.single_class`/ExampleClass#__init__().(b)
# ^ definition snapshot-util 0.1 single_class/ExampleClass#__init__().(b)
# ^^^ reference python-stdlib 3.11 builtins/int#
local_c = ", world!"
# ^^^^^^^ definition local 0

self.a = a
# ^^^^ reference snapshot-util 0.1 `src.single_class`/ExampleClass#__init__().(self)
# ^ reference snapshot-util 0.1 `src.single_class`/ExampleClass#a.
# ^ reference snapshot-util 0.1 `src.single_class`/ExampleClass#__init__().(a)
# ^^^^ reference snapshot-util 0.1 single_class/ExampleClass#__init__().(self)
# ^ reference snapshot-util 0.1 single_class/ExampleClass#a.
# ^ reference snapshot-util 0.1 single_class/ExampleClass#__init__().(a)
self.b = b
# ^^^^ reference snapshot-util 0.1 `src.single_class`/ExampleClass#__init__().(self)
# ^ reference snapshot-util 0.1 `src.single_class`/ExampleClass#b.
# ^ reference snapshot-util 0.1 `src.single_class`/ExampleClass#__init__().(b)
# ^^^^ reference snapshot-util 0.1 single_class/ExampleClass#__init__().(self)
# ^ reference snapshot-util 0.1 single_class/ExampleClass#b.
# ^ reference snapshot-util 0.1 single_class/ExampleClass#__init__().(b)
self.c = "hello" + local_c
# ^^^^ reference snapshot-util 0.1 `src.single_class`/ExampleClass#__init__().(self)
# ^ reference snapshot-util 0.1 `src.single_class`/ExampleClass#c.
# ^^^^ reference snapshot-util 0.1 single_class/ExampleClass#__init__().(self)
# ^ reference snapshot-util 0.1 single_class/ExampleClass#c.
# ^^^^^^^ reference local 0

Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# < definition scip-python python snapshot-util 0.1 `src.single_function`/__init__:
# < definition scip-python python snapshot-util 0.1 single_function/__init__:

def my_cool_function(a: str) -> str:
# ^^^^^^^^^^^^^^^^ definition snapshot-util 0.1 `src.single_function`/my_cool_function().
# ^ definition snapshot-util 0.1 `src.single_function`/my_cool_function().(a)
# ^^^^^^^^^^^^^^^^ definition snapshot-util 0.1 single_function/my_cool_function().
# ^ definition snapshot-util 0.1 single_function/my_cool_function().(a)
# ^^^ reference python-stdlib 3.11 builtins/str#
# ^^^ reference python-stdlib 3.11 builtins/str#
x = ", world"
# ^ definition local 0
return a + x
# ^ reference snapshot-util 0.1 `src.single_function`/my_cool_function().(a)
# ^ reference snapshot-util 0.1 single_function/my_cool_function().(a)
# ^ reference local 0

def my_cool_function_2(a: str):
# ^^^^^^^^^^^^^^^^^^ definition snapshot-util 0.1 `src.single_function`/my_cool_function_2().
# ^ definition snapshot-util 0.1 `src.single_function`/my_cool_function_2().(a)
# ^^^^^^^^^^^^^^^^^^ definition snapshot-util 0.1 single_function/my_cool_function_2().
# ^ definition snapshot-util 0.1 single_function/my_cool_function_2().(a)
# ^^^ reference python-stdlib 3.11 builtins/str#
x = ", world"
# ^ definition local 1
return (lambda y: a + x + y)("oh no")
# ^ definition local 2(y)
# ^ reference snapshot-util 0.1 `src.single_function`/my_cool_function_2().(a)
# ^ reference snapshot-util 0.1 single_function/my_cool_function_2().(a)
# ^ reference local 1
# ^ reference local 2(y)

def next_level():
# ^^^^^^^^^^ definition snapshot-util 0.1 `src.single_function`/next_level().
# ^^^^^^^^^^ definition snapshot-util 0.1 single_function/next_level().
return my_cool_function
# ^^^^^^^^^^^^^^^^ reference snapshot-util 0.1 `src.single_function`/my_cool_function().
# ^^^^^^^^^^^^^^^^ reference snapshot-util 0.1 single_function/my_cool_function().

my_cool_function("hello")
#^^^^^^^^^^^^^^^ reference snapshot-util 0.1 `src.single_function`/my_cool_function().
#^^^^^^^^^^^^^^^ reference snapshot-util 0.1 single_function/my_cool_function().
next_level()(a = "wow")
#^^^^^^^^^ reference snapshot-util 0.1 `src.single_function`/next_level().
# ^ reference snapshot-util 0.1 `src.single_function`/my_cool_function().(a)
#^^^^^^^^^ reference snapshot-util 0.1 single_function/next_level().
# ^ reference snapshot-util 0.1 single_function/my_cool_function().(a)

7 changes: 7 additions & 0 deletions packages/pyright-scip/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ export class ScipPyrightConfig {
configOptions.applyDiagnosticOverrides(commandLineOptions.diagnosticSeverityOverrides);
}

// Detect conventional src layouts only when search paths are unconfigured.
// In this Pyright version, execution-environment paths append to defaults;
// adding src before initialization would shadow explicit environment paths.
if (configOptions.defaultExtraPaths === undefined && configOptions.executionEnvironments.length === 0) {
configOptions.ensureDefaultExtraPaths(this.fs, true, undefined);
}

// Override the analyzeUnannotatedFunctions setting based on the command-line setting.
if (commandLineOptions.analyzeUnannotatedFunctions !== undefined) {
configOptions.diagnosticRuleSet.analyzeUnannotatedFunctions =
Expand Down
65 changes: 65 additions & 0 deletions packages/pyright-scip/test/test-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,70 @@ version = "16.05"`,
}
}

function testSourceSearchPaths(): void {
for (const testCase of [
{ config: undefined, expected: 'src_handler' },
{ config: {}, expected: 'src_handler' },
{ config: { extraPaths: ['custom'] }, expected: 'custom_handler' },
{ config: { executionEnvironments: [{ root: '.', extraPaths: ['custom'] }] }, expected: 'custom_handler' },
{ config: { extraPaths: [] }, expected: undefined },
{ config: undefined, srcIsPackage: true, expected: undefined },
]) {
// macOS temporary directories can be symlinked; match the analyzer's resolved file paths.
const projectRoot = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'scip-search-paths-')));
try {
for (const sourceRoot of ['src', 'custom']) {
const packageRoot = path.join(projectRoot, sourceRoot, 'demo');
fs.mkdirSync(packageRoot, { recursive: true });
fs.writeFileSync(path.join(packageRoot, '__init__.py'), '');
fs.writeFileSync(path.join(packageRoot, 'core.py'), `def ${sourceRoot}_handler():\n return 1\n`);
}
if (testCase.srcIsPackage) {
fs.writeFileSync(path.join(projectRoot, 'src', '__init__.py'), '');
}
if (testCase.config) {
fs.writeFileSync(path.join(projectRoot, 'pyrightconfig.json'), JSON.stringify(testCase.config));
}
fs.writeFileSync(
path.join(projectRoot, 'consumer.py'),
'from demo.core import src_handler, custom_handler\nsrc_handler()\ncustom_handler()\n'
);
indexAction({
projectName: 'search-paths',
projectVersion: '1.0',
cwd: projectRoot,
output: 'index.scip',
environment: path.resolve('snapshots/testEnv.json'),
infer: { projectVersionFromCommit: false },
quiet: true,
dev: false,
showProgressRateLimit: undefined,
});
const index = scip.Index.deserializeBinary(fs.readFileSync(path.join(projectRoot, 'index.scip')));
const consumer = index.documents.find((doc) => doc.relative_path === 'consumer.py')!;
for (const name of ['src_handler', 'custom_handler']) {
const references = consumer.occurrences.filter((occurrence) =>
occurrence.symbol.endsWith(`/${name}().`)
);
assert.strictEqual(references.length, name === testCase.expected ? 2 : 0, JSON.stringify(testCase));
if (references.length > 0) {
assert.ok(
index.documents.some((doc) =>
doc.occurrences.some(
(occurrence) =>
occurrence.symbol === references[0].symbol &&
(occurrence.symbol_roles & scip.SymbolRole.Definition) !== 0
)
)
);
}
}
} finally {
fs.rmSync(projectRoot, { recursive: true, force: true });
}
}
}

function testMissingProjectVersion(): void {
// macOS temporary directories can be symlinked; match the analyzer's resolved file paths.
const projectRoot = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'scip-missing-version-')));
Expand Down Expand Up @@ -317,6 +381,7 @@ function testMissingProjectVersion(): void {

function unitTests(): void {
testPyprojectParsing();
testSourceSearchPaths();
testMissingProjectVersion();
pythonCLITests();
}
Expand Down
Loading