Skip to content

GroupedDiagnostics accept any Syntax as the "source file" #2889

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 1 commit into from
Nov 4, 2024
Merged
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
13 changes: 5 additions & 8 deletions Sources/SwiftDiagnostics/GroupedDiagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public struct GroupedDiagnostics {
let id: SourceFileID

/// The syntax tree for the source file.
let tree: SourceFileSyntax
let tree: Syntax

/// The source location converter for this source file.
let sourceLocationConverter: SourceLocationConverter
Expand All @@ -55,7 +55,7 @@ public struct GroupedDiagnostics {

/// Mapping from the root source file syntax nodes to the corresponding
/// source file IDs.
var rootIndexes: [SourceFileSyntax: SourceFileID] = [:]
var rootIndexes: [Syntax: SourceFileID] = [:]

public init() {}

Expand All @@ -71,12 +71,13 @@ public struct GroupedDiagnostics {
/// - Returns: The unique ID for this source file.
@discardableResult
public mutating func addSourceFile(
tree: SourceFileSyntax,
tree: some SyntaxProtocol,
sourceLocationConverter: SourceLocationConverter? = nil,
displayName: String,
parent: (SourceFileID, AbsolutePosition)? = nil,
diagnostics: [Diagnostic] = []
) -> SourceFileID {
let tree = Syntax(tree)
// Determine the ID this source file will have.
let id = SourceFileID(id: sourceFiles.count)
let slc =
Expand Down Expand Up @@ -108,11 +109,7 @@ public struct GroupedDiagnostics {

/// Find the ID of the source file containing this syntax node.
func findSourceFileContaining(_ node: Syntax) -> SourceFileID? {
guard let rootSourceFile = node.root.as(SourceFileSyntax.self) else {
return nil
}

return rootIndexes[rootSourceFile]
return rootIndexes[node.root]
}

/// Add a diagnostic to the set of grouped diagnostics.
Expand Down