-
Notifications
You must be signed in to change notification settings - Fork 190
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
Directive argument name and value ranges are incorrect for single-line directives #71
Comments
The code snippet seems not compile. Could you update it so that I can better reproduce the bug? @ethan-kusters |
@Kyle-Ye - looks like that test only works in fileprivate extension RandomAccessCollection where Element == DirectiveArgument {
/// Look for an argument named `name` or log an XCTest failure.
subscript<S: StringProtocol>(_ name: S, file: StaticString = #filePath, line: UInt = #line) -> DirectiveArgument? {
guard let found = self.first(where: {
$0.name == name
}) else {
XCTFail("Expected argument named \(name) but it was not found", file: file, line: line)
return nil
}
return found
}
} |
This a new bug needs to be fixed. Even I revert the change in #50, the test case you provide still fails. A more simplified version to reproduce: func testDirectiveWithOneArgOnDifferentLines() throws {
let source = """
@Options(scope: page)
"""
let line = 2
let document = Document(parsing: source, options: .parseBlockDirectives)
let directive = try XCTUnwrap(document.child(at: 0) as? BlockDirective)
let arguments = directive.argumentText.parseNameValueArguments()
let scopeArg = try XCTUnwrap(arguments["scope"])
XCTAssertEqual("scope", scopeArg.name)
XCTAssertEqual(
SourceLocation(line: line, column: 10, source: nil) ..< SourceLocation(line: line, column: 15, source: nil),
scopeArg.nameRange,
"Unexpected name range when authored at line '\(line)'"
)
XCTAssertEqual("page", scopeArg.value)
XCTAssertEqual(
SourceLocation(line: line, column: 17, source: nil) ..< SourceLocation(line: line, column: 21, source: nil),
scopeArg.valueRange,
"Unexpected value range when authored at line '\(line)'"
)
} |
The block directive parser seems to parse properly. And you can verify it with the following code. (By testing on directive.argumentText.segments[0].range) let source = """
@Options(scope: page)
"""
let line = 2
let document = Document(parsing: source, options: .parseBlockDirectives)
let directive = try XCTUnwrap(document.child(at: 0) as? BlockDirective)
XCTAssertEqual(
directive.argumentText.segments[0].range,
SourceLocation(line: line, column: 10, source: nil) ..< SourceLocation(line: line, column: 21, source: nil)
) The root cause of the bug may be caused by the implementation of |
I have added a PR to fix it. Could you help review it? @ethan-kusters |
Summary
Directive argument name and value ranges are incorrect for single-line directives that are written anywhere besides the first line of the document.
Details
I've reproduced this issue with the following test run on the current
main
branch:which gives the following output:
showing that the name and value ranges are incorrect when the directive is authored beyond line 1.
Notes
This only reproduces for single-line directives and so seems related to #49.
The text was updated successfully, but these errors were encountered: