-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
red-knot: source_text
, line_index
, and parsed_module
queries
#11822
Conversation
95d1254
to
a98db3d
Compare
7217c36
to
385c1e7
Compare
source_text
, line_index
, and parsed_module
queriessource_text
, line_index
, and parsed_module
queries
9734de8
to
2fb8508
Compare
|
b81e1f3
to
b299766
Compare
2fb8508
to
0b6f5b2
Compare
let ty = match path { | ||
VfsPath::FileSystem(path) => path | ||
.extension() | ||
.map_or(PySourceType::Python, PySourceType::from_extension), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to assume a file is Python if it has no extension? Is that an existing Ruff behavior? That seems likely to lead to a lot of syntax/parsing errors. From a user perspective, I would expect to have to specially request via config if I want Ruff to treat an unknown-extension file as Python source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to filter out non-python files (according to the user's configuration) when walking the workspace so that we never end up calling parse on these files.
} | ||
|
||
#[cfg(test)] | ||
mod tests { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests also for stub file, vendored stub file, and unknown-extension file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a test for vendored paths. I prefer to not add a test for unknown extensions and stub files because I then end up re-testing PySourceType::from_extension
. I rather want to have integration tests for different file types (We write a lot of integration tests in ruff and only few unit tests. What we have in these PRs is already way above the average number of unit tests)
Oh, and let's make sure to fix the clippy errors before merging this. |
0b6f5b2
to
99cbb93
Compare
source_text
, line_index
, and parsed_module
queriessource_text
, line_index
, and parsed_module
queries
Summary
This PR adds the most basic file-based queries that are needed for semantic analysis, linting and formatting:
source_text
: Reads the content of a file. Changing a file's revision markes the query result as stale. I excluded jupyter notebook support for now.line_index
: Computes the line index for a file's source text.parsed_module
: Parses the file's text to a python module, infering the file type from the file extension.Test Plan
I added a few unit tests that demonstrate the basic functionality.