Skip to content

[SourceKit] Print backticks if needed in printDisplayName #82481

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
Jun 26, 2025

Conversation

hamishknight
Copy link
Contributor

Ensure we print raw identifier names with backticks for e.g the document structure request.

rdar://152524780

llvm::raw_ostream &print(llvm::raw_ostream &os,
bool skipEmptyArgumentNames = false) const;
bool skipEmptyArgumentNames = false,
bool escapeIfNeeded = false) const;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This probably ought to default to true, but I'm leaving that for a future PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we print raw identifiers in textual interfaces properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do, the ASTPrinter has its own implementation of this

@@ -6,7 +6,7 @@
{
key.kind: source.lang.swift.decl.class,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "<#MyCls#>",
key.name: "`<#MyCls#>`",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is consistent with how we classify raw identifiers, but admittedly does seem a little odd. It does reflect how placeholders are treated in decl name position though, they are effectively raw identifiers, e.g:

struct S {
  static func <#foo#>() {}
}
S.<#foo#>() // resolves to <#foo#>
S.<#bar#>() // error: type 'S' has no member '<#bar#>'

Any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Definitely a bit of an odd case. I think my preference here would be to only add backticks if the name itself actually has backticks vs just being a placeholder. I assume a placeholder within backticks causes all sorts of weirdness though?

Copy link
Contributor Author

@hamishknight hamishknight Jun 25, 2025

Choose a reason for hiding this comment

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

Yeah it's a weird case, really I would prefer if we could just ban editor placeholders in raw identifiers, although that would probably need some evolution discussion.

I think my preference here would be to only add backticks if the name itself actually has backticks

Trouble is that DeclName doesn't currently have that information, we'd either need to plumb it through, or this decision would need to be left up to the clients

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm happy leaving it for this PR 👍

Ensure we print raw identifier names with backticks for e.g the
document structure request.

rdar://152524780
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight
Copy link
Contributor Author

@swift-ci please test Linux

@hamishknight hamishknight enabled auto-merge June 26, 2025 10:41
@hamishknight hamishknight merged commit 46f5e41 into swiftlang:main Jun 26, 2025
4 of 5 checks passed
@hamishknight hamishknight deleted the tic-tac-toe branch June 26, 2025 20:00
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.

2 participants