lean4-htt/src/Lean/Util
Marc Huisinga 2ede81fe10
fix: search path related bugs (#7873)
This PR fixes a number of bugs related to the handling of the source
search path in the language server, where deleting files could cause
several features to stop functioning and both untitled files and files
that don't exist on disc could have conflicting module names.

In detail, it makes the following adjustments:
- The URI <-> module name conversion was adjusted to produce no name
collisions.
- File URIs in the search path yield a module name relative to the
search path, as before.
- File URIs not in the search path, non-file URIs and non-`.lean` files
yield a `«external:<full uri>»` module name.
- To avoid the issue of the URI -> module name conversion failing when a
file is deleted from disc, we now cache the result of this conversion in
the watchdog and the file worker when the file is first opened.
- All of the URI <-> module name conversions now consistently go through
`Server.documentUriFromModule?` and `moduleFromDocumentUri` to ensure
that we don't have minor deviations for this conversion all over the
place.
- The threading of the source search path through the file worker (from
`lake setup-file`) is removed. It turns out that `lake serve` already
sets the correct source search path in the environment, so we can just
always use the search path from the environment.
- Since we can now answer more requests that need the .ileans in
untitled files, a lot of the tests that test 'Go to definition' needed
to be adjusted so that they use the information from the watchdog, not
the file worker. As we load references asynchronously, this PR adds an
internal `$/lean/waitForILeans` request that tests can use to wait for
all .ilean files to be loaded and for the ilean references from the file
worker for the current document version to be finalized.
- As part of this PR, we noticed that the .ileans aren't available in
the NixOS setup, so @Kha adjusted the Nix CI to fix this.

### Breaking changes
- `Server.documentUriFromModule` has been renamed to
`Server.documentUriFromModule?` and doesn't take a `SearchPath` argument
anymore, as the `SearchPath` is now computed from the `LEAN_SRC_PATH`
environment variable. It has also been moved from `Lean.Server.GoTo` to
`Lean.Server.Utils`.
- `Server.moduleFromDocumentUri` does not take a `SearchPath` argument
anymore and won't return an `Option` anymore. It has also been moved
from `Lean.Server.GoTo` to `Lean.Server.Utils`.
- The `System.SearchPath.searchModuleNameOfUri` function has been
removed. It is recommended to use `Server.moduleFromDocumentUri`
instead.
- The `initSrcSearchPath` function has been renamed to
`getSrcSearchPath` and has been moved from `Lean.Util.Paths` to
`Lean.Util.Path`. It also doesn't need to take a `pkgSearchPath`
argument anymore.

---------

Co-authored-by: Sebastian Ullrich <sebasti@nullri.ch>
2025-04-09 15:37:49 +00:00
..
CollectAxioms.lean fix: avoid follow-up kernel errors (#7570) 2025-03-20 09:11:25 +00:00
CollectFVars.lean feat: add Expr.fvarsSubset (#6430) 2024-12-20 22:29:47 +00:00
CollectLevelMVars.lean feat: localize universe metavariable errors at let bindings and fun binders (#5402) 2024-09-24 05:30:42 +00:00
CollectLevelParams.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
CollectMVars.lean perf: replace hasMVar by hasExprMVar in CollectMVars, FindMVar (#4451) 2024-06-14 18:06:00 +00:00
Diff.lean chore: remove the old Lean.Data.HashMap implementation (#7519) 2025-03-20 23:49:55 +00:00
FileSetupInfo.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
FindExpr.lean feat: add Expr.fvarsSubset (#6430) 2024-12-20 22:29:47 +00:00
FindLevelMVar.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
FindMVar.lean perf: replace hasMVar by hasExprMVar in CollectMVars, FindMVar (#4451) 2024-06-14 18:06:00 +00:00
FoldConsts.lean feat: Environment.realizeConst (#7076) 2025-02-26 19:32:21 +00:00
ForEachExpr.lean feat: add Expr.fvarsSubset (#6430) 2024-12-20 22:29:47 +00:00
ForEachExprWhere.lean feat: deprecate Array.mkArray in favour of Array.replicate 2025-03-24 08:25:00 +01:00
FVarSubset.lean feat: add Expr.fvarsSubset (#6430) 2024-12-20 22:29:47 +00:00
HasConstCache.lean chore: use notation in favour of .empty functions (#7446) 2025-03-12 04:22:40 +00:00
Heartbeats.lean chore: remove mention of Lean.withSeconds (#5481) 2024-09-26 18:15:58 +00:00
InstantiateLevelParams.lean feat: change Array.get to take a Nat and a proof (#6032) 2024-11-12 03:30:46 +00:00
LakePath.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
LeanOptions.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
MonadBacktrack.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
MonadCache.lean chore: remove the old Lean.Data.HashMap implementation (#7519) 2025-03-20 23:49:55 +00:00
NumApps.lean feat: theorem diagnostics (#4924) 2024-08-06 01:01:28 +00:00
NumObjs.lean feat: add Lean.Expr.numObjs (#4754) 2024-07-16 15:52:33 +00:00
OccursCheck.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
Path.lean fix: search path related bugs (#7873) 2025-04-09 15:37:49 +00:00
Paths.lean fix: search path related bugs (#7873) 2025-04-09 15:37:49 +00:00
PPExt.lean feat: do not propagate pretty printer errors through messages (#3696) 2024-12-11 04:10:09 +00:00
Profile.lean doc: profiler 2024-04-03 17:53:36 +02:00
Profiler.lean perf: async optimizations for Init.Data.BitVec.Lemmas (#7546) 2025-03-18 12:56:16 +00:00
PtrSet.lean chore: remove the old Lean.Data.HashMap implementation (#7519) 2025-03-20 23:49:55 +00:00
RecDepth.lean perf: add prelude to all Lean modules 2024-02-18 14:55:17 -08:00
Recognizers.lean feat: Lean.Expr.name? (#5760) 2024-10-18 02:40:26 +00:00
ReplaceExpr.lean perf: Expr.replace (#4799) 2024-07-20 04:53:43 +00:00
ReplaceLevel.lean feat: deprecate Array.mkArray in favour of Array.replicate 2025-03-24 08:25:00 +01:00
SafeExponentiation.lean chore: preserve reported messages in MessageLog (#6307) 2024-12-11 12:24:00 +00:00
SCC.lean chore: remove the old Lean.Data.HashMap implementation (#7519) 2025-03-20 23:49:55 +00:00
SearchPath.lean chore: deprecated compile_time_search_path% (#7022) 2025-02-10 13:49:17 +00:00
ShareCommon.lean chore: rename HashMap.empty to HashMap.emptyWithCapacity (#7447) 2025-03-12 23:01:18 +00:00
Sorry.lean feat: labeled and unique sorries (#5757) 2024-12-11 23:53:02 +00:00
SortExprs.lean chore: use notation in favour of .empty functions (#7446) 2025-03-12 04:22:40 +00:00
TestExtern.lean chore: update copyrights (#5449) 2024-09-24 05:27:53 +00:00
Trace.lean perf: avoid contended access to IO.Ref in isTracingEnabledFor (#7601) 2025-03-21 12:07:25 +00:00