Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a different partitoning in base_db::input::SourceRoot #15888

Closed
alibektas opened this issue Nov 14, 2023 · 3 comments
Closed

Using a different partitoning in base_db::input::SourceRoot #15888

alibektas opened this issue Nov 14, 2023 · 3 comments

Comments

@alibektas
Copy link
Member

alibektas commented Nov 14, 2023

馃憢 I have been working on #13529 and (indirectly) on #15741 ( as a matter of fact there should have been a "toml support for rust-analyzer issue". In order for both of these features to be implemented there needs to be a map ( and its inv. ) that maps SourceFiles ( so essentially a FileId ) to its corresponding (most of the time the closest) Cargo.toml/RA.toml file. I believe that this should be handled when we get to partition a Vfs into SourceRoots. Based on my poor observation we partition with the intention to group as many files as possible into the same FileSet. I want to change that in such a way that Cargo.toml/RATOML files are used as anchors to a SourceRoot , meaning that if you encounter , say , a Cargo.toml you would know that this is a new SourceRoot. This change would enable me to map a FileId to the FileId of its corresponding SourceRoot, as in

srid = SourceDatabaseExt::file_source_root(db, file_id)
sr = SourceDatabaseExt::source_root(db, srid)
cargo_file_id = sr.cargo_toml_id()  // Option<FileId>

I cannot see any other way of doing this so I wanted to get community's opinion on this.

@Veykril
Copy link
Member

Veykril commented Nov 14, 2023

Can't you just store the FileId of the cargo.toml inside the SourceRoot? That aside, why do you need such a mapping?

@alibektas
Copy link
Member Author

alibektas commented Nov 14, 2023

Can't you just store the FileId of the cargo.toml inside the SourceRoot

That is what I am exactly trying to do. But the problem is that the current partition does not guarantee that there will be one or many Cargo.tomls in a SourceRoot. I want this to be limited to at most one

That aside, why do you need such a mapping?

Because when we introduce multiple rust-analyzer.toml files to be used to configure different parts of a project I always need to be able to ask what the nearest configuration file that applies to a certain FileId is.

@Veykril
Copy link
Member

Veykril commented Nov 15, 2023

Can't you just store the FileId of the cargo.toml inside the SourceRoot?

Answer is yes after some discussion in DMs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants