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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a replay feature to zls #857

Merged
merged 4 commits into from
Dec 31, 2022
Merged

Conversation

Techatrix
Copy link
Member

Debugging ZLS can be very annoying because it is hardly possible to use debugger like gdb or lldb because of how ZLS has to interacts with its client.

This PR adds a new command to ZLS zls --replay which allows you to replay a previously recorded zls session.
This should allow everyone to share reproducable issues with zls with just one file and make debugging them much easier.

Having this feature integrated into https://github.com/zigtools/sus and http://zls-fuzzing.augustera.me/ would be very useful.

A replay also saves and uses the configuration options used when the replay was recorded.
This could also be expanded to include the zig and zls version used while recording.

Unfortunately these replays are not perfect, reasons why they may not reproduce an issue are:

  • the Zig or ZLS version during recording and replaying are not the same
  • the source code this replay relies has changed or can't be found. (replays don't save every .zig file you have opened)
  • the issue relies on a specific operating system, architecture, etc
  • the issue is non-deterministic

How do i record a replay?

A replay contains the source code you are using in your editor. DO NOT share replays if you don't want to show your code.

Step 1: Enable record_session

Open your zls.json and set the record_session to true and specify record_session_path, which is where your replay will be created.
Example:

{
    "enable_ast_check_diagnostics": true,
    "enable_autofix": true,
    "enable_import_embedfile_argument_completions": true,
    "record_session": true,
    "record_session_path": "/house/xirtahcet/zls/output.zlsreplay"
}

NOTE: you can use zls --show-config-path to find your zls.json. If this fails you can run zls --config

Step 2: Record a session

Open your favorite editor which uses ZLS and do some random editing. Once you are finished you should find your .zlsreplay file where you specified it. Make sure you have closed your editor before using the .zlsreplay file.

In VS-Code you should find a message saying This zls session is being recorded to <your_path>.

Step 3: Replay a session

Now you can use zls --replay which will simulate your editor session you had in Step 2.
ZLS will find your replay file based on record_session_path.
Alternatively you can run zls --replay /path/to/file.zlsreplay or specify replay_session_path which has higher precedence that record_session_path.


hopefully i never have to see std.debug.print("HERE", .{}) again in my life.

@SuperAuguste SuperAuguste merged commit 3449269 into zigtools:master Dec 31, 2022
@Techatrix Techatrix deleted the zls-replay branch January 3, 2023 07:33
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

Successfully merging this pull request may close these issues.

2 participants