Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SourceManager {

/// Location converter to get line/column in the node.
lazy var locationConverter: SourceLocationConverter = .init(
file: self.location.fileName,
fileName: self.location.fileName,
tree: self.node
)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDiagnostics/Diagnostic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public struct Diagnostic: CustomDebugStringConvertible {
}

public var debugDescription: String {
let locationConverter = SourceLocationConverter(file: "", tree: node.root)
let locationConverter = SourceLocationConverter(fileName: "", tree: node.root)
let location = location(converter: locationConverter)
return "\(location.line):\(location.column): \(message)"
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDiagnostics/DiagnosticsFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public struct DiagnosticsFormatter {
suffixTexts: [AbsolutePosition: String],
sourceLocationConverter: SourceLocationConverter? = nil
) -> String {
let slc = sourceLocationConverter ?? SourceLocationConverter(file: fileName ?? "", tree: tree)
let slc = sourceLocationConverter ?? SourceLocationConverter(fileName: fileName ?? "", tree: tree)

// First, we need to put each line and its diagnostics together
var annotatedSourceLines = [AnnotatedSourceLine]()
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDiagnostics/GroupedDiagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ extension GroupedDiagnostics {
) -> String {
let sourceFile = sourceFiles[sourceFileID.id]
let slc = SourceLocationConverter(
file: sourceFile.displayName,
fileName: sourceFile.displayName,
tree: sourceFile.tree
)

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDiagnostics/Note.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public struct Note: CustomDebugStringConvertible {

public var debugDescription: String {
if let root = node.root.as(SourceFileSyntax.self) {
let locationConverter = SourceLocationConverter(file: "", tree: root)
let locationConverter = SourceLocationConverter(fileName: "", tree: root)
let location = location(converter: locationConverter)
return "\(location): \(message)"
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ extension BasicMacroExpansionContext: MacroExpansionContext {
fileName: String
) -> SourceLocation {
guard let nodeInOriginalTree = detachedNodes[node.root] else {
return SourceLocationConverter(file: fileName, tree: node.root).location(for: position)
return SourceLocationConverter(fileName: fileName, tree: node.root).location(for: position)
}
let adjustedPosition = position + SourceLength(utf8Length: nodeInOriginalTree.position.utf8Offset)
return SourceLocationConverter(file: fileName, tree: nodeInOriginalTree.root).location(for: adjustedPosition)
return SourceLocationConverter(fileName: fileName, tree: nodeInOriginalTree.root).location(for: adjustedPosition)
}

public func location(
Expand Down Expand Up @@ -197,7 +197,7 @@ extension BasicMacroExpansionContext: MacroExpansionContext {
}

// Do the location lookup.
let converter = SourceLocationConverter(file: fileName, tree: rootSourceFile)
let converter = SourceLocationConverter(fileName: fileName, tree: rootSourceFile)
return AbstractSourceLocation(converter.location(for: rawPosition + offsetAdjustment))
}
}
4 changes: 2 additions & 2 deletions Sources/_SwiftSyntaxTestSupport/SyntaxComparison.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ extension TreeDifference: CustomDebugStringConvertible {
public var debugDescription: String {
let includeTrivia = reason == .trivia

let expectedConverter = SourceLocationConverter(file: "Baseline.swift", tree: baseline.root)
let actualConverter = SourceLocationConverter(file: "Actual.swift", tree: node.root)
let expectedConverter = SourceLocationConverter(fileName: "Baseline.swift", tree: baseline.root)
let actualConverter = SourceLocationConverter(fileName: "Actual.swift", tree: node.root)

let expectedDesc = baseline.debugDescription(includeTrivia: includeTrivia, converter: expectedConverter)
let actualDesc = node.debugDescription(includeTrivia: includeTrivia, converter: actualConverter)
Expand Down
6 changes: 3 additions & 3 deletions Tests/SwiftParserTest/Assertions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func assertLocation<T: SyntaxProtocol>(
line: UInt = #line
) {
if let markerLoc = markerLocations[locationMarker] {
let locationConverter = SourceLocationConverter(file: "", tree: tree)
let locationConverter = SourceLocationConverter(fileName: "", tree: tree)
let actualLocation = location
let expectedLocation = locationConverter.location(for: AbsolutePosition(utf8Offset: markerLoc))
if actualLocation.line != expectedLocation.line || actualLocation.column != expectedLocation.column {
Expand All @@ -362,7 +362,7 @@ func assertNote<T: SyntaxProtocol>(
expected spec: NoteSpec
) {
XCTAssertEqual(note.message, spec.message, file: spec.file, line: spec.line)
let locationConverter = SourceLocationConverter(file: "", tree: tree)
let locationConverter = SourceLocationConverter(fileName: "", tree: tree)
assertLocation(
note.location(converter: locationConverter),
in: tree,
Expand All @@ -381,7 +381,7 @@ func assertDiagnostic<T: SyntaxProtocol>(
markerLocations: [String: Int],
expected spec: DiagnosticSpec
) {
let locationConverter = SourceLocationConverter(file: "", tree: tree)
let locationConverter = SourceLocationConverter(fileName: "", tree: tree)
assertLocation(
diag.location(converter: locationConverter),
in: tree,
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftParserTest/ParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ParserTests: XCTestCase {
let diagnostics = ParseDiagnosticsGenerator.diagnostics(for: parsed)
if !diagnostics.isEmpty {
var locationAndDiagnostics: [String] = []
let locationConverter = SourceLocationConverter(file: fileURL.lastPathComponent, tree: parsed)
let locationConverter = SourceLocationConverter(fileName: fileURL.lastPathComponent, tree: parsed)
for diag in diagnostics {
let location = diag.location(converter: locationConverter)
let message = diag.message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public class StringLiteralRepresentedLiteralValueTests: XCTestCase {

super.init(viewMode: .sourceAccurate)

self.locationConverter = SourceLocationConverter(file: "", tree: syntax)
self.locationConverter = SourceLocationConverter(fileName: "", tree: syntax)
self.walk(syntax)
self.locationConverter = nil
}
Expand Down