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

Make configuration more reliable right after starting VSCode #7326

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hunger
Copy link
Member

@hunger hunger commented Jan 10, 2025

We got reports that you need to tweak the configuration for it to become applied right after starting VSCode. This effects mostly the library_path and Include_path options that need to get applied to the code when building in LS or live-preview.

I ran into several issues:

  • The content cache was not initialized yet when the LSP sent the configuration
  • The LSP did not invalidate any files on configuration changes, so it never noticed that the include/library paths were changed (and thus did not send the new files on to the live preview.
  • The live preview raced against itself trying to render with the updated configuration but the old data. I added an explicit "commit configuration" step now to avoid that.

This greatly improves the reliability of configuration with the live preview and LS for me on first start of VSCode or when switching between WASM and binary preview.

Note: The WASM preview does not work with library_path at all for me: The compiler uses file existence tests, which always fail in WASM AFAICT.

@hunger hunger requested review from ogoffart and FloVanGH January 10, 2025 15:45
Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

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

Thanks for fixing the issue.

I don't quite understand what is the race. Could you elaborate with an example.
Maybe the config can be set directly on the cache by locking the CACHE mutex instead of message passing?

Note: The WASM preview does not work with library_path at all for me: The compiler uses file existence tests, which always fail in WASM AFAICT.

Indeed. That's another bug that can be fixed later.

tools/lsp/language/goto.rs Show resolved Hide resolved
tools/lsp/common.rs Show resolved Hide resolved
tools/lsp/preview.rs Outdated Show resolved Hide resolved
tools/lsp/preview.rs Outdated Show resolved Hide resolved
tools/lsp/preview.rs Outdated Show resolved Hide resolved
@hunger
Copy link
Member Author

hunger commented Jan 10, 2025

I don't quite understand what is the race. Could you elaborate with an example.
Maybe the config can be set directly on the cache by locking the CACHE mutex instead of message passing?

It needs to go through message passing for the WASM preview to work :-/

Remember: The LS does file system accesses, the live-preview just knows the files the LS tells it about to make working with WASM-mode bearable.

So what used to happen is this:

  1. LS sends "configuration changed" with a new library path.
    1.1 The live-preview sees it and re-renders with the set of sources the LS has told it about earlier
    1.1.1 The compiler checks for the library using a Path::exists. That works in binary mode, so it
    decides "@library_name is a library".
    1.1.2 It then tries to read the library. That fails as the live-preview still only knows about the old set of files
    1.1.3 It falls back further to ./@library_name, which fails, too.
    1.2 The DocumentCache records this fact and the dependency on ./@library_name.
  2. The LS discovers the file @library_name points to now and tells the live-preview
    2.1 The live-preview see no reason to update: Nothing depends on this file.
  3. The LS is done with its work at some point, but does not notify the live-preview about it

Tada! We are stuck in a broken state.

What happens now is this:

  1. LS sends "configuration changed" with a new library path.
    1.1 the live-preview stores the new configuration and blocks the rendering
  2. The LS discovers new files and tells the live-preview about it
    2.1 the live-preview records those new files but does nothing
  3. the LS notifies the live-preview that it is done
    3.1 the live-preview triggers a fresh rendering
    3.1.1 The compiler checks for the library using a Path::exists. That works in binary mode, so it
    decides "@library_name is a library".
    3.1.2 It then tries to read the library. That works now!
    3.2 The DocumentCache notes the dependency on the right library file.

Tada, it works.

We need to re-evaluate all files as the library/include resolution has changed.
@hunger hunger force-pushed the tobias/push-pstvqvvnunom branch 2 times, most recently from d2ea733 to 45dd73b Compare January 10, 2025 19:46
@hunger hunger force-pushed the tobias/push-pstvqvvnunom branch from 6950132 to 5b68bc6 Compare January 10, 2025 20:36
@ogoffart
Copy link
Member

2.1 The live-preview see no reason to update: Nothing depends on this file.

This is the same logic with the set content. If you just set the state to NeedsReload it will reload the preview.

We can talk about that over a call on Monday.

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