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

Fix relative paths in .fst.config.json fstar exe #40

Merged
merged 1 commit into from
May 8, 2024

Conversation

amosr
Copy link
Contributor

@amosr amosr commented May 3, 2024

This commit adds a pathPrefix option to allow modifying the search path without needing to change the project-specific .fst.config.json (which are often included in source control).

This also fixes a small bug in .fst.config.json where specifying the fstar executable with a relative path such as _opam/bin/fstar.exe was failing. Instead, we now interpret such a path as relative to the configuration file.

Workspace-specific .vscode/settings.json:

{
  "fstarVSCodeAssistant.pathPrefix": "/home/amos/proj/ext/fstar/_opam/bin"
}

@amosr
Copy link
Contributor Author

amosr commented May 3, 2024

I think this is a useful feature and wasn't much effort, but happy to discuss if I'm holding it wrong

@nikswamy nikswamy requested a review from gebner May 3, 2024 14:03
@nikswamy
Copy link
Contributor

nikswamy commented May 3, 2024

Looks good to me, thanks! @gebner, wdyt?

Copy link
Contributor

@gebner gebner left a comment

Choose a reason for hiding this comment

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

I am a bit lukewarm about this change. There are at the very least two executables that need to be in PATH: fstar.exe and z3. This PR only helps with the first one (if you're willing to manually set the vscode configuration option).

Additionally, many F* projects require you to set even more environment variables. (Note that since #17, .fst.config.json files can contain references to environment variables.) For example, everparse references KRML_HOME (and soon PULSE_HOME too).

FWIW, I usually open vscode from a command-line environment with all the right environment variables set:

eval `opam env`
export FSTAR_HOME=$HOME/FStar KRML_HOME=$HOME/karamel PATH=$HOME/FStar/bin:$PATH PULSE_HOME=$HOME/pulse
code .

With the new configuration setting from this PR, I would still to set all the other environment variables and add Z3 to the PATH. It would be really amazing if we could improve on that workflow, but this PR isn't it. I wonder if we should officially bless an extension like direnv?

As for your particular set up, from what I can tell you already have the F*-specific z3 in the PATH. Could you also add fstar.exe to the PATH for now?

package.json Outdated
"scope": "resource",
"type": "string",
"default": "",
"description": "Prefix PATH environment variable"
Copy link
Contributor

Choose a reason for hiding this comment

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

It is not clear to me based on the description alone how you would use it. For example, I would expect to write /home/amosr/bin: here, but reading through the code the : is implicit. An example would be helpful in the description.

// Check if fstar_exe can be found in the current path, taking into account
// the specified working directory and path overrides
const pathEnv =
configurationSettings.pathPrefix + path.delimiter + process.env.PATH;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this do the right thing if pathPrefix is empty?

@amosr
Copy link
Contributor Author

amosr commented May 4, 2024

Hi Gabriel,

Thanks for your feedback and especially your pointer to the direnv extension - this does exactly what I want! It resolves the main issue for me. (I couldn't figure out how to manually modify the environment variables because I was using Remote-SSH, which loads the remote host's default environment.)

So, there were actually two changes here - the environment issue is resolved, so I'll delete that part. The other change was a bugfix, which I still believe is a legitimate bug. If you agree I'll kill the path change and just keep the bugfix.

The bug is related to local paths relative to the configuration file. The exact bug I've hit (a student here has hit it too) is where the x.fst.config.json sets fstar_exe to _opam/bin/fstar.exe. When the _opam subdirectory and x.fst.config.json are in the root of the VSCode workspace, this works fine. But if I open the parent directory as the workspace, then the resolution doesn't work. The issue is that which.sync searches relative to the workspace root, but then cp.spawn searches relative to the config directory, so it's inconsistent.

@amosr amosr marked this pull request as draft May 6, 2024 00:34
This change fixes a small bug in `.fst.config.json` where specifying the
fstar executable with a relative path such as `_opam/bin/fstar.exe` was
failing. Instead, we now interpret such a path as relative to the
configuration file.
@amosr amosr changed the title Add pathPrefix workspace setting to find fstar.exe Fix relative paths in .fst.config.json fstar exe May 6, 2024
@amosr amosr marked this pull request as ready for review May 6, 2024 00:47
@amosr
Copy link
Contributor Author

amosr commented May 6, 2024

Hi Gabriel, hi Nik,

I've changed this PR to just fix the inconsistency in how relative paths are handled by which and spawn.

Amos

@gebner gebner merged commit 8a27799 into FStarLang:main May 8, 2024
1 check passed
@gebner
Copy link
Contributor

gebner commented May 8, 2024

The relative path change looks good to me. (Although it is not a setup that is commonly used---the fst.config.json file is usually checked in so it's awkward to have local configuration in there.)

Thanks for the PR!

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.

3 participants