|
40 | 40 | ;; --------------------------------------------------------------------- |
41 | 41 | ;; Customization |
42 | 42 | ;; --------------------------------------------------------------------- |
| 43 | +(defgroup lsp-sourcekit nil |
| 44 | + "LSP support for swift, using sourcekit-lsp." |
| 45 | + :group 'lsp-mode |
| 46 | + :prefix "lsp-sourcekit-" |
| 47 | + :link '(url-link "https://github.com/apple/sourcekit-lsp")) |
43 | 48 |
|
44 | | -(defcustom lsp-sourcekit-executable |
45 | | - "sourcekit" |
46 | | - "Path of the lsp-sourcekit executable." |
47 | | - :type 'file |
48 | | - :group 'sourcekit) |
| 49 | +(defcustom lsp-sourcekit-executable "sourcekit-lsp" |
| 50 | + "Path of the sourcekit-lsp executable." |
| 51 | + :group 'lsp-sourcekit |
| 52 | + :type 'file) |
49 | 53 |
|
50 | | -(defcustom lsp-sourcekit-extra-args |
51 | | - nil |
| 54 | +(defcustom lsp-sourcekit-extra-args nil |
52 | 55 | "Additional command line options passed to the lsp-sourcekit executable." |
53 | 56 | :type '(repeat string) |
54 | | - :group 'sourcekit) |
| 57 | + :group 'lsp-sourcekit) |
| 58 | + |
| 59 | + |
| 60 | +;;;###autoload |
| 61 | +(defun lsp-sourcekit--find-executable-with-xcrun () |
| 62 | + "sourcekit-lsp may be installed behind xcrun; if we can't find |
| 63 | +the `lsp-sourcekit-executable' on PATH, try it with xcrun." |
| 64 | + (and (not (file-name-absolute-p lsp-sourcekit-executable)) |
| 65 | + (executable-find "xcrun") |
| 66 | + (with-demoted-errors "lsp-sourcekit: find server with xcrun(1): %S" |
| 67 | + (car-safe (process-lines "xcrun" "--find" lsp-sourcekit-executable))))) |
| 68 | + |
55 | 69 |
|
56 | 70 | ;; --------------------------------------------------------------------- |
57 | 71 | ;; Register lsp client |
58 | 72 | ;; --------------------------------------------------------------------- |
| 73 | +;;;###autoload |
| 74 | +(with-eval-after-load 'lsp-mode |
| 75 | + (lsp-dependency |
| 76 | + 'sourcekit-lsp |
| 77 | + (list :system 'lsp-sourcekit-executable) |
| 78 | + (list :system #'lsp-sourcekit--find-executable-with-xcrun)) |
59 | 79 |
|
60 | | -(defun lsp-sourcekit--lsp-command () |
61 | | - "Generate the language server startup command." |
62 | | - `(,lsp-sourcekit-executable |
63 | | - ,@lsp-sourcekit-extra-args)) |
64 | 80 |
|
65 | | -(lsp-register-client |
66 | | - (make-lsp-client :new-connection (lsp-stdio-connection 'lsp-sourcekit--lsp-command) |
67 | | - :major-modes '(swift-mode) |
68 | | - :server-id 'sourcekit-ls)) |
| 81 | + (lsp-register-client |
| 82 | + (make-lsp-client :new-connection (lsp-stdio-connection |
| 83 | + (apply-partially #'lsp-package-path 'sourcekit-lsp)) |
| 84 | + :major-modes '(swift-mode) |
| 85 | + :server-id 'sourcekit-ls))) |
69 | 86 |
|
70 | 87 | (provide 'lsp-sourcekit) |
71 | 88 | ;;; lsp-sourcekit.el ends here |
0 commit comments