Skip to content

add AST printer support for _documentation attribute #64326

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 3 commits into from
Mar 31, 2023

Conversation

QuietMisdreavus
Copy link
Contributor

fixes #64309
fixes rdar://106657906

When the @_documentation attribute was added in #60242, i neglected to add a printer implementation for it. This didn't affect SymbolGraphGen, since it doesn't print UserInaccessible attributes in its declarations. However, sourcekit-lsp does print these attributes, which trips an assertion. This PR adds a printer implementation for the @_documentation attribute, allowing SourceKit to properly collect cursor info.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please smoke test.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please build toolchain Linux platform

// The @_documentation attribute caused sourcekit-lsp to crash
// cf. https://github.com/apple/swift/issues/64309

// RUN: %sourcekitd-test -req=cursor -pos=2:6 %s -- %s
Copy link
Contributor

@bnbarham bnbarham Mar 14, 2023

Choose a reason for hiding this comment

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

Where in the response is @_documentation showing up? If it's user inaccessible, I wouldn't have expected it in cursor info either (and if we do want it, it would be good to actually check for it).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bnbarham I added some output checking in this test; it seems to be showing up in the XML output. I'm not sure if this is expected, but i've updated the test.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is definitely very unexpected to me. IIUC the annotated description should not be including user inaccessible attributes. I guess we're missing adding the PrintUserInaccessibleAttrs in printQuickHelpDeclaration. Ideally we'd fix that as well, but if you don't want to do that it's fine.

If we really want a test for this I'd probably prefer something like a -dump-ast (assuming it includes user inaccessible?) in test/attr. Once we fix cursor info this test would be invalid otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding the test in test/attr makes sense as a way to ensure that the attribute gets printed correctly, but i'd like to leave the test here (without the output checking) since that was the original error case, if that's alright.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you're changing the test anyway, I'd strongly prefer just not including it. The crash has a known cause that we can test, so I don't think there's much use in testing the crash itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like -dump-ast doesn't include UserInaccessible attributes either:

(source_file "/Users/victoria_m/swift-base/swift/test/attr/attr_documentation.swift"
  (enum_decl range=[/Users/victoria_m/swift-base/swift/test/attr/attr_documentation.swift:5:1 - line:7:1] "E" interface type='E.Type' access=internal non-resilient))

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah that's a pity 😓. You can keep the cursor info test without output if you want. Really we should check that inaccessible attributes don't get printed in generated interface/completion/cursor info, but I don't expect you to do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took the output check out of the test. The test as a whole could be taken out or modified when the UserInaccessible filtering is added in the future.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please smoke test

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please smoke test

1 similar comment
@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please smoke test

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@QuietMisdreavus QuietMisdreavus merged commit 47bf147 into main Mar 31, 2023
@QuietMisdreavus QuietMisdreavus deleted the QuietMisdreavus/doc-attr-sourcekit branch March 31, 2023 16:33
QuietMisdreavus added a commit that referenced this pull request Apr 3, 2023
QuietMisdreavus added a commit that referenced this pull request Apr 14, 2023
etcwilde pushed a commit to etcwilde/swift that referenced this pull request Apr 19, 2023
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.

(lib/IDE) @_documentation attribute always crashes sourcekit-lsp
4 participants