From bfcde1fc536e4159ca3d596fa5b8bbbeb1524362 Mon Sep 17 00:00:00 2001 From: Khan Winter <35942988+thecoolwinter@users.noreply.github.com> Date: Thu, 21 Nov 2024 15:22:56 -0600 Subject: [PATCH] Fix TreeSitterClient Not Being Set (#280) --- .../Controller/TextViewController.swift | 5 +++++ .../TextViewControllerTests.swift | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/Sources/CodeEditSourceEditor/Controller/TextViewController.swift b/Sources/CodeEditSourceEditor/Controller/TextViewController.swift index edec536a7..cafbbc4b6 100644 --- a/Sources/CodeEditSourceEditor/Controller/TextViewController.swift +++ b/Sources/CodeEditSourceEditor/Controller/TextViewController.swift @@ -254,6 +254,11 @@ public class TextViewController: NSViewController { platformGuardedSystemCursor = false } + if let idx = highlightProviders.firstIndex(where: { $0 is TreeSitterClient }), + let client = highlightProviders[idx] as? TreeSitterClient { + self.treeSitterClient = client + } + self.textView = TextView( string: string, font: font, diff --git a/Tests/CodeEditSourceEditorTests/TextViewControllerTests.swift b/Tests/CodeEditSourceEditorTests/TextViewControllerTests.swift index 28b70557f..60f217a9e 100644 --- a/Tests/CodeEditSourceEditorTests/TextViewControllerTests.swift +++ b/Tests/CodeEditSourceEditorTests/TextViewControllerTests.swift @@ -418,5 +418,14 @@ final class TextViewControllerTests: XCTestCase { XCTAssertEqual(controller.cursorPositions[1].line, 3) XCTAssertEqual(controller.cursorPositions[1].column, 1) } + + // MARK: - TreeSitterClient + + func test_treeSitterSetUp() { + // Set up with a user-initiated `TreeSitterClient` should still use that client for things like tag + // completion. + let controller = Mock.textViewController(theme: Mock.theme()) + XCTAssertNotNil(controller.treeSitterClient) + } } // swiftlint:enable all