Skip to content

Return diagnostics if SwiftPM project is opened from a symlinked URL #1915

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
Jan 13, 2025

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jan 9, 2025

If you have a SwiftPM project at /projects/myProject and a symlink pointing from /myProject to /projects/myProject, we would correctly get build settings etc for the files. But, when getting diagnostics, sourcekitd would return these diagnostics for the full /projects/myProject path. We would then decide that those diagnostics didn’t matched the file you opened (inside /myProject) and thus suppress them.

Show diagnostics diagnostics if the originated from a file with the same realpath as the file you opened.

Fixes #1910
rdar://142386278

If you have a SwiftPM project at `/projects/myProject` and a symlink pointing from `/myProject` to `/projects/myProject`, we would correctly get build settings etc for the files. But, when getting diagnostics, sourcekitd would return these diagnostics for the full `/projects/myProject` path. We would then decide that those diagnostics didn’t matched the file you opened (inside `/myProject`) and thus suppress them.

Show diagnostics diagnostics if the originated from a file with the same realpath as the file you opened.

Fixes swiftlang#1910
rdar://142386278
@ahoppen
Copy link
Member Author

ahoppen commented Jan 9, 2025

@swift-ci Please test


guard
filePath == snapshot.uri.pseudoPath
|| haveSameRealpath(DocumentURI(filePath: filePath, isDirectory: false), snapshot.uri)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to use the realpath here at all?

Separately, this will allow diagnostics for symlinks across targets. Maybe that's fine though, since ... that really shouldn't happen?

Copy link
Member Author

Choose a reason for hiding this comment

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

Would it be possible to use the realpath here at all?

What do you mean?

Separately, this will allow diagnostics for symlinks across targets. Maybe that's fine though, since ... that really shouldn't happen?

Yes, but I really wouldn’t expect that.

Copy link
Contributor

@bnbarham bnbarham Jan 10, 2025

Choose a reason for hiding this comment

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

What do you mean?

I swear I had "realpath cache" here. I remember reading it back 😭! (ie. the realpath cache we have on the workspace)

Copy link
Member Author

Choose a reason for hiding this comment

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

No, we can’t. We can only use the realpath cache for files that we watch, so we get notified about changes to them. But the paths we are inspecting here are arbitrary and might thus not be in our watch patterns. Using a realpath cache would thus mean that we could get out-of-date file system information.

@ahoppen ahoppen merged commit e26d9f6 into swiftlang:main Jan 13, 2025
3 checks passed
Copy link
Member

@weliveindetail weliveindetail left a comment

Choose a reason for hiding this comment

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

@ahoppen Are symlinked URLs supposed to work on Windows at this point?

DocumentDiagnosticsRequest(textDocument: TextDocumentIdentifier(uri))
)
let diagnostic = try XCTUnwrap(diagnostics.fullReport?.items.only)
XCTAssertEqual(diagnostic.message, "Cannot convert value of type 'Int' to specified type 'String'")
Copy link
Member

Choose a reason for hiding this comment

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

This test failed in my PR test: swiftlang/swift#78630 (comment)

@ahoppen ahoppen deleted the diags-from-symlinks branch January 15, 2025 16:26
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.

Diagnostics do not show when there is a compiler error
3 participants