LSPKit is designed to easily integrate into the Cocoa Document Model and Text System.
NSDocument | LSPClient |
---|---|
- readFromURL: ofType: error: | - documentDidOpen: content: |
- saveToURL: ofType: forSaveOperation: completionHandler: | - documentWillSave: |
- writeToURL: ofType: forSaveOperation: originalContentsURL: error: | - documentDidSave: |
- close | - documentDidClose: |
LSPKit supports incremental document changes and uses coalescing on -document:changeTextInRange:replacementString:
.
What does that mean? When the user types text and the -textView:shouldChangeTextInRange:replacementString:
delegate gets called multiple times, -document:changeTextInRange:replacementString:
doesn't post immediately a 'textDocument/didChange' notification, but rather a notification is queued. Coalescing means that if a notification is posted which matches one already in the queue, the two are merged, so that only a single notification is posted to observers. When the user stops typing, the single 'textDocument/didChange' notification in the queue (due to coalescing) is posted when the run loop enters its wait state.
-addTerminationObserver:block:
makes it easy to restore the language server document state in case the language server process crashes.
Bundles are used to add language servers. Currently the two language servers bash-language-server and vscode-html-languageserver are included.
The sample shows how to integrate LSPKit and how to implement NSTextView features like highlight current line, highlighting of line for diagnotics, highlighting of words, and how to layout views left aligned to line content.
See highlight current line (code) and highlighting of words (code):
Postion NSPopover on a word (part1, part2):
Diagnostic view left aligned to line content (code):
LSPKit is licensed under the MIT license.
Get in touch via twitter, an issue, or a pull request.