feat: nested lean projects #699
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds for language server support for nested Lean projects. With this PR, nested Lean projects do not yield an error anymore. Files in nested projects are associated with the innermost language client containing them.
Other changes
lean4.fallBackToStringOccurrenceHighlightingis removed. We put this functionality behind thelean4.fallBackToStringOccurrenceHighlightingsetting (that is disabled by default) in feat: customizable occurrence highlighting #377 with the goal of removing it eventually.Implementation notes
Support for nested Lean projects was not deemed possible previously due to inadequate support for nested language clients in VS Code's language client library. In the language client library (and the VS Code API), files are associated with a language client (or in VS Code with a specific editor functionality) via globs. Hence, nesting two projects would associate the Lean files of the inner project with both the inner and the outer language client, duplicating language server support (e.g. producing duplicate hovers). These globs cannot express subfolder exclusions.
In this PR, we work around this limitation by abusing the general request and notification middleware extension points of the language client library to filter requests and notifications for excluded subfolders (i.e. inner Lean projects).
For notifications, this is as simple as not emitting the message. For requests, the API does not permit filtering a generic request, so we use another hack: the new middleware throws a
ContentModifiedexception for filtered requests, for which the current code of the language client library ensures that it is not displayed to the user and that it returns a default value. For every request type, this default value is chosen by the language client library such that VS Code will ignore the provider of the language client that produces it and query another provider to obtain a result. Thus, we can use this mechanism to triage requests for files in an inner project by letting them pass through to the inner language server and filtering them from communication with the outer language server.