Skip to content

Open documents using testClient.openDocument instead of constructing a DidOpenDocumentNotification #910

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
Oct 20, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Oct 19, 2023

Instead of constructing a DidOpenTextDocumentNotification inside the tests, add a TestSourceKitLSPClient.openDocument method that opens a document. In addition to being shorter to write than the DidOpenTextDocumentNotification, it does two smart things:

  • It infers the language of the test file from its file extension
  • It removes location markers (like 1️⃣) and returns their positions, which means that we don’t need to write fragile line-column based positions in the test files. Migrating all the tests from line-column based Position initializers to use location markers is quite a big change and not part of this PR.

…g a `DidOpenDocumentNotification`

This removes a lot of boilerplate and makes the tests easier to read.
@ahoppen
Copy link
Member Author

ahoppen commented Oct 19, 2023

@swift-ci Please test

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.

Nice!

//===----------------------------------------------------------------------===//

/// Finds all marked ranges in the given text, see `Marker`.
fileprivate func findMarkedRanges(text: String) -> [Marker] {
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't checked, is this basically just a copy paste from swift-syntax 😅?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this is a copy-paste from swift-syntax 😢

extension Language {
var fileExtension: String {
switch self {
case .objective_c: return "m"
Copy link
Contributor

Choose a reason for hiding this comment

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

objective_cpp could probably use a value here as well, though I assume we don't have tests with it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I wanted to add a case here once/if we ever have an Objective-C++ test case.

@ahoppen ahoppen merged commit e141933 into swiftlang:main Oct 20, 2023
@ahoppen ahoppen deleted the ahoppen/open-document branch October 20, 2023 00:13
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