Skip to content

adjust API to changes in SwiftPM #433

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 4 commits into from
Oct 22, 2021

Conversation

tomerd
Copy link
Contributor

@tomerd tomerd commented Oct 21, 2021

motivation: stay with the times

changes:

  • use observability system instead of diganostics engine
  • some APIs in SwiftPM are now throwing, adjust to this change

@tomerd tomerd requested a review from benlangmuir as a code owner October 21, 2021 20:59
motivation: stay with the times

changes:
* use observability system instead of diganostics engine
* some APIs in SwiftPM are now throwing, adjust to this change
@tomerd tomerd force-pushed the fix/adjust-to-swiftpm-3818 branch from 4e75720 to 493eab1 Compare October 21, 2021 20:59
@tomerd
Copy link
Contributor Author

tomerd commented Oct 21, 2021

@swift-ci please test

@@ -366,7 +369,7 @@ extension SwiftPMWorkspace {
args += ["-c"]
args += td.sources.map { $0.pathString }
args += ["-I", buildPath.pathString]
args += td.compileArguments()
args += try! td.compileArguments()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we know this cannot throw here? Same question for basicArguments below.

Copy link
Contributor Author

@tomerd tomerd Oct 21, 2021

Choose a reason for hiding this comment

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

this is in response to swiftlang/swift-package-manager#3818 which unwinds a case where previously SwiftPM had a fatalError when this failed. I started going down the path of changing the LSP codebase to throwing everywhere but that became a bit much for me to do without understanding the codebase (delegate signatures, etc) so I decided to use try! (which is the same as before in practice) and let the team unwind this more safely. wdyt?

Copy link
Contributor Author

@tomerd tomerd Oct 21, 2021

Choose a reason for hiding this comment

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

to be clear I am happy to bring these changes back in, but they end up effecting things like the BuildSystem protocol (registerForChangeNotifications needs to handle errors or marked as throwing) which is a bit beyond my understanding of LSP. basically:

 public func registerForChangeNotifications(for uri: DocumentURI, language: Language) {
    guard let delegate = self.delegate else { return }

    // TODO: Support for change detection (via file watching)
    let settings = try self.settings(for: uri, language) // <----- we need to deal with this
    DispatchQueue.global().async {
      delegate.fileBuildSettingsChanged([uri: FileBuildSettingsChange(settings)])
    }
  }

Copy link
Contributor

Choose a reason for hiding this comment

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

I see - the interesting question for us I guess is what kinds of errors there are here and whether we can prevent them or if we need to handle them. For example, I see that one error is related to validating the target -- that seems like something we would want to just handle up front. But if there are other kinds of errors here maybe we need to just log and continue.

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 think errors from here are rare, but fatalError seems wrong since it will cause a crash. logging is fine I guess. would you like me 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.

see 4c36e5a

@tomerd
Copy link
Contributor Author

tomerd commented Oct 21, 2021

@swift-ci please test

1 similar comment
@tomerd
Copy link
Contributor Author

tomerd commented Oct 21, 2021

@swift-ci please test

@tomerd
Copy link
Contributor Author

tomerd commented Oct 21, 2021

Let's log the error itself as well
We need to make the callback even on failure, so we should not return here, but instead in the block below if settings are nil we should call delegate.fileBuildSettingsChanged([uri: .removedOrUnavailable])

3fdc56c

@tomerd tomerd force-pushed the fix/adjust-to-swiftpm-3818 branch from 7f9e81f to 3fdc56c Compare October 21, 2021 22:34
@tomerd
Copy link
Contributor Author

tomerd commented Oct 21, 2021

@swift-ci please test

@tomerd
Copy link
Contributor Author

tomerd commented Oct 21, 2021

@swift-ci please test

@tomerd tomerd merged commit 89aa8ee into swiftlang:main Oct 22, 2021
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