-
Notifications
You must be signed in to change notification settings - Fork 60
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
Conversation
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. |
There was a problem hiding this 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?
I suggest to use a more descriptive name for |
It will look like |
Yes, I tested manually. |
Perhaps binaryPsth ? |
The thing is |
I changed |
ea8c7a9
to
f3eb068
Compare
There was a problem hiding this 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.
@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. |
server/src/server.ts
Outdated
@@ -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, |
There was a problem hiding this comment.
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.
server/src/utils.ts
Outdated
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); |
There was a problem hiding this comment.
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
server/src/utils.ts
Outdated
if (bscNativePath != null) { | ||
let result = childProcess.execFileSync(bscNativePath, [ | ||
// Default to using the formatter from the binaryPath setting from the configuration | ||
// or the project formatter. |
There was a problem hiding this comment.
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.
server/src/server.ts
Outdated
@@ -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) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which binary?
findBuildBinary
.
There was a problem hiding this comment.
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
.
server/src/utils.ts
Outdated
return { buildPath: rescriptNodePath, isReScript: true }; | ||
} else if (fs.existsSync(bsbNodePath)) { | ||
return { buildPath: bsbNodePath, isReScript: false }; | ||
let findBinaryBase = ({ |
There was a problem hiding this comment.
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.
server/src/server.ts
Outdated
@@ -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 = |
There was a problem hiding this comment.
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?
I made a few reviews, going commit after commit. |
Overall I think this should be the main logic:
The config would be mentioned only once in one place: find the binary path. |
Thanks a lot for your review! In the near future, I will try to polish this PR. |
@cristianoc I fixed the PR according to your reviews. Also, I have a few thoughts above. Could you please look at them? |
Thank you -- merging now as I need to do a couple of relevant changes. |
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.