Skip to content

feat: import auto-completion#2904

Merged
mhuisi merged 6 commits intoleanprover:masterfrom
mhuisi:mhuisi/import-auto-completion
Nov 24, 2023
Merged

feat: import auto-completion#2904
mhuisi merged 6 commits intoleanprover:masterfrom
mhuisi:mhuisi/import-auto-completion

Conversation

@mhuisi
Copy link
Copy Markdown
Contributor

@mhuisi mhuisi commented Nov 17, 2023

This PR adds basic auto-completion support for imports. Since it still lacks Lake support for accurate completion suggestions (cc @tydeu - we already know what needs to be done), it falls back to traversing the LEAN_SRC_PATH for available imports.

Three kinds of import completion requests are supported:

  • Completion of the full import command. Triggered when requesting completions in an empty space within the header.
    • Known issue: It is possible to trigger this completion within a comment in the header. Fixing this would require architecture for parsing some kind of sub-syntax between individual commands.
  • Completion of the full module name after an incomplete import command.
  • Completion of a partial module name with a trailing dot.

Since the set of imports is potentially expensive to compute, they are cached for 10 seconds after the last import auto-completion request.

Closes #2655.

Changes

This PR also makes the following changes:

  • To support completions on the trailing dot, the import syntax was adjusted to provide partial syntax when a trailing dot is used.
  • FileWorker.lean was refactored lightly with some larger definitions being broken apart.
  • The WorkerState gained two new fields:
    • currHeaderStx tracks the current header syntax, as opposed to tracking only the initial header syntax in initHeaderStx. When the header syntax changes, a task is launched that restarts the file worker after a certain delay to avoid constant restarts while editing the header. During this time period, we may still want to serve import auto-completion requests, so we need to know the up-to-date header syntax.
    • importCachingTask? contains a task that computes the set of available imports.
  • determineLakePath has moved to a new file Lean/Util/LakePath.lean as it is now needed both in ImportCompletion.lean and FileWorker.lean.
  • forEachModuleIn from Lake/Config/Blob.lean has moved to Lean/Util/Path.lean as it is a generally useful utility function that was useful for traversing the LEAN_SRC_PATH as well.

Tests

Unfortunately, this PR lacks tests since the set of imports available in tests/lean/interactive will not be stable. In the future, I will add support for testing LSP requests in full project setups, which is when tests for import auto-completion will be added as well.

@mhuisi mhuisi added enhancement New feature or request server Affects the Lean server code labels Nov 17, 2023
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Nov 17, 2023
@ghost
Copy link
Copy Markdown

ghost commented Nov 17, 2023

Copy link
Copy Markdown
Member

@tydeu tydeu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I imagine I may need to tweak a few things when I implement lake available-imports, but I presume that is okay.

@mhuisi mhuisi force-pushed the mhuisi/import-auto-completion branch from 38e478d to 3400b9e Compare November 20, 2023 10:12
Copy link
Copy Markdown
Member

@Kha Kha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't review ImportCompletion in much detail

@Kha Kha removed the request for review from leodemoura November 20, 2023 10:16
@mhuisi mhuisi force-pushed the mhuisi/import-auto-completion branch from 3400b9e to 2818511 Compare November 20, 2023 10:21
@mhuisi mhuisi force-pushed the mhuisi/import-auto-completion branch from cf1024b to 259f00c Compare November 21, 2023 09:29
ghost pushed a commit to leanprover-community/mathlib4 that referenced this pull request Nov 21, 2023
@ghost ghost added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Nov 21, 2023
mhuisi added a commit to mhuisi/std4 that referenced this pull request Nov 21, 2023
mhuisi added a commit to mhuisi/std4 that referenced this pull request Nov 21, 2023
mhuisi added a commit to leanprover-community/batteries that referenced this pull request Nov 22, 2023
mhuisi added a commit to leanprover-community/mathlib4 that referenced this pull request Nov 23, 2023
mhuisi pushed a commit to leanprover-community/mathlib4 that referenced this pull request Nov 23, 2023
mhuisi added a commit to leanprover-community/mathlib4 that referenced this pull request Nov 23, 2023
@ghost ghost added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Nov 23, 2023
@mhuisi mhuisi added this pull request to the merge queue Nov 24, 2023
Merged via the queue into leanprover:master with commit 681fca1 Nov 24, 2023
mathlib-bors bot pushed a commit to leanprover-community/mathlib4 that referenced this pull request Nov 26, 2023
As part of leanprover/lean4#2904, an unused parameter of `initSrcSearchPath` was removed. This PR adjusts Mathlib for this change. The corresponding Std PR that adjusts a use of `initSrcSearchPath` there is at leanprover-community/batteries#383.



Co-authored-by: mhuisi <mhuisi@protonmail.com>
Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
@ghost ghost added breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan and removed builds-mathlib CI has verified that Mathlib builds against this PR labels Nov 26, 2023
mathlib-bors bot pushed a commit to leanprover-community/mathlib4 that referenced this pull request Nov 27, 2023
As part of leanprover/lean4#2904, an unused parameter of `initSrcSearchPath` was removed. This PR adjusts Mathlib for this change. The corresponding Std PR that adjusts a use of `initSrcSearchPath` there is at leanprover-community/batteries#383.



Co-authored-by: mhuisi <mhuisi@protonmail.com>
Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
Co-authored-by: François G. Dorais <fgdorais@gmail.com>
Co-authored-by: Scott Morrison <scott@tqft.net>
Co-authored-by: Alex J Best <alex.j.best@gmail.com>
Co-authored-by: Eric Rodriguez <ericrboidi@gmail.com>
@ghost ghost added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Nov 27, 2023
@mhuisi mhuisi mentioned this pull request Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-mathlib CI has verified that Mathlib builds against this PR enhancement New feature or request server Affects the Lean server code toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFC: autocompletion of imports

4 participants