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

Generate initializer in case multiple variables defined in a line. #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion SourceEditorExtension/SIG.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ func generate(selection: [String], indentation: String, leadingIndent: String) t
let variableType = scanner.scanUpTo("\n") else {
throw SIGError.parseError
}
variables.append((variableName, variableType))

// In case multiple variables defined in a line.
let variableNames = variableName.components(separatedBy: ",")
for vname in variableNames {
Copy link
Owner

Choose a reason for hiding this comment

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

Variable names should be clearer. I.e. change the variable names around so the inner loop variable can be named variableName.

Copy link
Owner

Choose a reason for hiding this comment

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

You could also move this to the scanner part and use scanUpTo(characterSet:) to directly scan the variables into an array. That way there's no need to separate and trim them afterwards.

variables.append((vname.trimmingCharacters(in: .whitespaces), variableType))
}
}

let arguments = variables.map { "\($0.0): \(addEscapingAttributeIfNeeded(to: $0.1))" }.joined(separator: ", ")
Expand Down