@@ -24,8 +24,6 @@ public class TextViewController: NSViewController {
2424
2525 // MARK: - Views and Child VCs
2626
27- // MARK: - Views and Child VCs
28-
2927 weak var findViewController : FindViewController ?
3028
3129 internal( set) public var scrollView : NSScrollView !
@@ -89,6 +87,18 @@ public class TextViewController: NSViewController {
8987
9088 public weak var completionDelegate : CodeSuggestionDelegate ?
9189
90+ /// A delegate object that responds to requests for jump to definition actions. see ``JumpToDefinitionDelegate``.
91+ /// - Note: The ``TextViewController`` keeps only a `weak` reference to this object. To function properly, ensure a
92+ /// strong reference to the delegate is kept *outside* of this variable.
93+ public var jumpToDefinitionDelegate : JumpToDefinitionDelegate ? {
94+ get {
95+ jumpToDefinitionModel. delegate
96+ }
97+ set {
98+ jumpToDefinitionModel. delegate = newValue
99+ }
100+ }
101+
92102 // MARK: - Config Helpers
93103
94104 /// The font to use in the `textView`
@@ -177,7 +187,7 @@ public class TextViewController: NSViewController {
177187 /// This will be `nil` if another highlighter provider is passed to the source editor.
178188 internal( set) public var treeSitterClient : TreeSitterClient ? {
179189 didSet {
180- jumpToDefinitionModel? . treeSitterClient = treeSitterClient
190+ jumpToDefinitionModel. treeSitterClient = treeSitterClient
181191 }
182192 }
183193
@@ -186,7 +196,7 @@ public class TextViewController: NSViewController {
186196 /// Filters used when applying edits..
187197 var textFilters : [ TextFormation . Filter ] = [ ]
188198
189- var jumpToDefinitionModel : JumpToDefinitionModel ?
199+ var jumpToDefinitionModel : JumpToDefinitionModel
190200
191201 var cancellables = Set < AnyCancellable > ( )
192202
@@ -214,7 +224,8 @@ public class TextViewController: NSViewController {
214224 highlightProviders: [ HighlightProviding ] = [ TreeSitterClient ( ) ] ,
215225 foldProvider: LineFoldProvider ? = nil ,
216226 undoManager: CEUndoManager ? = nil ,
217- coordinators: [ TextViewCoordinator ] = [ ]
227+ coordinators: [ TextViewCoordinator ] = [ ] ,
228+ jumpToDefinitionDelegate: JumpToDefinitionDelegate ? = nil
218229 ) {
219230 self . language = language
220231 self . configuration = configuration
@@ -223,9 +234,15 @@ public class TextViewController: NSViewController {
223234 self . foldProvider = foldProvider ?? LineIndentationFoldProvider ( )
224235 self . _undoManager = undoManager
225236 self . invisibleCharactersCoordinator = InvisibleCharactersCoordinator ( configuration: configuration)
237+ self . jumpToDefinitionModel = JumpToDefinitionModel (
238+ controller: nil ,
239+ treeSitterClient: treeSitterClient,
240+ delegate: jumpToDefinitionDelegate
241+ )
226242
227243 super. init ( nibName: nil , bundle: nil )
228244
245+ jumpToDefinitionModel. controller = self
229246 suggestionTriggerModel. controller = self
230247
231248 if let idx = highlightProviders. firstIndex ( where: { $0 is TreeSitterClient } ) ,
@@ -253,11 +270,6 @@ public class TextViewController: NSViewController {
253270 }
254271 self . textCoordinators = coordinators. map { WeakCoordinator ( $0) }
255272
256- jumpToDefinitionModel = JumpToDefinitionModel (
257- controller: self ,
258- treeSitterClient: treeSitterClient,
259- delegate: nil
260- )
261273 }
262274
263275 required init ? ( coder: NSCoder ) {
0 commit comments