Skip to content
This repository was archived by the owner on Jun 18, 2025. It is now read-only.

Commit f4ea0f6

Browse files
committed
Fix focused code
1 parent 2749e2e commit f4ea0f6

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

Tool/Sources/FocusedCodeFinder/ObjectiveC/ObjectiveCCodeFinder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public class ObjectiveCFocusedCodeFinder: KnownLanguageFocusedCodeFinder<
201201
node: node,
202202
signature: signature,
203203
name: name ?? "N/A",
204-
canBeUsedAsCodeRange: false
204+
canBeUsedAsCodeRange: true
205205
)
206206
}
207207
}
@@ -228,7 +228,7 @@ extension ObjectiveCFocusedCodeFinder {
228228
node: node,
229229
signature: signature,
230230
name: name ?? "N/A",
231-
canBeUsedAsCodeRange: false
231+
canBeUsedAsCodeRange: true
232232
)
233233
}
234234
}

Tool/Tests/FocusedCodeFinderTests/ObjectiveCFocusedCodeFinderTests.swift

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,85 @@ final class ObjectiveCFocusedCodeFinder_Selection_Tests: XCTestCase {
344344
}
345345
}
346346

347+
final class ObjectiveCFocusedCodeFinder_Focus_Tests: XCTestCase {
348+
func test_get_focused_code_inside_method_the_method_should_be_the_focused_code() {
349+
let code = """
350+
@implementation Foo
351+
- (void)fooWith:(NSInteger)foo {
352+
NSInteger foo = 0;
353+
NSLog(@"Hello");
354+
NSLog(@"World");
355+
}
356+
@end
357+
"""
358+
let range = CursorRange(
359+
start: CursorPosition(line: 2, character: 0),
360+
end: CursorPosition(line: 2, character: 0)
361+
)
362+
let context = ObjectiveCFocusedCodeFinder().findFocusedCode(
363+
in: document(code: code),
364+
containingRange: range
365+
)
366+
XCTAssertEqual(context, .init(
367+
scope: .scope(signature: [
368+
.init(
369+
signature: "@implementation Foo",
370+
name: "Foo",
371+
range: .init(startPair: (0, 0), endPair: (6, 4))
372+
),
373+
]),
374+
contextRange: .init(startPair: (0, 0), endPair: (6, 4)),
375+
focusedRange: .init(startPair: (1, 0), endPair: (5, 1)),
376+
focusedCode: """
377+
- (void)fooWith:(NSInteger)foo {
378+
NSInteger foo = 0;
379+
NSLog(@"Hello");
380+
NSLog(@"World");
381+
}
382+
383+
""",
384+
imports: [],
385+
includes: []
386+
))
387+
}
388+
389+
func test_get_focused_code_inside_an_interface_category_the_focused_code_should_be_the_interface() {
390+
let code = """
391+
@interface __GENERICS(NSArray, ObjectType) (BlocksKit)
392+
- (void)fooWith:(NSInteger)foo;
393+
- (void)fooWith:(NSInteger)foo;
394+
- (void)fooWith:(NSInteger)foo;
395+
@end
396+
397+
@implementation Foo
398+
@end
399+
"""
400+
let range = CursorRange(
401+
start: CursorPosition(line: 1, character: 0),
402+
end: CursorPosition(line: 1, character: 0)
403+
)
404+
let context = ObjectiveCFocusedCodeFinder().findFocusedCode(
405+
in: document(code: code),
406+
containingRange: range
407+
)
408+
XCTAssertEqual(context, .init(
409+
scope: .file,
410+
contextRange: .init(startPair: (0, 0), endPair: (0, 0)),
411+
focusedRange: .init(startPair: (0, 0), endPair: (4, 4)),
412+
focusedCode: """
413+
@interface __GENERICS(NSArray, ObjectType) (BlocksKit)
414+
- (void)fooWith:(NSInteger)foo;
415+
- (void)fooWith:(NSInteger)foo;
416+
- (void)fooWith:(NSInteger)foo;
417+
@end
418+
419+
""",
420+
imports: [],
421+
includes: []
422+
))
423+
}
424+
}
425+
347426
final class ObjectiveCFocusedCodeFinder_Imports_Tests: XCTestCase {
348427
func test_parsing_imports() {
349428
let code = """

0 commit comments

Comments
 (0)