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

Source Control Navigator: Added support for viewing file changes. #596

Closed
wants to merge 8 commits into from
Closed

Conversation

nanashili
Copy link
Contributor

Description

Added support for showing changed/created files in the currently opened workspace.

Related Issue

✨ Source Control Navigator #352

Checklist

  • I read and understood the contributing guide as well as the code of conduct
  • My changes generate no new warnings
  • My code builds and runs on my machine
  • I documented my code
  • Review requested

Screenshots

Screenshot 2022-05-05 at 14 02 00

0xWDG
0xWDG previously approved these changes May 5, 2022
@@ -59,6 +59,25 @@ public extension GitClient {
}
}

/// Displays paths that have differences between the index file and the current HEAD commit,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would put this comment above the closure in the interface

Copy link
Collaborator

Choose a reason for hiding this comment

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

marked as unresolved since it wasn't changed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not enough information to do what you are asking for

Copy link
Collaborator

Choose a reason for hiding this comment

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

marked as unresolved since it wasn't changed

Copy link
Collaborator

Choose a reason for hiding this comment

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

What I'm suggesting to do here is moving this comment above the closure declaration which you can find in the Interface

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What interface... Direct me to the line

Copy link
Collaborator

Choose a reason for hiding this comment

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

public var getChangedFiles: () throws -> [ChangedFiles]

.map { line -> ChangedFiles in
let paramData = line.trimmingCharacters(in: .whitespacesAndNewlines)
let parameters = paramData.components(separatedBy: " ")
return ChangedFiles(changeType: parameters[safe: 0] ?? "",
Copy link
Collaborator

Choose a reason for hiding this comment

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

thoughts on not using optionals and checking that the array contains the value we expect? If not we can return nil and change this from being a map to a compactMap 

Copy link
Collaborator

Choose a reason for hiding this comment

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

marked as unresolved since this was unchanged

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not enough information to do what you are asking for

0xWDG
0xWDG previously approved these changes May 6, 2022
Copy link
Collaborator

@0xWDG 0xWDG left a comment

Choose a reason for hiding this comment

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

Good work!
I suggest a (small) amount of improvements.

0xWDG
0xWDG previously approved these changes May 6, 2022
/// Initialize with a GitClient
/// - Parameter workspaceURL: the current workspace URL
///
public init(workspaceURL: URL) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is the workspaceURL here used only for initializing the GitClient ? If so we should inject the git client instead of the workspaceURL

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used for ChangedFileItemView to open files in the finder also

Copy link
Collaborator

Choose a reason for hiding this comment

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

marking as unresolved since it wasn't resolved. The ChangedFileItemView seems to already have a workspaceURL

/// Initialize with GitClient
/// - Parameter gitClient: a GitClient
init(workspaceURL: URL) {
self.model = .init(workspaceURL: workspaceURL)
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of passing the workspaceURL we can pass the SourceControlModel directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used for ChangedFileItemView to open files in the finder also

Copy link
Collaborator

Choose a reason for hiding this comment

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

could you indicate me in which file this is used please? It's a weird pattern

Copy link
Collaborator

Choose a reason for hiding this comment

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

seems that ChangedFileItemView has the workspaceURL too so it should be fine if we remove it from here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you read my comment right you would see I said it is used to open the finder at the file directory.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@nanashili I definitely read your comment right, but a link to the actual reference might be helpful for the context. Thank you!

}

/// Returns the file name (e.g.: `Package.swift`)
public var fileName: String {
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need to have a comptued property ? We can retrieve this info directly from the URL

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes because we use it do display on the list.

Copy link
Collaborator

Choose a reason for hiding this comment

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

please do not mark comments as resolved if not resolved

Copy link
Collaborator

Choose a reason for hiding this comment

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

when we display this on the list we could actually access the URL directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you want clean code or do you want a mess because that's what you are suggesting right now.

0xWDG
0xWDG previously approved these changes May 6, 2022
.compactMap { line -> ChangedFiles in
let paramData = line.trimmingCharacters(in: .whitespacesAndNewlines)
let parameters = paramData.components(separatedBy: " ")
guard let url = URL(string: parameters[safe: 1] ?? "") else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

since we are guarding for the url we shouldn't handle the optional with an empty string. we can return an error or nil if we can't find what we are looking for on the array

}
return try output
.split(whereSeparator: \.isNewline)
.compactMap { line -> ChangedFiles in
Copy link
Collaborator

Choose a reason for hiding this comment

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

it seems we are not returning nil anywhere else which means we don't have to use a compactMap

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Imma need you to decide now if you want this to be a map or compactMap...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I gave you options. I suggested you to return a nil and use a compactMap but you decided to handle the optional and throw an error, in that case a compactMap is not needed. Here it is a good resource for this:
https://www.hackingwithswift.com/articles/205/whats-the-difference-between-map-flatmap-and-compactmap


// swiftlint:disable identifier_name
public enum GitType: String, Codable {
case M = "M"
Copy link
Collaborator

Choose a reason for hiding this comment

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

a couple of things here.

  1. Cases shouldn't be capitalized
  2. Each case should be more descriptive
  3. if the case is equal to the rawValue you don't have to specify the actual rawValue


// swiftlint:disable identifier_name
public enum FileType: String {
case json = "json"
Copy link
Collaborator

Choose a reason for hiding this comment

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

if the rawValue is equal to the actual case name we can omit the rawValue itself

@nanashili
Copy link
Contributor Author

nanashili commented May 6, 2022

Closing this PR since there is to much small issues that @MarcoCarnevali has with this PR

@nanashili nanashili closed this May 6, 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.

7 participants