Skip to content

Add a subcommand to sourcekit-lsp that automatically reduces sourcekitd issues #1037

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 2 commits into from
Jan 31, 2024

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jan 26, 2024

Essentially, this is adding three pieces of functionality:

  1. sourcekit-lsp run-sourcekitd-request takes a JSON sourcekitd request and a path to sourcekitd.framework and executes that request using that sourcekitd. This is basically equivalent to sourcekitd-test -json-request-path but it works even if the toolchain with sourcekitd.framework doesn’t have a sourcekitd-test.
  2. sourcekit-lsp diagnose --request-file takes a path to a JSON sourcekitd request, gets the source file’s contents from disk and reduces the source file + compiler arguments to create a reduced reproducer. It then copies all files referenced from the compiler arguments to a temporary folder and asks the user to file an issue with that information. To reproduce non-crashes an NSPredicate can be passed via the --predicate parameter. Any sourcekitd response that satisfies the predicate is considered a reproducer.
  3. sourcekit-lsp diagnose without arguments is similar to (2) but looks in OSLog for the last sourcekitd crash.

So far, this tool has been able to automatically reduce a crash I found while working on sourcekit-lsp to the following input file and reduced the compiler arguments to only include the input file itself.

public actor TranslatableName {

  init(
    definitionName: String,
    definitionDocumentUri: DocumentURI,
    definitionPosition: Position,
    definitionLanguageService: any ToolchainLanguageServer,
    isObjectiveCSelector: Bool
  ) {
    self.isObjectiveCSelector = isObjectiveCSelector
  }
}

@ahoppen ahoppen requested a review from benlangmuir as a code owner January 26, 2024 01:03
@ahoppen ahoppen changed the title Add a subcommand to sourcekit-lsp that automatically reduces sourcekitd crashes Add a subcommand to sourcekit-lsp that automatically reduces sourcekitd issues Jan 26, 2024
@ahoppen ahoppen force-pushed the ahoppen/diagnose branch 4 times, most recently from 4d970a1 to 6643411 Compare January 29, 2024 22:30
@ahoppen
Copy link
Member Author

ahoppen commented Jan 29, 2024

@swift-ci Please test Windows

…td crashes

Essentially, this is adding three pieces of functionality:
1. `sourcekit-lsp run-sourcekitd-request` takes a JSON sourcekitd request and a path to `sourcekitd.framework` and executes that request using that sourcekitd. This is basically equivalent to `sourcekitd-test -json-request-path` but it works even if the toolchain with `sourcekitd.framework` doesn’t have a `sourcekitd-test`.
2. `sourcekit-lsp diagnose --request-file` takes a path to a JSON sourcekitd request, gets the source file’s contents from disk and reduces the source file + compiler arguments to create a reduced reproducer. It then copies all files referenced from the compiler arguments to a temporary folder and asks the user to file an issue with that information.
3. `sourcekit-lsp diagnose` without arguments is similar to (2) but looks in OSLog for the last sourcekitd crash.
@ahoppen
Copy link
Member Author

ahoppen commented Jan 30, 2024

@swift-ci Please test Windows

@ahoppen
Copy link
Member Author

ahoppen commented Jan 30, 2024

@swift-ci Please test macOS

@ahoppen
Copy link
Member Author

ahoppen commented Jan 30, 2024

@swift-ci Please test Linux

@ahoppen
Copy link
Member Author

ahoppen commented Jan 31, 2024

Merging this as-is so I can iterate on it in-tree. I will address review comments in follow-up PRs.

@ahoppen ahoppen merged commit 35f07f5 into swiftlang:main Jan 31, 2024
@ahoppen ahoppen deleted the ahoppen/diagnose branch January 31, 2024 00:42
Copy link
Contributor

@bnbarham bnbarham left a comment

Choose a reason for hiding this comment

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

Very cool!


@Option(
name: .customLong("request-file"),
help: "Path to a JSON sourcekitd request"
Copy link
Contributor

Choose a reason for hiding this comment

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

Our requests are really yaml aren't they? Why do we keep calling it JSON everywhere?

ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this pull request Feb 1, 2024
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this pull request Feb 1, 2024
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this pull request Feb 2, 2024
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this pull request Feb 2, 2024
ahoppen added a commit that referenced this pull request Feb 3, 2024
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