Skip to content

Commit 54948ca

Browse files
dsyzlingyyoncho
authored andcommitted
Add custom client capability registration. (#1013)
Metals requires a set of experimental client capabilities to be sent to the lsp server to enable the treeview provider. client capabilities can be registered as part of the lsp-client definition and sent during initialisation.
1 parent 5f556e4 commit 54948ca

File tree

1 file changed

+51
-46
lines changed

1 file changed

+51
-46
lines changed

lsp-mode.el

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,8 @@ INHERIT-INPUT-METHOD will be proxied to `completing-read' without changes."
10261026
(multi-root)
10271027
;; Initialization options or a function that returns initialization options.
10281028
(initialization-options)
1029+
;; Provides support for registering LSP Server specific capabilities.
1030+
(custom-capabilities)
10291031
;; Function which returns the folders that are considered to be not projects but library files.
10301032
;; The function accepts one parameter currently active workspace.
10311033
;; See: https://github.com/emacs-lsp/lsp-mode/issues/225.
@@ -2438,52 +2440,54 @@ disappearing, unset all the variables related to it."
24382440
(unless (lsp-workspaces)
24392441
(lsp--managed-mode -1))))
24402442

2441-
(defun lsp--client-capabilities ()
2443+
(defun lsp--client-capabilities (&optional custom-capabilities)
24422444
"Return the client capabilites."
2443-
`((workspace . ((workspaceEdit . ((documentChanges . t)
2444-
(resourceOperations . ["create" "rename" "delete"])))
2445-
(applyEdit . t)
2446-
(symbol . ((symbolKind . ((valueSet . ,(apply 'vector (number-sequence 1 26)))))))
2447-
(executeCommand . ((dynamicRegistration . :json-false)))
2448-
(didChangeWatchedFiles . ((dynamicRegistration . t)))
2449-
(workspaceFolders . t)
2450-
(configuration . t)))
2451-
(textDocument . ((declaration . ((linkSupport . t)))
2452-
(definition . ((linkSupport . t)))
2453-
(implementation . ((linkSupport . t)))
2454-
(typeDefinition . ((linkSupport . t)))
2455-
(synchronization . ((willSave . t) (didSave . t) (willSaveWaitUntil . t)))
2456-
(documentSymbol . ((symbolKind . ((valueSet . ,(apply 'vector (number-sequence 1 26)))))
2457-
(hierarchicalDocumentSymbolSupport . t)))
2458-
(formatting . ((dynamicRegistration . t)))
2459-
(rename . ((dynamicRegistration . t)))
2460-
(semanticHighlightingCapabilities . ((semanticHighlighting . ,lsp-enable-semantic-highlighting)))
2461-
(codeAction . ((dynamicRegistration . t)
2462-
(codeActionLiteralSupport . ((codeActionKind . ((valueSet . [""
2463-
"quickfix"
2464-
"refactor"
2465-
"refactor.extract"
2466-
"refactor.inline"
2467-
"refactor.rewrite"
2468-
"source"
2469-
"source.organizeImports"])))))))
2470-
(completion . ((completionItem . ((snippetSupport . ,(if lsp-enable-snippet
2471-
(or
2472-
(fboundp 'yas-expand-snippet)
2473-
(warn (concat
2474-
"Yasnippet is not required but `lsp-enable-snippet' is set to `t'. "
2475-
"You must either required yasnippet or disable snippet support."))
2476-
t)
2477-
:json-false))
2478-
(documentationFormat . ["markdown"])))
2479-
(contextSupport . t)))
2480-
(signatureHelp . ((signatureInformation . ((parameterInformation . ((labelOffsetSupport . t)))))))
2481-
(documentLink . ((dynamicRegistration . t)))
2482-
(hover . ((contentFormat . ["markdown" "plaintext"])))
2483-
(foldingRange . ,(when lsp-enable-folding
2484-
`((dynamicRegistration . t)
2485-
(rangeLimit . ,lsp-folding-range-limit)
2486-
(lineFoldingOnly . ,(or lsp-folding-line-folding-only :json-false)))))))))
2445+
(append
2446+
`((workspace . ((workspaceEdit . ((documentChanges . t)
2447+
(resourceOperations . ["create" "rename" "delete"])))
2448+
(applyEdit . t)
2449+
(symbol . ((symbolKind . ((valueSet . ,(apply 'vector (number-sequence 1 26)))))))
2450+
(executeCommand . ((dynamicRegistration . :json-false)))
2451+
(didChangeWatchedFiles . ((dynamicRegistration . t)))
2452+
(workspaceFolders . t)
2453+
(configuration . t)))
2454+
(textDocument . ((declaration . ((linkSupport . t)))
2455+
(definition . ((linkSupport . t)))
2456+
(implementation . ((linkSupport . t)))
2457+
(typeDefinition . ((linkSupport . t)))
2458+
(synchronization . ((willSave . t) (didSave . t) (willSaveWaitUntil . t)))
2459+
(documentSymbol . ((symbolKind . ((valueSet . ,(apply 'vector (number-sequence 1 26)))))
2460+
(hierarchicalDocumentSymbolSupport . t)))
2461+
(formatting . ((dynamicRegistration . t)))
2462+
(rename . ((dynamicRegistration . t)))
2463+
(semanticHighlightingCapabilities . ((semanticHighlighting . ,lsp-enable-semantic-highlighting)))
2464+
(codeAction . ((dynamicRegistration . t)
2465+
(codeActionLiteralSupport . ((codeActionKind . ((valueSet . [""
2466+
"quickfix"
2467+
"refactor"
2468+
"refactor.extract"
2469+
"refactor.inline"
2470+
"refactor.rewrite"
2471+
"source"
2472+
"source.organizeImports"])))))))
2473+
(completion . ((completionItem . ((snippetSupport . ,(if lsp-enable-snippet
2474+
(or
2475+
(fboundp 'yas-expand-snippet)
2476+
(warn (concat
2477+
"Yasnippet is not required but `lsp-enable-snippet' is set to `t'. "
2478+
"You must either required yasnippet or disable snippet support."))
2479+
t)
2480+
:json-false))
2481+
(documentationFormat . ["markdown"])))
2482+
(contextSupport . t)))
2483+
(signatureHelp . ((signatureInformation . ((parameterInformation . ((labelOffsetSupport . t)))))))
2484+
(documentLink . ((dynamicRegistration . t)))
2485+
(hover . ((contentFormat . ["markdown" "plaintext"])))
2486+
(foldingRange . ,(when lsp-enable-folding
2487+
`((dynamicRegistration . t)
2488+
(rangeLimit . ,lsp-folding-range-limit)
2489+
(lineFoldingOnly . ,(or lsp-folding-line-folding-only :json-false))))))))
2490+
custom-capabilities))
24872491

24882492
(defun lsp-find-roots-for-workspace (workspace session)
24892493
"Get all roots for the WORKSPACE."
@@ -5250,7 +5254,8 @@ SESSION is the active session."
52505254
(list :processId (emacs-pid)
52515255
:rootPath (lsp-file-local-name (expand-file-name root))
52525256
:rootUri (lsp--path-to-uri root)
5253-
:capabilities (lsp--client-capabilities)
5257+
:capabilities (lsp--client-capabilities
5258+
(lsp--client-custom-capabilities client))
52545259
:initializationOptions initialization-options)
52555260
(when lsp-server-trace
52565261
(list :trace lsp-server-trace))

0 commit comments

Comments
 (0)