Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Refactoring #168

Merged
merged 3 commits into from
Feb 9, 2017
Merged

Refactoring #168

merged 3 commits into from
Feb 9, 2017

Conversation

KalitaAlexey
Copy link
Contributor

@KalitaAlexey KalitaAlexey commented Feb 4, 2017

Hi everybody.

I made small refactoring.
Moved actions.rs to actions/mod.rs.
Extracted parsing compiler messages into actions/compiler_message_parsing.rs

Copy link
Member

@nrc nrc 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 this PR! I think the idea of factoring out stuff from build in actions.rs is a good one, however, I think there a few places where we can improve on the design in this PR. I left a few comments inline as a first pass, but this is kind of a hard PR to review because of the diff, so we might have to iterate on it a bit...


fn lock_previous_results(&self) -> MutexGuard<Results> {
self.previous_results.lock().expect("previous results lock failed")
Copy link
Member

Choose a reason for hiding this comment

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

I would inline this function - I think repeating the message string is OK and makes it a bit clearer what is going on

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not quite sure whether you are agree with this change or not)

Copy link
Member

Choose a reason for hiding this comment

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

I agree with changing unwrap to expect, but not with factoring out a function.

@@ -76,11 +71,10 @@ impl Build {
}
}

fn convert_build_results_to_notifications(build_results: &Results,
project_path: &Path)
fn convert_results_to_notifications(results: &Results, project_path: &Path)
Copy link
Member

Choose a reason for hiding this comment

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

It's not really your fault, more a weakness in Git, but this diff is really hard to review. When you're doing refactoring, could you make your commits as small as possible please? E.g., here, I think factoring out process_build_result should be its own commit, deleting the structs one commit, and the other renaming another commit.

@@ -0,0 +1,96 @@
use std::path::PathBuf;
Copy link
Member

Choose a reason for hiding this comment

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

Again, not your fault, but for easier review, could you separate the moving of code to another file into a separate commit from any changes?

Copy link
Member

Choose a reason for hiding this comment

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

These new files should have the copyright boilerplate

Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit confused about the module structure here - we have build.rs at the root, plus a complex build submodule of actions. That seems confusing. I assume that actions/build is just the stuff from the build action. I think it would be better just to have this module inside actions, and not have a build submodule of actions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nrc,
I moved it in another file because I like small files)

Copy link
Member

Choose a reason for hiding this comment

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

You can keep it another file, just not in a new module/directory, i.e., add actions/compiler_message_parser.rs


type Results = HashMap<PathBuf, Vec<Diagnostic>>;

pub struct Build {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this is just a naming thing or whether this abstraction could be improved, but it seems kind of wrong at the moment. A Build is not a single build, it seems to be more like a BuildManager or BuildHandler, but that has some overlap with the BuildQueue. I think I'm not convinced that there is something worth abstracting out of ActionHandler here.

Copy link
Member

Choose a reason for hiding this comment

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

To be clear, I think you are correct about pulling out some of the build-related functions from inside build, but I don't think pulling out the data into a Build struct is the right approach to doing this.

results.clear();
}

pub fn execute(&self, project_path: &Path, priority: BuildPriority, out: &Output) {
Copy link
Member

Choose a reason for hiding this comment

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

Similar to the last comment, this is method is just handling the build request and so I think it should be in the action handler. It is not executing the build, it is enqueing it, and then handling the result.

}
}

pub struct CompilerMessageParser {}
Copy link
Member

Choose a reason for hiding this comment

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

If there is no data, this struct should not exist.

pub struct CompilerMessageParser {}

impl CompilerMessageParser {
pub fn parse(message: &str) -> Result<FileDiagnostic, ParseError> {
Copy link
Member

Choose a reason for hiding this comment

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

This could be a module-level function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nrc,
Yes it could.
I unlearned to use functions.

@KalitaAlexey
Copy link
Contributor Author

KalitaAlexey commented Feb 6, 2017

@nrc,
Should I close this PR or just force push to separate things by commits?

@nrc
Copy link
Member

nrc commented Feb 6, 2017

force push would be good, thanks

@KalitaAlexey
Copy link
Contributor Author

@nrc,
I will do that tomorrow.

@KalitaAlexey
Copy link
Contributor Author

@nrc,
Now it is indisputable diff.

@KalitaAlexey KalitaAlexey changed the title Refactored fn build out of struct ActionHandler. Refactoring Feb 7, 2017
Copy link
Member

@nrc nrc left a comment

Choose a reason for hiding this comment

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

Looks good, just needs the copyright notice on the new file.

@@ -0,0 +1,92 @@
use std::path::PathBuf;
Copy link
Member

Choose a reason for hiding this comment

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

Needs copyright notice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay.

@nrc
Copy link
Member

nrc commented Feb 9, 2017

Thank you!

@nrc nrc merged commit c1fa6fe into rust-lang:master Feb 9, 2017
@KalitaAlexey KalitaAlexey deleted the refactoring branch February 9, 2017 06:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants