Skip to content
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

Correct source code locations of link diagnostics for Objective-C doc comments #734

Merged

Conversation

patshaughnessy
Copy link
Contributor

@patshaughnessy patshaughnessy commented Oct 6, 2023

Explanation: Fix the source location for some Obj-C diagnostics.
Scope: Fixes the line and column numbers that appear in the diagnostics.json file, used by Xcode to determine where to show them in the editor.
GitHub Issue: none.
Risk: Low. Minor code changes impacting diagnostic source locations only..
Testing: Ran the ./bin/test script and it succeeded
Reviewer: @d-ronnqvist

Bug/issue #, if applicable:

rdar://102855081

Summary

Correct the line and character locations of invalid link diagnostics in Objective-C source code doc comments.

Previously, DocumentationContext#resolveLinks would use the default symbol to calculate the offset of each doc comment in a source file. However, the default symbol is always set to a Swift symbol even for Objective-C source code. This lead to a bug when Objective-C diagnostics would always use a zero offset.

Example:

Example of an Objective-C link diagnostic at the wrong location

Instead, save the offset of each doc comment in the DocumentationChunk structure, which is initialized using the documented symbol, i.e. the Swift or Objective-C symbol which actually contains the doc comment.

Also decrement the line and character indexes by 1 for both Objective-C doc comments so Xcode displays them in the proper location.

Same example with the fix in place:

Example of an Objective-C link diagnostic at the wrong location

Dependencies

None.

Testing

Introduced invalid links into doc comments inside of various Objective-C header files, and built the documentation. Tested that Xcode displayed the diagnostics in the proper location in the source code editor.

Steps:

  1. Add invalid-link or some other invalid DocC link in a doc comment in an Objective-C header file.
  2. Build the documentation using Xcode.
  3. Check that the yellow warning diagnostic appears in the proper location. See the screen shots above.

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • [ x ] Added tests
  • [ x ] Ran the ./bin/test script and it succeeded
  • [ ] Updated documentation if necessary

patshaughnessy and others added 2 commits October 6, 2023 15:51
Correct the line and character locations of invalid link diagnostics in
Objective-C source code doc comments.

Previously, DocumentationContext#resolveLinks would use the default
symbol to calculate the offset of each doc comment in the source file.
However, the default symbol is always set to a Swift symbol even for
Objective-C source code doc comments. This lead to a bug when
Objective-C diagnostics would always use a zero offset.

Instead, save the offset of each doc comment in the DocumentationChunk
structure, which is initialized using the documented symbol, i.e. the
Swift or Objective-C symbol which actually contains the doc comment.

Also decrement the line and character indexes by 1 for both Objective-C
doc comments so Xcode displays them in the proper location.
@patshaughnessy
Copy link
Contributor Author

@swift-ci please test

- Removed Test Bundles/ObjCFrameworkWithInvalidLink.docc/Info.plist
- SymbolGraph.Symbol#offsetAdjustedForInterfaceLanguage uses the
  SourceLanguage struct as a type safe way of checking the source
  language vs. a string comparison.
- Clean up SymbolExtensionsTests.swift a bit so it uses more accurate
  path fixture values.
@patshaughnessy
Copy link
Contributor Author

@swift-ci please test

@patshaughnessy
Copy link
Contributor Author

@swift-ci please test

@patshaughnessy patshaughnessy merged commit da16aa9 into apple:main Oct 17, 2023
2 checks passed
@patshaughnessy patshaughnessy deleted the fix-objc-diagnostic-locations branch October 17, 2023 21:18
patshaughnessy added a commit to patshaughnessy/swift-docc that referenced this pull request Oct 25, 2023
… comments (apple#734)

* rdar://102855081

Correct the line and character locations of invalid link diagnostics in
Objective-C source code doc comments.

Previously, DocumentationContext#resolveLinks would use the default
symbol to calculate the offset of each doc comment in the source file.
However, the default symbol is always set to a Swift symbol even for
Objective-C source code doc comments. This lead to a bug when
Objective-C diagnostics would always use a zero offset.

Instead, save the offset of each doc comment in the DocumentationChunk
structure, which is initialized using the documented symbol, i.e. the
Swift or Objective-C symbol which actually contains the doc comment.

Also decrement the line and character indexes by 1 for both Objective-C
doc comments so Xcode displays them in the proper location.
patshaughnessy added a commit that referenced this pull request Nov 9, 2023
… comments (#734) (#747)

* rdar://102855081

Correct the line and character locations of invalid link diagnostics in
Objective-C source code doc comments.

Previously, DocumentationContext#resolveLinks would use the default
symbol to calculate the offset of each doc comment in the source file.
However, the default symbol is always set to a Swift symbol even for
Objective-C source code doc comments. This lead to a bug when
Objective-C diagnostics would always use a zero offset.

Instead, save the offset of each doc comment in the DocumentationChunk
structure, which is initialized using the documented symbol, i.e. the
Swift or Objective-C symbol which actually contains the doc comment.

Also decrement the line and character indexes by 1 for both Objective-C
doc comments so Xcode displays them in the proper location.
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.

None yet

3 participants