Skip to content

Cherry-pick some post-4.2 changes into swift-4.2-branch #6

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

Merged
merged 25 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d259fcc
Simplify AbsolutePosition offset calculation and support columns
Apr 10, 2018
5018466
Clarify comment
Apr 24, 2018
8044478
Un-rename property
Apr 24, 2018
b664867
Monomorphize AbsolutePosition.copy()
Apr 24, 2018
23502d3
Rename byteOffset to utf8Offset and remove utf16
Apr 24, 2018
b970c42
Re-add AbsolutePosition.swift
Apr 24, 2018
cc54246
Actually add offsets in add(columns:) and add(lines:size:)
Apr 24, 2018
60e37d0
Add accessors for source locations and test diagnostic emission (#16141)
harlanhaskins Apr 26, 2018
3dc6e42
Manually cherry-pick tests from apple/swift:
allevato Aug 31, 2018
a2ed7fb
Add descriptions for SwiftSyntax errors (#16339)
harlanhaskins May 3, 2018
54ea839
SwiftSyntax: Allow absolute position access for dangling nodes.
nkcsgexi May 3, 2018
08fb8a0
Add incremental syntax tree deserialization to SwiftSyntax
ahoppen May 24, 2018
7deb6b4
Make RawSyntax a struct
ahoppen May 24, 2018
f104c5f
Add type annotations to speed up compile time
ahoppen Jun 26, 2018
156cc9f
Don't throw just because compilation fails
ahoppen Jul 26, 2018
9bf9210
Record the nodes that have been reused during an incremental transfer
ahoppen May 30, 2018
6294ff3
Refactor AbsolutePosition
ahoppen Jun 28, 2018
84c6d0d
Make AbsolutePosition a value type
ahoppen Aug 14, 2018
b7deaa6
Remove validate methods
ahoppen Aug 23, 2018
9cef71e
Make SourceLength a struct
ahoppen Aug 29, 2018
2703c00
Make RawSyntaxData a direct enum
ahoppen Aug 29, 2018
f511ccc
Don't set the process terminationHandler in SwiftcInvocation
ahoppen Aug 29, 2018
e58d288
Update tests after cherrypicks.
allevato Sep 7, 2018
5d9650b
Allow *ListSyntax nodes to be visited.
allevato Sep 7, 2018
bd3484b
Apply review fixes
allevato Sep 7, 2018
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
27 changes: 27 additions & 0 deletions Sources/SwiftSyntax/AbsolutePosition.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===--------------- AbsolutePosition.swift - Source Positions ------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

/// An absolute position in a source file as text - the absolute utf8Offset from
/// the start, line, and column.
public struct AbsolutePosition {
public let utf8Offset: Int
public let line: Int
public let column: Int

static let startOfFile = AbsolutePosition(line: 1, column: 1, utf8Offset: 0)

public init(line: Int, column: Int, utf8Offset: Int) {
self.line = line
self.column = column
self.utf8Offset = utf8Offset
}
}
15 changes: 9 additions & 6 deletions Sources/SwiftSyntax/Diagnostic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ public struct SourceLocation: Codable {
public let file: String

public init(file: String, position: AbsolutePosition) {
assert(position is UTF8Position, "must be utf8 position")
self.init(line: position.line, column: position.column,
offset: position.byteOffset, file: file)
offset: position.utf8Offset, file: file)
}

public init(line: Int, column: Int, offset: Int, file: String) {
Expand Down Expand Up @@ -88,7 +87,7 @@ public enum FixIt: Codable {
let string = try container.decode(String.self, forKey: .string)
let loc = try container.decode(SourceLocation.self, forKey: .location)
self = .insert(loc, string)
case "replace":
case "replace":
let string = try container.decode(String.self, forKey: .string)
let range = try container.decode(SourceRange.self, forKey: .range)
self = .replace(range, string)
Expand Down Expand Up @@ -202,7 +201,11 @@ public struct Diagnostic: Codable {
/// An array of possible FixIts to apply to this diagnostic.
public let fixIts: [FixIt]

/// A diagnostic builder that
/// A diagnostic builder that exposes mutating operations for notes,
/// highlights, and FixIts. When a Diagnostic is created, a builder
/// will be provided in a closure where the user can conditionally
/// add notes, highlights, and FixIts, that will then be wrapped
/// into the immutable Diagnostic object.
public struct Builder {
/// An in-flight array of notes.
internal var notes = [Note]()
Expand All @@ -225,7 +228,7 @@ public struct Diagnostic: Codable {
/// - fixIts: Any FixIts that should be attached to this note.
public mutating func note(_ message: Message,
location: SourceLocation? = nil,
highlights: [SourceRange] = [],
highlights: [SourceRange] = [],
fixIts: [FixIt] = []) {
self.notes.append(Note(message: message, location: location,
highlights: highlights, fixIts: fixIts))
Expand All @@ -252,7 +255,7 @@ public struct Diagnostic: Codable {

/// Adds a FixIt to replace the contents of the source file corresponding
/// to the provided SourceRange with the provided text.
public mutating
public mutating
func fixItReplace(_ sourceRange: SourceRange, with text: String) {
fixIts.append(.replace(sourceRange, text))
}
Expand Down
Loading