Skip to content

The path option was added to the rescript.settings #478

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

Merged
merged 9 commits into from
Jul 12, 2022

Conversation

An-Tu
Copy link
Contributor

@An-Tu An-Tu commented Jul 5, 2022

This PR fixes #412 .

I added the handling of the relative path and also the path with contains the home directory symbol. But I'm not sure that it is ok.

@An-Tu
Copy link
Contributor Author

An-Tu commented Jul 5, 2022

It seems that I missed. I thought that the relative paths handling is necessary but I double-checked and it looks like not. I removed the extra code.

Copy link
Collaborator

@cristianoc cristianoc 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 working on this.
Was this PR tested?

@amiralies
Copy link
Contributor

I suggest to use a more descriptive name for path. path is very generic something like pathToRescript rescriptPath is better IMO.

@An-Tu
Copy link
Contributor Author

An-Tu commented Jul 6, 2022

I suggest to use a more descriptive name for path. path is very generic something like pathToRescript rescriptPath is better IMO.

It will look like "rescript.settings.path": "/some/path" in settings. It doesn't seem very generic. Or do you think that there will be more settings in the future that can contain other paths?

@An-Tu
Copy link
Contributor Author

An-Tu commented Jul 6, 2022

Was this PR tested?

Yes, I tested manually.

@cristianoc
Copy link
Collaborator

Perhaps binaryPsth ?

@amiralies
Copy link
Contributor

The thing is path itself doesn't show what it actually means.
is this path to rescript binary? path to a custom analysis binary or even project root path?
some other extensions i've used also use more descriptive or scoped names.
for example iirc rust-analyzer uses rust-analyzer.server.path (path to language server) and flow uses pathToFlow.

@An-Tu An-Tu force-pushed the path_to_config branch from 2a7e73c to 79185cc Compare July 7, 2022 21:04
@An-Tu
Copy link
Contributor Author

An-Tu commented Jul 7, 2022

I changed path to binaryPath

@An-Tu An-Tu force-pushed the path_to_config branch 2 times, most recently from ea8c7a9 to f3eb068 Compare July 8, 2022 17:06
Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

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

I was wondering whether this can possibly affect the existing way of determining how the path is computed.
I could not answer the question as there are a dozen changes happening at the same time.

If there's a way to change less, then it's easier to review.

If there isn't then this needs to be broken up into several small refactoring PRs where each one is obviously correct.

@An-Tu
Copy link
Contributor Author

An-Tu commented Jul 10, 2022

@cristianoc I have divided all changes into commits which should be easy to check. But if it is not suitable please tell me and I will prepare the separate PRs.

@cristianoc
Copy link
Collaborator

@cristianoc I have divided all changes into commits which should be easy to check. But if it is not suitable please tell me and I will prepare the separate PRs.

This format is perfect thanks. Let me take a look.

@@ -596,7 +596,11 @@ function format(msg: p.RequestMessage): Array<p.Message> {
} else {
// code will always be defined here, even though technically it can be undefined
let code = getOpenedFileContent(params.textDocument.uri);
let formattedResult = utils.formatCode(filePath, code);
let formattedResult = utils.formatCode(
extensionConfiguration.binaryPath,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand this logic. The fact that there exists a configuration, which is optional, should not show up here.
The logic should be: find the binary path and use it. Either here or directly in the utils command.

let extension = path.extname(filePath);
let formatTempFileFullPath = createFileInTempDir(extension);
fs.writeFileSync(formatTempFileFullPath, code, {
encoding: "utf-8",
});
try {
// Try to find the bsc bin from the binaryPath setting from the configuration.
let bscPath = findBscBinFromConfig(pathToBinFromConfig);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This logic is a bit strange. Seems biased towards the configuration. While the configuration is the exception not the rule.

The logic I would expect is:

  • find the normal binary path
  • if the config has a setting use that instead

if (bscNativePath != null) {
let result = childProcess.execFileSync(bscNativePath, [
// Default to using the formatter from the binaryPath setting from the configuration
// or the project formatter.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment is also inverted.
Default to use the binary path that ships with the analysis binary.
But if there is one in the config, override.

This is only about how the code reads, the semantics is the same.

@@ -65,6 +65,11 @@ let codeActionsFromDiagnostics: codeActions.filesCodeActions = {};
// will be properly defined later depending on the mode (stdio/node-rpc)
let send: (msg: p.Message) => void = (_) => {};

let findBinary = (projectRootPath: p.DocumentUri) =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Which binary?
findBuildBinary.

Copy link
Collaborator

Choose a reason for hiding this comment

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

All these functions, including findNodeBuildOfProjectRoot need to be renamed to contain the name Build.
So findBuildBinaryFromProjectRoot and findBuildBinaryFromConfig.

return { buildPath: rescriptNodePath, isReScript: true };
} else if (fs.existsSync(bsbNodePath)) {
return { buildPath: bsbNodePath, isReScript: false };
let findBinaryBase = ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a comment to explain what this does.

@@ -262,7 +262,20 @@ let openedFile = (fileUri: string, fileContent: string) => {
// handle in the isResponseMessage check in the message handling way
// below
} else {
// we should send something to say that we can't find bsb.exe. But right now we'll silently not do anything
let binaryPath =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't there already a function that does this: finding the binary directory?

@cristianoc
Copy link
Collaborator

I made a few reviews, going commit after commit.
The semantics seems fine. All the comments are about naming and clarity.

@cristianoc
Copy link
Collaborator

Overall I think this should be the main logic:

  • There's a concept of binary path, that's the path where binaries are found.
  • There's a concept of finding specific binaries.
  • There's a list of binaries, probably a variant.
  • There are functions to obtain specific binaries.

The config would be mentioned only once in one place: find the binary path.

@An-Tu
Copy link
Contributor Author

An-Tu commented Jul 11, 2022

Thanks a lot for your review! In the near future, I will try to polish this PR.

@An-Tu
Copy link
Contributor Author

An-Tu commented Jul 12, 2022

@cristianoc I fixed the PR according to your reviews. Also, I have a few thoughts above. Could you please look at them?

@cristianoc
Copy link
Collaborator

Thank you -- merging now as I need to do a couple of relevant changes.

@cristianoc cristianoc merged commit 8adf920 into rescript-lang:master Jul 12, 2022
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.

Feature request: use rescript binary from ancestor node_modules
3 participants