Commit f28056f
committed
fix: Use the correct project root when there are multiple workspaces
Previously, Config::root_path() would always return the LSP rootUri of
the first workspace folder. This can cause issues when the user has
multiple workspaces open in their editor, especially if the first one
in the list isn't a Rust project.
This was noted as an issue in rust-lang/rust-analyzer#21483, and added
comments suggesting that we should deprecate root_path().
This change splits root_path() into a `workspace_root_for()` function
that handles the multiple workspace case correctly, and a
`default_root_path()` fallback.
This is particularly useful when the user has configured
project-relative paths to e.g. their discover command or rustfmt, but
it's the correct behaviour in general.
AI disclosure: First draft was written with Claude Opus.1 parent 96f289b commit f28056f
4 files changed
Lines changed: 44 additions & 10 deletions
File tree
- src/tools/rust-analyzer/crates/rust-analyzer/src
- handlers
Lines changed: 25 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1070 | 1070 | | |
1071 | 1071 | | |
1072 | 1072 | | |
| 1073 | + | |
1073 | 1074 | | |
1074 | 1075 | | |
1075 | 1076 | | |
| |||
1079 | 1080 | | |
1080 | 1081 | | |
1081 | 1082 | | |
1082 | | - | |
| 1083 | + | |
1083 | 1084 | | |
1084 | 1085 | | |
1085 | | - | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
1086 | 1091 | | |
| 1092 | + | |
1087 | 1093 | | |
1088 | 1094 | | |
1089 | 1095 | | |
| |||
1787 | 1793 | | |
1788 | 1794 | | |
1789 | 1795 | | |
1790 | | - | |
1791 | | - | |
1792 | | - | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
1793 | 1813 | | |
1794 | 1814 | | |
1795 | 1815 | | |
| |||
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2453 | 2453 | | |
2454 | 2454 | | |
2455 | 2455 | | |
2456 | | - | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
| 2460 | + | |
| 2461 | + | |
| 2462 | + | |
| 2463 | + | |
2457 | 2464 | | |
2458 | 2465 | | |
2459 | 2466 | | |
| |||
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
830 | 830 | | |
831 | 831 | | |
832 | 832 | | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
833 | 840 | | |
834 | 841 | | |
835 | 842 | | |
836 | 843 | | |
837 | 844 | | |
838 | | - | |
| 845 | + | |
839 | 846 | | |
840 | 847 | | |
841 | 848 | | |
| |||
953 | 960 | | |
954 | 961 | | |
955 | 962 | | |
956 | | - | |
| 963 | + | |
957 | 964 | | |
958 | 965 | | |
959 | 966 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
393 | | - | |
| 393 | + | |
394 | 394 | | |
395 | 395 | | |
396 | 396 | | |
| |||
883 | 883 | | |
884 | 884 | | |
885 | 885 | | |
886 | | - | |
| 886 | + | |
887 | 887 | | |
888 | 888 | | |
889 | 889 | | |
| |||
0 commit comments